Refactor the setName stuff, moving it down the inheritance hierarchy, to
solve a crash in -instcombine -debug that was hit while investigating PR1217
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34544 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index 2a740fc..feff59d 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -19,7 +19,7 @@
using namespace llvm;
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const std::string &Name, Instruction *InsertBefore)
+ Instruction *InsertBefore)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
// Make sure that we get added to a basicblock
LeakDetector::addGarbageObject(this);
@@ -30,11 +30,10 @@
"Instruction to insert before is not in a basic block!");
InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
}
- setName(Name);
}
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const std::string &Name, BasicBlock *InsertAtEnd)
+ BasicBlock *InsertAtEnd)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
// Make sure that we get added to a basicblock
LeakDetector::addGarbageObject(this);
@@ -42,34 +41,6 @@
// append this instruction into the basic block
assert(InsertAtEnd && "Basic block to append to may not be NULL!");
InsertAtEnd->getInstList().push_back(this);
- setName(Name);
-}
-
-Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const char *Name, Instruction *InsertBefore)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
- // Make sure that we get added to a basicblock
- LeakDetector::addGarbageObject(this);
-
- // If requested, insert this instruction into a basic block...
- if (InsertBefore) {
- assert(InsertBefore->getParent() &&
- "Instruction to insert before is not in a basic block!");
- InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
- }
- if (Name && *Name) setName(Name);
-}
-
-Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const char *Name, BasicBlock *InsertAtEnd)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
- // Make sure that we get added to a basicblock
- LeakDetector::addGarbageObject(this);
-
- // append this instruction into the basic block
- assert(InsertAtEnd && "Basic block to append to may not be NULL!");
- InsertAtEnd->getInstList().push_back(this);
- if (Name && *Name) setName(Name);
}
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 39fbb3a..e1af531 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -40,16 +40,6 @@
// TerminatorInst Class
//===----------------------------------------------------------------------===//
-TerminatorInst::TerminatorInst(Instruction::TermOps iType,
- Use *Ops, unsigned NumOps, Instruction *IB)
- : Instruction(Type::VoidTy, iType, Ops, NumOps, "", IB) {
-}
-
-TerminatorInst::TerminatorInst(Instruction::TermOps iType,
- Use *Ops, unsigned NumOps, BasicBlock *IAE)
- : Instruction(Type::VoidTy, iType, Ops, NumOps, "", IAE) {
-}
-
// Out of line virtual method, so the vtable, etc has a home.
TerminatorInst::~TerminatorInst() {
}
@@ -272,63 +262,71 @@
const std::string &Name, BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertAtEnd) {
+ Instruction::Call, 0, 0, InsertAtEnd) {
init(Func, Args, NumArgs);
+ setName(Name);
}
CallInst::CallInst(Value *Func, Value* const *Args, unsigned NumArgs,
const std::string &Name, Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertBefore) {
+ Instruction::Call, 0, 0, InsertBefore) {
init(Func, Args, NumArgs);
+ setName(Name);
}
CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2,
const std::string &Name, Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertBefore) {
+ Instruction::Call, 0, 0, InsertBefore) {
init(Func, Actual1, Actual2);
+ setName(Name);
}
CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2,
const std::string &Name, BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertAtEnd) {
+ Instruction::Call, 0, 0, InsertAtEnd) {
init(Func, Actual1, Actual2);
+ setName(Name);
}
CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name,
- Instruction *InsertBefore)
+ Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertBefore) {
+ Instruction::Call, 0, 0, InsertBefore) {
init(Func, Actual);
+ setName(Name);
}
CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name,
BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertAtEnd) {
+ Instruction::Call, 0, 0, InsertAtEnd) {
init(Func, Actual);
+ setName(Name);
}
CallInst::CallInst(Value *Func, const std::string &Name,
Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertBefore) {
+ Instruction::Call, 0, 0, InsertBefore) {
init(Func);
+ setName(Name);
}
CallInst::CallInst(Value *Func, const std::string &Name,
BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertAtEnd) {
+ Instruction::Call, 0, 0, InsertAtEnd) {
init(Func);
+ setName(Name);
}
CallInst::CallInst(const CallInst &CI)
@@ -380,8 +378,9 @@
const std::string &Name, Instruction *InsertBefore)
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
->getElementType())->getReturnType(),
- Instruction::Invoke, 0, 0, Name, InsertBefore) {
+ Instruction::Invoke, 0, 0, InsertBefore) {
init(Fn, IfNormal, IfException, Args, NumArgs);
+ setName(Name);
}
InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
@@ -390,8 +389,9 @@
const std::string &Name, BasicBlock *InsertAtEnd)
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
->getElementType())->getReturnType(),
- Instruction::Invoke, 0, 0, Name, InsertAtEnd) {
+ Instruction::Invoke, 0, 0, InsertAtEnd) {
init(Fn, IfNormal, IfException, Args, NumArgs);
+ setName(Name);
}
InvokeInst::InvokeInst(const InvokeInst &II)
@@ -418,6 +418,27 @@
// ReturnInst Implementation
//===----------------------------------------------------------------------===//
+ReturnInst::ReturnInst(const ReturnInst &RI)
+ : TerminatorInst(Type::VoidTy, Instruction::Ret,
+ &RetVal, RI.getNumOperands()) {
+ if (RI.getNumOperands())
+ RetVal.init(RI.RetVal, this);
+}
+
+ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore)
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertBefore) {
+ init(retVal);
+}
+ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) {
+ init(retVal);
+}
+ReturnInst::ReturnInst(BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) {
+}
+
+
+
void ReturnInst::init(Value *retVal) {
if (retVal && retVal->getType() != Type::VoidTy) {
assert(!isa<BasicBlock>(retVal) &&
@@ -448,6 +469,14 @@
// UnwindInst Implementation
//===----------------------------------------------------------------------===//
+UnwindInst::UnwindInst(Instruction *InsertBefore)
+ : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertBefore) {
+}
+UnwindInst::UnwindInst(BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertAtEnd) {
+}
+
+
unsigned UnwindInst::getNumSuccessorsV() const {
return getNumSuccessors();
}
@@ -466,6 +495,13 @@
// UnreachableInst Implementation
//===----------------------------------------------------------------------===//
+UnreachableInst::UnreachableInst(Instruction *InsertBefore)
+ : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertBefore) {
+}
+UnreachableInst::UnreachableInst(BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertAtEnd) {
+}
+
unsigned UnreachableInst::getNumSuccessorsV() const {
return getNumSuccessors();
}
@@ -490,8 +526,42 @@
"May only branch on boolean predicates!");
}
+BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
+ : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 1, InsertBefore) {
+ assert(IfTrue != 0 && "Branch destination may not be null!");
+ Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
+}
+BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
+ Instruction *InsertBefore)
+: TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 3, InsertBefore) {
+ Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
+ Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
+ Ops[2].init(Cond, this);
+#ifndef NDEBUG
+ AssertOK();
+#endif
+}
+
+BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 1, InsertAtEnd) {
+ assert(IfTrue != 0 && "Branch destination may not be null!");
+ Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
+}
+
+BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
+ BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Br, Ops, 3, InsertAtEnd) {
+ Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
+ Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
+ Ops[2].init(Cond, this);
+#ifndef NDEBUG
+ AssertOK();
+#endif
+}
+
+
BranchInst::BranchInst(const BranchInst &BI) :
- TerminatorInst(Instruction::Br, Ops, BI.getNumOperands()) {
+ TerminatorInst(Type::VoidTy, Instruction::Br, Ops, BI.getNumOperands()) {
OperandList[0].init(BI.getOperand(0), this);
if (BI.getNumOperands() != 1) {
assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!");
@@ -531,7 +601,7 @@
unsigned Align, const std::string &Name,
Instruction *InsertBefore)
: UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize),
- 0, InsertBefore), Alignment(Align) {
+ InsertBefore), Alignment(Align) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name);
@@ -541,7 +611,7 @@
unsigned Align, const std::string &Name,
BasicBlock *InsertAtEnd)
: UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize),
- 0, InsertAtEnd), Alignment(Align) {
+ InsertAtEnd), Alignment(Align) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name);
@@ -581,12 +651,12 @@
}
FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
- : UnaryInstruction(Type::VoidTy, Free, Ptr, 0, InsertBefore) {
+ : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertBefore) {
AssertOK();
}
FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd)
- : UnaryInstruction(Type::VoidTy, Free, Ptr, 0, InsertAtEnd) {
+ : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertAtEnd) {
AssertOK();
}
@@ -602,7 +672,7 @@
LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, 0, InsertBef) {
+ Load, Ptr, InsertBef) {
setVolatile(false);
AssertOK();
setName(Name);
@@ -610,7 +680,7 @@
LoadInst::LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAE)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, 0, InsertAE) {
+ Load, Ptr, InsertAE) {
setVolatile(false);
AssertOK();
setName(Name);
@@ -619,7 +689,7 @@
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
Instruction *InsertBef)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, 0, InsertBef) {
+ Load, Ptr, InsertBef) {
setVolatile(isVolatile);
AssertOK();
setName(Name);
@@ -628,7 +698,7 @@
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
BasicBlock *InsertAE)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, 0, InsertAE) {
+ Load, Ptr, InsertAE) {
setVolatile(isVolatile);
AssertOK();
setName(Name);
@@ -637,33 +707,37 @@
LoadInst::LoadInst(Value *Ptr, const char *Name, Instruction *InsertBef)
-: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertBef) {
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertBef) {
setVolatile(false);
AssertOK();
+ if (Name && Name[0]) setName(Name);
}
LoadInst::LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAE)
-: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertAE) {
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertAE) {
setVolatile(false);
AssertOK();
+ if (Name && Name[0]) setName(Name);
}
LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile,
Instruction *InsertBef)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertBef) {
+ Load, Ptr, InsertBef) {
setVolatile(isVolatile);
AssertOK();
+ if (Name && Name[0]) setName(Name);
}
LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile,
BasicBlock *InsertAE)
-: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertAE) {
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertAE) {
setVolatile(isVolatile);
AssertOK();
+ if (Name && Name[0]) setName(Name);
}
@@ -681,7 +755,7 @@
StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
- : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertBefore) {
+ : Instruction(Type::VoidTy, Store, Ops, 2, InsertBefore) {
Ops[0].init(val, this);
Ops[1].init(addr, this);
setVolatile(false);
@@ -689,7 +763,7 @@
}
StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
- : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertAtEnd) {
+ : Instruction(Type::VoidTy, Store, Ops, 2, InsertAtEnd) {
Ops[0].init(val, this);
Ops[1].init(addr, this);
setVolatile(false);
@@ -698,7 +772,7 @@
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
Instruction *InsertBefore)
- : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertBefore) {
+ : Instruction(Type::VoidTy, Store, Ops, 2, InsertBefore) {
Ops[0].init(val, this);
Ops[1].init(addr, this);
setVolatile(isVolatile);
@@ -707,7 +781,7 @@
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
BasicBlock *InsertAtEnd)
- : Instruction(Type::VoidTy, Store, Ops, 2, "", InsertAtEnd) {
+ : Instruction(Type::VoidTy, Store, Ops, 2, InsertAtEnd) {
Ops[0].init(val, this);
Ops[1].init(addr, this);
setVolatile(isVolatile);
@@ -756,8 +830,9 @@
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx, NumIdx, true))),
- GetElementPtr, 0, 0, Name, InBe) {
+ GetElementPtr, 0, 0, InBe) {
init(Ptr, Idx, NumIdx);
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
@@ -765,40 +840,43 @@
const std::string &Name, BasicBlock *IAE)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx, NumIdx, true))),
- GetElementPtr, 0, 0, Name, IAE) {
+ GetElementPtr, 0, 0, IAE) {
init(Ptr, Idx, NumIdx);
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, Instruction *InBe)
- : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx))),
- GetElementPtr, 0, 0, Name, InBe) {
+ : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
+ GetElementPtr, 0, 0, InBe) {
init(Ptr, Idx);
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, BasicBlock *IAE)
- : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx))),
- GetElementPtr, 0, 0, Name, IAE) {
+ : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
+ GetElementPtr, 0, 0, IAE) {
init(Ptr, Idx);
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx0, Idx1, true))),
- GetElementPtr, 0, 0, Name, InBe) {
+ GetElementPtr, 0, 0, InBe) {
init(Ptr, Idx0, Idx1);
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name, BasicBlock *IAE)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx0, Idx1, true))),
- GetElementPtr, 0, 0, Name, IAE) {
+ GetElementPtr, 0, 0, IAE) {
init(Ptr, Idx0, Idx1);
+ setName(Name);
}
GetElementPtrInst::~GetElementPtrInst() {
@@ -885,23 +963,25 @@
const std::string &Name,
Instruction *InsertBef)
: Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertBef) {
+ ExtractElement, Ops, 2, InsertBef) {
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
Ops[0].init(Val, this);
Ops[1].init(Index, this);
+ setName(Name);
}
ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
const std::string &Name,
Instruction *InsertBef)
: Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertBef) {
+ ExtractElement, Ops, 2, InsertBef) {
Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
Ops[0].init(Val, this);
Ops[1].init(Index, this);
+ setName(Name);
}
@@ -909,25 +989,27 @@
const std::string &Name,
BasicBlock *InsertAE)
: Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertAE) {
+ ExtractElement, Ops, 2, InsertAE) {
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
Ops[0].init(Val, this);
Ops[1].init(Index, this);
+ setName(Name);
}
ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
const std::string &Name,
BasicBlock *InsertAE)
: Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertAE) {
+ ExtractElement, Ops, 2, InsertAE) {
Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
assert(isValidOperands(Val, Index) &&
"Invalid extractelement instruction operands!");
Ops[0].init(Val, this);
Ops[1].init(Index, this);
+ setName(Name);
}
@@ -951,43 +1033,46 @@
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
Instruction *InsertBef)
- : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) {
+ : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertBef) {
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
Ops[0].init(Vec, this);
Ops[1].init(Elt, this);
Ops[2].init(Index, this);
+ setName(Name);
}
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
const std::string &Name,
Instruction *InsertBef)
- : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) {
+ : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertBef) {
Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
Ops[0].init(Vec, this);
Ops[1].init(Elt, this);
Ops[2].init(Index, this);
+ setName(Name);
}
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
- : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) {
+ : Instruction(Vec->getType(), InsertElement, Ops, 3, InsertAE) {
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
Ops[0].init(Vec, this);
Ops[1].init(Elt, this);
Ops[2].init(Index, this);
+ setName(Name);
}
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
const std::string &Name,
BasicBlock *InsertAE)
-: Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) {
+: Instruction(Vec->getType(), InsertElement, Ops, 3, InsertAE) {
Constant *Index = ConstantInt::get(Type::Int32Ty, IndexV);
assert(isValidOperands(Vec, Elt, Index) &&
"Invalid insertelement instruction operands!");
@@ -995,6 +1080,7 @@
Ops[0].init(Vec, this);
Ops[1].init(Elt, this);
Ops[2].init(Index, this);
+ setName(Name);
}
bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
@@ -1025,24 +1111,26 @@
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const std::string &Name,
Instruction *InsertBefore)
- : Instruction(V1->getType(), ShuffleVector, Ops, 3, Name, InsertBefore) {
+ : Instruction(V1->getType(), ShuffleVector, Ops, 3, InsertBefore) {
assert(isValidOperands(V1, V2, Mask) &&
"Invalid shuffle vector instruction operands!");
Ops[0].init(V1, this);
Ops[1].init(V2, this);
Ops[2].init(Mask, this);
+ setName(Name);
}
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const std::string &Name,
BasicBlock *InsertAtEnd)
- : Instruction(V1->getType(), ShuffleVector, Ops, 3, Name, InsertAtEnd) {
+ : Instruction(V1->getType(), ShuffleVector, Ops, 3, InsertAtEnd) {
assert(isValidOperands(V1, V2, Mask) &&
"Invalid shuffle vector instruction operands!");
Ops[0].init(V1, this);
Ops[1].init(V2, this);
Ops[2].init(Mask, this);
+ setName(Name);
}
bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
@@ -1062,8 +1150,28 @@
// BinaryOperator Class
//===----------------------------------------------------------------------===//
-void BinaryOperator::init(BinaryOps iType)
-{
+BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
+ const Type *Ty, const std::string &Name,
+ Instruction *InsertBefore)
+ : Instruction(Ty, iType, Ops, 2, InsertBefore) {
+ Ops[0].init(S1, this);
+ Ops[1].init(S2, this);
+ init(iType);
+ setName(Name);
+}
+
+BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
+ const Type *Ty, const std::string &Name,
+ BasicBlock *InsertAtEnd)
+ : Instruction(Ty, iType, Ops, 2, InsertAtEnd) {
+ Ops[0].init(S1, this);
+ Ops[1].init(S2, this);
+ init(iType);
+ setName(Name);
+}
+
+
+void BinaryOperator::init(BinaryOps iType) {
Value *LHS = getOperand(0), *RHS = getOperand(1);
LHS = LHS; RHS = RHS; // Silence warnings.
assert(LHS->getType() == RHS->getType() &&
@@ -1947,7 +2055,7 @@
CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
const std::string &Name, Instruction *InsertBefore)
- : Instruction(Type::Int1Ty, op, Ops, 2, Name, InsertBefore) {
+ : Instruction(Type::Int1Ty, op, Ops, 2, InsertBefore) {
Ops[0].init(LHS, this);
Ops[1].init(RHS, this);
SubclassData = predicate;
@@ -1974,11 +2082,12 @@
// Check that the operands are the right type
assert(Op0Ty->isFloatingPoint() &&
"Invalid operand types for FCmp instruction");
+ setName(Name);
}
CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
const std::string &Name, BasicBlock *InsertAtEnd)
- : Instruction(Type::Int1Ty, op, Ops, 2, Name, InsertAtEnd) {
+ : Instruction(Type::Int1Ty, op, Ops, 2, InsertAtEnd) {
Ops[0].init(LHS, this);
Ops[1].init(RHS, this);
SubclassData = predicate;
@@ -2006,6 +2115,7 @@
// Check that the operands are the right type
assert(Op0Ty->isFloatingPoint() &&
"Invalid operand types for FCmp instruction");
+ setName(Name);
}
CmpInst *
@@ -2197,9 +2307,29 @@
OperandList[1].init(Default, this);
}
+/// SwitchInst ctor - Create a new switch instruction, specifying a value to
+/// switch on and a default destination. The number of additional cases can
+/// be specified here to make memory allocation more efficient. This
+/// constructor can also autoinsert before another instruction.
+SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
+ Instruction *InsertBefore)
+ : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertBefore) {
+ init(Value, Default, NumCases);
+}
+
+/// SwitchInst ctor - Create a new switch instruction, specifying a value to
+/// switch on and a default destination. The number of additional cases can
+/// be specified here to make memory allocation more efficient. This
+/// constructor also autoinserts at the end of the specified BasicBlock.
+SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
+ BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertAtEnd) {
+ init(Value, Default, NumCases);
+}
+
SwitchInst::SwitchInst(const SwitchInst &SI)
- : TerminatorInst(Instruction::Switch, new Use[SI.getNumOperands()],
- SI.getNumOperands()) {
+ : TerminatorInst(Type::VoidTy, Instruction::Switch,
+ new Use[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);