//
//===----------------------------------------------------------------------===//
-#include "llvm/BasicBlock.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
cast<InvokeInst>(I)->setDoesNotThrow(doesNotThrow);
}
+bool CallSite::hasArgument(const Value *Arg) const {
+ for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E; ++AI)
+ if (AI->get() == Arg)
+ return true;
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// TerminatorInst Class
//===----------------------------------------------------------------------===//
ReservedSpace(PN.getNumOperands()) {
Use *OL = OperandList;
for (unsigned i = 0, e = PN.getNumOperands(); i != e; i+=2) {
- OL[i].init(PN.getOperand(i), this);
- OL[i+1].init(PN.getOperand(i+1), this);
+ OL[i] = PN.getOperand(i);
+ OL[i+1] = PN.getOperand(i+1);
}
}
PHINode::~PHINode() {
- dropHungoffUses(OperandList);
+ if (OperandList)
+ dropHungoffUses(OperandList);
}
// removeIncomingValue - Remove an incoming value. This is useful if a
Use *OldOps = OperandList;
Use *NewOps = allocHungoffUses(NumOps);
for (unsigned i = 0; i != e; ++i) {
- NewOps[i].init(OldOps[i], this);
+ NewOps[i] = OldOps[i];
}
OperandList = NewOps;
if (OldOps) Use::zap(OldOps, OldOps + e, true);
void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
assert(NumOperands == NumParams+1 && "NumOperands not set up?");
Use *OL = OperandList;
- OL[0].init(Func, this);
+ OL[0] = Func;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
assert((i >= FTy->getNumParams() ||
FTy->getParamType(i) == Params[i]->getType()) &&
"Calling a function with a bad signature!");
- OL[i+1].init(Params[i], this);
+ OL[i+1] = Params[i];
}
}
void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
assert(NumOperands == 3 && "NumOperands not set up?");
Use *OL = OperandList;
- OL[0].init(Func, this);
- OL[1].init(Actual1, this);
- OL[2].init(Actual2, this);
+ OL[0] = Func;
+ OL[1] = Actual1;
+ OL[2] = Actual2;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
void CallInst::init(Value *Func, Value *Actual) {
assert(NumOperands == 2 && "NumOperands not set up?");
Use *OL = OperandList;
- OL[0].init(Func, this);
- OL[1].init(Actual, this);
+ OL[0] = Func;
+ OL[1] = Actual;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
void CallInst::init(Value *Func) {
assert(NumOperands == 1 && "NumOperands not set up?");
Use *OL = OperandList;
- OL[0].init(Func, this);
+ OL[0] = Func;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
Use *OL = OperandList;
Use *InOL = CI.OperandList;
for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
- OL[i].init(InOL[i], this);
+ OL[i] = InOL[i];
+}
+
+void CallInst::addParamAttr(unsigned i, ParameterAttributes attr) {
+ PAListPtr PAL = getParamAttrs();
+ PAL = PAL.addAttr(i, attr);
+ setParamAttrs(PAL);
}
bool CallInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
Value* const *Args, unsigned NumArgs) {
assert(NumOperands == 3+NumArgs && "NumOperands not set up?");
Use *OL = OperandList;
- OL[0].init(Fn, this);
- OL[1].init(IfNormal, this);
- OL[2].init(IfException, this);
+ OL[0] = Fn;
+ OL[1] = IfNormal;
+ OL[2] = IfException;
const FunctionType *FTy =
cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
FTy = FTy; // silence warning.
FTy->getParamType(i) == Args[i]->getType()) &&
"Invoking a function with a bad signature!");
- OL[i+3].init(Args[i], this);
+ OL[i+3] = Args[i];
}
}
SubclassData = II.SubclassData;
Use *OL = OperandList, *InOL = II.OperandList;
for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
- OL[i].init(InOL[i], this);
+ OL[i] = InOL[i];
}
BasicBlock *InvokeInst::getSuccessorV(unsigned idx) const {
return false;
}
+void InvokeInst::addParamAttr(unsigned i, ParameterAttributes attr) {
+ PAListPtr PAL = getParamAttrs();
+ PAL = PAL.addAttr(i, attr);
+ setParamAttrs(PAL);
+}
+
void InvokeInst::setDoesNotThrow(bool doesNotThrow) {
PAListPtr PAL = getParamAttrs();
if (doesNotThrow)
RI.getNumOperands()) {
unsigned N = RI.getNumOperands();
if (N == 1)
- Op<0>().init(RI.Op<0>(), this);
+ Op<0>() = RI.Op<0>();
else if (N) {
Use *OL = OperandList;
for (unsigned i = 0; i < N; ++i)
- OL[i].init(RI.getOperand(i), this);
+ OL[i] = RI.getOperand(i);
}
}
Value *V = *retVals;
if (V->getType() == Type::VoidTy)
return;
- Op<0>().init(V, this);
+ Op<0>() = V;
return;
}
Value *V = *retVals++;
assert(!isa<BasicBlock>(V) &&
"Cannot return basic block. Probably using the incorrect ctor");
- OL[i].init(V, this);
+ OL[i] = V;
}
}
OperandTraits<BranchInst>::op_end(this) - 1,
1, InsertBefore) {
assert(IfTrue != 0 && "Branch destination may not be null!");
- Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
+ Op<0>() = IfTrue;
}
BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Instruction *InsertBefore)
: TerminatorInst(Type::VoidTy, Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 3,
3, InsertBefore) {
- Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
- Op<1>().init(reinterpret_cast<Value*>(IfFalse), this);
- Op<2>().init(Cond, this);
+ Op<0>() = IfTrue;
+ Op<1>() = IfFalse;
+ Op<2>() = Cond;
#ifndef NDEBUG
AssertOK();
#endif
OperandTraits<BranchInst>::op_end(this) - 1,
1, InsertAtEnd) {
assert(IfTrue != 0 && "Branch destination may not be null!");
- Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
+ Op<0>() = IfTrue;
}
BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
: TerminatorInst(Type::VoidTy, Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 3,
3, InsertAtEnd) {
- Op<0>().init(reinterpret_cast<Value*>(IfTrue), this);
- Op<1>().init(reinterpret_cast<Value*>(IfFalse), this);
- Op<2>().init(Cond, this);
+ Op<0>() = IfTrue;
+ Op<1>() = IfFalse;
+ Op<2>() = Cond;
#ifndef NDEBUG
AssertOK();
#endif
TerminatorInst(Type::VoidTy, Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(),
BI.getNumOperands()) {
- OperandList[0].init(BI.getOperand(0), this);
+ OperandList[0] = BI.getOperand(0);
if (BI.getNumOperands() != 1) {
assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!");
- OperandList[1].init(BI.getOperand(1), this);
- OperandList[2].init(BI.getOperand(2), this);
+ OperandList[1] = BI.getOperand(1);
+ OperandList[2] = BI.getOperand(2);
}
}
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertBefore) {
- Op<0>().init(val, this);
- Op<1>().init(addr, this);
+ Op<0>() = val;
+ Op<1>() = addr;
setVolatile(false);
setAlignment(0);
AssertOK();
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertAtEnd) {
- Op<0>().init(val, this);
- Op<1>().init(addr, this);
+ Op<0>() = val;
+ Op<1>() = addr;
setVolatile(false);
setAlignment(0);
AssertOK();
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertBefore) {
- Op<0>().init(val, this);
- Op<1>().init(addr, this);
+ Op<0>() = val;
+ Op<1>() = addr;
setVolatile(isVolatile);
setAlignment(0);
AssertOK();
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertBefore) {
- Op<0>().init(val, this);
- Op<1>().init(addr, this);
+ Op<0>() = val;
+ Op<1>() = addr;
setVolatile(isVolatile);
setAlignment(Align);
AssertOK();
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertAtEnd) {
- Op<0>().init(val, this);
- Op<1>().init(addr, this);
+ Op<0>() = val;
+ Op<1>() = addr;
setVolatile(isVolatile);
setAlignment(Align);
AssertOK();
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this),
InsertAtEnd) {
- Op<0>().init(val, this);
- Op<1>().init(addr, this);
+ Op<0>() = val;
+ Op<1>() = addr;
setVolatile(isVolatile);
setAlignment(0);
AssertOK();
return cast<PointerType>(Val->getType())->getAddressSpace();
}
-void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
+void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
+ const std::string &Name) {
assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
Use *OL = OperandList;
- OL[0].init(Ptr, this);
+ OL[0] = Ptr;
for (unsigned i = 0; i != NumIdx; ++i)
- OL[i+1].init(Idx[i], this);
+ OL[i+1] = Idx[i];
+
+ setName(Name);
}
-void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
+void GetElementPtrInst::init(Value *Ptr, Value *Idx, const std::string &Name) {
assert(NumOperands == 2 && "NumOperands not initialized?");
Use *OL = OperandList;
- OL[0].init(Ptr, this);
- OL[1].init(Idx, this);
+ OL[0] = Ptr;
+ OL[1] = Idx;
+
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
- : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
+ : Instruction(GEPI.getType(), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this)
- GEPI.getNumOperands(),
GEPI.getNumOperands()) {
Use *OL = OperandList;
Use *GEPIOL = GEPI.OperandList;
for (unsigned i = 0, E = NumOperands; i != E; ++i)
- OL[i].init(GEPIOL[i], this);
+ OL[i] = GEPIOL[i];
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - 2,
2, InBe) {
- init(Ptr, Idx);
- setName(Name);
+ init(Ptr, Idx, Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - 2,
2, IAE) {
- init(Ptr, Idx);
- setName(Name);
+ init(Ptr, Idx, Name);
}
// getIndexedType - Returns the type of the element that would be loaded with
if (NumIdx == 0)
return Agg;
- return ExtractValueInst::getIndexedType(Agg, Idxs+1, Idxs+NumIdx);
+ unsigned CurIdx = 1;
+ for (; CurIdx != NumIdx; ++CurIdx) {
+ const CompositeType *CT = dyn_cast<CompositeType>(Agg);
+ if (!CT || isa<PointerType>(CT)) return 0;
+ Value *Index = Idxs[CurIdx];
+ if (!CT->indexValid(Index)) return 0;
+ Agg = CT->getTypeAtIndex(Index);
+
+ // If the new type forwards to another type, then it is in the middle
+ // of being refined to another type (and hence, may have dropped all
+ // references to what it was using before). So, use the new forwarded
+ // type.
+ if (const Type *Ty = Agg->getForwardedType())
+ Agg = Ty;
+ }
+ return CurIdx == NumIdx ? Agg : 0;
}
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
2, InsertBef) {
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
- Op<0>().init(Val, this);
- Op<1>().init(Index, this);
+ Op<0>() = Val;
+ Op<1>() = Index;
setName(Name);
}
Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
- Op<0>().init(Val, this);
- Op<1>().init(Index, this);
+ Op<0>() = Val;
+ Op<1>() = Index;
setName(Name);
}
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
- Op<0>().init(Val, this);
- Op<1>().init(Index, this);
+ Op<0>() = Val;
+ Op<1>() = Index;
setName(Name);
}
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
- Op<0>().init(Val, this);
- Op<1>().init(Index, this);
+ Op<0>() = Val;
+ Op<1>() = Index;
setName(Name);
}
InsertElementInst::InsertElementInst(const InsertElementInst &IE)
: Instruction(IE.getType(), InsertElement,
OperandTraits<InsertElementInst>::op_begin(this), 3) {
- Op<0>().init(IE.Op<0>(), this);
- Op<1>().init(IE.Op<1>(), this);
- Op<2>().init(IE.Op<2>(), this);
+ Op<0>() = IE.Op<0>();
+ Op<1>() = IE.Op<1>();
+ Op<2>() = IE.Op<2>();
}
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
3, InsertBef) {
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
- Op<0>().init(Vec, this);
- Op<1>().init(Elt, this);
- Op<2>().init(Index, this);
+ Op<0>() = Vec;
+ Op<1>() = Elt;
+ Op<2>() = Index;
setName(Name);
}
Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
- Op<0>().init(Vec, this);
- Op<1>().init(Elt, this);
- Op<2>().init(Index, this);
+ Op<0>() = Vec;
+ Op<1>() = Elt;
+ Op<2>() = Index;
setName(Name);
}
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
- Op<0>().init(Vec, this);
- Op<1>().init(Elt, this);
- Op<2>().init(Index, this);
+ Op<0>() = Vec;
+ Op<1>() = Elt;
+ Op<2>() = Index;
setName(Name);
}
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
- Op<0>().init(Vec, this);
- Op<1>().init(Elt, this);
- Op<2>().init(Index, this);
+ Op<0>() = Vec;
+ Op<1>() = Elt;
+ Op<2>() = Index;
setName(Name);
}
: Instruction(SV.getType(), ShuffleVector,
OperandTraits<ShuffleVectorInst>::op_begin(this),
OperandTraits<ShuffleVectorInst>::operands(this)) {
- Op<0>().init(SV.Op<0>(), this);
- Op<1>().init(SV.Op<1>(), this);
- Op<2>().init(SV.Op<2>(), this);
+ Op<0>() = SV.Op<0>();
+ Op<1>() = SV.Op<1>();
+ Op<2>() = SV.Op<2>();
}
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
InsertBefore) {
assert(isValidOperands(V1, V2, Mask) &&
"Invalid shuffle vector instruction operands!");
- Op<0>().init(V1, this);
- Op<1>().init(V2, this);
- Op<2>().init(Mask, this);
+ Op<0>() = V1;
+ Op<1>() = V2;
+ Op<2>() = Mask;
setName(Name);
}
assert(isValidOperands(V1, V2, Mask) &&
"Invalid shuffle vector instruction operands!");
- Op<0>().init(V1, this);
- Op<1>().init(V2, this);
- Op<2>().init(Mask, this);
+ Op<0>() = V1;
+ Op<1>() = V2;
+ Op<2>() = Mask;
setName(Name);
}
return cast<ConstantInt>(MaskCV->getOperand(i))->getZExtValue();
}
+//===----------------------------------------------------------------------===//
+// InsertValueInst Class
+//===----------------------------------------------------------------------===//
+
+void InsertValueInst::init(Value *Agg, Value *Val, const unsigned *Idx,
+ unsigned NumIdx, const std::string &Name) {
+ assert(NumOperands == 2 && "NumOperands not initialized?");
+ Op<0>() = Agg;
+ Op<1>() = Val;
+
+ Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+ setName(Name);
+}
+
+void InsertValueInst::init(Value *Agg, Value *Val, unsigned Idx,
+ const std::string &Name) {
+ assert(NumOperands == 2 && "NumOperands not initialized?");
+ Op<0>() = Agg;
+ Op<1>() = Val;
+
+ Indices.push_back(Idx);
+ setName(Name);
+}
+
+InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
+ : Instruction(IVI.getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this), 2),
+ Indices(IVI.Indices) {
+ Op<0>() = IVI.getOperand(0);
+ Op<1>() = IVI.getOperand(1);
+}
+
+InsertValueInst::InsertValueInst(Value *Agg,
+ Value *Val,
+ unsigned Idx,
+ const std::string &Name,
+ Instruction *InsertBefore)
+ : Instruction(Agg->getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this),
+ 2, InsertBefore) {
+ init(Agg, Val, Idx, Name);
+}
+
+InsertValueInst::InsertValueInst(Value *Agg,
+ Value *Val,
+ unsigned Idx,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd)
+ : Instruction(Agg->getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this),
+ 2, InsertAtEnd) {
+ init(Agg, Val, Idx, Name);
+}
+
//===----------------------------------------------------------------------===//
// ExtractValueInst Class
//===----------------------------------------------------------------------===//
+void ExtractValueInst::init(const unsigned *Idx, unsigned NumIdx,
+ const std::string &Name) {
+ assert(NumOperands == 1 && "NumOperands not initialized?");
+
+ Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+ setName(Name);
+}
+
+void ExtractValueInst::init(unsigned Idx, const std::string &Name) {
+ assert(NumOperands == 1 && "NumOperands not initialized?");
+
+ Indices.push_back(Idx);
+ setName(Name);
+}
+
+ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
+ : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
+ Indices(EVI.Indices) {
+}
+
// getIndexedType - Returns the type of the element that would be extracted
// with an extractvalue instruction with the specified parameters.
//
// pointer type.
//
const Type* ExtractValueInst::getIndexedType(const Type *Agg,
- Value* const *Idxs,
+ const unsigned *Idxs,
unsigned NumIdx) {
unsigned CurIdx = 0;
for (; CurIdx != NumIdx; ++CurIdx) {
const CompositeType *CT = dyn_cast<CompositeType>(Agg);
- if (!CT) return 0;
- Value *Index = Idxs[CurIdx];
+ if (!CT || isa<PointerType>(CT) || isa<VectorType>(CT)) return 0;
+ unsigned Index = Idxs[CurIdx];
if (!CT->indexValid(Index)) return 0;
Agg = CT->getTypeAtIndex(Index);
return CurIdx == NumIdx ? Agg : 0;
}
+const Type* ExtractValueInst::getIndexedType(const Type *Agg,
+ unsigned Idx) {
+ return getIndexedType(Agg, &Idx, 1);
+}
+
+ExtractValueInst::ExtractValueInst(Value *Agg,
+ unsigned Idx,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd)
+ : UnaryInstruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)),
+ ExtractValue, Agg, InsertAtEnd) {
+ init(Idx, Name);
+}
+
+ExtractValueInst::ExtractValueInst(Value *Agg,
+ unsigned Idx,
+ const std::string &Name,
+ Instruction *InsertBefore)
+ : UnaryInstruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)),
+ ExtractValue, Agg, InsertBefore) {
+ init(Idx, Name);
+}
+
//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//
OperandTraits<BinaryOperator>::op_begin(this),
OperandTraits<BinaryOperator>::operands(this),
InsertBefore) {
- Op<0>().init(S1, this);
- Op<1>().init(S2, this);
+ Op<0>() = S1;
+ Op<1>() = S2;
init(iType);
setName(Name);
}
OperandTraits<BinaryOperator>::op_begin(this),
OperandTraits<BinaryOperator>::operands(this),
InsertAtEnd) {
- Op<0>().init(S1, this);
- Op<1>().init(S2, this);
+ Op<0>() = S1;
+ Op<1>() = S2;
init(iType);
setName(Name);
}
#endif
}
-BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
+BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
const std::string &Name,
Instruction *InsertBefore) {
assert(S1->getType() == S2->getType() &&
return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
}
-BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
+BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
const std::string &Name,
BasicBlock *InsertAtEnd) {
- BinaryOperator *Res = create(Op, S1, S2, Name);
+ BinaryOperator *Res = Create(Op, S1, S2, Name);
InsertAtEnd->getInstList().push_back(Res);
return Res;
}
-BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const std::string &Name,
Instruction *InsertBefore) {
Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
return new BinaryOperator(Instruction::Sub,
Op->getType(), Name, InsertBefore);
}
-BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const std::string &Name,
BasicBlock *InsertAtEnd) {
Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
return new BinaryOperator(Instruction::Sub,
Op->getType(), Name, InsertAtEnd);
}
-BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
Instruction *InsertBefore) {
Constant *C;
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
Op->getType(), Name, InsertBefore);
}
-BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
BasicBlock *InsertAtEnd) {
Constant *AllOnes;
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
return 0;
}
-CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty,
+CastInst *CastInst::Create(Instruction::CastOps op, Value *S, const Type *Ty,
const std::string &Name, Instruction *InsertBefore) {
// Construct and return the appropriate CastInst subclass
switch (op) {
return 0;
}
-CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty,
+CastInst *CastInst::Create(Instruction::CastOps op, Value *S, const Type *Ty,
const std::string &Name, BasicBlock *InsertAtEnd) {
// Construct and return the appropriate CastInst subclass
switch (op) {
return 0;
}
-CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateZExtOrBitCast(Value *S, const Type *Ty,
const std::string &Name,
Instruction *InsertBefore) {
if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
- return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return create(Instruction::ZExt, S, Ty, Name, InsertBefore);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateZExtOrBitCast(Value *S, const Type *Ty,
const std::string &Name,
BasicBlock *InsertAtEnd) {
if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
- return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
- return create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
}
-CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateSExtOrBitCast(Value *S, const Type *Ty,
const std::string &Name,
Instruction *InsertBefore) {
if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
- return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return create(Instruction::SExt, S, Ty, Name, InsertBefore);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateSExtOrBitCast(Value *S, const Type *Ty,
const std::string &Name,
BasicBlock *InsertAtEnd) {
if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
- return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
- return create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
}
-CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateTruncOrBitCast(Value *S, const Type *Ty,
const std::string &Name,
Instruction *InsertBefore) {
if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
- return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return create(Instruction::Trunc, S, Ty, Name, InsertBefore);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreateTruncOrBitCast(Value *S, const Type *Ty,
const std::string &Name,
BasicBlock *InsertAtEnd) {
if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
- return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
- return create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
}
-CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreatePointerCast(Value *S, const Type *Ty,
const std::string &Name,
BasicBlock *InsertAtEnd) {
assert(isa<PointerType>(S->getType()) && "Invalid cast");
"Invalid cast");
if (Ty->isInteger())
- return create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
- return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
}
/// @brief Create a BitCast or a PtrToInt cast instruction
-CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
+CastInst *CastInst::CreatePointerCast(Value *S, const Type *Ty,
const std::string &Name,
Instruction *InsertBefore) {
assert(isa<PointerType>(S->getType()) && "Invalid cast");
"Invalid cast");
if (Ty->isInteger())
- return create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
- return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty,
+CastInst *CastInst::CreateIntegerCast(Value *C, const Type *Ty,
bool isSigned, const std::string &Name,
Instruction *InsertBefore) {
assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast");
(SrcBits == DstBits ? Instruction::BitCast :
(SrcBits > DstBits ? Instruction::Trunc :
(isSigned ? Instruction::SExt : Instruction::ZExt)));
- return create(opcode, C, Ty, Name, InsertBefore);
+ return Create(opcode, C, Ty, Name, InsertBefore);
}
-CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty,
+CastInst *CastInst::CreateIntegerCast(Value *C, const Type *Ty,
bool isSigned, const std::string &Name,
BasicBlock *InsertAtEnd) {
assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast");
(SrcBits == DstBits ? Instruction::BitCast :
(SrcBits > DstBits ? Instruction::Trunc :
(isSigned ? Instruction::SExt : Instruction::ZExt)));
- return create(opcode, C, Ty, Name, InsertAtEnd);
+ return Create(opcode, C, Ty, Name, InsertAtEnd);
}
-CastInst *CastInst::createFPCast(Value *C, const Type *Ty,
+CastInst *CastInst::CreateFPCast(Value *C, const Type *Ty,
const std::string &Name,
Instruction *InsertBefore) {
assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() &&
Instruction::CastOps opcode =
(SrcBits == DstBits ? Instruction::BitCast :
(SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
- return create(opcode, C, Ty, Name, InsertBefore);
+ return Create(opcode, C, Ty, Name, InsertBefore);
}
-CastInst *CastInst::createFPCast(Value *C, const Type *Ty,
+CastInst *CastInst::CreateFPCast(Value *C, const Type *Ty,
const std::string &Name,
BasicBlock *InsertAtEnd) {
assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() &&
Instruction::CastOps opcode =
(SrcBits == DstBits ? Instruction::BitCast :
(SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
- return create(opcode, C, Ty, Name, InsertAtEnd);
+ return Create(opcode, C, Ty, Name, InsertAtEnd);
}
// Check whether it is valid to call getCastOpcode for these types.
OperandTraits<CmpInst>::op_begin(this),
OperandTraits<CmpInst>::operands(this),
InsertBefore) {
- Op<0>().init(LHS, this);
- Op<1>().init(RHS, this);
+ Op<0>() = LHS;
+ Op<1>() = RHS;
SubclassData = predicate;
setName(Name);
}
OperandTraits<CmpInst>::op_begin(this),
OperandTraits<CmpInst>::operands(this),
InsertAtEnd) {
- Op<0>().init(LHS, this);
- Op<1>().init(RHS, this);
+ Op<0>() = LHS;
+ Op<1>() = RHS;
SubclassData = predicate;
setName(Name);
}
CmpInst *
-CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
+CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
const std::string &Name, Instruction *InsertBefore) {
if (Op == Instruction::ICmp) {
return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
}
CmpInst *
-CmpInst::create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
+CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
const std::string &Name, BasicBlock *InsertAtEnd) {
if (Op == Instruction::ICmp) {
return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
}
-ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {
+CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
switch (pred) {
- default:
- assert(!"Unknown icmp predicate!");
+ default: assert(!"Unknown cmp predicate!");
case ICMP_EQ: return ICMP_NE;
case ICMP_NE: return ICMP_EQ;
case ICMP_UGT: return ICMP_ULE;
case ICMP_SLT: return ICMP_SGE;
case ICMP_SGE: return ICMP_SLT;
case ICMP_SLE: return ICMP_SGT;
- }
-}
-ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) {
- switch (pred) {
- default: assert(! "Unknown icmp predicate!");
- case ICMP_EQ: case ICMP_NE:
- return pred;
- case ICMP_SGT: return ICMP_SLT;
- case ICMP_SLT: return ICMP_SGT;
- case ICMP_SGE: return ICMP_SLE;
- case ICMP_SLE: return ICMP_SGE;
- case ICMP_UGT: return ICMP_ULT;
- case ICMP_ULT: return ICMP_UGT;
- case ICMP_UGE: return ICMP_ULE;
- case ICMP_ULE: return ICMP_UGE;
+ case FCMP_OEQ: return FCMP_UNE;
+ case FCMP_ONE: return FCMP_UEQ;
+ case FCMP_OGT: return FCMP_ULE;
+ case FCMP_OLT: return FCMP_UGE;
+ case FCMP_OGE: return FCMP_ULT;
+ case FCMP_OLE: return FCMP_UGT;
+ case FCMP_UEQ: return FCMP_ONE;
+ case FCMP_UNE: return FCMP_OEQ;
+ case FCMP_UGT: return FCMP_OLE;
+ case FCMP_ULT: return FCMP_OGE;
+ case FCMP_UGE: return FCMP_OLT;
+ case FCMP_ULE: return FCMP_OGT;
+ case FCMP_ORD: return FCMP_UNO;
+ case FCMP_UNO: return FCMP_ORD;
+ case FCMP_TRUE: return FCMP_FALSE;
+ case FCMP_FALSE: return FCMP_TRUE;
}
}
return ConstantRange(Lower, Upper);
}
-FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {
+CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
- default:
- assert(!"Unknown icmp predicate!");
- case FCMP_OEQ: return FCMP_UNE;
- case FCMP_ONE: return FCMP_UEQ;
- case FCMP_OGT: return FCMP_ULE;
- case FCMP_OLT: return FCMP_UGE;
- case FCMP_OGE: return FCMP_ULT;
- case FCMP_OLE: return FCMP_UGT;
- case FCMP_UEQ: return FCMP_ONE;
- case FCMP_UNE: return FCMP_OEQ;
- case FCMP_UGT: return FCMP_OLE;
- case FCMP_ULT: return FCMP_OGE;
- case FCMP_UGE: return FCMP_OLT;
- case FCMP_ULE: return FCMP_OGT;
- case FCMP_ORD: return FCMP_UNO;
- case FCMP_UNO: return FCMP_ORD;
- case FCMP_TRUE: return FCMP_FALSE;
- case FCMP_FALSE: return FCMP_TRUE;
- }
-}
-
-FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) {
- switch (pred) {
- default: assert(!"Unknown fcmp predicate!");
+ default: assert(!"Unknown cmp predicate!");
+ case ICMP_EQ: case ICMP_NE:
+ return pred;
+ case ICMP_SGT: return ICMP_SLT;
+ case ICMP_SLT: return ICMP_SGT;
+ case ICMP_SGE: return ICMP_SLE;
+ case ICMP_SLE: return ICMP_SGE;
+ case ICMP_UGT: return ICMP_ULT;
+ case ICMP_ULT: return ICMP_UGT;
+ case ICMP_UGE: return ICMP_ULE;
+ case ICMP_ULE: return ICMP_UGE;
+
case FCMP_FALSE: case FCMP_TRUE:
case FCMP_OEQ: case FCMP_ONE:
case FCMP_UEQ: case FCMP_UNE:
NumOperands = 2;
OperandList = allocHungoffUses(ReservedSpace);
- OperandList[0].init(Value, this);
- OperandList[1].init(Default, this);
+ OperandList[0] = Value;
+ OperandList[1] = Default;
}
/// SwitchInst ctor - Create a new switch instruction, specifying a value to
allocHungoffUses(SI.getNumOperands()), SI.getNumOperands()) {
Use *OL = OperandList, *InOL = SI.OperandList;
for (unsigned i = 0, E = SI.getNumOperands(); i != E; i+=2) {
- OL[i].init(InOL[i], this);
- OL[i+1].init(InOL[i+1], this);
+ OL[i] = InOL[i];
+ OL[i+1] = InOL[i+1];
}
}
// Initialize some new operands.
assert(OpNo+1 < ReservedSpace && "Growing didn't work!");
NumOperands = OpNo+2;
- OperandList[OpNo].init(OnVal, this);
- OperandList[OpNo+1].init(Dest, this);
+ OperandList[OpNo] = OnVal;
+ OperandList[OpNo+1] = Dest;
}
/// removeCase - This method removes the specified successor from the switch
Use *NewOps = allocHungoffUses(NumOps);
Use *OldOps = OperandList;
for (unsigned i = 0; i != e; ++i) {
- NewOps[i].init(OldOps[i], this);
+ NewOps[i] = OldOps[i];
}
OperandList = NewOps;
if (OldOps) Use::zap(OldOps, OldOps + e, true);
}
BinaryOperator *BinaryOperator::clone() const {
- return create(getOpcode(), Op<0>(), Op<1>());
+ return Create(getOpcode(), Op<0>(), Op<1>());
}
FCmpInst* FCmpInst::clone() const {
return new VICmpInst(getPredicate(), Op<0>(), Op<1>());
}
+ExtractValueInst *ExtractValueInst::clone() const {
+ return new ExtractValueInst(*this);
+}
+InsertValueInst *InsertValueInst::clone() const {
+ return new InsertValueInst(*this);
+}
+
+
MallocInst *MallocInst::clone() const { return new MallocInst(*this); }
AllocaInst *AllocaInst::clone() const { return new AllocaInst(*this); }
FreeInst *FreeInst::clone() const { return new FreeInst(getOperand(0)); }