rotate CallInst operands, i.e. move callee to the back

of the operand array

the motivation for this patch are laid out in my mail to llvm-commits:
more efficient access to operands and callee, faster callgraph-construction,
smaller compiler binary


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101364 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gabor Greif 2010-04-15 10:49:53 +00:00
parent e6987587d6
commit 165dac08d1
43 changed files with 578 additions and 587 deletions

View File

@ -1031,17 +1031,17 @@ public:
/// indirect function invocation.
///
Function *getCalledFunction() const {
return dyn_cast<Function>(Op<0>());
return dyn_cast<Function>(Op<-1>());
}
/// getCalledValue - Get a pointer to the function that is invoked by this
/// instruction.
const Value *getCalledValue() const { return Op<0>(); }
Value *getCalledValue() { return Op<0>(); }
const Value *getCalledValue() const { return Op<-1>(); }
Value *getCalledValue() { return Op<-1>(); }
/// setCalledFunction - Set the function called.
void setCalledFunction(Value* Fn) {
Op<0>() = Fn;
Op<-1>() = Fn;
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
@ -1071,7 +1071,7 @@ CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
->getElementType())->getReturnType(),
Instruction::Call,
OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
(unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
unsigned(ArgEnd - ArgBegin + 1), InsertAtEnd) {
init(Func, ArgBegin, ArgEnd, NameStr,
typename std::iterator_traits<InputIterator>::iterator_category());
}

View File

