summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/VMCore/Constants.cpp')
-rw-r--r--llvm/lib/VMCore/Constants.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 29fc0dbdf8d..46daa61d998 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1546,8 +1546,9 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
}
+template<typename IndexTy>
Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
- Value* const *Idxs,
+ IndexTy const *Idxs,
unsigned NumIdx) {
assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs,
Idxs+NumIdx) ==
@@ -1555,7 +1556,7 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
"GEP indices invalid!");
if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/false,
- (Constant**)Idxs, NumIdx))
+ Idxs, NumIdx))
return FC; // Fold a few common cases...
assert(C->getType()->isPointerTy() &&
@@ -1572,9 +1573,10 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
}
+template<typename IndexTy>
Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
Constant *C,
- Value *const *Idxs,
+ IndexTy const *Idxs,
unsigned NumIdx) {
assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs,
Idxs+NumIdx) ==
@@ -1582,7 +1584,7 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
"GEP indices invalid!");
if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/true,
- (Constant**)Idxs, NumIdx))
+ Idxs, NumIdx))
return FC; // Fold a few common cases...
assert(C->getType()->isPointerTy() &&
@@ -1600,8 +1602,9 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
}
-Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
- unsigned NumIdx) {
+template<typename IndexTy>
+Constant *ConstantExpr::getGetElementPtrImpl(Constant *C, IndexTy const *Idxs,
+ unsigned NumIdx) {
// Get the result type of the getelementptr!
const Type *Ty =
GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
@@ -1610,9 +1613,10 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
}
-Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
- Value* const *Idxs,
- unsigned 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);
@@ -1621,15 +1625,26 @@ Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
return getInBoundsGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
}
-Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs,
+Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
+ unsigned NumIdx) {
+ return getGetElementPtrImpl(C, Idxs, NumIdx);
+}
+
+Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant *const *Idxs,
unsigned NumIdx) {
- return getGetElementPtr(C, (Value* const *)Idxs, 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,
+ Constant *const *Idxs,
unsigned NumIdx) {
- return getInBoundsGetElementPtr(C, (Value* const *)Idxs, NumIdx);
+ return getInBoundsGetElementPtrImpl(C, Idxs, NumIdx);
}
Constant *
OpenPOWER on IntegriCloud