make the constantexpr interfaces for inbounds GEPs follow the same style

as other constantexpr flags, reducing redundancy.

llvm-svn: 125365
This commit is contained in:
Chris Lattner 2011-02-11 05:34:33 +00:00
parent fc217469c2
commit 94c8d2941f
2 changed files with 23 additions and 77 deletions

View File

@ -631,11 +631,8 @@ protected:
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,
@ -650,11 +647,7 @@ protected:
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
@ -849,18 +842,24 @@ public:
/// 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);

View File

@ -1502,43 +1502,14 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
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");
@ -1549,7 +1520,7 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
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);
@ -1557,47 +1528,23 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
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 *