#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/Support/CallSite.h"
+#include "llvm/Support/ConstantRange.h"
+#include "llvm/Support/MathExtras.h"
using namespace llvm;
unsigned CallSite::getCallingConv() const {
// 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() {
}
if (HasUndefInput && !AllowNonDominatingInstruction)
if (Instruction *IV = dyn_cast<Instruction>(InVal))
// If it's in the entry block, it dominates everything.
- if (IV->getParent() != &IV->getParent()->getParent()->front() ||
+ if (IV->getParent() != &IV->getParent()->getParent()->getEntryBlock() ||
isa<InvokeInst>(IV))
return 0; // Cannot guarantee that InVal dominates this PHINode.
CallInst::~CallInst() {
delete [] OperandList;
+ if (ParamAttrs)
+ ParamAttrs->dropRef();
}
void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
+ ParamAttrs = 0;
NumOperands = NumParams+1;
Use *OL = OperandList = new Use[NumParams+1];
OL[0].init(Func, this);
}
void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
+ ParamAttrs = 0;
NumOperands = 3;
Use *OL = OperandList = new Use[3];
OL[0].init(Func, this);
}
void CallInst::init(Value *Func, Value *Actual) {
+ ParamAttrs = 0;
NumOperands = 2;
Use *OL = OperandList = new Use[2];
OL[0].init(Func, this);
}
void CallInst::init(Value *Func) {
+ ParamAttrs = 0;
NumOperands = 1;
Use *OL = OperandList = new Use[1];
OL[0].init(Func, this);
assert(FTy->getNumParams() == 0 && "Calling a function with bad signature");
}
-CallInst::CallInst(Value *Func, const std::vector<Value*> &Params,
- const std::string &Name, Instruction *InsertBefore)
- : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
- ->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertBefore) {
- init(Func, &Params[0], Params.size());
-}
-
+#if 0
+// Leave for llvm-gcc
CallInst::CallInst(Value *Func, Value* const *Args, unsigned NumArgs,
const std::string &Name, BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
- ->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertAtEnd) {
+ ->getElementType())->getReturnType(),
+ 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(cast<FunctionType>(cast<PointerType>(Func->getType())
+ ->getElementType())->getReturnType(),
+ Instruction::Call, 0, 0, InsertBefore) {
init(Func, Args, NumArgs);
+ setName(Name);
}
-CallInst::CallInst(Value *Func, const std::vector<Value*> &Params,
- const std::string &Name, BasicBlock *InsertAtEnd)
-: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
- ->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, Name, InsertAtEnd) {
- init(Func, &Params[0], Params.size());
-}
-
-
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);
}
-
+#endif
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)
: Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()],
CI.getNumOperands()) {
+ ParamAttrs = 0;
SubclassData = CI.SubclassData;
Use *OL = OperandList;
Use *InOL = CI.OperandList;
OL[i].init(InOL[i], this);
}
+void CallInst::setParamAttrs(ParamAttrsList *newAttrs) {
+ if (ParamAttrs)
+ ParamAttrs->dropRef();
+
+ if (newAttrs)
+ newAttrs->addRef();
+
+ ParamAttrs = newAttrs;
+}
//===----------------------------------------------------------------------===//
// InvokeInst Implementation
InvokeInst::~InvokeInst() {
delete [] OperandList;
+ if (ParamAttrs)
+ ParamAttrs->dropRef();
}
void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Value* const *Args, unsigned NumArgs) {
+ ParamAttrs = 0;
NumOperands = 3+NumArgs;
Use *OL = OperandList = new Use[3+NumArgs];
OL[0].init(Fn, this);
}
}
-InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
- BasicBlock *IfException,
- Value* const *Args, unsigned NumArgs,
- const std::string &Name, Instruction *InsertBefore)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
- ->getElementType())->getReturnType(),
- Instruction::Invoke, 0, 0, Name, InsertBefore) {
- init(Fn, IfNormal, IfException, Args, NumArgs);
-}
-
-InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
- BasicBlock *IfException,
- Value* const *Args, unsigned NumArgs,
- const std::string &Name, BasicBlock *InsertAtEnd)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
- ->getElementType())->getReturnType(),
- Instruction::Invoke, 0, 0, Name, InsertAtEnd) {
- init(Fn, IfNormal, IfException, Args, NumArgs);
-}
-
-InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
- BasicBlock *IfException,
- const std::vector<Value*> &Params,
- const std::string &Name, Instruction *InsertBefore)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
- ->getElementType())->getReturnType(),
- Instruction::Invoke, 0, 0, Name, InsertBefore) {
- init(Fn, IfNormal, IfException, &Params[0], Params.size());
-}
-
-InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
- BasicBlock *IfException,
- const std::vector<Value*> &Params,
- const std::string &Name, BasicBlock *InsertAtEnd)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
- ->getElementType())->getReturnType(),
- Instruction::Invoke, 0, 0, Name, InsertAtEnd) {
- init(Fn, IfNormal, IfException, &Params[0], Params.size());
-}
-
InvokeInst::InvokeInst(const InvokeInst &II)
: TerminatorInst(II.getType(), Instruction::Invoke,
new Use[II.getNumOperands()], II.getNumOperands()) {
+ ParamAttrs = 0;
SubclassData = II.SubclassData;
Use *OL = OperandList, *InOL = II.OperandList;
for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
return setSuccessor(idx, B);
}
+void InvokeInst::setParamAttrs(ParamAttrsList *newAttrs) {
+ if (ParamAttrs)
+ ParamAttrs->dropRef();
+
+ if (newAttrs)
+ newAttrs->addRef();
+
+ ParamAttrs = newAttrs;
+}
//===----------------------------------------------------------------------===//
// 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) &&
// 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();
}
// 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();
}
"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!");
Amt = ConstantInt::get(Type::Int32Ty, 1);
else {
assert(!isa<BasicBlock>(Amt) &&
- "Passed basic block into allocation size parameter! Ue other ctor");
+ "Passed basic block into allocation size parameter! Use other ctor");
assert(Amt->getType() == Type::Int32Ty &&
"Malloc/Allocation array size is not a 32-bit integer!");
}
unsigned Align, const std::string &Name,
Instruction *InsertBefore)
: UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize),
- Name, 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);
}
AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name,
BasicBlock *InsertAtEnd)
: UnaryInstruction(PointerType::get(Ty), iTy, getAISize(ArraySize),
- Name, 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);
}
// Out of line virtual method, so the vtable, etc has a home.
}
bool AllocationInst::isArrayAllocation() const {
- if (ConstantInt *CUI = dyn_cast<ConstantInt>(getOperand(0)))
- return CUI->getZExtValue() != 1;
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
+ return CI->getZExtValue() != 1;
return true;
}
}
FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
- : UnaryInstruction(Type::VoidTy, Free, Ptr, "", InsertBefore) {
+ : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertBefore) {
AssertOK();
}
FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd)
- : UnaryInstruction(Type::VoidTy, Free, Ptr, "", InsertAtEnd) {
+ : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertAtEnd) {
AssertOK();
}
LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertBef) {
+ Load, Ptr, InsertBef) {
setVolatile(false);
+ setAlignment(0);
AssertOK();
+ setName(Name);
}
LoadInst::LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAE)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertAE) {
+ Load, Ptr, InsertAE) {
setVolatile(false);
+ setAlignment(0);
AssertOK();
+ setName(Name);
}
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
Instruction *InsertBef)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertBef) {
+ Load, Ptr, InsertBef) {
setVolatile(isVolatile);
+ setAlignment(0);
AssertOK();
+ setName(Name);
+}
+
+LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
+ unsigned Align, Instruction *InsertBef)
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertBef) {
+ setVolatile(isVolatile);
+ setAlignment(Align);
+ AssertOK();
+ setName(Name);
+}
+
+LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
+ unsigned Align, BasicBlock *InsertAE)
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertAE) {
+ setVolatile(isVolatile);
+ setAlignment(Align);
+ AssertOK();
+ setName(Name);
}
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
BasicBlock *InsertAE)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
- Load, Ptr, Name, InsertAE) {
+ Load, Ptr, InsertAE) {
+ setVolatile(isVolatile);
+ setAlignment(0);
+ AssertOK();
+ setName(Name);
+}
+
+
+
+LoadInst::LoadInst(Value *Ptr, const char *Name, Instruction *InsertBef)
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertBef) {
+ setVolatile(false);
+ setAlignment(0);
+ AssertOK();
+ if (Name && Name[0]) setName(Name);
+}
+
+LoadInst::LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAE)
+ : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
+ Load, Ptr, InsertAE) {
+ setVolatile(false);
+ setAlignment(0);
+ 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, InsertBef) {
+ setVolatile(isVolatile);
+ setAlignment(0);
+ 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, InsertAE) {
setVolatile(isVolatile);
+ setAlignment(0);
AssertOK();
+ if (Name && Name[0]) setName(Name);
}
+void LoadInst::setAlignment(unsigned Align) {
+ assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
+ SubclassData = (SubclassData & 1) | ((Log2_32(Align)+1)<<1);
+}
//===----------------------------------------------------------------------===//
// StoreInst Implementation
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);
+ setAlignment(0);
AssertOK();
}
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);
+ setAlignment(0);
AssertOK();
}
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);
+ setAlignment(0);
+ AssertOK();
+}
+
+StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
+ unsigned Align, Instruction *InsertBefore)
+ : Instruction(Type::VoidTy, Store, Ops, 2, InsertBefore) {
Ops[0].init(val, this);
Ops[1].init(addr, this);
setVolatile(isVolatile);
+ setAlignment(Align);
+ AssertOK();
+}
+
+StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
+ unsigned Align, BasicBlock *InsertAtEnd)
+ : Instruction(Type::VoidTy, Store, Ops, 2, InsertAtEnd) {
+ Ops[0].init(val, this);
+ Ops[1].init(addr, this);
+ setVolatile(isVolatile);
+ setAlignment(Align);
AssertOK();
}
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);
+ setAlignment(0);
AssertOK();
}
+void StoreInst::setAlignment(unsigned Align) {
+ assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
+ SubclassData = (SubclassData & 1) | ((Log2_32(Align)+1)<<1);
+}
+
//===----------------------------------------------------------------------===//
// GetElementPtrInst Implementation
//===----------------------------------------------------------------------===//
-// checkType - Simple wrapper function to give a better assertion failure
-// message on bad indexes for a gep instruction.
-//
-static inline const Type *checkType(const Type *Ty) {
- assert(Ty && "Invalid GetElementPtrInst indices for type!");
- return Ty;
-}
-
void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
NumOperands = 1+NumIdx;
Use *OL = OperandList = new Use[NumOperands];
OL[i+1].init(Idx[i], this);
}
-void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) {
- NumOperands = 3;
- Use *OL = OperandList = new Use[3];
- OL[0].init(Ptr, this);
- OL[1].init(Idx0, this);
- OL[2].init(Idx1, this);
-}
-
void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
NumOperands = 2;
Use *OL = OperandList = new Use[2];
OL[1].init(Idx, this);
}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
- unsigned NumIdx,
- const std::string &Name, Instruction *InBe)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx, NumIdx, true))),
- GetElementPtr, 0, 0, Name, InBe) {
- init(Ptr, Idx, NumIdx);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
- unsigned NumIdx,
- const std::string &Name, BasicBlock *IAE)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx, NumIdx, true))),
- GetElementPtr, 0, 0, Name, IAE) {
- init(Ptr, Idx, NumIdx);
-}
-
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);
-}
-
-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) {
- init(Ptr, Idx0, Idx1);
-}
-
-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) {
- init(Ptr, Idx0, Idx1);
+ setName(Name);
}
GetElementPtrInst::~GetElementPtrInst() {
return CurIdx == NumIdx ? Ptr : 0;
}
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
- Value *Idx0, Value *Idx1,
- bool AllowCompositeLeaf) {
+const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
const PointerType *PTy = dyn_cast<PointerType>(Ptr);
if (!PTy) return 0; // Type isn't a pointer type!
// Check the pointer index.
- if (!PTy->indexValid(Idx0)) return 0;
-
- const CompositeType *CT = dyn_cast<CompositeType>(PTy->getElementType());
- if (!CT || !CT->indexValid(Idx1)) return 0;
+ if (!PTy->indexValid(Idx)) return 0;
- const Type *ElTy = CT->getTypeAtIndex(Idx1);
- if (AllowCompositeLeaf || ElTy->isFirstClassType())
- return ElTy;
- return 0;
+ return PTy->getElementType();
}
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
- const PointerType *PTy = dyn_cast<PointerType>(Ptr);
- if (!PTy) return 0; // Type isn't a pointer type!
- // Check the pointer index.
- if (!PTy->indexValid(Idx)) return 0;
+/// hasAllZeroIndices - Return true if all of the indices of this GEP are
+/// zeros. If so, the result pointer and the first operand have the same
+/// value, just potentially different types.
+bool GetElementPtrInst::hasAllZeroIndices() const {
+ for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(i))) {
+ if (!CI->isZero()) return false;
+ } else {
+ return false;
+ }
+ }
+ return true;
+}
- return PTy->getElementType();
+/// hasAllConstantIndices - Return true if all of the indices of this GEP are
+/// constant integers. If so, the result pointer and the first operand have
+/// a constant offset between them.
+bool GetElementPtrInst::hasAllConstantIndices() const {
+ for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
+ if (!isa<ConstantInt>(getOperand(i)))
+ return false;
+ }
+ return true;
}
+
//===----------------------------------------------------------------------===//
// ExtractElementInst Implementation
//===----------------------------------------------------------------------===//
ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
const std::string &Name,
Instruction *InsertBef)
- : Instruction(cast<PackedType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertBef) {
+ : Instruction(cast<VectorType>(Val->getType())->getElementType(),
+ 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<PackedType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertBef) {
+ : Instruction(cast<VectorType>(Val->getType())->getElementType(),
+ 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);
}
ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
- : Instruction(cast<PackedType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertAE) {
+ : Instruction(cast<VectorType>(Val->getType())->getElementType(),
+ 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<PackedType>(Val->getType())->getElementType(),
- ExtractElement, Ops, 2, Name, InsertAE) {
+ : Instruction(cast<VectorType>(Val->getType())->getElementType(),
+ 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);
}
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
- if (!isa<PackedType>(Val->getType()) || Index->getType() != Type::Int32Ty)
+ if (!isa<VectorType>(Val->getType()) || Index->getType() != Type::Int32Ty)
return false;
return true;
}
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!");
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,
const Value *Index) {
- if (!isa<PackedType>(Vec->getType()))
- return false; // First operand of insertelement must be packed type.
+ if (!isa<VectorType>(Vec->getType()))
+ return false; // First operand of insertelement must be vector type.
- if (Elt->getType() != cast<PackedType>(Vec->getType())->getElementType())
- return false;// Second operand of insertelement must be packed element type.
+ if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
+ return false;// Second operand of insertelement must be vector element type.
if (Index->getType() != Type::Int32Ty)
return false; // Third operand of insertelement must be uint.
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,
const Value *Mask) {
- if (!isa<PackedType>(V1->getType())) return false;
+ if (!isa<VectorType>(V1->getType())) return false;
if (V1->getType() != V2->getType()) return false;
- if (!isa<PackedType>(Mask->getType()) ||
- cast<PackedType>(Mask->getType())->getElementType() != Type::Int32Ty ||
- cast<PackedType>(Mask->getType())->getNumElements() !=
- cast<PackedType>(V1->getType())->getNumElements())
+ if (!isa<VectorType>(Mask->getType()) ||
+ cast<VectorType>(Mask->getType())->getElementType() != Type::Int32Ty ||
+ cast<VectorType>(Mask->getType())->getNumElements() !=
+ cast<VectorType>(V1->getType())->getNumElements())
return false;
return true;
}
// 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() &&
assert(getType() == LHS->getType() &&
"Arithmetic operation should return same type as operands!");
assert((getType()->isInteger() || getType()->isFloatingPoint() ||
- isa<PackedType>(getType())) &&
+ isa<VectorType>(getType())) &&
"Tried to create an arithmetic operation on a non-arithmetic type!");
break;
case UDiv:
case SDiv:
assert(getType() == LHS->getType() &&
"Arithmetic operation should return same type as operands!");
- assert((getType()->isInteger() || (isa<PackedType>(getType()) &&
- cast<PackedType>(getType())->getElementType()->isInteger())) &&
+ assert((getType()->isInteger() || (isa<VectorType>(getType()) &&
+ cast<VectorType>(getType())->getElementType()->isInteger())) &&
"Incorrect operand type (not integer) for S/UDIV");
break;
case FDiv:
assert(getType() == LHS->getType() &&
"Arithmetic operation should return same type as operands!");
- assert((getType()->isFloatingPoint() || (isa<PackedType>(getType()) &&
- cast<PackedType>(getType())->getElementType()->isFloatingPoint()))
+ assert((getType()->isFloatingPoint() || (isa<VectorType>(getType()) &&
+ cast<VectorType>(getType())->getElementType()->isFloatingPoint()))
&& "Incorrect operand type (not floating point) for FDIV");
break;
case URem:
case SRem:
assert(getType() == LHS->getType() &&
"Arithmetic operation should return same type as operands!");
- assert((getType()->isInteger() || (isa<PackedType>(getType()) &&
- cast<PackedType>(getType())->getElementType()->isInteger())) &&
+ assert((getType()->isInteger() || (isa<VectorType>(getType()) &&
+ cast<VectorType>(getType())->getElementType()->isInteger())) &&
"Incorrect operand type (not integer) for S/UREM");
break;
case FRem:
assert(getType() == LHS->getType() &&
"Arithmetic operation should return same type as operands!");
- assert((getType()->isFloatingPoint() || (isa<PackedType>(getType()) &&
- cast<PackedType>(getType())->getElementType()->isFloatingPoint()))
+ assert((getType()->isFloatingPoint() || (isa<VectorType>(getType()) &&
+ cast<VectorType>(getType())->getElementType()->isFloatingPoint()))
&& "Incorrect operand type (not floating point) for FREM");
break;
case Shl:
assert(getType() == LHS->getType() &&
"Logical operation should return same type as operands!");
assert((getType()->isInteger() ||
- (isa<PackedType>(getType()) &&
- cast<PackedType>(getType())->getElementType()->isInteger())) &&
+ (isa<VectorType>(getType()) &&
+ cast<VectorType>(getType())->getElementType()->isInteger())) &&
"Tried to create a logical operation on a non-integral type!");
break;
default:
BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
Instruction *InsertBefore) {
Constant *C;
- if (const PackedType *PTy = dyn_cast<PackedType>(Op->getType())) {
+ if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
C = ConstantInt::getAllOnesValue(PTy->getElementType());
- C = ConstantPacked::get(std::vector<Constant*>(PTy->getNumElements(), C));
+ C = ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), C));
} else {
C = ConstantInt::getAllOnesValue(Op->getType());
}
BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
BasicBlock *InsertAtEnd) {
Constant *AllOnes;
- if (const PackedType *PTy = dyn_cast<PackedType>(Op->getType())) {
+ if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
// Create a vector of all ones values.
Constant *Elt = ConstantInt::getAllOnesValue(PTy->getElementType());
AllOnes =
- ConstantPacked::get(std::vector<Constant*>(PTy->getNumElements(), Elt));
+ ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), Elt));
} else {
AllOnes = ConstantInt::getAllOnesValue(Op->getType());
}
// isConstantAllOnes - Helper function for several functions below
static inline bool isConstantAllOnes(const Value *V) {
- return isa<ConstantInt>(V) &&cast<ConstantInt>(V)->isAllOnesValue();
+ if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
+ return CI->isAllOnesValue();
+ if (const ConstantVector *CV = dyn_cast<ConstantVector>(V))
+ return CV->isAllOnesValue();
+ return false;
}
bool BinaryOperator::isNeg(const Value *V) {
/// example, the following are all no-op casts:
/// # bitcast uint %X, int
/// # bitcast uint* %x, sbyte*
-/// # bitcast packed< 2 x int > %x, packed< 4 x short>
+/// # bitcast vector< 2 x int > %x, vector< 4 x short>
/// # ptrtoint uint* %x, uint ; on 32-bit plaforms only
/// @brief Determine if a cast is a no-op.
bool CastInst::isNoopCast(const Type *IntPtrTy) const {
const Value *Src, bool SrcIsSigned, const Type *DestTy, bool DestIsSigned) {
// Get the bit sizes, we'll need these
const Type *SrcTy = Src->getType();
- unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr/packed
- unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr/packed
+ unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr/vector
+ unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr/vector
// Run through the possibilities ...
if (DestTy->isInteger()) { // Casting to integral
return FPToSI; // FP -> sint
else
return FPToUI; // FP -> uint
- } else if (const PackedType *PTy = dyn_cast<PackedType>(SrcTy)) {
+ } else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) {
assert(DestBits == PTy->getBitWidth() &&
- "Casting packed to integer of different width");
+ "Casting vector to integer of different width");
return BitCast; // Same size, no-op cast
} else {
assert(isa<PointerType>(SrcTy) &&
} else {
return BitCast; // same size, no-op cast
}
- } else if (const PackedType *PTy = dyn_cast<PackedType>(SrcTy)) {
+ } else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) {
assert(DestBits == PTy->getBitWidth() &&
- "Casting packed to floating point of different width");
+ "Casting vector to floating point of different width");
return BitCast; // same size, no-op cast
} else {
assert(0 && "Casting pointer or non-first class to float");
}
- } else if (const PackedType *DestPTy = dyn_cast<PackedType>(DestTy)) {
- if (const PackedType *SrcPTy = dyn_cast<PackedType>(SrcTy)) {
+ } else if (const VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
+ if (const VectorType *SrcPTy = dyn_cast<VectorType>(SrcTy)) {
assert(DestPTy->getBitWidth() == SrcPTy->getBitWidth() &&
- "Casting packed to packed of different widths");
- return BitCast; // packed -> packed
+ "Casting vector to vector of different widths");
+ return BitCast; // vector -> vector
} else if (DestPTy->getBitWidth() == SrcBits) {
- return BitCast; // float/int -> packed
+ return BitCast; // float/int -> vector
} else {
- assert(!"Illegal cast to packed (wrong type or size)");
+ assert(!"Illegal cast to vector (wrong type or size)");
}
} else if (isa<PointerType>(DestTy)) {
if (isa<PointerType>(SrcTy)) {
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;
+ setName(Name);
if (op == Instruction::ICmp) {
assert(predicate >= ICmpInst::FIRST_ICMP_PREDICATE &&
predicate <= ICmpInst::LAST_ICMP_PREDICATE &&
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;
+ setName(Name);
if (op == Instruction::ICmp) {
assert(predicate >= ICmpInst::FIRST_ICMP_PREDICATE &&
predicate <= ICmpInst::LAST_ICMP_PREDICATE &&
}
}
+/// Initialize a set of values that all satisfy the condition with C.
+///
+ConstantRange
+ICmpInst::makeConstantRange(Predicate pred, const APInt &C) {
+ APInt Lower(C);
+ APInt Upper(C);
+ uint32_t BitWidth = C.getBitWidth();
+ switch (pred) {
+ default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
+ case ICmpInst::ICMP_EQ: Upper++; break;
+ case ICmpInst::ICMP_NE: Lower++; break;
+ case ICmpInst::ICMP_ULT: Lower = APInt::getMinValue(BitWidth); break;
+ case ICmpInst::ICMP_SLT: Lower = APInt::getSignedMinValue(BitWidth); break;
+ case ICmpInst::ICMP_UGT:
+ Lower++; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
+ break;
+ case ICmpInst::ICMP_SGT:
+ Lower++; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
+ break;
+ case ICmpInst::ICMP_ULE:
+ Lower = APInt::getMinValue(BitWidth); Upper++;
+ break;
+ case ICmpInst::ICMP_SLE:
+ Lower = APInt::getSignedMinValue(BitWidth); Upper++;
+ break;
+ case ICmpInst::ICMP_UGE:
+ Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
+ break;
+ case ICmpInst::ICMP_SGE:
+ Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
+ break;
+ }
+ return ConstantRange(Lower, Upper);
+}
+
FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {
switch (pred) {
default:
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);
return create(getOpcode(), Ops[0], Ops[1]);
}
-CmpInst* CmpInst::clone() const {
- return create(getOpcode(), getPredicate(), Ops[0], Ops[1]);
+FCmpInst* FCmpInst::clone() const {
+ return new FCmpInst(getPredicate(), Ops[0], Ops[1]);
+}
+ICmpInst* ICmpInst::clone() const {
+ return new ICmpInst(getPredicate(), Ops[0], Ops[1]);
}
MallocInst *MallocInst::clone() const { return new MallocInst(*this); }