summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/VMCore/Instructions.cpp')
-rw-r--r--contrib/llvm/lib/VMCore/Instructions.cpp65
1 files changed, 40 insertions, 25 deletions
diff --git a/contrib/llvm/lib/VMCore/Instructions.cpp b/contrib/llvm/lib/VMCore/Instructions.cpp
index f64b220..c13696f 100644
--- a/contrib/llvm/lib/VMCore/Instructions.cpp
+++ b/contrib/llvm/lib/VMCore/Instructions.cpp
@@ -33,7 +33,9 @@ using namespace llvm;
User::op_iterator CallSite::getCallee() const {
Instruction *II(getInstruction());
return isCall()
- ? cast<CallInst>(II)->op_begin()
+ ? (CallInst::ArgOffset
+ ? cast</*FIXME: CallInst*/User>(II)->op_begin()
+ : cast</*FIXME: CallInst*/User>(II)->op_end() - 1)
: cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Function
}
@@ -231,8 +233,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<ArgOffset -1>() = Func;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@@ -245,16 +246,15 @@ void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
assert((i >= FTy->getNumParams() ||
FTy->getParamType(i) == Params[i]->getType()) &&
"Calling a function with a bad signature!");
- OL[i+1] = Params[i];
+ OperandList[i + ArgOffset] = 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<ArgOffset -1>() = Func;
+ Op<ArgOffset + 0>() = Actual1;
+ Op<ArgOffset + 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<ArgOffset -1>() = Func;
+ Op<ArgOffset + 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<ArgOffset -1>() = Func;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
@@ -473,9 +471,10 @@ static Instruction *createMalloc(Instruction *InsertBefore,
Instruction *CallInst::CreateMalloc(Instruction *InsertBefore,
const Type *IntPtrTy, const Type *AllocTy,
Value *AllocSize, Value *ArraySize,
+ Function * MallocF,
const Twine &Name) {
return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, AllocSize,
- ArraySize, NULL, Name);
+ ArraySize, MallocF, Name);
}
/// CreateMalloc - Generate the IR for a call to malloc:
@@ -527,8 +526,8 @@ static Instruction* createFree(Value* Source, Instruction *InsertBefore,
}
/// CreateFree - Generate the IR for a call to the builtin free function.
-void CallInst::CreateFree(Value* Source, Instruction *InsertBefore) {
- createFree(Source, InsertBefore, NULL);
+Instruction * CallInst::CreateFree(Value* Source, Instruction *InsertBefore) {
+ return createFree(Source, InsertBefore, NULL);
}
/// CreateFree - Generate the IR for a call to the builtin free function.
@@ -828,8 +827,8 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
else {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
- assert(Amt->getType()->isIntegerTy(32) &&
- "Allocation array size is not a 32-bit integer!");
+ assert(Amt->getType()->isIntegerTy() &&
+ "Allocation array size is not an integer!");
}
return Amt;
}
@@ -1456,7 +1455,7 @@ void InsertValueInst::init(Value *Agg, Value *Val, const unsigned *Idx,
Op<0>() = Agg;
Op<1>() = Val;
- Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+ Indices.append(Idx, Idx + NumIdx);
setName(Name);
}
@@ -1509,7 +1508,7 @@ void ExtractValueInst::init(const unsigned *Idx, unsigned NumIdx,
const Twine &Name) {
assert(NumOperands == 1 && "NumOperands not initialized?");
- Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+ Indices.append(Idx, Idx + NumIdx);
setName(Name);
}
@@ -1911,9 +1910,12 @@ bool CastInst::isLosslessCast() const {
/// # bitcast i32* %x to i8*
/// # bitcast <2 x i32> %x to <4 x i16>
/// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only
-/// @brief Determine if a cast is a no-op.
-bool CastInst::isNoopCast(const Type *IntPtrTy) const {
- switch (getOpcode()) {
+/// @brief Determine if the described cast is a no-op.
+bool CastInst::isNoopCast(Instruction::CastOps Opcode,
+ const Type *SrcTy,
+ const Type *DestTy,
+ const Type *IntPtrTy) {
+ switch (Opcode) {
default:
assert(!"Invalid CastOp");
case Instruction::Trunc:
@@ -1930,13 +1932,18 @@ bool CastInst::isNoopCast(const Type *IntPtrTy) const {
return true; // BitCast never modifies bits.
case Instruction::PtrToInt:
return IntPtrTy->getScalarSizeInBits() ==
- getType()->getScalarSizeInBits();
+ DestTy->getScalarSizeInBits();
case Instruction::IntToPtr:
return IntPtrTy->getScalarSizeInBits() ==
- getOperand(0)->getType()->getScalarSizeInBits();
+ SrcTy->getScalarSizeInBits();
}
}
+/// @brief Determine if a cast is a no-op.
+bool CastInst::isNoopCast(const Type *IntPtrTy) const {
+ return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy);
+}
+
/// This function determines if a pair of casts can be eliminated and what
/// opcode should be used in the elimination. This assumes that there are two
/// instructions like this:
@@ -1999,6 +2006,14 @@ unsigned CastInst::isEliminableCastPair(
{ 99,99,99,99,99,99,99,99,99,13,99,12 }, // IntToPtr |
{ 5, 5, 5, 6, 6, 5, 5, 6, 6,11, 5, 1 }, // BitCast -+
};
+
+ // If either of the casts are a bitcast from scalar to vector, disallow the
+ // merging.
+ if ((firstOp == Instruction::BitCast &&
+ isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
+ (secondOp == Instruction::BitCast &&
+ isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
+ return 0; // Disallowed
int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
[secondOp-Instruction::CastOpsBegin];
OpenPOWER on IntegriCloud