@ -43,7 +43,7 @@ namespace llvm {
Intrinsic::ID getIntrinsicID() const {
return (Intrinsic::ID)getCalledFunction()->getIntrinsicID();
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const IntrinsicInst *) { return true; }
static inline bool classof(const CallInst *I) {
@ -74,7 +74,7 @@ namespace llvm {
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
static Value *StripCast(Value *C);
};
@ -83,7 +83,7 @@ namespace llvm {
class DbgDeclareInst : public DbgInfoIntrinsic {
public:
Value *getAddress() const;
MDNode *getVariable() const { return cast<MDNode>(getOperand(2)); }
MDNode *getVariable() const { return cast<MDNode>(getOperand(1)); }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const DbgDeclareInst *) { return true; }
@ -103,9 +103,9 @@ namespace llvm {
Value *getValue();
uint64_t getOffset() const {
return cast<ConstantInt>(
const_cast<Value*>(getOperand(2)))->getZExtValue();
const_cast<Value*>(getOperand(1)))->getZExtValue();
}
MDNode *getVariable() const { return cast<MDNode>(getOperand(3)); }
MDNode *getVariable() const { return cast<MDNode>(getOperand(2)); }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const DbgValueInst *) { return true; }
@ -121,19 +121,19 @@ namespace llvm {
///
class MemIntrinsic : public IntrinsicInst {
public:
Value *getRawDest() const { return const_cast<Value*>(getOperand(1)); }
Value *getRawDest() const { return const_cast<Value*>(getOperand(0)); }
Value *getLength() const { return const_cast<Value*>(getOperand(3)); }
Value *getLength() const { return const_cast<Value*>(getOperand(2)); }
ConstantInt *getAlignmentCst() const {
return cast<ConstantInt>(const_cast<Value*>(getOperand(4)));
return cast<ConstantInt>(const_cast<Value*>(getOperand(3)));
}
unsigned getAlignment() const {
return getAlignmentCst()->getZExtValue();
}
ConstantInt *getVolatileCst() const {
return cast<ConstantInt>(const_cast<Value*>(getOperand(5)));
return cast<ConstantInt>(const_cast<Value*>(getOperand(4)));
}
bool isVolatile() const {
return getVolatileCst()->getZExtValue() != 0;
@ -149,27 +149,27 @@ namespace llvm {
void setDest(Value *Ptr) {
assert(getRawDest()->getType() == Ptr->getType() &&
"setDest called with pointer of wrong type!");
setOperand(1, Ptr);
setOperand(0, Ptr);
}
void setLength(Value *L) {
assert(getLength()->getType() == L->getType() &&
"setLength called with value of wrong type!");
setOperand(3, L);
setOperand(2, L);
}
void setAlignment(Constant* A) {
setOperand(4, A);
setOperand(3, A);
}
void setVolatile(Constant* V) {
setOperand(5, V);
setOperand(4, V);
}
const Type *getAlignmentType() const {
return getOperand(4)->getType();
return getOperand(3)->getType();
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MemIntrinsic *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
@ -192,14 +192,14 @@ namespace llvm {
public:
/// get* - Return the arguments to the instruction.
///
Value *getValue() const { return const_cast<Value*>(getOperand(2)); }
Value *getValue() const { return const_cast<Value*>(getOperand(1)); }
void setValue(Value *Val) {
assert(getValue()->getType() == Val->getType() &&
"setSource called with pointer of wrong type!");
setOperand(2, Val);
"setValue called with value of wrong type!");
setOperand(1, Val);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MemSetInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
@ -209,26 +209,26 @@ namespace llvm {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
/// MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
///
class MemTransferInst : public MemIntrinsic {
public:
/// get* - Return the arguments to the instruction.
///
Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); }
Value *getRawSource() const { return const_cast<Value*>(getOperand(1)); }
/// getSource - This is just like getRawSource, but it strips off any cast
/// instructions that feed it, giving the original input. The returned
/// value is guaranteed to be a pointer.
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
void setSource(Value *Ptr) {
assert(getRawSource()->getType() == Ptr->getType() &&
"setSource called with pointer of wrong type!");
setOperand(2, Ptr);
setOperand(1, Ptr);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MemTransferInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
@ -239,8 +239,8 @@ namespace llvm {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
/// MemCpyInst - This class wraps the llvm.memcpy intrinsic.
///
class MemCpyInst : public MemTransferInst {
@ -282,7 +282,7 @@ namespace llvm {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
/// MemoryUseIntrinsic - This is the common base class for the memory use
/// marker intrinsics.
///

View File

@ -255,27 +255,21 @@ public:
private:
/// Returns the operand number of the first argument
unsigned getArgumentOffset() const {
if (isCall())
return 1; // Skip Function (ATM)
else
return 0; // Args are at the front
}
unsigned getArgumentEndOffset() const {
if (isCall())
return 0; // Unchanged (ATM)
return 1; // Skip Function
else
return 3; // Skip BB, BB, Function
}
IterTy getCallee() const {
// FIXME: this is slow, since we do not have the fast versions
// of the op_*() functions here. See CallSite::getCallee.
//
if (isCall())
return getInstruction()->op_begin(); // Unchanged (ATM)
else
return getInstruction()->op_end() - 3; // Skip BB, BB, Function
// FIXME: this is slow, since we do not have the fast versions
// of the op_*() functions here. See CallSite::getCallee.
//
return arg_end();
}
};

View File

@ -94,7 +94,7 @@ static bool isObjectSmallerThan(const Value *V, unsigned Size,
} else if (const CallInst* CI = extractMallocCall(V)) {
if (!isArrayMalloc(V, &TD))
// The size is the argument to the malloc call.
if (const ConstantInt* C = dyn_cast<ConstantInt>(CI->getOperand(1)))
if (const ConstantInt* C = dyn_cast<ConstantInt>(CI->getOperand(0)))
return (C->getZExtValue() < Size);
return false;
} else if (const Argument *A = dyn_cast<Argument>(V)) {
@ -318,10 +318,10 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
case Intrinsic::memcpy:
case Intrinsic::memmove: {
unsigned Len = ~0U;
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getOperand(3)))
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getOperand(2)))
Len = LenCI->getZExtValue();
Value *Dest = II->getOperand(1);
Value *Src = II->getOperand(2);
Value *Dest = II->getOperand(0);
Value *Src = II->getOperand(1);
if (isNoAlias(Dest, Len, P, Size)) {
if (isNoAlias(Src, Len, P, Size))
return NoModRef;
@ -332,9 +332,9 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
case Intrinsic::memset:
// Since memset is 'accesses arguments' only, the AliasAnalysis base class
// will handle it for the variable length case.
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getOperand(3))) {
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getOperand(2))) {
unsigned Len = LenCI->getZExtValue();
Value *Dest = II->getOperand(1);
Value *Dest = II->getOperand(0);
if (isNoAlias(Dest, Len, P, Size))
return NoModRef;
}
@ -352,7 +352,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
case Intrinsic::atomic_load_umax:
case Intrinsic::atomic_load_umin:
if (TD) {
Value *Op1 = II->getOperand(1);
Value *Op1 = II->getOperand(0);
unsigned Op1Size = TD->getTypeStoreSize(Op1->getType());
if (isNoAlias(Op1, Op1Size, P, Size))
return NoModRef;
@ -361,14 +361,14 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
case Intrinsic::invariant_start: {
unsigned PtrSize = cast<ConstantInt>(II->getOperand(1))->getZExtValue();
if (isNoAlias(II->getOperand(2), PtrSize, P, Size))
unsigned PtrSize = cast<ConstantInt>(II->getOperand(0))->getZExtValue();
if (isNoAlias(II->getOperand(1), PtrSize, P, Size))
return NoModRef;
break;
}
case Intrinsic::invariant_end: {
unsigned PtrSize = cast<ConstantInt>(II->getOperand(2))->getZExtValue();
if (isNoAlias(II->getOperand(3), PtrSize, P, Size))
unsigned PtrSize = cast<ConstantInt>(II->getOperand(1))->getZExtValue();
if (isNoAlias(II->getOperand(2), PtrSize, P, Size))
return NoModRef;
break;
}

View File

@ -772,9 +772,9 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
case Instruction::ICmp:
case Instruction::FCmp: assert(0 && "Invalid for compares");
case Instruction::Call:
if (Function *F = dyn_cast<Function>(Ops[0]))
if (Function *F = dyn_cast<Function>(Ops[NumOps - 1]))
if (canConstantFoldCallTo(F))
return ConstantFoldCall(F, Ops+1, NumOps-1);
return ConstantFoldCall(F, Ops, NumOps - 1);
return 0;
case Instruction::PtrToInt:
// If the input is a inttoptr, eliminate the pair. This requires knowing

View File

@ -252,7 +252,7 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V,
} else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
// Make sure that this is just the function being called, not that it is
// passing into the function.
for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
for (unsigned i = 0, e = CI->getNumOperands() - 1; i != e; ++i)
if (CI->getOperand(i) == V) return true;
} else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) {
// Make sure that this is just the function being called, not that it is

View File

@ -103,7 +103,7 @@ static Value *computeArraySize(const CallInst *CI, const TargetData *TD,
// If malloc calls' arg can be determined to be a multiple of ElementSize,
// return the multiple. Otherwise, return NULL.
Value *MallocArg = CI->getOperand(1);
Value *MallocArg = CI->getOperand(0);
Value *Multiple = NULL;
if (ComputeMultiple(MallocArg, ElementSize, Multiple,
LookThroughSExt))
@ -120,7 +120,7 @@ const CallInst *llvm::isArrayMalloc(const Value *I, const TargetData *TD) {
Value *ArraySize = computeArraySize(CI, TD);
if (ArraySize &&
ArraySize != ConstantInt::get(CI->getOperand(1)->getType(), 1))
ArraySize != ConstantInt::get(CI->getOperand(0)->getType(), 1))
return CI;
// CI is a non-array malloc or we can't figure out that it is an array malloc.

View File

@ -117,7 +117,7 @@ getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall,
Pointer = V->getOperand(0);
PointerSize = AA->getTypeStoreSize(V->getType());
} else if (isFreeCall(Inst)) {
Pointer = Inst->getOperand(1);
Pointer = Inst->getOperand(0);
// calls to free() erase the entire structure
PointerSize = ~0ULL;
} else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) {
@ -197,9 +197,9 @@ getPointerDependencyFrom(Value *MemPtr, uint64_t MemSize, bool isLoad,
// pointer, not on query pointers that are indexed off of them. It'd
// be nice to handle that at some point.
AliasAnalysis::AliasResult R =
AA->alias(II->getOperand(3), ~0U, MemPtr, ~0U);
AA->alias(II->getOperand(2), ~0U, MemPtr, ~0U);
if (R == AliasAnalysis::MustAlias) {
InvariantTag = II->getOperand(1);
InvariantTag = II->getOperand(0);
continue;
}
@ -210,7 +210,7 @@ getPointerDependencyFrom(Value *MemPtr, uint64_t MemSize, bool isLoad,
// pointer, not on query pointers that are indexed off of them. It'd
// be nice to handle that at some point.
AliasAnalysis::AliasResult R =
AA->alias(II->getOperand(2), ~0U, MemPtr, ~0U);
AA->alias(II->getOperand(1), ~0U, MemPtr, ~0U);
if (R == AliasAnalysis::MustAlias)
return MemDepResult::getDef(II);
}
@ -366,7 +366,7 @@ MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
MemSize = AA->getTypeStoreSize(LI->getType());
}
} else if (isFreeCall(QueryInst)) {
MemPtr = QueryInst->getOperand(1);
MemPtr = QueryInst->getOperand(0);
// calls to free() erase the entire structure, not just a field.
MemSize = ~0UL;
} else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
@ -378,12 +378,12 @@ MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
case Intrinsic::invariant_start:
MemPtr = QueryInst->getOperand(2);
MemSize = cast<ConstantInt>(QueryInst->getOperand(1))->getZExtValue();
MemPtr = QueryInst->getOperand(1);
MemSize = cast<ConstantInt>(QueryInst->getOperand(0))->getZExtValue();
break;
case Intrinsic::invariant_end:
MemPtr = QueryInst->getOperand(3);
MemSize = cast<ConstantInt>(QueryInst->getOperand(2))->getZExtValue();
MemPtr = QueryInst->getOperand(2);
MemSize = cast<ConstantInt>(QueryInst->getOperand(1))->getZExtValue();
break;
default:
CallSite QueryCS = CallSite::get(QueryInst);

View File

@ -953,7 +953,7 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
// sqrt(-0.0) = -0.0, no other negative results are possible.
if (II->getIntrinsicID() == Intrinsic::sqrt)
return CannotBeNegativeZero(II->getOperand(1), Depth+1);
return CannotBeNegativeZero(II->getOperand(0), Depth+1);
if (const CallInst *CI = dyn_cast<CallInst>(I))
if (const Function *F = CI->getCalledFunction()) {
@ -966,7 +966,7 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
if (F->getName() == "fabsl") return true;
if (F->getName() == "sqrt" || F->getName() == "sqrtf" ||
F->getName() == "sqrtl")
return CannotBeNegativeZero(CI->getOperand(1), Depth+1);
return CannotBeNegativeZero(CI->getOperand(0), Depth+1);
}
}

View File

@ -1134,24 +1134,23 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
Vals.push_back(cast<StoreInst>(I).isVolatile());
break;
case Instruction::Call: {
const PointerType *PTy = cast<PointerType>(I.getOperand(0)->getType());
const CallInst &CI = cast<CallInst>(I);
const PointerType *PTy = cast<PointerType>(CI.getCalledValue()->getType());
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
Code = bitc::FUNC_CODE_INST_CALL;
const CallInst *CI = cast<CallInst>(&I);
Vals.push_back(VE.getAttributeID(CI->getAttributes()));
Vals.push_back((CI->getCallingConv() << 1) | unsigned(CI->isTailCall()));
PushValueAndType(CI->getOperand(0), InstID, Vals, VE); // Callee
Vals.push_back(VE.getAttributeID(CI.getAttributes()));
Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()));
PushValueAndType(CI.getCalledValue(), InstID, Vals, VE); // Callee
// Emit value #'s for the fixed parameters.
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
Vals.push_back(VE.getValueID(I.getOperand(i+1))); // fixed param.
Vals.push_back(VE.getValueID(I.getOperand(i))); // fixed param.
// Emit type/value pairs for varargs params.
if (FTy->isVarArg()) {
unsigned NumVarargs = I.getNumOperands()-1-FTy->getNumParams();
for (unsigned i = I.getNumOperands()-NumVarargs, e = I.getNumOperands();
for (unsigned i = FTy->getNumParams(), e = I.getNumOperands()-1;
i != e; ++i)
PushValueAndType(I.getOperand(i), InstID, Vals, VE); // varargs
}

View File

@ -198,7 +198,7 @@ FindAllCleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels) {
bool IsCleanUp = (NumOps == 3);
if (!IsCleanUp)
if (ConstantInt *CI = dyn_cast<ConstantInt>(SI->getOperand(3)))
if (ConstantInt *CI = dyn_cast<ConstantInt>(SI->getOperand(2)))
IsCleanUp = (CI->getZExtValue() == 0);
if (IsCleanUp)
@ -237,7 +237,7 @@ bool DwarfEHPrepare::CleanupSelectors() {
if (!Sel || Sel->getParent()->getParent() != F) continue;
// Index of the ".llvm.eh.catch.all.value" variable.
unsigned OpIdx = Sel->getNumOperands() - 1;
unsigned OpIdx = Sel->getNumOperands() - 2;
GlobalVariable *GV = dyn_cast<GlobalVariable>(Sel->getOperand(OpIdx));
if (GV != EHCatchAllValue) continue;
Sel->setOperand(OpIdx, EHCatchAllValue->getInitializer());
@ -366,7 +366,7 @@ bool DwarfEHPrepare::HandleURoRInvokes() {
bool IsCleanUp = (NumOps == 3);
if (!IsCleanUp)
if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getOperand(3)))
if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getOperand(2)))
IsCleanUp = (CI->getZExtValue() == 0);
if (IsCleanUp)
@ -390,8 +390,8 @@ bool DwarfEHPrepare::HandleURoRInvokes() {
// Use the exception object pointer and the personality function
// from the original selector.
Args.push_back(II->getOperand(1)); // Exception object pointer.
Args.push_back(II->getOperand(2)); // Personality function.
Args.push_back(II->getOperand(0)); // Exception object pointer.
Args.push_back(II->getOperand(1)); // Personality function.
Args.push_back(EHCatchAllValue->getInitializer()); // Catch-all indicator.
CallInst *NewSelector =

View File

@ -270,7 +270,7 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
case Intrinsic::gcwrite:
if (LowerWr) {
// Replace a write barrier with a simple store.
Value *St = new StoreInst(CI->getOperand(1), CI->getOperand(3), CI);
Value *St = new StoreInst(CI->getOperand(0), CI->getOperand(2), CI);
CI->replaceAllUsesWith(St);
CI->eraseFromParent();
}
@ -278,7 +278,7 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
case Intrinsic::gcread:
if (LowerRd) {
// Replace a read barrier with a simple load.
Value *Ld = new LoadInst(CI->getOperand(2), "", CI);
Value *Ld = new LoadInst(CI->getOperand(1), "", CI);
Ld->takeName(CI);
CI->replaceAllUsesWith(Ld);
CI->eraseFromParent();
@ -289,7 +289,7 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
// Initialize the GC root, but do not delete the intrinsic. The
// backend needs the intrinsic to flag the stack slot.
Roots.push_back(cast<AllocaInst>(
CI->getOperand(1)->stripPointerCasts()));
CI->getOperand(0)->stripPointerCasts()));
}
break;
default:

View File

@ -308,21 +308,21 @@ static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) {
static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname,
const char *Dname,
const char *LDname) {
switch (CI->getOperand(1)->getType()->getTypeID()) {
switch (CI->getOperand(0)->getType()->getTypeID()) {
default: llvm_unreachable("Invalid type in intrinsic");
case Type::FloatTyID:
ReplaceCallWith(Fname, CI, CI->op_begin() + 1, CI->op_end(),
ReplaceCallWith(Fname, CI, CI->op_begin(), CI->op_end() - 1,
Type::getFloatTy(CI->getContext()));
break;
case Type::DoubleTyID:
ReplaceCallWith(Dname, CI, CI->op_begin() + 1, CI->op_end(),
ReplaceCallWith(Dname, CI, CI->op_begin(), CI->op_end() - 1,
Type::getDoubleTy(CI->getContext()));
break;
case Type::X86_FP80TyID:
case Type::FP128TyID:
case Type::PPC_FP128TyID:
ReplaceCallWith(LDname, CI, CI->op_begin() + 1, CI->op_end(),
CI->getOperand(1)->getType());
ReplaceCallWith(LDname, CI, CI->op_begin(), CI->op_end() - 1,
CI->getOperand(0)->getType());
break;
}
}
@ -347,7 +347,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
// by the lowerinvoke pass. In both cases, the right thing to do is to
// convert the call to an explicit setjmp or longjmp call.
case Intrinsic::setjmp: {
Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin() + 1, CI->op_end(),
Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin(), CI->op_end() - 1,
Type::getInt32Ty(Context));
if (!CI->getType()->isVoidTy())
CI->replaceAllUsesWith(V);
@ -359,7 +359,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
break;
case Intrinsic::longjmp: {
ReplaceCallWith("longjmp", CI, CI->op_begin() + 1, CI->op_end(),
ReplaceCallWith("longjmp", CI, CI->op_begin(), CI->op_end() - 1,
Type::getVoidTy(Context));
break;
}
@ -371,20 +371,20 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
break;
}
case Intrinsic::ctpop:
CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getOperand(1), CI));
CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getOperand(0), CI));
break;
case Intrinsic::bswap:
CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getOperand(1), CI));
CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getOperand(0), CI));
break;
case Intrinsic::ctlz:
CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getOperand(1), CI));
CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getOperand(0), CI));
break;
case Intrinsic::cttz: {
// cttz(x) -> ctpop(~X & (X-1))
Value *Src = CI->getOperand(1);
Value *Src = CI->getOperand(0);
Value *NotSrc = Builder.CreateNot(Src);
NotSrc->setName(Src->getName() + ".not");
Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
@ -445,37 +445,37 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::memcpy: {
const IntegerType *IntPtr = TD.getIntPtrType(Context);
Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr,
Value *Size = Builder.CreateIntCast(CI->getOperand(2), IntPtr,
/* isSigned */ false);
Value *Ops[3];
Ops[0] = CI->getOperand(1);
Ops[1] = CI->getOperand(2);
Ops[0] = CI->getOperand(0);
Ops[1] = CI->getOperand(1);
Ops[2] = Size;
ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getOperand(1)->getType());
ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getOperand(0)->getType());
break;
}
case Intrinsic::memmove: {
const IntegerType *IntPtr = TD.getIntPtrType(Context);
Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr,
Value *Size = Builder.CreateIntCast(CI->getOperand(2), IntPtr,
/* isSigned */ false);
Value *Ops[3];
Ops[0] = CI->getOperand(1);
Ops[1] = CI->getOperand(2);
Ops[0] = CI->getOperand(0);
Ops[1] = CI->getOperand(1);
Ops[2] = Size;
ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getOperand(1)->getType());
ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getOperand(0)->getType());
break;
}
case Intrinsic::memset: {
const IntegerType *IntPtr = TD.getIntPtrType(Context);
Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr,
Value *Size = Builder.CreateIntCast(CI->getOperand(2), IntPtr,
/* isSigned */ false);
Value *Ops[3];
Ops[0] = CI->getOperand(1);
Ops[0] = CI->getOperand(0);
// Extend the amount to i32.
Ops[1] = Builder.CreateIntCast(CI->getOperand(2), Type::getInt32Ty(Context),
Ops[1] = Builder.CreateIntCast(CI->getOperand(1), Type::getInt32Ty(Context),
/* isSigned */ false);
Ops[2] = Size;
ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(1)->getType());
ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(0)->getType());
break;
}
case Intrinsic::sqrt: {

View File

@ -31,7 +31,6 @@
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetIntrinsicInfo.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Support/Compiler.h"
@ -310,7 +309,7 @@ GlobalVariable *llvm::ExtractTypeInfo(Value *V) {
void llvm::AddCatchInfo(const CallInst &I, MachineModuleInfo *MMI,
MachineBasicBlock *MBB) {
// Inform the MachineModuleInfo of the personality for this landing pad.
const ConstantExpr *CE = cast<ConstantExpr>(I.getOperand(2));
const ConstantExpr *CE = cast<ConstantExpr>(I.getOperand(1));
assert(CE->getOpcode() == Instruction::BitCast &&
isa<Function>(CE->getOperand(0)) &&
"Personality should be a function");
@ -319,9 +318,9 @@ void llvm::AddCatchInfo(const CallInst &I, MachineModuleInfo *MMI,
// Gather all the type infos for this landing pad and pass them along to
// MachineModuleInfo.
std::vector<const GlobalVariable *> TyInfo;
unsigned N = I.getNumOperands();
unsigned N = I.getNumOperands() - 1;
for (unsigned i = N - 1; i > 2; --i) {
for (unsigned i = N - 1; i > 1; --i) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(i))) {
unsigned FilterLength = CI->getZExtValue();
unsigned FirstCatch = i + FilterLength + !FilterLength;
@ -351,9 +350,9 @@ void llvm::AddCatchInfo(const CallInst &I, MachineModuleInfo *MMI,
}
}
if (N > 3) {
TyInfo.reserve(N - 3);
for (unsigned j = 3; j < N; ++j)
if (N > 2) {
TyInfo.reserve(N - 2);
for (unsigned j = 2; j < N - 1; ++j)
TyInfo.push_back(ExtractTypeInfo(I.getOperand(j)));
MMI->addCatchTypeInfo(MBB, TyInfo);
}

View File

@ -2771,7 +2771,7 @@ void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,
Ops.push_back(DAG.getConstant(Intrinsic, TLI.getPointerTy()));
// Add all operands of the call to the operand list.
for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
for (unsigned i = 0, e = I.getNumOperands()-1; i != e; ++i) {
SDValue Op = getValue(I.getOperand(i));
assert(TLI.isTypeLegal(Op.getValueType()) &&
"Intrinsic uses a non-legal type?");
@ -2877,11 +2877,11 @@ SelectionDAGBuilder::implVisitBinaryAtomic(const CallInst& I,
SDValue Root = getRoot();
SDValue L =
DAG.getAtomic(Op, getCurDebugLoc(),
getValue(I.getOperand(2)).getValueType().getSimpleVT(),
getValue(I.getOperand(1)).getValueType().getSimpleVT(),
Root,
getValue(I.getOperand(0)),
getValue(I.getOperand(1)),
getValue(I.getOperand(2)),
I.getOperand(1));
I.getOperand(0));
setValue(&I, L);
DAG.setRoot(L.getValue(1));
return 0;
@ -2890,8 +2890,8 @@ SelectionDAGBuilder::implVisitBinaryAtomic(const CallInst& I,
// implVisitAluOverflow - Lower arithmetic overflow instrinsics.
const char *
SelectionDAGBuilder::implVisitAluOverflow(const CallInst &I, ISD::NodeType Op) {
SDValue Op1 = getValue(I.getOperand(1));
SDValue Op2 = getValue(I.getOperand(2));
SDValue Op1 = getValue(I.getOperand(0));
SDValue Op2 = getValue(I.getOperand(1));
SDVTList VTs = DAG.getVTList(Op1.getValueType(), MVT::i1);
setValue(&I, DAG.getNode(Op, getCurDebugLoc(), VTs, Op1, Op2));
@ -2905,9 +2905,9 @@ SelectionDAGBuilder::visitExp(const CallInst &I) {
SDValue result;
DebugLoc dl = getCurDebugLoc();
if (getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
if (getValue(I.getOperand(0)).getValueType() == MVT::f32 &&
LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
SDValue Op = getValue(I.getOperand(1));
SDValue Op = getValue(I.getOperand(0));
// Put the exponent in the right bit position for later addition to the
// final result:
@ -3017,8 +3017,8 @@ SelectionDAGBuilder::visitExp(const CallInst &I) {
} else {
// No special expansion.
result = DAG.getNode(ISD::FEXP, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0)));
}
setValue(&I, result);
@ -3031,9 +3031,9 @@ SelectionDAGBuilder::visitLog(const CallInst &I) {
SDValue result;
DebugLoc dl = getCurDebugLoc();
if (getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
if (getValue(I.getOperand(0)).getValueType() == MVT::f32 &&
LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
SDValue Op = getValue(I.getOperand(1));
SDValue Op = getValue(I.getOperand(0));
SDValue Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op);
// Scale the exponent by log(2) [0.69314718f].
@ -3127,8 +3127,8 @@ SelectionDAGBuilder::visitLog(const CallInst &I) {
} else {
// No special expansion.
result = DAG.getNode(ISD::FLOG, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0)));
}
setValue(&I, result);
@ -3141,9 +3141,9 @@ SelectionDAGBuilder::visitLog2(const CallInst &I) {
SDValue result;
DebugLoc dl = getCurDebugLoc();
if (getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
if (getValue(I.getOperand(0)).getValueType() == MVT::f32 &&
LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
SDValue Op = getValue(I.getOperand(1));
SDValue Op = getValue(I.getOperand(0));
SDValue Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op);
// Get the exponent.
@ -3236,8 +3236,8 @@ SelectionDAGBuilder::visitLog2(const CallInst &I) {
} else {
// No special expansion.
result = DAG.getNode(ISD::FLOG2, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0)));
}
setValue(&I, result);
@ -3250,9 +3250,9 @@ SelectionDAGBuilder::visitLog10(const CallInst &I) {
SDValue result;
DebugLoc dl = getCurDebugLoc();
if (getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
if (getValue(I.getOperand(0)).getValueType() == MVT::f32 &&
LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
SDValue Op = getValue(I.getOperand(1));
SDValue Op = getValue(I.getOperand(0));
SDValue Op1 = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Op);
// Scale the exponent by log10(2) [0.30102999f].
@ -3338,8 +3338,8 @@ SelectionDAGBuilder::visitLog10(const CallInst &I) {
} else {
// No special expansion.
result = DAG.getNode(ISD::FLOG10, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0)));
}
setValue(&I, result);
@ -3352,9 +3352,9 @@ SelectionDAGBuilder::visitExp2(const CallInst &I) {
SDValue result;
DebugLoc dl = getCurDebugLoc();
if (getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
if (getValue(I.getOperand(0)).getValueType() == MVT::f32 &&
LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
SDValue Op = getValue(I.getOperand(1));
SDValue Op = getValue(I.getOperand(0));
SDValue IntegerPartOfX = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32, Op);
@ -3452,8 +3452,8 @@ SelectionDAGBuilder::visitExp2(const CallInst &I) {
} else {
// No special expansion.
result = DAG.getNode(ISD::FEXP2, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0)));
}
setValue(&I, result);
@ -3464,12 +3464,12 @@ SelectionDAGBuilder::visitExp2(const CallInst &I) {
void
SelectionDAGBuilder::visitPow(const CallInst &I) {
SDValue result;
const Value *Val = I.getOperand(1);
const Value *Val = I.getOperand(0);
DebugLoc dl = getCurDebugLoc();
bool IsExp10 = false;
if (getValue(Val).getValueType() == MVT::f32 &&
getValue(I.getOperand(2)).getValueType() == MVT::f32 &&
getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
if (Constant *C = const_cast<Constant*>(dyn_cast<Constant>(Val))) {
if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
@ -3480,7 +3480,7 @@ SelectionDAGBuilder::visitPow(const CallInst &I) {
}
if (IsExp10 && LimitFloatPrecision > 0 && LimitFloatPrecision <= 18) {
SDValue Op = getValue(I.getOperand(2));
SDValue Op = getValue(I.getOperand(1));
// Put the exponent in the right bit position for later addition to the
// final result:
@ -3585,9 +3585,9 @@ SelectionDAGBuilder::visitPow(const CallInst &I) {
} else {
// No special expansion.
result = DAG.getNode(ISD::FPOW, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)),
getValue(I.getOperand(2)));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0)),
getValue(I.getOperand(1)));
}
setValue(&I, result);
@ -3665,11 +3665,11 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
case Intrinsic::vacopy: visitVACopy(I); return 0;
case Intrinsic::returnaddress:
setValue(&I, DAG.getNode(ISD::RETURNADDR, dl, TLI.getPointerTy(),
getValue(I.getOperand(1))));
getValue(I.getOperand(0))));
return 0;
case Intrinsic::frameaddress:
setValue(&I, DAG.getNode(ISD::FRAMEADDR, dl, TLI.getPointerTy(),
getValue(I.getOperand(1))));
getValue(I.getOperand(0))));
return 0;
case Intrinsic::setjmp:
return "_setjmp"+!TLI.usesUnderscoreSetJmp();
@ -3678,63 +3678,63 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
case Intrinsic::memcpy: {
// Assert for address < 256 since we support only user defined address
// spaces.
assert(cast<PointerType>(I.getOperand(1)->getType())->getAddressSpace()
assert(cast<PointerType>(I.getOperand(0)->getType())->getAddressSpace()
< 256 &&
cast<PointerType>(I.getOperand(2)->getType())->getAddressSpace()
cast<PointerType>(I.getOperand(1)->getType())->getAddressSpace()
< 256 &&
"Unknown address space");
SDValue Op1 = getValue(I.getOperand(1));
SDValue Op2 = getValue(I.getOperand(2));
SDValue Op3 = getValue(I.getOperand(3));
unsigned Align = cast<ConstantInt>(I.getOperand(4))->getZExtValue();
bool isVol = cast<ConstantInt>(I.getOperand(5))->getZExtValue();
SDValue Op1 = getValue(I.getOperand(0));
SDValue Op2 = getValue(I.getOperand(1));
SDValue Op3 = getValue(I.getOperand(2));
unsigned Align = cast<ConstantInt>(I.getOperand(3))->getZExtValue();
bool isVol = cast<ConstantInt>(I.getOperand(4))->getZExtValue();
DAG.setRoot(DAG.getMemcpy(getRoot(), dl, Op1, Op2, Op3, Align, isVol, false,
I.getOperand(1), 0, I.getOperand(2), 0));
I.getOperand(0), 0, I.getOperand(1), 0));
return 0;
}
case Intrinsic::memset: {
// Assert for address < 256 since we support only user defined address
// spaces.
assert(cast<PointerType>(I.getOperand(1)->getType())->getAddressSpace()
assert(cast<PointerType>(I.getOperand(0)->getType())->getAddressSpace()
< 256 &&
"Unknown address space");
SDValue Op1 = getValue(I.getOperand(1));
SDValue Op2 = getValue(I.getOperand(2));
SDValue Op3 = getValue(I.getOperand(3));
unsigned Align = cast<ConstantInt>(I.getOperand(4))->getZExtValue();
bool isVol = cast<ConstantInt>(I.getOperand(5))->getZExtValue();
SDValue Op1 = getValue(I.getOperand(0));
SDValue Op2 = getValue(I.getOperand(1));
SDValue Op3 = getValue(I.getOperand(2));
unsigned Align = cast<ConstantInt>(I.getOperand(3))->getZExtValue();
bool isVol = cast<ConstantInt>(I.getOperand(4))->getZExtValue();
DAG.setRoot(DAG.getMemset(getRoot(), dl, Op1, Op2, Op3, Align, isVol,
I.getOperand(1), 0));
I.getOperand(0), 0));
return 0;
}
case Intrinsic::memmove: {
// Assert for address < 256 since we support only user defined address
// spaces.
assert(cast<PointerType>(I.getOperand(1)->getType())->getAddressSpace()
assert(cast<PointerType>(I.getOperand(0)->getType())->getAddressSpace()
< 256 &&
cast<PointerType>(I.getOperand(2)->getType())->getAddressSpace()
cast<PointerType>(I.getOperand(1)->getType())->getAddressSpace()
< 256 &&
"Unknown address space");
SDValue Op1 = getValue(I.getOperand(1));
SDValue Op2 = getValue(I.getOperand(2));
SDValue Op3 = getValue(I.getOperand(3));
unsigned Align = cast<ConstantInt>(I.getOperand(4))->getZExtValue();
bool isVol = cast<ConstantInt>(I.getOperand(5))->getZExtValue();
SDValue Op1 = getValue(I.getOperand(0));
SDValue Op2 = getValue(I.getOperand(1));
SDValue Op3 = getValue(I.getOperand(2));
unsigned Align = cast<ConstantInt>(I.getOperand(3))->getZExtValue();
bool isVol = cast<ConstantInt>(I.getOperand(4))->getZExtValue();
// If the source and destination are known to not be aliases, we can
// lower memmove as memcpy.
uint64_t Size = -1ULL;
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op3))
Size = C->getZExtValue();
if (AA->alias(I.getOperand(1), Size, I.getOperand(2), Size) ==
if (AA->alias(I.getOperand(0), Size, I.getOperand(1), Size) ==
AliasAnalysis::NoAlias) {
DAG.setRoot(DAG.getMemcpy(getRoot(), dl, Op1, Op2, Op3, Align, isVol,
false, I.getOperand(1), 0, I.getOperand(2), 0));
false, I.getOperand(0), 0, I.getOperand(1), 0));
return 0;
}
DAG.setRoot(DAG.getMemmove(getRoot(), dl, Op1, Op2, Op3, Align, isVol,
I.getOperand(1), 0, I.getOperand(2), 0));
I.getOperand(0), 0, I.getOperand(1), 0));
return 0;
}
case Intrinsic::dbg_declare: {
@ -3846,7 +3846,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
// Insert the EHSELECTION instruction.
SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
SDValue Ops[2];
Ops[0] = getValue(I.getOperand(1));
Ops[0] = getValue(I.getOperand(0));
Ops[1] = getRoot();
SDValue Op = DAG.getNode(ISD::EHSELECTION, dl, VTs, Ops, 2);
DAG.setRoot(Op.getValue(1));
@ -3856,7 +3856,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
case Intrinsic::eh_typeid_for: {
// Find the type id for the given typeinfo.
GlobalVariable *GV = ExtractTypeInfo(I.getOperand(1));
GlobalVariable *GV = ExtractTypeInfo(I.getOperand(0));
unsigned TypeID = DAG.getMachineFunction().getMMI().getTypeIDFor(GV);
Res = DAG.getConstant(TypeID, MVT::i32);
setValue(&I, Res);
@ -3869,15 +3869,15 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
DAG.setRoot(DAG.getNode(ISD::EH_RETURN, dl,
MVT::Other,
getControlRoot(),
getValue(I.getOperand(1)),
getValue(I.getOperand(2))));
getValue(I.getOperand(0)),
getValue(I.getOperand(1))));
return 0;
case Intrinsic::eh_unwind_init:
DAG.getMachineFunction().getMMI().setCallsUnwindInit(true);
return 0;
case Intrinsic::eh_dwarf_cfa: {
EVT VT = getValue(I.getOperand(1)).getValueType();
SDValue CfaArg = DAG.getSExtOrTrunc(getValue(I.getOperand(1)), dl,
EVT VT = getValue(I.getOperand(0)).getValueType();
SDValue CfaArg = DAG.getSExtOrTrunc(getValue(I.getOperand(0)), dl,
TLI.getPointerTy());
SDValue Offset = DAG.getNode(ISD::ADD, dl,
TLI.getPointerTy(),
@ -3893,7 +3893,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
}
case Intrinsic::eh_sjlj_callsite: {
MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(1));
ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(0));
assert(CI && "Non-constant call site value in eh.sjlj.callsite!");
assert(MMI.getCurrentCallSite() == 0 && "Overlapping call sites!");
@ -3923,34 +3923,34 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
case Intrinsic::convertuu: Code = ISD::CVT_UU; break;
}
EVT DestVT = TLI.getValueType(I.getType());
const Value *Op1 = I.getOperand(1);
const Value *Op1 = I.getOperand(0);
Res = DAG.getConvertRndSat(DestVT, getCurDebugLoc(), getValue(Op1),
DAG.getValueType(DestVT),
DAG.getValueType(getValue(Op1).getValueType()),
getValue(I.getOperand(1)),
getValue(I.getOperand(2)),
getValue(I.getOperand(3)),
Code);
setValue(&I, Res);
return 0;
}
case Intrinsic::sqrt:
setValue(&I, DAG.getNode(ISD::FSQRT, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1))));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0))));
return 0;
case Intrinsic::powi:
setValue(&I, ExpandPowI(dl, getValue(I.getOperand(1)),
getValue(I.getOperand(2)), DAG));
setValue(&I, ExpandPowI(dl, getValue(I.getOperand(0)),
getValue(I.getOperand(1)), DAG));
return 0;
case Intrinsic::sin:
setValue(&I, DAG.getNode(ISD::FSIN, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1))));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0))));
return 0;
case Intrinsic::cos:
setValue(&I, DAG.getNode(ISD::FCOS, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1))));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0))));
return 0;
case Intrinsic::log:
visitLog(I);
@ -3972,14 +3972,14 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
return 0;
case Intrinsic::convert_to_fp16:
setValue(&I, DAG.getNode(ISD::FP32_TO_FP16, dl,
MVT::i16, getValue(I.getOperand(1))));
MVT::i16, getValue(I.getOperand(0))));
return 0;
case Intrinsic::convert_from_fp16:
setValue(&I, DAG.getNode(ISD::FP16_TO_FP32, dl,
MVT::f32, getValue(I.getOperand(1))));
MVT::f32, getValue(I.getOperand(0))));
return 0;
case Intrinsic::pcmarker: {
SDValue Tmp = getValue(I.getOperand(1));
SDValue Tmp = getValue(I.getOperand(0));
DAG.setRoot(DAG.getNode(ISD::PCMARKER, dl, MVT::Other, getRoot(), Tmp));
return 0;
}
@ -3994,23 +3994,23 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
}
case Intrinsic::bswap:
setValue(&I, DAG.getNode(ISD::BSWAP, dl,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1))));
getValue(I.getOperand(0)).getValueType(),
getValue(I.getOperand(0))));
return 0;
case Intrinsic::cttz: {
SDValue Arg = getValue(I.getOperand(1));
SDValue Arg = getValue(I.getOperand(0));
EVT Ty = Arg.getValueType();
setValue(&I, DAG.getNode(ISD::CTTZ, dl, Ty, Arg));
return 0;
}
case Intrinsic::ctlz: {
SDValue Arg = getValue(I.getOperand(1));
SDValue Arg = getValue(I.getOperand(0));
EVT Ty = Arg.getValueType();
setValue(&I, DAG.getNode(ISD::CTLZ, dl, Ty, Arg));
return 0;
}
case Intrinsic::ctpop: {
SDValue Arg = getValue(I.getOperand(1));
SDValue Arg = getValue(I.getOperand(0));
EVT Ty = Arg.getValueType();
setValue(&I, DAG.getNode(ISD::CTPOP, dl, Ty, Arg));
return 0;
@ -4024,7 +4024,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
return 0;
}
case Intrinsic::stackrestore: {
Res = getValue(I.getOperand(1));
Res = getValue(I.getOperand(0));
DAG.setRoot(DAG.getNode(ISD::STACKRESTORE, dl, MVT::Other, getRoot(), Res));
return 0;
}
@ -4034,8 +4034,8 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
MachineFrameInfo *MFI = MF.getFrameInfo();
EVT PtrTy = TLI.getPointerTy();
SDValue Src = getValue(I.getOperand(1)); // The guard's value.
AllocaInst *Slot = cast<AllocaInst>(I.getOperand(2));
SDValue Src = getValue(I.getOperand(0)); // The guard's value.
AllocaInst *Slot = cast<AllocaInst>(I.getOperand(1));
int FI = FuncInfo.StaticAllocaMap[Slot];
MFI->setStackProtectorIndex(FI);
@ -4072,14 +4072,14 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
return 0;
case Intrinsic::init_trampoline: {
const Function *F = cast<Function>(I.getOperand(2)->stripPointerCasts());
const Function *F = cast<Function>(I.getOperand(1)->stripPointerCasts());
SDValue Ops[6];
Ops[0] = getRoot();
Ops[1] = getValue(I.getOperand(1));
Ops[2] = getValue(I.getOperand(2));
Ops[3] = getValue(I.getOperand(3));
Ops[4] = DAG.getSrcValue(I.getOperand(1));
Ops[1] = getValue(I.getOperand(0));
Ops[2] = getValue(I.getOperand(1));
Ops[3] = getValue(I.getOperand(2));
Ops[4] = DAG.getSrcValue(I.getOperand(0));
Ops[5] = DAG.getSrcValue(F);
Res = DAG.getNode(ISD::TRAMPOLINE, dl,
@ -4092,8 +4092,8 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
}
case Intrinsic::gcroot:
if (GFI) {
const Value *Alloca = I.getOperand(1);
const Constant *TypeMap = cast<Constant>(I.getOperand(2));
const Value *Alloca = I.getOperand(0);
const Constant *TypeMap = cast<Constant>(I.getOperand(1));
FrameIndexSDNode *FI = cast<FrameIndexSDNode>(getValue(Alloca).getNode());
GFI->addStackRoot(FI->getIndex(), TypeMap);
@ -4125,9 +4125,9 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
case Intrinsic::prefetch: {
SDValue Ops[4];
Ops[0] = getRoot();
Ops[1] = getValue(I.getOperand(1));
Ops[2] = getValue(I.getOperand(2));
Ops[3] = getValue(I.getOperand(3));
Ops[1] = getValue(I.getOperand(0));
Ops[2] = getValue(I.getOperand(1));
Ops[3] = getValue(I.getOperand(2));
DAG.setRoot(DAG.getNode(ISD::PREFETCH, dl, MVT::Other, &Ops[0], 4));
return 0;
}
@ -4136,7 +4136,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
SDValue Ops[6];
Ops[0] = getRoot();
for (int x = 1; x < 6; ++x)
Ops[x] = getValue(I.getOperand(x));
Ops[x] = getValue(I.getOperand(x - 1));
DAG.setRoot(DAG.getNode(ISD::MEMBARRIER, dl, MVT::Other, &Ops[0], 6));
return 0;
@ -4145,12 +4145,12 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
SDValue Root = getRoot();
SDValue L =
DAG.getAtomic(ISD::ATOMIC_CMP_SWAP, getCurDebugLoc(),
getValue(I.getOperand(2)).getValueType().getSimpleVT(),
getValue(I.getOperand(1)).getValueType().getSimpleVT(),
Root,
getValue(I.getOperand(0)),
getValue(I.getOperand(1)),
getValue(I.getOperand(2)),
getValue(I.getOperand(3)),
I.getOperand(1));
I.getOperand(0));
setValue(&I, L);
DAG.setRoot(L.getValue(1));
return 0;
@ -4520,13 +4520,13 @@ bool SelectionDAGBuilder::visitMemCmpCall(const CallInst &I) {
if (I.getNumOperands() != 4)
return false;
const Value *LHS = I.getOperand(1), *RHS = I.getOperand(2);
const Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
if (!LHS->getType()->isPointerTy() || !RHS->getType()->isPointerTy() ||
!I.getOperand(3)->getType()->isIntegerTy() ||
!I.getOperand(2)->getType()->isIntegerTy() ||
!I.getType()->isIntegerTy())
return false;
const ConstantInt *Size = dyn_cast<ConstantInt>(I.getOperand(3));
const ConstantInt *Size = dyn_cast<ConstantInt>(I.getOperand(2));
// memcmp(S1,S2,2) != 0 -> (*(short*)LHS != *(short*)RHS) != 0
// memcmp(S1,S2,4) != 0 -> (*(int*)LHS != *(int*)RHS) != 0
@ -4617,50 +4617,50 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
StringRef Name = F->getName();
if (Name == "copysign" || Name == "copysignf" || Name == "copysignl") {
if (I.getNumOperands() == 3 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(1)->getType() &&
I.getType() == I.getOperand(2)->getType()) {
SDValue LHS = getValue(I.getOperand(1));
SDValue RHS = getValue(I.getOperand(2));
I.getOperand(0)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(0)->getType() &&
I.getType() == I.getOperand(1)->getType()) {
SDValue LHS = getValue(I.getOperand(0));
SDValue RHS = getValue(I.getOperand(1));
setValue(&I, DAG.getNode(ISD::FCOPYSIGN, getCurDebugLoc(),
LHS.getValueType(), LHS, RHS));
return;
}
} else if (Name == "fabs" || Name == "fabsf" || Name == "fabsl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(1)->getType()) {
SDValue Tmp = getValue(I.getOperand(1));
I.getOperand(0)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(0)->getType()) {
SDValue Tmp = getValue(I.getOperand(0));
setValue(&I, DAG.getNode(ISD::FABS, getCurDebugLoc(),
Tmp.getValueType(), Tmp));
return;
}
} else if (Name == "sin" || Name == "sinf" || Name == "sinl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(1)->getType() &&
I.getOperand(0)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(0)->getType() &&
I.onlyReadsMemory()) {
SDValue Tmp = getValue(I.getOperand(1));
SDValue Tmp = getValue(I.getOperand(0));
setValue(&I, DAG.getNode(ISD::FSIN, getCurDebugLoc(),
Tmp.getValueType(), Tmp));
return;
}
} else if (Name == "cos" || Name == "cosf" || Name == "cosl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(1)->getType() &&
I.getOperand(0)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(0)->getType() &&
I.onlyReadsMemory()) {
SDValue Tmp = getValue(I.getOperand(1));
SDValue Tmp = getValue(I.getOperand(0));
setValue(&I, DAG.getNode(ISD::FCOS, getCurDebugLoc(),
Tmp.getValueType(), Tmp));
return;
}
} else if (Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(1)->getType() &&
I.getOperand(0)->getType()->isFloatingPointTy() &&
I.getType() == I.getOperand(0)->getType() &&
I.onlyReadsMemory()) {
SDValue Tmp = getValue(I.getOperand(1));
SDValue Tmp = getValue(I.getOperand(0));
setValue(&I, DAG.getNode(ISD::FSQRT, getCurDebugLoc(),
Tmp.getValueType(), Tmp));
return;
@ -4670,14 +4670,14 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
return;
}
}
} else if (isa<InlineAsm>(I.getOperand(0))) {
} else if (isa<InlineAsm>(I.getCalledValue())) {
visitInlineAsm(&I);
return;
}
SDValue Callee;
if (!RenameFn)
Callee = getValue(I.getOperand(0));
Callee = getValue(I.getCalledValue());
else
Callee = DAG.getExternalSymbol(RenameFn, TLI.getPointerTy());
@ -5609,8 +5609,8 @@ void SelectionDAGBuilder::visitInlineAsm(ImmutableCallSite CS) {
void SelectionDAGBuilder::visitVAStart(const CallInst &I) {
DAG.setRoot(DAG.getNode(ISD::VASTART, getCurDebugLoc(),
MVT::Other, getRoot(),
getValue(I.getOperand(1)),
DAG.getSrcValue(I.getOperand(1))));
getValue(I.getOperand(0)),
DAG.getSrcValue(I.getOperand(0))));
}
void SelectionDAGBuilder::visitVAArg(const VAArgInst &I) {
@ -5624,17 +5624,17 @@ void SelectionDAGBuilder::visitVAArg(const VAArgInst &I) {
void SelectionDAGBuilder::visitVAEnd(const CallInst &I) {
DAG.setRoot(DAG.getNode(ISD::VAEND, getCurDebugLoc(),
MVT::Other, getRoot(),
getValue(I.getOperand(1)),
DAG.getSrcValue(I.getOperand(1))));
getValue(I.getOperand(0)),
DAG.getSrcValue(I.getOperand(0))));
}
void SelectionDAGBuilder::visitVACopy(const CallInst &I) {
DAG.setRoot(DAG.getNode(ISD::VACOPY, getCurDebugLoc(),
MVT::Other, getRoot(),
getValue(I.getOperand(0)),
getValue(I.getOperand(1)),
getValue(I.getOperand(2)),
DAG.getSrcValue(I.getOperand(1)),
DAG.getSrcValue(I.getOperand(2))));
DAG.getSrcValue(I.getOperand(0)),
DAG.getSrcValue(I.getOperand(1))));
}
/// TargetLowering::LowerCallTo - This is the default LowerCallTo

