}
+
+
//===----------------------------------------------------------------------===//
// TerminatorInst Class
//===----------------------------------------------------------------------===//
: Instruction(Type::VoidTy, iType, Ops, NumOps, "", IAE) {
}
+// Out of line virtual method, so the vtable, etc has a home.
+TerminatorInst::~TerminatorInst() {
+}
+
+// Out of line virtual method, so the vtable, etc has a home.
+UnaryInstruction::~UnaryInstruction() {
+}
//===----------------------------------------------------------------------===//
assert((Params.size() == FTy->getNumParams() ||
(FTy->isVarArg() && Params.size() > FTy->getNumParams())) &&
- "Calling a function with bad signature");
- for (unsigned i = 0, e = Params.size(); i != e; ++i)
+ "Calling a function with bad signature!");
+ for (unsigned i = 0, e = Params.size(); i != e; ++i) {
+ assert((i >= FTy->getNumParams() ||
+ FTy->getParamType(i) == Params[i]->getType()) &&
+ "Calling a function with a bad signature!");
OL[i+1].init(Params[i], this);
+ }
}
void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
assert((FTy->getNumParams() == 2 ||
- (FTy->isVarArg() && FTy->getNumParams() == 0)) &&
+ (FTy->isVarArg() && FTy->getNumParams() < 2)) &&
"Calling a function with bad signature");
+ assert((0 >= FTy->getNumParams() ||
+ FTy->getParamType(0) == Actual1->getType()) &&
+ "Calling a function with a bad signature!");
+ assert((1 >= FTy->getNumParams() ||
+ FTy->getParamType(1) == Actual2->getType()) &&
+ "Calling a function with a bad signature!");
}
void CallInst::init(Value *Func, Value *Actual) {
assert((FTy->getNumParams() == 1 ||
(FTy->isVarArg() && FTy->getNumParams() == 0)) &&
"Calling a function with bad signature");
+ assert((0 == FTy->getNumParams() ||
+ FTy->getParamType(0) == Actual->getType()) &&
+ "Calling a function with a bad signature!");
}
void CallInst::init(Value *Func) {
(FTy->isVarArg() && Params.size() > FTy->getNumParams()) &&
"Calling a function with bad signature");
- for (unsigned i = 0, e = Params.size(); i != e; i++)
+ for (unsigned i = 0, e = Params.size(); i != e; i++) {
+ assert((i >= FTy->getNumParams() ||
+ FTy->getParamType(i) == Params[i]->getType()) &&
+ "Invoking a function with a bad signature!");
+
OL[i+3].init(Params[i], this);
+ }
}
InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
static Value *getAISize(Value *Amt) {
if (!Amt)
- Amt = ConstantUInt::get(Type::UIntTy, 1);
- else
+ Amt = ConstantInt::get(Type::UIntTy, 1);
+ else {
+ assert(!isa<BasicBlock>(Amt) &&
+ "Passed basic block into allocation size parameter! Ue other ctor");
assert(Amt->getType() == Type::UIntTy &&
"Malloc/Allocation array size != UIntTy!");
+ }
return Amt;
}
assert(Ty != Type::VoidTy && "Cannot allocate void!");
}
+// Out of line virtual method, so the vtable, etc has a home.
+AllocationInst::~AllocationInst() {
+}
+
bool AllocationInst::isArrayAllocation() const {
- if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(getOperand(0)))
- return CUI->getValue() != 1;
+ if (ConstantInt *CUI = dyn_cast<ConstantInt>(getOperand(0)))
+ return CUI->getZExtValue() != 1;
return true;
}
// message on bad indexes for a gep instruction.
//
static inline const Type *checkType(const Type *Ty) {
- assert(Ty && "Invalid indices for type!");
+ assert(Ty && "Invalid GetElementPtrInst indices for type!");
return Ty;
}
Ops[1].init(Index, this);
}
+ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
+ const std::string &Name,
+ Instruction *InsertBef)
+ : Instruction(cast<PackedType>(Val->getType())->getElementType(),
+ ExtractElement, Ops, 2, Name, InsertBef) {
+ Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
+ assert(isValidOperands(Val, Index) &&
+ "Invalid extractelement instruction operands!");
+ Ops[0].init(Val, this);
+ Ops[1].init(Index, this);
+}
+
+
ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
Ops[1].init(Index, this);
}
+ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
+ const std::string &Name,
+ BasicBlock *InsertAE)
+ : Instruction(cast<PackedType>(Val->getType())->getElementType(),
+ ExtractElement, Ops, 2, Name, InsertAE) {
+ Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
+ assert(isValidOperands(Val, Index) &&
+ "Invalid extractelement instruction operands!");
+
+ Ops[0].init(Val, this);
+ Ops[1].init(Index, this);
+}
+
+
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
if (!isa<PackedType>(Val->getType()) || Index->getType() != Type::UIntTy)
return false;
// InsertElementInst Implementation
//===----------------------------------------------------------------------===//
+InsertElementInst::InsertElementInst(const InsertElementInst &IE)
+ : Instruction(IE.getType(), InsertElement, Ops, 3) {
+ Ops[0].init(IE.Ops[0], this);
+ Ops[1].init(IE.Ops[1], this);
+ Ops[2].init(IE.Ops[2], this);
+}
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
Instruction *InsertBef)
Ops[2].init(Index, this);
}
+InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
+ const std::string &Name,
+ Instruction *InsertBef)
+ : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) {
+ Constant *Index = ConstantInt::get(Type::UIntTy, 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);
+}
+
+
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
Ops[2].init(Index, this);
}
+InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
+ const std::string &Name,
+ BasicBlock *InsertAE)
+: Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) {
+ Constant *Index = ConstantInt::get(Type::UIntTy, 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);
+}
+
bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
const Value *Index) {
if (!isa<PackedType>(Vec->getType()))
// ShuffleVectorInst Implementation
//===----------------------------------------------------------------------===//
+ShuffleVectorInst::ShuffleVectorInst(const ShuffleVectorInst &SV)
+ : Instruction(SV.getType(), ShuffleVector, Ops, 3) {
+ Ops[0].init(SV.Ops[0], this);
+ Ops[1].init(SV.Ops[1], this);
+ Ops[2].init(SV.Ops[2], this);
+}
+
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const std::string &Name,
Instruction *InsertBefore)
}
+//===----------------------------------------------------------------------===//
+// ShiftInst Class
+//===----------------------------------------------------------------------===//
+
+/// isLogicalShift - Return true if this is a logical shift left or a logical
+/// shift right.
+bool ShiftInst::isLogicalShift() const {
+ return getOpcode() == Instruction::Shl || getType()->isUnsigned();
+}
+
+//===----------------------------------------------------------------------===//
+// CastInst Class
+//===----------------------------------------------------------------------===//
+
+/// isTruncIntCast - Return true if this is a truncating integer cast
+/// instruction, e.g. a cast from long to uint.
+bool CastInst::isTruncIntCast() const {
+ // The dest type has to be integral, the input has to be integer.
+ if (!getType()->isIntegral() || !getOperand(0)->getType()->isInteger())
+ return false;
+
+ // Has to be large to smaller.
+ return getOperand(0)->getType()->getPrimitiveSizeInBits() >
+ getType()->getPrimitiveSizeInBits();
+}
+
+
//===----------------------------------------------------------------------===//
// SetCondInst Class
//===----------------------------------------------------------------------===//