Constant *C1, Constant *C2, Constant *C3);
template<typename IndexTy>
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
- IndexTy const *Idxs, unsigned NumIdxs);
- template<typename IndexTy>
- static Constant *getInBoundsGetElementPtrTy(const Type *Ty, Constant *C,
- IndexTy const *Idxs,
- unsigned NumIdxs);
+ IndexTy const *Idxs, unsigned NumIdxs,
+ bool InBounds);
static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
Constant *Idx);
static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
template<typename IndexTy>
static Constant *getGetElementPtrImpl(Constant *C,
IndexTy const *IdxList,
- unsigned NumIdx);
- template<typename IndexTy>
- static Constant *getInBoundsGetElementPtrImpl(Constant *C,
- IndexTy const *IdxList,
- unsigned NumIdx);
+ unsigned NumIdx, bool InBounds);
public:
// Static methods to construct a ConstantExpr of different kinds. Note that
/// all elements must be Constant's.
///
static Constant *getGetElementPtr(Constant *C,
- Constant *const *IdxList, unsigned NumIdx);
+ Constant *const *IdxList, unsigned NumIdx,
+ bool InBounds = false);
static Constant *getGetElementPtr(Constant *C,
- Value* const *IdxList, unsigned NumIdx);
+ Value *const *IdxList, unsigned NumIdx,
+ bool InBounds = false);
/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
static Constant *getInBoundsGetElementPtr(Constant *C,
Constant *const *IdxList,
- unsigned NumIdx);
+ unsigned NumIdx) {
+ return getGetElementPtr(C, IdxList, NumIdx, true);
+ }
static Constant *getInBoundsGetElementPtr(Constant *C,
Value* const *IdxList,
- unsigned NumIdx);
+ unsigned NumIdx) {
+ return getGetElementPtr(C, IdxList, NumIdx, true);
+ }
static Constant *getExtractElement(Constant *Vec, Constant *Idx);
static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
template<typename IndexTy>
Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
IndexTy const *Idxs,
- unsigned NumIdx) {
+ unsigned NumIdx, bool InBounds) {
assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs,
Idxs+NumIdx) ==
cast<PointerType>(ReqTy)->getElementType() &&
"GEP indices invalid!");
- if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/false,
- Idxs, NumIdx))
- return FC; // Fold a few common cases...
-
- assert(C->getType()->isPointerTy() &&
- "Non-pointer type for constant GetElementPtr expression");
- // Look up the constant in the table first to ensure uniqueness
- std::vector<Constant*> ArgVec;
- ArgVec.reserve(NumIdx+1);
- ArgVec.push_back(C);
- for (unsigned i = 0; i != NumIdx; ++i)
- ArgVec.push_back(cast<Constant>(Idxs[i]));
- const ExprMapKeyType Key(Instruction::GetElementPtr, ArgVec);
-
- LLVMContextImpl *pImpl = ReqTy->getContext().pImpl;
- return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
-}
-
-template<typename IndexTy>
-Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
- Constant *C,
- IndexTy const *Idxs,
- unsigned NumIdx) {
- assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs,
- Idxs+NumIdx) ==
- cast<PointerType>(ReqTy)->getElementType() &&
- "GEP indices invalid!");
-
- if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/true,
- Idxs, NumIdx))
- return FC; // Fold a few common cases...
+ if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds, Idxs, NumIdx))
+ return FC; // Fold a few common cases.
assert(C->getType()->isPointerTy() &&
"Non-pointer type for constant GetElementPtr expression");
for (unsigned i = 0; i != NumIdx; ++i)
ArgVec.push_back(cast<Constant>(Idxs[i]));
const ExprMapKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
- GEPOperator::IsInBounds);
+ InBounds ? GEPOperator::IsInBounds : 0);
LLVMContextImpl *pImpl = ReqTy->getContext().pImpl;
return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
template<typename IndexTy>
Constant *ConstantExpr::getGetElementPtrImpl(Constant *C, IndexTy const *Idxs,
- unsigned NumIdx) {
+ unsigned NumIdx, bool InBounds) {
// Get the result type of the getelementptr!
const Type *Ty =
GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
assert(Ty && "GEP indices invalid!");
unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
- return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
-}
-
-template<typename IndexTy>
-Constant *ConstantExpr::getInBoundsGetElementPtrImpl(Constant *C,
- IndexTy const *Idxs,
- unsigned NumIdx) {
- // Get the result type of the getelementptr!
- const Type *Ty =
- GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
- assert(Ty && "GEP indices invalid!");
- unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
- return getInBoundsGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
+ return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx,InBounds);
}
Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
- unsigned NumIdx) {
- return getGetElementPtrImpl(C, Idxs, NumIdx);
+ unsigned NumIdx, bool InBounds) {
+ return getGetElementPtrImpl(C, Idxs, NumIdx, InBounds);
}
Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant *const *Idxs,
- unsigned NumIdx) {
- return getGetElementPtrImpl(C, Idxs, NumIdx);
-}
-
-Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
- Value* const *Idxs,
- unsigned NumIdx) {
- return getInBoundsGetElementPtrImpl(C, Idxs, NumIdx);
-}
-
-Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
- Constant *const *Idxs,
- unsigned NumIdx) {
- return getInBoundsGetElementPtrImpl(C, Idxs, NumIdx);
+ unsigned NumIdx, bool InBounds) {
+ return getGetElementPtrImpl(C, Idxs, NumIdx, InBounds);
}
Constant *