View File

@ -158,9 +158,9 @@ namespace {
// Create a new invoke instruction.
Args.clear();
Args.append(CI->op_begin() + 1, CI->op_end());
Args.append(CI->op_begin(), CI->op_end() - 1);
InvokeInst *II = InvokeInst::Create(CI->getOperand(0),
InvokeInst *II = InvokeInst::Create(CI->getCalledValue(),
NewBB, CleanupBB,
Args.begin(), Args.end(),
CI->getName(), CallBB);
@ -194,7 +194,7 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
unsigned NumMeta = 0;
SmallVector<Constant*,16> Metadata;
for (unsigned I = 0; I != Roots.size(); ++I) {
Constant *C = cast<Constant>(Roots[I].first->getOperand(2));
Constant *C = cast<Constant>(Roots[I].first->getOperand(1));
if (!C->isNullValue())
NumMeta = I + 1;
Metadata.push_back(ConstantExpr::getBitCast(C, VoidPtr));
@ -322,16 +322,16 @@ void ShadowStackGC::CollectRoots(Function &F) {
assert(Roots.empty() && "Not cleaned up?");
SmallVector<std::pair<CallInst*,AllocaInst*>,16> MetaRoots;
SmallVector<std::pair<CallInst*, AllocaInst*>,16> MetaRoots;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;)
if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(II++))
if (Function *F = CI->getCalledFunction())
if (F->getIntrinsicID() == Intrinsic::gcroot) {
std::pair<CallInst*,AllocaInst*> Pair = std::make_pair(
CI, cast<AllocaInst>(CI->getOperand(1)->stripPointerCasts()));
if (IsNullValue(CI->getOperand(2)))
std::pair<CallInst*, AllocaInst*> Pair = std::make_pair(
CI, cast<AllocaInst>(CI->getOperand(0)->stripPointerCasts()));
if (IsNullValue(CI->getOperand(1)))
Roots.push_back(Pair);
else
MetaRoots.push_back(Pair);

View File

@ -305,7 +305,7 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
if (CallInst *CI = dyn_cast<CallInst>(I)) {
if (CI->getCalledFunction() == SelectorFn) {
if (!PersonalityFn) PersonalityFn = CI->getOperand(2);
if (!PersonalityFn) PersonalityFn = CI->getOperand(1);
EH_Selectors.push_back(CI);
} else if (CI->getCalledFunction() == ExceptionFn) {
EH_Exceptions.push_back(CI);

View File

@ -2886,7 +2886,7 @@ void CWriter::visitCallInst(CallInst &I) {
bool hasByVal = I.hasByValArgument();
bool isStructRet = I.hasStructRetAttr();
if (isStructRet) {
writeOperandDeref(I.getOperand(1));
writeOperandDeref(I.getOperand(0));
Out << " = ";
}
@ -2942,7 +2942,7 @@ void CWriter::visitCallInst(CallInst &I) {
unsigned NumDeclaredParams = FTy->getNumParams();
CallSite::arg_iterator AI = I.op_begin()+1, AE = I.op_end();
CallInst::op_iterator AI = I.op_begin(), AE = I.op_end() - 1;
unsigned ArgNo = 0;
if (isStructRet) { // Skip struct return argument.
++AI;
@ -2996,7 +2996,7 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
Out << "0; ";
Out << "va_start(*(va_list*)";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ", ";
// Output the last argument to the enclosing function.
if (I.getParent()->getParent()->arg_empty())
@ -3006,9 +3006,9 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
Out << ')';
return true;
case Intrinsic::vaend:
if (!isa<ConstantPointerNull>(I.getOperand(1))) {
if (!isa<ConstantPointerNull>(I.getOperand(0))) {
Out << "0; va_end(*(va_list*)";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ')';
} else {
Out << "va_end(*(va_list*)0)";
@ -3017,47 +3017,47 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
case Intrinsic::vacopy:
Out << "0; ";
Out << "va_copy(*(va_list*)";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ", *(va_list*)";
writeOperand(I.getOperand(2));
writeOperand(I.getOperand(1));
Out << ')';
return true;
case Intrinsic::returnaddress:
Out << "__builtin_return_address(";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ')';
return true;
case Intrinsic::frameaddress:
Out << "__builtin_frame_address(";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ')';
return true;
case Intrinsic::powi:
Out << "__builtin_powi(";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ", ";
writeOperand(I.getOperand(2));
writeOperand(I.getOperand(1));
Out << ')';
return true;
case Intrinsic::setjmp:
Out << "setjmp(*(jmp_buf*)";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ')';
return true;
case Intrinsic::longjmp:
Out << "longjmp(*(jmp_buf*)";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ", ";
writeOperand(I.getOperand(2));
writeOperand(I.getOperand(1));
Out << ')';
return true;
case Intrinsic::prefetch:
Out << "LLVM_PREFETCH((const void *)";
writeOperand(I.getOperand(0));
Out << ", ";
writeOperand(I.getOperand(1));
Out << ", ";
writeOperand(I.getOperand(2));
Out << ", ";
writeOperand(I.getOperand(3));
Out << ")";
return true;
case Intrinsic::stacksave:
@ -3074,7 +3074,7 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
printType(Out, I.getType());
Out << ')';
// Multiple GCC builtins multiplex onto this intrinsic.
switch (cast<ConstantInt>(I.getOperand(3))->getZExtValue()) {
switch (cast<ConstantInt>(I.getOperand(2))->getZExtValue()) {
default: llvm_unreachable("Invalid llvm.x86.sse.cmp!");
case 0: Out << "__builtin_ia32_cmpeq"; break;
case 1: Out << "__builtin_ia32_cmplt"; break;
@ -3095,9 +3095,9 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
Out << 'd';
Out << "(";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ", ";
writeOperand(I.getOperand(2));
writeOperand(I.getOperand(1));
Out << ")";
return true;
case Intrinsic::ppc_altivec_lvsl:
@ -3105,7 +3105,7 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
printType(Out, I.getType());
Out << ')';
Out << "__builtin_altivec_lvsl(0, (void*)";
writeOperand(I.getOperand(1));
writeOperand(I.getOperand(0));
Out << ")";
return true;
}
@ -3218,7 +3218,7 @@ void CWriter::visitInlineAsm(CallInst &CI) {
DestVal = ResultVals[ValueCount].first;
DestValNo = ResultVals[ValueCount].second;
} else
DestVal = CI.getOperand(ValueCount-ResultVals.size()+1);
DestVal = CI.getOperand(ValueCount-ResultVals.size());
if (I->isEarlyClobber)
C = "&"+C;
@ -3252,7 +3252,7 @@ void CWriter::visitInlineAsm(CallInst &CI) {
}
assert(ValueCount >= ResultVals.size() && "Input can't refer to result");
Value *SrcVal = CI.getOperand(ValueCount-ResultVals.size()+1);
Value *SrcVal = CI.getOperand(ValueCount-ResultVals.size());
Out << "\"" << C << "\"(";
if (!I->isIndirect)

View File

@ -1082,8 +1082,9 @@ namespace {
// Before we emit this instruction, we need to take care of generating any
// forward references. So, we get the names of all the operands in advance
std::string* opNames = new std::string[I->getNumOperands()];
for (unsigned i = 0; i < I->getNumOperands(); i++) {
const unsigned Ops(I->getNumOperands());
std::string* opNames = new std::string[Ops];
for (unsigned i = 0; i < Ops; i++) {
opNames[i] = getOpName(I->getOperand(i));
}
@ -1144,15 +1145,15 @@ namespace {
const InvokeInst* inv = cast<InvokeInst>(I);
Out << "std::vector<Value*> " << iName << "_params;";
nl(Out);
for (unsigned i = 3; i < inv->getNumOperands(); ++i) {
for (unsigned i = 0; i < inv->getNumOperands() - 3; ++i) {
Out << iName << "_params.push_back("
<< opNames[i] << ");";
nl(Out);
}
Out << "InvokeInst *" << iName << " = InvokeInst::Create("
<< opNames[0] << ", "
<< opNames[1] << ", "
<< opNames[2] << ", "
<< opNames[Ops - 3] << ", "
<< opNames[Ops - 2] << ", "
<< opNames[Ops - 1] << ", "
<< iName << "_params.begin(), " << iName << "_params.end(), \"";
printEscapedString(inv->getName());
Out << "\", " << bbname << ");";
@ -1388,18 +1389,18 @@ namespace {
if (call->getNumOperands() > 2) {
Out << "std::vector<Value*> " << iName << "_params;";
nl(Out);
for (unsigned i = 1; i < call->getNumOperands(); ++i) {
for (unsigned i = 0; i < call->getNumOperands() - 1; ++i) {
Out << iName << "_params.push_back(" << opNames[i] << ");";
nl(Out);
}
Out << "CallInst* " << iName << " = CallInst::Create("
<< opNames[0] << ", " << iName << "_params.begin(), "
<< opNames[Ops - 1] << ", " << iName << "_params.begin(), "
<< iName << "_params.end(), \"";
} else if (call->getNumOperands() == 2) {
Out << "CallInst* " << iName << " = CallInst::Create("
<< opNames[0] << ", " << opNames[1] << ", \"";
<< opNames[Ops - 1] << ", " << opNames[0] << ", \"";
} else {
Out << "CallInst* " << iName << " = CallInst::Create(" << opNames[0]
Out << "CallInst* " << iName << " = CallInst::Create(" << opNames[Ops - 1]
<< ", \"";
}
printEscapedString(call->getName());

View File

@ -1170,8 +1170,8 @@ bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
// Emit code inline code to store the stack guard onto the stack.
EVT PtrTy = TLI.getPointerTy();
const Value *Op1 = I.getOperand(1); // The guard's value.
const AllocaInst *Slot = cast<AllocaInst>(I.getOperand(2));
const Value *Op1 = I.getOperand(0); // The guard's value.
const AllocaInst *Slot = cast<AllocaInst>(I.getOperand(1));
// Grab the frame index.
X86AddressMode AM;
@ -1182,7 +1182,7 @@ bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
return true;
}
case Intrinsic::objectsize: {
ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(2));
ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(1));
const Type *Ty = I.getCalledFunction()->getReturnType();
assert(CI && "Non-constant type in Intrinsic::objectsize?");
@ -1237,8 +1237,8 @@ bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
if (!isTypeLegal(RetTy, VT))
return false;
const Value *Op1 = I.getOperand(1);
const Value *Op2 = I.getOperand(2);
const Value *Op1 = I.getOperand(0);
const Value *Op2 = I.getOperand(1);
unsigned Reg1 = getRegForValue(Op1);
unsigned Reg2 = getRegForValue(Op2);
@ -1281,7 +1281,7 @@ bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
bool X86FastISel::X86SelectCall(const Instruction *I) {
const CallInst *CI = cast<CallInst>(I);
const Value *Callee = I->getOperand(0);
const Value *Callee = CI->getCalledValue();
// Can't handle inline asm yet.
if (isa<InlineAsm>(Callee))

View File

@ -9918,7 +9918,7 @@ static bool LowerToBSwap(CallInst *CI) {
// Verify this is a simple bswap.
if (CI->getNumOperands() != 2 ||
CI->getType() != CI->getOperand(1)->getType() ||
CI->getType() != CI->getOperand(0)->getType() ||
!CI->getType()->isIntegerTy())
return false;
@ -9931,7 +9931,7 @@ static bool LowerToBSwap(CallInst *CI) {
Module *M = CI->getParent()->getParent()->getParent();
Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
Value *Op = CI->getOperand(1);
Value *Op = CI->getOperand(0);
Op = CallInst::Create(Int, Op, CI->getName(), CI);
CI->replaceAllUsesWith(Op);

View File

@ -222,12 +222,12 @@ static bool AnalyzeGlobal(const Value *V, GlobalStatus &GS,
GS.HasPHIUser = true;
} else if (isa<CmpInst>(I)) {
} else if (isa<MemTransferInst>(I)) {
if (I->getOperand(1) == V)
if (I->getOperand(0) == V)
GS.StoredType = GlobalStatus::isStored;
if (I->getOperand(2) == V)
if (I->getOperand(1) == V)
GS.isLoaded = true;
} else if (isa<MemSetInst>(I)) {
assert(I->getOperand(1) == V && "Memset only takes one pointer!");
assert(I->getOperand(0) == V && "Memset only takes one pointer!");
GS.StoredType = GlobalStatus::isStored;
} else {
return true; // Any other non-load instruction might take address!
@ -1323,8 +1323,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, CallInst *CI,
// if (F2) { free(F2); F2 = 0; }
// }
// The malloc can also fail if its argument is too large.
Constant *ConstantZero = ConstantInt::get(CI->getOperand(1)->getType(), 0);
Value *RunningOr = new ICmpInst(CI, ICmpInst::ICMP_SLT, CI->getOperand(1),
Constant *ConstantZero = ConstantInt::get(CI->getOperand(0)->getType(), 0);
Value *RunningOr = new ICmpInst(CI, ICmpInst::ICMP_SLT, CI->getOperand(0),
ConstantZero, "isneg");
for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
Value *Cond = new ICmpInst(CI, ICmpInst::ICMP_EQ, FieldMallocs[i],
@ -1511,10 +1511,10 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
// If this is an allocation of a fixed size array of structs, analyze as a
// variable size array. malloc [100 x struct],1 -> malloc struct, 100
if (NElems == ConstantInt::get(CI->getOperand(1)->getType(), 1))
if (NElems == ConstantInt::get(CI->getOperand(0)->getType(), 1))
if (const ArrayType *AT = dyn_cast<ArrayType>(AllocTy))
AllocTy = AT->getElementType();
const StructType *AllocSTy = dyn_cast<StructType>(AllocTy);
if (!AllocSTy)
return false;
@ -1641,7 +1641,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
// bool.
Instruction *StoredVal = cast<Instruction>(SI->getOperand(0));
// If we're already replaced the input, StoredVal will be a cast or
// If we've already replaced the input, StoredVal will be a cast or
// select instruction. If not, it will be a load of the original
// global.
if (LoadInst *LI = dyn_cast<LoadInst>(StoredVal)) {
@ -2262,8 +2262,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
} else if (SelectInst *SI = dyn_cast<SelectInst>(CurInst)) {
InstResult =
ConstantExpr::getSelect(getVal(Values, SI->getOperand(0)),
getVal(Values, SI->getOperand(1)),
getVal(Values, SI->getOperand(2)));
getVal(Values, SI->getOperand(1)),
getVal(Values, SI->getOperand(2)));
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
Constant *P = getVal(Values, GEP->getOperand(0));
SmallVector<Constant*, 8> GEPOps;
@ -2295,14 +2295,14 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
}
// Cannot handle inline asm.
if (isa<InlineAsm>(CI->getOperand(0))) return false;
if (isa<InlineAsm>(CI->getCalledValue())) return false;
// Resolve function pointers.
Function *Callee = dyn_cast<Function>(getVal(Values, CI->getOperand(0)));
Function *Callee = dyn_cast<Function>(getVal(Values, CI->getCalledValue()));
if (!Callee) return false; // Cannot resolve.
SmallVector<Constant*, 8> Formals;
for (User::op_iterator i = CI->op_begin() + 1, e = CI->op_end();
for (User::op_iterator i = CI->op_begin(), e = CI->op_end() - 1;
i != e; ++i)
Formals.push_back(getVal(Values, *i));

View File

@ -262,8 +262,8 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
// char*. It returns "void", so it doesn't need to replace any of
// Inst's uses and doesn't get a name.
CastInst* CI =
new BitCastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
Value *Args[] = { CI, Inst->getOperand(2) };
new BitCastInst(Inst->getOperand(0), SBPTy, "LJBuf", Inst);
Value *Args[] = { CI, Inst->getOperand(1) };
CallInst::Create(ThrowLongJmp, Args, Args + 2, "", Inst);
SwitchValuePair& SVP = SwitchValMap[Inst->getParent()->getParent()];
@ -378,7 +378,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
const Type* SBPTy =
Type::getInt8PtrTy(Inst->getContext());
CastInst* BufPtr =
new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
new BitCastInst(Inst->getOperand(0), SBPTy, "SBJmpBuf", Inst);
Value *Args[] = {
GetSetJmpMap(Func), BufPtr,
ConstantInt::get(Type::getInt32Ty(Inst->getContext()), SetJmpIDMap[Func]++)
@ -473,7 +473,7 @@ void LowerSetJmp::visitCallInst(CallInst& CI)
// Construct the new "invoke" instruction.
TerminatorInst* Term = OldBB->getTerminator();
std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end());
std::vector<Value*> Params(CI.op_begin(), CI.op_end() - 1);
InvokeInst* II =
InvokeInst::Create(CI.getCalledValue(), NewBB, PrelimBBMap[Func],
Params.begin(), Params.end(), CI.getName(), Term);

View File

@ -109,8 +109,8 @@ unsigned InstCombiner::GetOrEnforceKnownAlignment(Value *V,
}
Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
unsigned DstAlign = GetOrEnforceKnownAlignment(MI->getOperand(1));
unsigned SrcAlign = GetOrEnforceKnownAlignment(MI->getOperand(2));
unsigned DstAlign = GetOrEnforceKnownAlignment(MI->getOperand(0));
unsigned SrcAlign = GetOrEnforceKnownAlignment(MI->getOperand(1));
unsigned MinAlign = std::min(DstAlign, SrcAlign);
unsigned CopyAlign = MI->getAlignment();
@ -122,7 +122,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
// If MemCpyInst length is 1/2/4/8 bytes then replace memcpy with
// load/store.
ConstantInt *MemOpLength = dyn_cast<ConstantInt>(MI->getOperand(3));
ConstantInt *MemOpLength = dyn_cast<ConstantInt>(MI->getOperand(2));
if (MemOpLength == 0) return 0;
// Source and destination pointer types are always "i8*" for intrinsic. See
@ -137,9 +137,9 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
// Use an integer load+store unless we can find something better.
unsigned SrcAddrSp =
cast<PointerType>(MI->getOperand(2)->getType())->getAddressSpace();
unsigned DstAddrSp =
cast<PointerType>(MI->getOperand(1)->getType())->getAddressSpace();
unsigned DstAddrSp =
cast<PointerType>(MI->getOperand(0)->getType())->getAddressSpace();
const IntegerType* IntType = IntegerType::get(MI->getContext(), Size<<3);
Type *NewSrcPtrTy = PointerType::get(IntType, SrcAddrSp);
@ -151,8 +151,8 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
// an i64 load+store, here because this improves the odds that the source or
// dest address will be promotable. See if we can find a better type than the
// integer datatype.
Value *StrippedDest = MI->getOperand(1)->stripPointerCasts();
if (StrippedDest != MI->getOperand(1)) {
Value *StrippedDest = MI->getOperand(0)->stripPointerCasts();
if (StrippedDest != MI->getOperand(0)) {
const Type *SrcETy = cast<PointerType>(StrippedDest->getType())
->getElementType();
if (TD && SrcETy->isSized() && TD->getTypeStoreSize(SrcETy) == Size) {
@ -186,15 +186,15 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
SrcAlign = std::max(SrcAlign, CopyAlign);
DstAlign = std::max(DstAlign, CopyAlign);
Value *Src = Builder->CreateBitCast(MI->getOperand(2), NewSrcPtrTy);
Value *Dest = Builder->CreateBitCast(MI->getOperand(1), NewDstPtrTy);
Value *Src = Builder->CreateBitCast(MI->getOperand(1), NewSrcPtrTy);
Value *Dest = Builder->CreateBitCast(MI->getOperand(0), NewDstPtrTy);
Instruction *L = new LoadInst(Src, "tmp", MI->isVolatile(), SrcAlign);
InsertNewInstBefore(L, *MI);
InsertNewInstBefore(new StoreInst(L, Dest, MI->isVolatile(), DstAlign),
*MI);
// Set the size of the copy to 0, it will be deleted on the next iteration.
MI->setOperand(3, Constant::getNullValue(MemOpLength->getType()));
MI->setOperand(2, Constant::getNullValue(MemOpLength->getType()));
return MI;
}
@ -258,7 +258,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
IntrinsicInst *II = dyn_cast<IntrinsicInst>(&CI);
if (!II) return visitCallSite(&CI);
// Intrinsics cannot occur in an invoke, so handle them here instead of in
// visitCallSite.
if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(II)) {
@ -282,12 +282,12 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (MemMoveInst *MMI = dyn_cast<MemMoveInst>(MI)) {
if (GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
if (GVSrc->isConstant()) {
Module *M = CI.getParent()->getParent()->getParent();
Module *M = MMI->getParent()->getParent()->getParent();
Intrinsic::ID MemCpyID = Intrinsic::memcpy;
const Type *Tys[3] = { CI.getOperand(1)->getType(),
CI.getOperand(2)->getType(),
CI.getOperand(3)->getType() };
CI.setOperand(0,
const Type *Tys[3] = { CI.getOperand(0)->getType(),
CI.getOperand(1)->getType(),
CI.getOperand(2)->getType() };
MMI->setCalledFunction(
Intrinsic::getDeclaration(M, MemCpyID, Tys, 3));
Changed = true;
}
@ -297,21 +297,19 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// memmove(x,x,size) -> noop.
if (MTI->getSource() == MTI->getDest())
return EraseInstFromFunction(CI);
}
// If we can determine a pointer alignment that is bigger than currently
// set, update the alignment.
if (isa<MemTransferInst>(MI)) {
if (Instruction *I = SimplifyMemTransfer(MI))
// If we can determine a pointer alignment that is bigger than currently
// set, update the alignment.
if (Instruction *I = SimplifyMemTransfer(MTI))
return I;
} else if (MemSetInst *MSI = dyn_cast<MemSetInst>(MI)) {
if (Instruction *I = SimplifyMemSet(MSI))
return I;
}
if (Changed) return II;
}
switch (II->getIntrinsicID()) {
default: break;
case Intrinsic::objectsize: {
@ -319,10 +317,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (!TD) break;
const Type *ReturnTy = CI.getType();
bool Min = (cast<ConstantInt>(II->getOperand(2))->getZExtValue() == 1);
bool Min = (cast<ConstantInt>(II->getOperand(1))->getZExtValue() == 1);
// Get to the real allocated thing and offset as fast as possible.
Value *Op1 = II->getOperand(1)->stripPointerCasts();
Value *Op1 = II->getOperand(0)->stripPointerCasts();
// If we've stripped down to a single global variable that we
// can know the size of then just return that.
@ -390,7 +388,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
Constant *RetVal = ConstantInt::get(ReturnTy, Size-Offset);
return ReplaceInstUsesWith(CI, RetVal);
}
// Do not return "I don't know" here. Later optimization passes could
@ -399,45 +396,45 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
}
case Intrinsic::bswap:
// bswap(bswap(x)) -> x
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(II->getOperand(1)))
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(II->getOperand(0)))
if (Operand->getIntrinsicID() == Intrinsic::bswap)
return ReplaceInstUsesWith(CI, Operand->getOperand(1));
return ReplaceInstUsesWith(CI, Operand->getOperand(0));
// bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
if (TruncInst *TI = dyn_cast<TruncInst>(II->getOperand(1))) {
if (TruncInst *TI = dyn_cast<TruncInst>(II->getOperand(0))) {
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(TI->getOperand(0)))
if (Operand->getIntrinsicID() == Intrinsic::bswap) {
unsigned C = Operand->getType()->getPrimitiveSizeInBits() -
TI->getType()->getPrimitiveSizeInBits();
Value *CV = ConstantInt::get(Operand->getType(), C);
Value *V = Builder->CreateLShr(Operand->getOperand(1), CV);
Value *V = Builder->CreateLShr(Operand->getOperand(0), CV);
return new TruncInst(V, TI->getType());
}
}
break;
case Intrinsic::powi:
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getOperand(2))) {
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getOperand(1))) {
// powi(x, 0) -> 1.0
if (Power->isZero())
return ReplaceInstUsesWith(CI, ConstantFP::get(CI.getType(), 1.0));
// powi(x, 1) -> x
if (Power->isOne())
return ReplaceInstUsesWith(CI, II->getOperand(1));
return ReplaceInstUsesWith(CI, II->getOperand(0));
// powi(x, -1) -> 1/x
if (Power->isAllOnesValue())
return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0),
II->getOperand(1));
II->getOperand(0));
}
break;
case Intrinsic::cttz: {
// If all bits below the first known one are known zero,
// this value is constant.
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType());
const IntegerType *IT = cast<IntegerType>(II->getOperand(0)->getType());
uint32_t BitWidth = IT->getBitWidth();
APInt KnownZero(BitWidth, 0);
APInt KnownOne(BitWidth, 0);
ComputeMaskedBits(II->getOperand(1), APInt::getAllOnesValue(BitWidth),
ComputeMaskedBits(II->getOperand(0), APInt::getAllOnesValue(BitWidth),
KnownZero, KnownOne);
unsigned TrailingZeros = KnownOne.countTrailingZeros();
APInt Mask(APInt::getLowBitsSet(BitWidth, TrailingZeros));
@ -450,11 +447,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::ctlz: {
// If all bits above the first known one are known zero,
// this value is constant.
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType());
const IntegerType *IT = cast<IntegerType>(II->getOperand(0)->getType());
uint32_t BitWidth = IT->getBitWidth();
APInt KnownZero(BitWidth, 0);
APInt KnownOne(BitWidth, 0);
ComputeMaskedBits(II->getOperand(1), APInt::getAllOnesValue(BitWidth),
ComputeMaskedBits(II->getOperand(0), APInt::getAllOnesValue(BitWidth),
KnownZero, KnownOne);
unsigned LeadingZeros = KnownOne.countLeadingZeros();
APInt Mask(APInt::getHighBitsSet(BitWidth, LeadingZeros));
@ -465,8 +462,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
}
break;
case Intrinsic::uadd_with_overflow: {
Value *LHS = II->getOperand(1), *RHS = II->getOperand(2);
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType());
Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
const IntegerType *IT = cast<IntegerType>(II->getOperand(0)->getType());
uint32_t BitWidth = IT->getBitWidth();
APInt Mask = APInt::getSignBit(BitWidth);
APInt LHSKnownZero(BitWidth, 0);
@ -510,19 +507,19 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// FALL THROUGH uadd into sadd
case Intrinsic::sadd_with_overflow:
// Canonicalize constants into the RHS.
if (isa<Constant>(II->getOperand(1)) &&
!isa<Constant>(II->getOperand(2))) {
Value *LHS = II->getOperand(1);
II->setOperand(1, II->getOperand(2));
II->setOperand(2, LHS);
if (isa<Constant>(II->getOperand(0)) &&
!isa<Constant>(II->getOperand(1))) {
Value *LHS = II->getOperand(0);
II->setOperand(0, II->getOperand(1));
II->setOperand(1, LHS);
return II;
}
// X + undef -> undef
if (isa<UndefValue>(II->getOperand(2)))
if (isa<UndefValue>(II->getOperand(1)))
return ReplaceInstUsesWith(CI, UndefValue::get(II->getType()));
if (ConstantInt *RHS = dyn_cast<ConstantInt>(II->getOperand(2))) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(II->getOperand(1))) {
// X + 0 -> {X, false}
if (RHS->isZero()) {
Constant *V[] = {
@ -530,7 +527,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
ConstantInt::getFalse(II->getContext())
};
Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false);
return InsertValueInst::Create(Struct, II->getOperand(1), 0);
return InsertValueInst::Create(Struct, II->getOperand(0), 0);
}
}
break;
@ -538,38 +535,38 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::ssub_with_overflow:
// undef - X -> undef
// X - undef -> undef
if (isa<UndefValue>(II->getOperand(1)) ||
isa<UndefValue>(II->getOperand(2)))
if (isa<UndefValue>(II->getOperand(0)) ||
isa<UndefValue>(II->getOperand(1)))
return ReplaceInstUsesWith(CI, UndefValue::get(II->getType()));
if (ConstantInt *RHS = dyn_cast<ConstantInt>(II->getOperand(2))) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(II->getOperand(1))) {
// X - 0 -> {X, false}
if (RHS->isZero()) {
Constant *V[] = {
UndefValue::get(II->getOperand(1)->getType()),
UndefValue::get(II->getOperand(0)->getType()),
ConstantInt::getFalse(II->getContext())
};
Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false);
return InsertValueInst::Create(Struct, II->getOperand(1), 0);
return InsertValueInst::Create(Struct, II->getOperand(0), 0);
}
}
break;
case Intrinsic::umul_with_overflow:
case Intrinsic::smul_with_overflow:
// Canonicalize constants into the RHS.
if (isa<Constant>(II->getOperand(1)) &&
!isa<Constant>(II->getOperand(2))) {
Value *LHS = II->getOperand(1);
II->setOperand(1, II->getOperand(2));
II->setOperand(2, LHS);
if (isa<Constant>(II->getOperand(0)) &&
!isa<Constant>(II->getOperand(1))) {
Value *LHS = II->getOperand(0);
II->setOperand(0, II->getOperand(1));
II->setOperand(1, LHS);
return II;
}
// X * undef -> undef
if (isa<UndefValue>(II->getOperand(2)))
if (isa<UndefValue>(II->getOperand(1)))
return ReplaceInstUsesWith(CI, UndefValue::get(II->getType()));
if (ConstantInt *RHSI = dyn_cast<ConstantInt>(II->getOperand(2))) {
if (ConstantInt *RHSI = dyn_cast<ConstantInt>(II->getOperand(1))) {
// X*0 -> {0, false}
if (RHSI->isZero())
return ReplaceInstUsesWith(CI, Constant::getNullValue(II->getType()));
@ -577,11 +574,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// X * 1 -> {X, false}
if (RHSI->equalsInt(1)) {
Constant *V[] = {
UndefValue::get(II->getOperand(1)->getType()),
UndefValue::get(II->getOperand(0)->getType()),
ConstantInt::getFalse(II->getContext())
};
Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false);
return InsertValueInst::Create(Struct, II->getOperand(1), 0);
return InsertValueInst::Create(Struct, II->getOperand(0), 0);
}
}
break;
@ -592,8 +589,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::x86_sse2_loadu_dq:
// Turn PPC lvx -> load if the pointer is known aligned.
// Turn X86 loadups -> load if the pointer is known aligned.
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
Value *Ptr = Builder->CreateBitCast(II->getOperand(1),
if (GetOrEnforceKnownAlignment(II->getOperand(0), 16) >= 16) {
Value *Ptr = Builder->CreateBitCast(II->getOperand(0),
PointerType::getUnqual(II->getType()));
return new LoadInst(Ptr);
}
@ -601,22 +598,22 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::ppc_altivec_stvx:
case Intrinsic::ppc_altivec_stvxl:
// Turn stvx -> store if the pointer is known aligned.
if (GetOrEnforceKnownAlignment(II->getOperand(2), 16) >= 16) {
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
const Type *OpPtrTy =
PointerType::getUnqual(II->getOperand(1)->getType());
Value *Ptr = Builder->CreateBitCast(II->getOperand(2), OpPtrTy);
return new StoreInst(II->getOperand(1), Ptr);
PointerType::getUnqual(II->getOperand(0)->getType());
Value *Ptr = Builder->CreateBitCast(II->getOperand(1), OpPtrTy);
return new StoreInst(II->getOperand(0), Ptr);
}
break;
case Intrinsic::x86_sse_storeu_ps:
case Intrinsic::x86_sse2_storeu_pd:
case Intrinsic::x86_sse2_storeu_dq:
// Turn X86 storeu -> store if the pointer is known aligned.
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
if (GetOrEnforceKnownAlignment(II->getOperand(0), 16) >= 16) {
const Type *OpPtrTy =
PointerType::getUnqual(II->getOperand(2)->getType());
Value *Ptr = Builder->CreateBitCast(II->getOperand(1), OpPtrTy);
return new StoreInst(II->getOperand(2), Ptr);
PointerType::getUnqual(II->getOperand(1)->getType());
Value *Ptr = Builder->CreateBitCast(II->getOperand(0), OpPtrTy);
return new StoreInst(II->getOperand(1), Ptr);
}
break;
@ -624,12 +621,12 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// These intrinsics only demands the 0th element of its input vector. If
// we can simplify the input based on that, do so now.
unsigned VWidth =
cast<VectorType>(II->getOperand(1)->getType())->getNumElements();
cast<VectorType>(II->getOperand(0)->getType())->getNumElements();
APInt DemandedElts(VWidth, 1);
APInt UndefElts(VWidth, 0);
if (Value *V = SimplifyDemandedVectorElts(II->getOperand(1), DemandedElts,
if (Value *V = SimplifyDemandedVectorElts(II->getOperand(0), DemandedElts,
UndefElts)) {
II->setOperand(1, V);
II->setOperand(0, V);
return II;
}
break;
@ -637,7 +634,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::ppc_altivec_vperm:
// Turn vperm(V1,V2,mask) -> shuffle(V1,V2,mask) if mask is a constant.
if (ConstantVector *Mask = dyn_cast<ConstantVector>(II->getOperand(3))) {
if (ConstantVector *Mask = dyn_cast<ConstantVector>(II->getOperand(2))) {
assert(Mask->getNumOperands() == 16 && "Bad type for intrinsic!");
// Check that all of the elements are integer constants or undefs.
@ -652,8 +649,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (AllEltsOk) {
// Cast the input vectors to byte vectors.
Value *Op0 = Builder->CreateBitCast(II->getOperand(1), Mask->getType());
Value *Op1 = Builder->CreateBitCast(II->getOperand(2), Mask->getType());
Value *Op0 = Builder->CreateBitCast(II->getOperand(0), Mask->getType());
Value *Op1 = Builder->CreateBitCast(II->getOperand(1), Mask->getType());
Value *Result = UndefValue::get(Op0->getType());
// Only extract each element once.
@ -686,7 +683,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::stackrestore: {
// If the save is right next to the restore, remove the restore. This can
// happen when variable allocas are DCE'd.
if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getOperand(1))) {
if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getOperand(0))) {
if (SS->getIntrinsicID() == Intrinsic::stacksave) {
BasicBlock::iterator BI = SS;
if (&*++BI == II)
@ -843,7 +840,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
UndefValue::get(Type::getInt1PtrTy(Callee->getContext())),
CS.getInstruction());
// If CS dues not return void then replaceAllUsesWith undef.
// If CS does not return void then replaceAllUsesWith undef.
// This allows ValueHandlers and custom metadata to adjust itself.
if (!CS.getInstruction()->getType()->isVoidTy())
CS.getInstruction()->
@ -1137,7 +1134,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
IntrinsicInst *Tramp =
cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0));
Function *NestF = cast<Function>(Tramp->getOperand(2)->stripPointerCasts());
Function *NestF = cast<Function>(Tramp->getOperand(1)->stripPointerCasts());
const PointerType *NestFPTy = cast<PointerType>(NestF->getType());
const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType());
@ -1178,7 +1175,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
do {
if (Idx == NestIdx) {
// Add the chain argument and attributes.
Value *NestVal = Tramp->getOperand(3);
Value *NestVal = Tramp->getOperand(2);
if (NestVal->getType() != NestTy)
NestVal = new BitCastInst(NestVal, NestTy, "nest", Caller);
NewArgs.push_back(NestVal);

View File

@ -1423,7 +1423,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
switch (II->getIntrinsicID()) {
case Intrinsic::bswap:
Worklist.Add(II);
ICI.setOperand(0, II->getOperand(1));
ICI.setOperand(0, II->getOperand(0));
ICI.setOperand(1, ConstantInt::get(II->getContext(), RHSV.byteSwap()));
return &ICI;
case Intrinsic::ctlz:
@ -1431,7 +1431,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
// ctz(A) == bitwidth(a) -> A == 0 and likewise for !=
if (RHSV == RHS->getType()->getBitWidth()) {
Worklist.Add(II);
ICI.setOperand(0, II->getOperand(1));
ICI.setOperand(0, II->getOperand(0));
ICI.setOperand(1, ConstantInt::get(RHS->getType(), 0));
return &ICI;
}
@ -1440,7 +1440,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
// popcount(A) == 0 -> A == 0 and likewise for !=
if (RHS->isZero()) {
Worklist.Add(II);
ICI.setOperand(0, II->getOperand(1));
ICI.setOperand(0, II->getOperand(0));
ICI.setOperand(1, RHS);
return &ICI;
}

View File

@ -404,7 +404,7 @@ Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
isPowerOf2_32(BitWidth) && Log2_32(BitWidth) == Op1C->getZExtValue()){
bool isCtPop = II->getIntrinsicID() == Intrinsic::ctpop;
Constant *RHS = ConstantInt::getSigned(Op0->getType(), isCtPop ? -1:0);
Value *Cmp = Builder->CreateICmpEQ(II->getOperand(1), RHS);
Value *Cmp = Builder->CreateICmpEQ(II->getOperand(0), RHS);
return new ZExtInst(Cmp, II->getType());
}
}

View File

@ -732,10 +732,10 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// the right place.
Instruction *NewVal;
if (InputBit > ResultBit)
NewVal = BinaryOperator::CreateLShr(I->getOperand(1),
NewVal = BinaryOperator::CreateLShr(II->getOperand(0),
ConstantInt::get(I->getType(), InputBit-ResultBit));
else
NewVal = BinaryOperator::CreateShl(I->getOperand(1),
NewVal = BinaryOperator::CreateShl(II->getOperand(0),
ConstantInt::get(I->getType(), ResultBit-InputBit));
NewVal->takeName(I);
return InsertNewInstBefore(NewVal, *I);
@ -1052,12 +1052,12 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
case Intrinsic::x86_sse2_mul_sd:
case Intrinsic::x86_sse2_min_sd:
case Intrinsic::x86_sse2_max_sd:
TmpV = SimplifyDemandedVectorElts(II->getOperand(1), DemandedElts,
TmpV = SimplifyDemandedVectorElts(II->getOperand(0), DemandedElts,
UndefElts, Depth+1);
if (TmpV) { II->setOperand(1, TmpV); MadeChange = true; }
TmpV = SimplifyDemandedVectorElts(II->getOperand(2), DemandedElts,
if (TmpV) { II->setOperand(0, TmpV); MadeChange = true; }
TmpV = SimplifyDemandedVectorElts(II->getOperand(1), DemandedElts,
UndefElts2, Depth+1);
if (TmpV) { II->setOperand(2, TmpV); MadeChange = true; }
if (TmpV) { II->setOperand(1, TmpV); MadeChange = true; }
// If only the low elt is demanded and this is a scalarizable intrinsic,
// scalarize it now.
@ -1069,8 +1069,8 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
case Intrinsic::x86_sse2_sub_sd:
case Intrinsic::x86_sse2_mul_sd:
// TODO: Lower MIN/MAX/ABS/etc
Value *LHS = II->getOperand(1);
Value *RHS = II->getOperand(2);
Value *LHS = II->getOperand(0);
Value *RHS = II->getOperand(1);
// Extract the element as scalars.
LHS = InsertNewInstBefore(ExtractElementInst::Create(LHS,
ConstantInt::get(Type::getInt32Ty(I->getContext()), 0U)), *II);

View File

@ -711,7 +711,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
}
Instruction *InstCombiner::visitFree(Instruction &FI) {
Value *Op = FI.getOperand(1);
Value *Op = FI.getOperand(0);
// free undef -> unreachable.
if (isa<UndefValue>(Op)) {
@ -896,7 +896,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Agg)) {
// We're extracting from an intrinsic, see if we're the only user, which
// allows us to simplify multiple result intrinsics to simpler things that
// just get one value..
// just get one value.
if (II->hasOneUse()) {
// Check if we're grabbing the overflow bit or the result of a 'with
// overflow' intrinsic. If it's the latter we can remove the intrinsic
@ -905,7 +905,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
case Intrinsic::uadd_with_overflow:
case Intrinsic::sadd_with_overflow:
if (*EV.idx_begin() == 0) { // Normal result.
Value *LHS = II->getOperand(1), *RHS = II->getOperand(2);
Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
II->replaceAllUsesWith(UndefValue::get(II->getType()));
EraseInstFromFunction(*II);
return BinaryOperator::CreateAdd(LHS, RHS);
@ -914,7 +914,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
case Intrinsic::usub_with_overflow:
case Intrinsic::ssub_with_overflow:
if (*EV.idx_begin() == 0) { // Normal result.
Value *LHS = II->getOperand(1), *RHS = II->getOperand(2);
Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
II->replaceAllUsesWith(UndefValue::get(II->getType()));
EraseInstFromFunction(*II);
return BinaryOperator::CreateSub(LHS, RHS);
@ -923,7 +923,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
case Intrinsic::umul_with_overflow:
case Intrinsic::smul_with_overflow:
if (*EV.idx_begin() == 0) { // Normal result.
Value *LHS = II->getOperand(1), *RHS = II->getOperand(2);
Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
II->replaceAllUsesWith(UndefValue::get(II->getType()));
EraseInstFromFunction(*II);
return BinaryOperator::CreateMul(LHS, RHS);

View File

@ -73,10 +73,10 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
if (AI->getType() != ArgVTy) {
Instruction::CastOps opcode = CastInst::getCastOpcode(AI, false, ArgVTy,
false);
InitCall->setOperand(2,
InitCall->setOperand(1,
CastInst::Create(opcode, AI, ArgVTy, "argv.cast", InitCall));
} else {
InitCall->setOperand(2, AI);
InitCall->setOperand(1, AI);
}
/* FALL THROUGH */
@ -93,12 +93,12 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
}
opcode = CastInst::getCastOpcode(AI, true,
Type::getInt32Ty(Context), true);
InitCall->setOperand(1,
InitCall->setOperand(0,
CastInst::Create(opcode, AI, Type::getInt32Ty(Context),
"argc.cast", InitCall));
} else {
AI->replaceAllUsesWith(InitCall);
InitCall->setOperand(1, AI);
InitCall->setOperand(0, AI);
}
case 0: break;

View File

@ -123,14 +123,14 @@ static Value *getPointerOperand(Instruction *I) {
if (StoreInst *SI = dyn_cast<StoreInst>(I))
return SI->getPointerOperand();
if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I))
return MI->getOperand(1);
return MI->getOperand(0);
switch (cast<IntrinsicInst>(I)->getIntrinsicID()) {
default: assert(false && "Unexpected intrinsic!");
case Intrinsic::init_trampoline:
return I->getOperand(1);
return I->getOperand(0);
case Intrinsic::lifetime_end:
return I->getOperand(2);
return I->getOperand(1);
}
}
@ -152,7 +152,7 @@ static unsigned getStoreSize(Instruction *I, const TargetData *TD) {
case Intrinsic::init_trampoline:
return -1u;
case Intrinsic::lifetime_end:
Len = I->getOperand(1);
Len = I->getOperand(0);
break;
}
}
@ -287,7 +287,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
/// handleFreeWithNonTrivialDependency - Handle frees of entire structures whose
/// dependency is a store to a field of that structure.
bool DSE::handleFreeWithNonTrivialDependency(Instruction *F, MemDepResult Dep) {
bool DSE::handleFreeWithNonTrivialDependency(/*FIXME: Call*/Instruction *F, MemDepResult Dep) {
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
Instruction *Dependency = Dep.getInst();
@ -297,7 +297,7 @@ bool DSE::handleFreeWithNonTrivialDependency(Instruction *F, MemDepResult Dep) {
Value *DepPointer = getPointerOperand(Dependency)->getUnderlyingObject();
// Check for aliasing.
if (AA.alias(F->getOperand(1), 1, DepPointer, 1) !=
if (AA.alias(F->getOperand(0), 1, DepPointer, 1) !=
AliasAnalysis::MustAlias)
return false;

View File

@ -271,7 +271,7 @@ Expression ValueTable::create_expression(CallInst* C) {
e.function = C->getCalledFunction();
e.opcode = Expression::CALL;
for (CallInst::op_iterator I = C->op_begin()+1, E = C->op_end();
for (CallInst::op_iterator I = C->op_begin(), E = C->op_end() - 1;
I != E; ++I)
e.varargs.push_back(lookup_or_add(*I));
@ -452,7 +452,7 @@ uint32_t ValueTable::lookup_or_add_call(CallInst* C) {
return nextValueNumber++;
}
for (unsigned i = 1; i < C->getNumOperands(); ++i) {
for (unsigned i = 0, e = C->getNumOperands() - 1; i < e; ++i) {
uint32_t c_vn = lookup_or_add(C->getOperand(i));
uint32_t cd_vn = lookup_or_add(local_cdep->getOperand(i));
if (c_vn != cd_vn) {
@ -508,7 +508,7 @@ uint32_t ValueTable::lookup_or_add_call(CallInst* C) {
valueNumbering[C] = nextValueNumber;
return nextValueNumber++;
}
for (unsigned i = 1; i < C->getNumOperands(); ++i) {
for (unsigned i = 0, e = C->getNumOperands() - 1; i < e; ++i) {
uint32_t c_vn = lookup_or_add(C->getOperand(i));
uint32_t cd_vn = lookup_or_add(cdep->getOperand(i));
if (c_vn != cd_vn) {

View File

@ -744,7 +744,7 @@ bool MemCpyOpt::processMemMove(MemMoveInst *M) {
const Type *ArgTys[3] = { M->getRawDest()->getType(),
M->getRawSource()->getType(),
M->getLength()->getType() };
M->setOperand(0,Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, ArgTys, 3));
M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, ArgTys, 3));
// MemDep may have over conservative information about this instruction, just
// conservatively flush it from the cache.

View File

@ -254,7 +254,7 @@ bool SROA::performScalarRepl(Function &F) {
if (Instruction *TheCopy = isOnlyCopiedFromConstantGlobal(AI)) {
DEBUG(dbgs() << "Found alloca equal to global: " << *AI << '\n');
DEBUG(dbgs() << " memcpy = " << *TheCopy << '\n');
Constant *TheSrc = cast<Constant>(TheCopy->getOperand(2));
Constant *TheSrc = cast<Constant>(TheCopy->getOperand(1));
AI->replaceAllUsesWith(ConstantExpr::getBitCast(TheSrc, AI->getType()));
TheCopy->eraseFromParent(); // Don't mutate the global.
AI->eraseFromParent();
@ -404,11 +404,11 @@ void SROA::isSafeForScalarRepl(Instruction *I, AllocaInst *AI, uint64_t Offset,
isSafeGEP(GEPI, AI, GEPOffset, Info);
if (!Info.isUnsafe)
isSafeForScalarRepl(GEPI, AI, GEPOffset, Info);
} else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(UI)) {
} else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(User)) {
ConstantInt *Length = dyn_cast<ConstantInt>(MI->getLength());
if (Length)
isSafeMemAccess(AI, Offset, Length->getZExtValue(), 0,
UI.getOperandNo() == 1, Info);
UI.getOperandNo() == 0, Info);
else
MarkUnsafe(Info);
} else if (LoadInst *LI = dyn_cast<LoadInst>(User)) {
@ -756,7 +756,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst,
}
// Process each element of the aggregate.
Value *TheFn = MI->getOperand(0);
Value *TheFn = MI->getCalledValue();
const Type *BytePtrTy = MI->getRawDest()->getType();
bool SROADest = MI->getRawDest() == Inst;
@ -814,7 +814,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst,
// If the stored element is zero (common case), just store a null
// constant.
Constant *StoreVal;
if (ConstantInt *CI = dyn_cast<ConstantInt>(MI->getOperand(2))) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(MI->getOperand(1))) {
if (CI->isZero()) {
StoreVal = Constant::getNullValue(EltTy); // 0.0, null, 0, <0,0>
} else {
@ -877,7 +877,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst,
Value *Ops[] = {
SROADest ? EltPtr : OtherElt, // Dest ptr
SROADest ? OtherElt : EltPtr, // Src ptr
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
ConstantInt::get(MI->getOperand(2)->getType(), EltSize), // Size
// Align
ConstantInt::get(Type::getInt32Ty(MI->getContext()), OtherEltAlign),
MI->getVolatileCst()
@ -892,8 +892,8 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst,
} else {
assert(isa<MemSetInst>(MI));
Value *Ops[] = {
EltPtr, MI->getOperand(2), // Dest, Value,
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
EltPtr, MI->getOperand(1), // Dest, Value,
ConstantInt::get(MI->getOperand(2)->getType(), EltSize), // Size
Zero, // Align
ConstantInt::get(Type::getInt1Ty(MI->getContext()), 0) // isVolatile
};
@ -1737,12 +1737,12 @@ static bool isOnlyCopiedFromConstantGlobal(Value *V, Instruction *&TheCopy,
if (isOffset) return false;
// If the memintrinsic isn't using the alloca as the dest, reject it.
if (UI.getOperandNo() != 1) return false;
if (UI.getOperandNo() != 0) return false;
MemIntrinsic *MI = cast<MemIntrinsic>(U);
// If the source of the memcpy/move is not a constant global, reject it.
if (!PointsToConstantGlobal(MI->getOperand(2)))
if (!PointsToConstantGlobal(MI->getOperand(1)))
return false;
// Otherwise, the transform is safe. Remember the copy instruction.

View File

@ -110,8 +110,8 @@ struct StrCatOpt : public LibCallOptimization {
return 0;
// Extract some information from the instruction
Value *Dst = CI->getOperand(1);
Value *Src = CI->getOperand(2);
Value *Dst = CI->getOperand(0);
Value *Src = CI->getOperand(1);
// See if we can get the length of the input string.
uint64_t Len = GetStringLength(Src);
@ -162,12 +162,12 @@ struct StrNCatOpt : public StrCatOpt {
return 0;
// Extract some information from the instruction
Value *Dst = CI->getOperand(1);
Value *Src = CI->getOperand(2);
Value *Dst = CI->getOperand(0);
Value *Src = CI->getOperand(1);
uint64_t Len;
// We don't do anything if length is not constant
if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getOperand(3)))
if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getOperand(2)))
Len = LengthArg->getZExtValue();
else
return 0;
@ -207,11 +207,11 @@ struct StrChrOpt : public LibCallOptimization {
FT->getParamType(0) != FT->getReturnType())
return 0;
Value *SrcStr = CI->getOperand(1);
Value *SrcStr = CI->getOperand(0);
// If the second operand is non-constant, see if we can compute the length
// of the input string and turn this into memchr.
ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getOperand(2));
ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getOperand(1));
if (CharC == 0) {
// These optimizations require TargetData.
if (!TD) return 0;
@ -220,7 +220,7 @@ struct StrChrOpt : public LibCallOptimization {
if (Len == 0 || !FT->getParamType(1)->isIntegerTy(32))// memchr needs i32.
return 0;
return EmitMemChr(SrcStr, CI->getOperand(2), // include nul.
return EmitMemChr(SrcStr, CI->getOperand(1), // include nul.
ConstantInt::get(TD->getIntPtrType(*Context), Len),
B, TD);
}
@ -265,7 +265,7 @@ struct StrCmpOpt : public LibCallOptimization {
FT->getParamType(0) != Type::getInt8PtrTy(*Context))
return 0;
Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2);
Value *Str1P = CI->getOperand(0), *Str2P = CI->getOperand(1);
if (Str1P == Str2P) // strcmp(x,x) -> 0
return ConstantInt::get(CI->getType(), 0);
@ -314,13 +314,13 @@ struct StrNCmpOpt : public LibCallOptimization {
!FT->getParamType(2)->isIntegerTy())
return 0;
Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2);
Value *Str1P = CI->getOperand(0), *Str2P = CI->getOperand(1);
if (Str1P == Str2P) // strncmp(x,x,n) -> 0
return ConstantInt::get(CI->getType(), 0);
// Get the length argument if it is constant.
uint64_t Length;
if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getOperand(3)))
if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getOperand(2)))
Length = LengthArg->getZExtValue();
else
return 0;
@ -365,7 +365,7 @@ struct StrCpyOpt : public LibCallOptimization {
FT->getParamType(0) != Type::getInt8PtrTy(*Context))
return 0;
Value *Dst = CI->getOperand(1), *Src = CI->getOperand(2);
Value *Dst = CI->getOperand(0), *Src = CI->getOperand(1);
if (Dst == Src) // strcpy(x,x) -> x
return Src;
@ -381,7 +381,7 @@ struct StrCpyOpt : public LibCallOptimization {
if (OptChkCall)
EmitMemCpyChk(Dst, Src,
ConstantInt::get(TD->getIntPtrType(*Context), Len),
CI->getOperand(3), B, TD);
CI->getOperand(2), B, TD);
else
EmitMemCpy(Dst, Src,
ConstantInt::get(TD->getIntPtrType(*Context), Len),
@ -402,9 +402,9 @@ struct StrNCpyOpt : public LibCallOptimization {
!FT->getParamType(2)->isIntegerTy())
return 0;
Value *Dst = CI->getOperand(1);
Value *Src = CI->getOperand(2);
Value *LenOp = CI->getOperand(3);
Value *Dst = CI->getOperand(0);
Value *Src = CI->getOperand(1);
Value *LenOp = CI->getOperand(2);
// See if we can get the length of the input string.
uint64_t SrcLen = GetStringLength(Src);
@ -452,7 +452,7 @@ struct StrLenOpt : public LibCallOptimization {
!FT->getReturnType()->isIntegerTy())
return 0;
Value *Src = CI->getOperand(1);
Value *Src = CI->getOperand(0);
// Constant folding: strlen("xyz") -> 3
if (uint64_t Len = GetStringLength(Src))
@ -477,7 +477,7 @@ struct StrToOpt : public LibCallOptimization {
!FT->getParamType(1)->isPointerTy())
return 0;
Value *EndPtr = CI->getOperand(2);
Value *EndPtr = CI->getOperand(1);
if (isa<ConstantPointerNull>(EndPtr)) {
CI->setOnlyReadsMemory();
CI->addAttribute(1, Attribute::NoCapture);
@ -500,17 +500,17 @@ struct StrStrOpt : public LibCallOptimization {
return 0;
// fold strstr(x, x) -> x.
if (CI->getOperand(1) == CI->getOperand(2))
return B.CreateBitCast(CI->getOperand(1), CI->getType());
if (CI->getOperand(0) == CI->getOperand(1))
return B.CreateBitCast(CI->getOperand(0), CI->getType());
// See if either input string is a constant string.
std::string SearchStr, ToFindStr;
bool HasStr1 = GetConstantStringInfo(CI->getOperand(1), SearchStr);
bool HasStr2 = GetConstantStringInfo(CI->getOperand(2), ToFindStr);
bool HasStr1 = GetConstantStringInfo(CI->getOperand(0), SearchStr);
bool HasStr2 = GetConstantStringInfo(CI->getOperand(1), ToFindStr);
// fold strstr(x, "") -> x.
if (HasStr2 && ToFindStr.empty())
return B.CreateBitCast(CI->getOperand(1), CI->getType());
return B.CreateBitCast(CI->getOperand(0), CI->getType());
// If both strings are known, constant fold it.
if (HasStr1 && HasStr2) {
@ -520,14 +520,14 @@ struct StrStrOpt : public LibCallOptimization {
return Constant::getNullValue(CI->getType());
// strstr("abcd", "bc") -> gep((char*)"abcd", 1)
Value *Result = CastToCStr(CI->getOperand(1), B);
Value *Result = CastToCStr(CI->getOperand(0), B);
Result = B.CreateConstInBoundsGEP1_64(Result, Offset, "strstr");
return B.CreateBitCast(Result, CI->getType());
}
// fold strstr(x, "y") -> strchr(x, 'y').
if (HasStr2 && ToFindStr.size() == 1)
return B.CreateBitCast(EmitStrChr(CI->getOperand(1), ToFindStr[0], B, TD),
return B.CreateBitCast(EmitStrChr(CI->getOperand(0), ToFindStr[0], B, TD),
CI->getType());
return 0;
}
@ -545,13 +545,13 @@ struct MemCmpOpt : public LibCallOptimization {
!FT->getReturnType()->isIntegerTy(32))
return 0;
Value *LHS = CI->getOperand(1), *RHS = CI->getOperand(2);
Value *LHS = CI->getOperand(0), *RHS = CI->getOperand(1);
if (LHS == RHS) // memcmp(s,s,x) -> 0
return Constant::getNullValue(CI->getType());
// Make sure we have a constant length.
ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getOperand(3));
ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getOperand(2));
if (!LenC) return 0;
uint64_t Len = LenC->getZExtValue();
@ -595,9 +595,9 @@ struct MemCpyOpt : public LibCallOptimization {
return 0;
// memcpy(x, y, n) -> llvm.memcpy(x, y, n, 1)
EmitMemCpy(CI->getOperand(1), CI->getOperand(2),
CI->getOperand(3), 1, false, B, TD);
return CI->getOperand(1);
EmitMemCpy(CI->getOperand(0), CI->getOperand(1),
CI->getOperand(2), 1, false, B, TD);
return CI->getOperand(0);
}
};
@ -617,9 +617,9 @@ struct MemMoveOpt : public LibCallOptimization {
return 0;
// memmove(x, y, n) -> llvm.memmove(x, y, n, 1)
EmitMemMove(CI->getOperand(1), CI->getOperand(2),
CI->getOperand(3), 1, false, B, TD);
return CI->getOperand(1);
EmitMemMove(CI->getOperand(0), CI->getOperand(1),
CI->getOperand(2), 1, false, B, TD);
return CI->getOperand(0);
}
};
@ -639,10 +639,10 @@ struct MemSetOpt : public LibCallOptimization {
return 0;
// memset(p, v, n) -> llvm.memset(p, v, n, 1)
Value *Val = B.CreateIntCast(CI->getOperand(2), Type::getInt8Ty(*Context),
false);
EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), false, B, TD);
return CI->getOperand(1);
Value *Val = B.CreateIntCast(CI->getOperand(1), Type::getInt8Ty(*Context),
false);
EmitMemSet(CI->getOperand(0), Val, CI->getOperand(2), false, B, TD);
return CI->getOperand(0);
}
};
@ -663,7 +663,7 @@ struct PowOpt : public LibCallOptimization {
!FT->getParamType(0)->isFloatingPointTy())
return 0;
Value *Op1 = CI->getOperand(1), *Op2 = CI->getOperand(2);
Value *Op1 = CI->getOperand(0), *Op2 = CI->getOperand(1);
if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
if (Op1C->isExactlyValue(1.0)) // pow(1.0, x) -> 1.0
return Op1C;
@ -717,7 +717,7 @@ struct Exp2Opt : public LibCallOptimization {
!FT->getParamType(0)->isFloatingPointTy())
return 0;
Value *Op = CI->getOperand(1);
Value *Op = CI->getOperand(0);
// Turn exp2(sitofp(x)) -> ldexp(1.0, sext(x)) if sizeof(x) <= 32
// Turn exp2(uitofp(x)) -> ldexp(1.0, zext(x)) if sizeof(x) < 32
Value *LdExpArg = 0;
@ -769,7 +769,7 @@ struct UnaryDoubleFPOpt : public LibCallOptimization {
return 0;
// If this is something like 'floor((double)floatval)', convert to floorf.
FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getOperand(1));
FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getOperand(0));
if (Cast == 0 || !Cast->getOperand(0)->getType()->isFloatTy())
return 0;
@ -798,7 +798,7 @@ struct FFSOpt : public LibCallOptimization {
!FT->getParamType(0)->isIntegerTy())
return 0;
Value *Op = CI->getOperand(1);
Value *Op = CI->getOperand(0);
// Constant fold.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
@ -834,7 +834,7 @@ struct IsDigitOpt : public LibCallOptimization {
return 0;
// isdigit(c) -> (c-'0') <u 10
Value *Op = CI->getOperand(1);
Value *Op = CI->getOperand(0);
Op = B.CreateSub(Op, ConstantInt::get(Type::getInt32Ty(*Context), '0'),
"isdigittmp");
Op = B.CreateICmpULT(Op, ConstantInt::get(Type::getInt32Ty(*Context), 10),
@ -855,7 +855,7 @@ struct IsAsciiOpt : public LibCallOptimization {
return 0;
// isascii(c) -> c <u 128
Value *Op = CI->getOperand(1);
Value *Op = CI->getOperand(0);
Op = B.CreateICmpULT(Op, ConstantInt::get(Type::getInt32Ty(*Context), 128),
"isascii");
return B.CreateZExt(Op, CI->getType());
@ -874,7 +874,7 @@ struct AbsOpt : public LibCallOptimization {
return 0;
// abs(x) -> x >s -1 ? x : -x
Value *Op = CI->getOperand(1);
Value *Op = CI->getOperand(0);
Value *Pos = B.CreateICmpSGT(Op,
Constant::getAllOnesValue(Op->getType()),
"ispos");
@ -896,7 +896,7 @@ struct ToAsciiOpt : public LibCallOptimization {
return 0;
// isascii(c) -> c & 0x7f
return B.CreateAnd(CI->getOperand(1),
return B.CreateAnd(CI->getOperand(0),
ConstantInt::get(CI->getType(),0x7F));
}
};
@ -919,7 +919,7 @@ struct PrintFOpt : public LibCallOptimization {
// Check for a fixed format string.
std::string FormatStr;
if (!GetConstantStringInfo(CI->getOperand(1), FormatStr))
if (!GetConstantStringInfo(CI->getOperand(0), FormatStr))
return 0;
// Empty format string -> noop.
@ -951,10 +951,10 @@ struct PrintFOpt : public LibCallOptimization {
}
// Optimize specific format strings.
// printf("%c", chr) --> putchar(*(i8*)dst)
// printf("%c", chr) --> putchar(chr)
if (FormatStr == "%c" && CI->getNumOperands() > 2 &&
CI->getOperand(2)->getType()->isIntegerTy()) {
Value *Res = EmitPutChar(CI->getOperand(2), B, TD);
CI->getOperand(1)->getType()->isIntegerTy()) {
Value *Res = EmitPutChar(CI->getOperand(1), B, TD);
if (CI->use_empty()) return CI;
return B.CreateIntCast(Res, CI->getType(), true);
@ -962,9 +962,9 @@ struct PrintFOpt : public LibCallOptimization {
// printf("%s\n", str) --> puts(str)
if (FormatStr == "%s\n" && CI->getNumOperands() > 2 &&
CI->getOperand(2)->getType()->isPointerTy() &&
CI->getOperand(1)->getType()->isPointerTy() &&
CI->use_empty()) {
EmitPutS(CI->getOperand(2), B, TD);
EmitPutS(CI->getOperand(1), B, TD);
return CI;
}
return 0;
@ -985,7 +985,7 @@ struct SPrintFOpt : public LibCallOptimization {
// Check for a fixed format string.
std::string FormatStr;
if (!GetConstantStringInfo(CI->getOperand(2), FormatStr))
if (!GetConstantStringInfo(CI->getOperand(1), FormatStr))
return 0;
// If we just have a format string (nothing else crazy) transform it.
@ -1000,7 +1000,7 @@ struct SPrintFOpt : public LibCallOptimization {
if (!TD) return 0;
// sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1)
EmitMemCpy(CI->getOperand(1), CI->getOperand(2), // Copy the nul byte.
EmitMemCpy(CI->getOperand(0), CI->getOperand(1), // Copy the nul byte.
ConstantInt::get(TD->getIntPtrType(*Context),
FormatStr.size()+1), 1, false, B, TD);
return ConstantInt::get(CI->getType(), FormatStr.size());
@ -1014,10 +1014,10 @@ struct SPrintFOpt : public LibCallOptimization {
// Decode the second character of the format string.
if (FormatStr[1] == 'c') {
// sprintf(dst, "%c", chr) --> *(i8*)dst = chr; *((i8*)dst+1) = 0
if (!CI->getOperand(3)->getType()->isIntegerTy()) return 0;
Value *V = B.CreateTrunc(CI->getOperand(3),
if (!CI->getOperand(2)->getType()->isIntegerTy()) return 0;
Value *V = B.CreateTrunc(CI->getOperand(2),
Type::getInt8Ty(*Context), "char");
Value *Ptr = CastToCStr(CI->getOperand(1), B);
Value *Ptr = CastToCStr(CI->getOperand(0), B);
B.CreateStore(V, Ptr);
Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::getInt32Ty(*Context), 1),
"nul");
@ -1031,13 +1031,13 @@ struct SPrintFOpt : public LibCallOptimization {
if (!TD) return 0;
// sprintf(dest, "%s", str) -> llvm.memcpy(dest, str, strlen(str)+1, 1)
if (!CI->getOperand(3)->getType()->isPointerTy()) return 0;
if (!CI->getOperand(2)->getType()->isPointerTy()) return 0;
Value *Len = EmitStrLen(CI->getOperand(3), B, TD);
Value *Len = EmitStrLen(CI->getOperand(2), B, TD);
Value *IncLen = B.CreateAdd(Len,
ConstantInt::get(Len->getType(), 1),
"leninc");
EmitMemCpy(CI->getOperand(1), CI->getOperand(3), IncLen, 1, false, B, TD);
EmitMemCpy(CI->getOperand(0), CI->getOperand(2), IncLen, 1, false, B, TD);
// The sprintf result is the unincremented number of bytes in the string.
return B.CreateIntCast(Len, CI->getType(), false);
@ -1061,8 +1061,8 @@ struct FWriteOpt : public LibCallOptimization {
return 0;
// Get the element size and count.
ConstantInt *SizeC = dyn_cast<ConstantInt>(CI->getOperand(2));
ConstantInt *CountC = dyn_cast<ConstantInt>(CI->getOperand(3));
ConstantInt *SizeC = dyn_cast<ConstantInt>(CI->getOperand(1));
ConstantInt *CountC = dyn_cast<ConstantInt>(CI->getOperand(2));
if (!SizeC || !CountC) return 0;
uint64_t Bytes = SizeC->getZExtValue()*CountC->getZExtValue();
@ -1072,8 +1072,8 @@ struct FWriteOpt : public LibCallOptimization {
// If this is writing one byte, turn it into fputc.
if (Bytes == 1) { // fwrite(S,1,1,F) -> fputc(S[0],F)
Value *Char = B.CreateLoad(CastToCStr(CI->getOperand(1), B), "char");
EmitFPutC(Char, CI->getOperand(4), B, TD);
Value *Char = B.CreateLoad(CastToCStr(CI->getOperand(0), B), "char");
EmitFPutC(Char, CI->getOperand(3), B, TD);
return ConstantInt::get(CI->getType(), 1);
}
@ -1097,11 +1097,11 @@ struct FPutsOpt : public LibCallOptimization {
return 0;
// fputs(s,F) --> fwrite(s,1,strlen(s),F)
uint64_t Len = GetStringLength(CI->getOperand(1));
uint64_t Len = GetStringLength(CI->getOperand(0));
if (!Len) return 0;
EmitFWrite(CI->getOperand(1),
EmitFWrite(CI->getOperand(0),
ConstantInt::get(TD->getIntPtrType(*Context), Len-1),
CI->getOperand(2), B, TD);
CI->getOperand(1), B, TD);
return CI; // Known to have no uses (see above).
}
};
@ -1120,7 +1120,7 @@ struct FPrintFOpt : public LibCallOptimization {
// All the optimizations depend on the format string.
std::string FormatStr;
if (!GetConstantStringInfo(CI->getOperand(2), FormatStr))
if (!GetConstantStringInfo(CI->getOperand(1), FormatStr))
return 0;
// fprintf(F, "foo") --> fwrite("foo", 3, 1, F)
@ -1132,10 +1132,10 @@ struct FPrintFOpt : public LibCallOptimization {
// These optimizations require TargetData.
if (!TD) return 0;
EmitFWrite(CI->getOperand(2),
EmitFWrite(CI->getOperand(1),
ConstantInt::get(TD->getIntPtrType(*Context),
FormatStr.size()),
CI->getOperand(1), B, TD);
CI->getOperand(0), B, TD);
return ConstantInt::get(CI->getType(), FormatStr.size());
}
@ -1146,17 +1146,17 @@ struct FPrintFOpt : public LibCallOptimization {
// Decode the second character of the format string.
if (FormatStr[1] == 'c') {
// fprintf(F, "%c", chr) --> *(i8*)dst = chr
if (!CI->getOperand(3)->getType()->isIntegerTy()) return 0;
EmitFPutC(CI->getOperand(3), CI->getOperand(1), B, TD);
// fprintf(F, "%c", chr) --> fputc(chr, F)
if (!CI->getOperand(2)->getType()->isIntegerTy()) return 0;
EmitFPutC(CI->getOperand(2), CI->getOperand(0), B, TD);
return ConstantInt::get(CI->getType(), 1);
}
if (FormatStr[1] == 's') {
// fprintf(F, "%s", str) -> fputs(str, F)
if (!CI->getOperand(3)->getType()->isPointerTy() || !CI->use_empty())
// fprintf(F, "%s", str) --> fputs(str, F)
if (!CI->getOperand(2)->getType()->isPointerTy() || !CI->use_empty())
return 0;
EmitFPutS(CI->getOperand(3), CI->getOperand(1), B, TD);
EmitFPutS(CI->getOperand(2), CI->getOperand(0), B, TD);
return CI;
}
return 0;

View File

@ -250,7 +250,7 @@ static bool isDynamicConstant(Value *V, CallInst *CI, ReturnInst *RI) {
// If we are passing this argument into call as the corresponding
// argument operand, then the argument is dynamically constant.
// Otherwise, we cannot transform this function safely.
if (CI->getOperand(ArgNo+1) == Arg)
if (CI->getOperand(ArgNo) == Arg)
return true;
}
@ -442,7 +442,7 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry,
// required PHI nodes, add entries into the PHI node for the actual
// parameters passed into the tail-recursive call.
for (unsigned i = 0, e = CI->getNumOperands()-1; i != e; ++i)
ArgumentPHIs[i]->addIncoming(CI->getOperand(i+1), BB);
ArgumentPHIs[i]->addIncoming(CI->getOperand(i), BB);
// If we are introducing an accumulator variable to eliminate the recursion,
// do so now. Note that we _know_ that no subsequent tail recursion

View File

@ -382,7 +382,7 @@ static bool IsOperandAMemoryOperand(CallInst *CI, InlineAsm *IA, Value *OpVal,
std::vector<InlineAsm::ConstraintInfo>
Constraints = IA->ParseConstraints();
unsigned ArgNo = 1; // ArgNo - The operand of the CallInst.
unsigned ArgNo = 0; // ArgNo - The operand of the CallInst.
for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
TargetLowering::AsmOperandInfo OpInfo(Constraints[i]);
@ -450,7 +450,7 @@ static bool FindAllMemoryUses(Instruction *I,
if (CallInst *CI = dyn_cast<CallInst>(U)) {
InlineAsm *IA = dyn_cast<InlineAsm>(CI->getCalledValue());
if (IA == 0) return true;
if (!IA) return true;
// If this is a memory operand, we're cool, otherwise bail out.
if (!IsOperandAMemoryOperand(CI, IA, I, TLI))

View File

@ -395,11 +395,11 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
FT->getParamType(2) != TD->getIntPtrType(Context) ||
FT->getParamType(3) != TD->getIntPtrType(Context))
return false;
if (isFoldable(4, 3, false)) {
EmitMemCpy(CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
if (isFoldable(3, 2, false)) {
EmitMemCpy(CI->getOperand(0), CI->getOperand(1), CI->getOperand(2),
1, false, B, TD);
replaceCall(CI->getOperand(1));
replaceCall(CI->getOperand(0));
return true;
}
return false;
@ -418,11 +418,11 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
FT->getParamType(2) != TD->getIntPtrType(Context) ||
FT->getParamType(3) != TD->getIntPtrType(Context))
return false;
if (isFoldable(4, 3, false)) {
EmitMemMove(CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
if (isFoldable(3, 2, false)) {
EmitMemMove(CI->getOperand(0), CI->getOperand(1), CI->getOperand(2),
1, false, B, TD);
replaceCall(CI->getOperand(1));
replaceCall(CI->getOperand(0));
return true;
}
return false;
@ -436,12 +436,12 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
FT->getParamType(2) != TD->getIntPtrType(Context) ||
FT->getParamType(3) != TD->getIntPtrType(Context))
return false;
if (isFoldable(4, 3, false)) {
Value *Val = B.CreateIntCast(CI->getOperand(2), B.getInt8Ty(),
if (isFoldable(3, 2, false)) {
Value *Val = B.CreateIntCast(CI->getOperand(1), B.getInt8Ty(),
false);
EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), false, B, TD);
replaceCall(CI->getOperand(1));
EmitMemSet(CI->getOperand(0), Val, CI->getOperand(2), false, B, TD);
replaceCall(CI->getOperand(0));
return true;
}
return false;
@ -462,8 +462,8 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
// st[rp]cpy_chk call which may fail at runtime if the size is too long.
// TODO: It might be nice to get a maximum length out of the possible
// string lengths for varying.
if (isFoldable(3, 2, true)) {
Value *Ret = EmitStrCpy(CI->getOperand(1), CI->getOperand(2), B, TD,
if (isFoldable(2, 1, true)) {
Value *Ret = EmitStrCpy(CI->getOperand(0), CI->getOperand(1), B, TD,
Name.substr(2, 6));
replaceCall(Ret);
return true;
@ -479,10 +479,10 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
!FT->getParamType(2)->isIntegerTy() ||
FT->getParamType(3) != TD->getIntPtrType(Context))
return false;
if (isFoldable(4, 3, false)) {
Value *Ret = EmitStrNCpy(CI->getOperand(1), CI->getOperand(2),
CI->getOperand(3), B, TD, Name.substr(2, 7));
if (isFoldable(3, 2, false)) {
Value *Ret = EmitStrNCpy(CI->getOperand(0), CI->getOperand(1),
CI->getOperand(2), B, TD, Name.substr(2, 7));
replaceCall(Ret);
return true;
}

View File

@ -66,7 +66,7 @@ static void HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB,
// Next, create the new invoke instruction, inserting it at the end
// of the old basic block.
SmallVector<Value*, 8> InvokeArgs(CI->op_begin()+1, CI->op_end());
SmallVector<Value*, 8> InvokeArgs(CI->op_begin(), CI->op_end() - 1);
InvokeInst *II =
InvokeInst::Create(CI->getCalledValue(), Split, InvokeDest,
InvokeArgs.begin(), InvokeArgs.end(),

View File

@ -1847,6 +1847,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
default: Out << " cc" << CI->getCallingConv(); break;
}
Operand = CI->getCalledValue();
const PointerType *PTy = cast<PointerType>(Operand->getType());
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
const Type *RetTy = FTy->getReturnType();
@ -1870,10 +1871,10 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
writeOperand(Operand, true);
}
Out << '(';
for (unsigned op = 1, Eop = I.getNumOperands(); op < Eop; ++op) {
if (op > 1)
for (unsigned op = 0, Eop = CI->getNumOperands() - 1; op < Eop; ++op) {
if (op > 0)
Out << ", ";
writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op));
writeParamOperand(CI->getOperand(op), PAL.getParamAttributes(op + 1));
}
Out << ')';
if (PAL.getFnAttributes() != Attribute::None)
@ -1917,10 +1918,10 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
writeOperand(Operand, true);
}
Out << '(';
for (unsigned op = 0, Eop = I.getNumOperands() - 3; op < Eop; ++op) {
for (unsigned op = 0, Eop = II->getNumOperands() - 3; op < Eop; ++op) {
if (op)
Out << ", ";
writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op + 1));
writeParamOperand(II->getOperand(op), PAL.getParamAttributes(op + 1));
}
Out << ')';

View File

@ -338,11 +338,11 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
if (isLoadH || isLoadL || isMovL || isMovSD || isShufPD ||
isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) {
std::vector<Constant*> Idxs;
Value *Op0 = CI->getOperand(1);
Value *Op0 = CI->getOperand(0);
ShuffleVectorInst *SI = NULL;
if (isLoadH || isLoadL) {
Value *Op1 = UndefValue::get(Op0->getType());
Value *Addr = new BitCastInst(CI->getOperand(2),
Value *Addr = new BitCastInst(CI->getOperand(1),
Type::getDoublePtrTy(C),
"upgraded.", CI);
Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI);
@ -375,7 +375,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI);
} else if (isMovSD ||
isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) {
Value *Op1 = CI->getOperand(2);
Value *Op1 = CI->getOperand(1);
if (isMovSD) {
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2));
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1));
@ -389,8 +389,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
} else if (isShufPD) {
Value *Op1 = CI->getOperand(2);
unsigned MaskVal = cast<ConstantInt>(CI->getOperand(3))->getZExtValue();
Value *Op1 = CI->getOperand(1);
unsigned MaskVal = cast<ConstantInt>(CI->getOperand(2))->getZExtValue();
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), MaskVal & 1));
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C),
((MaskVal >> 1) & 1)+2));
@ -410,8 +410,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
CI->eraseFromParent();
} else if (F->getName() == "llvm.x86.sse41.pmulld") {
// Upgrade this set of intrinsics into vector multiplies.
Instruction *Mul = BinaryOperator::CreateMul(CI->getOperand(1),
CI->getOperand(2),
Instruction *Mul = BinaryOperator::CreateMul(CI->getOperand(0),
CI->getOperand(1),
CI->getName(),
CI);
// Fix up all the uses with our new multiply.
@ -438,10 +438,10 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
case Intrinsic::x86_mmx_psrl_w: {
Value *Operands[2];
Operands[0] = CI->getOperand(1);
Operands[0] = CI->getOperand(0);
// Cast the second parameter to the correct type.
BitCastInst *BC = new BitCastInst(CI->getOperand(2),
BitCastInst *BC = new BitCastInst(CI->getOperand(1),
NewFn->getFunctionType()->getParamType(1),
"upgraded.", CI);
Operands[1] = BC;
@ -465,9 +465,9 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
case Intrinsic::ctlz:
case Intrinsic::ctpop:
case Intrinsic::cttz: {
// Build a small vector of the 1..(N-1) operands, which are the
// Build a small vector of the 0..(N-1) operands, which are the
// parameters.
SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end());
SmallVector<Value*, 8> Operands(CI->op_begin(), CI->op_end() - 1);
// Construct a new CallInst
CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(),
@ -502,7 +502,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
case Intrinsic::eh_selector:
case Intrinsic::eh_typeid_for: {
// Only the return type changed.
SmallVector<Value*, 8> Operands(CI->op_begin() + 1, CI->op_end());
SmallVector<Value*, 8> Operands(CI->op_begin(), CI->op_end() - 1);
CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(),
"upgraded." + CI->getName(), CI);
NewCI->setTailCall(CI->isTailCall());
@ -525,8 +525,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
case Intrinsic::memset: {
// Add isVolatile
const llvm::Type *I1Ty = llvm::Type::getInt1Ty(CI->getContext());
Value *Operands[5] = { CI->getOperand(1), CI->getOperand(2),
CI->getOperand(3), CI->getOperand(4),
Value *Operands[5] = { CI->getOperand(0), CI->getOperand(1),
CI->getOperand(2), CI->getOperand(3),
llvm::ConstantInt::get(I1Ty, 0) };
CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+5,
CI->getName(), CI);
@ -608,7 +608,8 @@ void llvm::CheckDebugInfoIntrinsics(Module *M) {
if (Function *Declare = M->getFunction("llvm.dbg.declare")) {
if (!Declare->use_empty()) {
DbgDeclareInst *DDI = cast<DbgDeclareInst>(Declare->use_back());
if (!isa<MDNode>(DDI->getOperand(1)) ||!isa<MDNode>(DDI->getOperand(2))) {
if (!isa<MDNode>(DDI->getOperand(0)) ||
!isa<MDNode>(DDI->getOperand(1))) {
while (!Declare->use_empty()) {
CallInst *CI = cast<CallInst>(Declare->use_back());
CI->eraseFromParent();

View File

@ -33,7 +33,7 @@ using namespace llvm;
User::op_iterator CallSite::getCallee() const {
Instruction *II(getInstruction());
return isCall()
? cast<CallInst>(II)->op_begin()
? cast<CallInst>(II)->op_end() - 1 // Skip Function
: cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Function
}
@ -231,8 +231,7 @@ CallInst::~CallInst() {
void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
assert(NumOperands == NumParams+1 && "NumOperands not set up?");
Use *OL = OperandList;
OL[0] = Func;
Op<-1>() = Func;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@ -241,20 +240,21 @@ void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
assert((NumParams == FTy->getNumParams() ||
(FTy->isVarArg() && NumParams > FTy->getNumParams())) &&
"Calling a function with bad signature!");
Use *OL = OperandList;
for (unsigned i = 0; i != NumParams; ++i) {
assert((i >= FTy->getNumParams() ||
FTy->getParamType(i) == Params[i]->getType()) &&
"Calling a function with a bad signature!");
OL[i+1] = Params[i];
OL[i] = Params[i];
}
}
void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
assert(NumOperands == 3 && "NumOperands not set up?");
Use *OL = OperandList;
OL[0] = Func;
OL[1] = Actual1;
OL[2] = Actual2;
Op<-1>() = Func;
Op<0>() = Actual1;
Op<1>() = Actual2;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@ -273,9 +273,8 @@ void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
void CallInst::init(Value *Func, Value *Actual) {
assert(NumOperands == 2 && "NumOperands not set up?");
Use *OL = OperandList;
OL[0] = Func;
OL[1] = Actual;
Op<-1>() = Func;
Op<0>() = Actual;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@ -291,8 +290,7 @@ void CallInst::init(Value *Func, Value *Actual) {
void CallInst::init(Value *Func) {
assert(NumOperands == 1 && "NumOperands not set up?");
Use *OL = OperandList;
OL[0] = Func;
Op<-1>() = Func;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());

View File

@ -54,7 +54,7 @@ Value *DbgInfoIntrinsic::StripCast(Value *C) {
///
Value *DbgDeclareInst::getAddress() const {
if (MDNode* MD = cast_or_null<MDNode>(getOperand(1)))
if (MDNode* MD = cast_or_null<MDNode>(getOperand(0)))
return MD->getOperand(0);
else
return NULL;
@ -65,9 +65,9 @@ Value *DbgDeclareInst::getAddress() const {
///
const Value *DbgValueInst::getValue() const {
return cast<MDNode>(getOperand(1))->getOperand(0);
return cast<MDNode>(getOperand(0))->getOperand(0);
}
Value *DbgValueInst::getValue() {
return cast<MDNode>(getOperand(1))->getOperand(0);
return cast<MDNode>(getOperand(0))->getOperand(0);
}

View File

@ -1396,7 +1396,7 @@ void Verifier::visitInstruction(Instruction &I) {
if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
// Check to make sure that the "address of" an intrinsic function is never
// taken.
Assert1(!F->isIntrinsic() || (i == 0 && isa<CallInst>(I)),
Assert1(!F->isIntrinsic() || (i + 1 == e && isa<CallInst>(I)),
"Cannot take the address of an intrinsic!", &I);
Assert1(F->getParent() == Mod, "Referencing function in another module!",
&I);
@ -1479,7 +1479,8 @@ void Verifier::visitInstruction(Instruction &I) {
"Instruction does not dominate all uses!", Op, &I);
}
} else if (isa<InlineAsm>(I.getOperand(i))) {
Assert1((i == 0 && isa<CallInst>(I)) || (i + 3 == e && isa<InvokeInst>(I)),
Assert1((i + 1 == e && isa<CallInst>(I)) ||
(i + 3 == e && isa<InvokeInst>(I)),
"Cannot take the address of an inline asm!", &I);
}
}
@ -1614,16 +1615,16 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
default:
break;
case Intrinsic::dbg_declare: { // llvm.dbg.declare
Assert1(CI.getOperand(1) && isa<MDNode>(CI.getOperand(1)),
Assert1(CI.getOperand(0) && isa<MDNode>(CI.getOperand(0)),
"invalid llvm.dbg.declare intrinsic call 1", &CI);
MDNode *MD = cast<MDNode>(CI.getOperand(1));
MDNode *MD = cast<MDNode>(CI.getOperand(0));
Assert1(MD->getNumOperands() == 1,
"invalid llvm.dbg.declare intrinsic call 2", &CI);
} break;
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memset:
Assert1(isa<ConstantInt>(CI.getOperand(4)),
Assert1(isa<ConstantInt>(CI.getOperand(3)),
"alignment argument of memory intrinsics must be a constant int",
&CI);
break;
@ -1632,10 +1633,10 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
case Intrinsic::gcread:
if (ID == Intrinsic::gcroot) {
AllocaInst *AI =
dyn_cast<AllocaInst>(CI.getOperand(1)->stripPointerCasts());
dyn_cast<AllocaInst>(CI.getOperand(0)->stripPointerCasts());
Assert1(AI && AI->getType()->getElementType()->isPointerTy(),
"llvm.gcroot parameter #1 must be a pointer alloca.", &CI);
Assert1(isa<Constant>(CI.getOperand(2)),
Assert1(isa<Constant>(CI.getOperand(1)),
"llvm.gcroot parameter #2 must be a constant.", &CI);
}
@ -1643,32 +1644,32 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
"Enclosing function does not use GC.", &CI);
break;
case Intrinsic::init_trampoline:
Assert1(isa<Function>(CI.getOperand(2)->stripPointerCasts()),
Assert1(isa<Function>(CI.getOperand(1)->stripPointerCasts()),
"llvm.init_trampoline parameter #2 must resolve to a function.",
&CI);
break;
case Intrinsic::prefetch:
Assert1(isa<ConstantInt>(CI.getOperand(2)) &&
isa<ConstantInt>(CI.getOperand(3)) &&
cast<ConstantInt>(CI.getOperand(2))->getZExtValue() < 2 &&
cast<ConstantInt>(CI.getOperand(3))->getZExtValue() < 4,
Assert1(isa<ConstantInt>(CI.getOperand(1)) &&
isa<ConstantInt>(CI.getOperand(2)) &&
cast<ConstantInt>(CI.getOperand(1))->getZExtValue() < 2 &&
cast<ConstantInt>(CI.getOperand(2))->getZExtValue() < 4,
"invalid arguments to llvm.prefetch",
&CI);
break;
case Intrinsic::stackprotector:
Assert1(isa<AllocaInst>(CI.getOperand(2)->stripPointerCasts()),
Assert1(isa<AllocaInst>(CI.getOperand(1)->stripPointerCasts()),
"llvm.stackprotector parameter #2 must resolve to an alloca.",
&CI);
break;
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
case Intrinsic::invariant_start:
Assert1(isa<ConstantInt>(CI.getOperand(1)),
Assert1(isa<ConstantInt>(CI.getOperand(0)),
"size argument of memory use markers must be a constant integer",
&CI);
break;
case Intrinsic::invariant_end:
Assert1(isa<ConstantInt>(CI.getOperand(2)),
Assert1(isa<ConstantInt>(CI.getOperand(1)),
"llvm.invariant.end parameter #2 must be a constant integer", &CI);
break;
}