summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Constants.h4
-rw-r--r--llvm/lib/VMCore/Constants.cpp7
2 files changed, 11 insertions, 0 deletions
diff --git a/llvm/include/llvm/Constants.h b/llvm/include/llvm/Constants.h
index 91e7b208a21..99b768f69b4 100644
--- a/llvm/include/llvm/Constants.h
+++ b/llvm/include/llvm/Constants.h
@@ -562,6 +562,10 @@ public:
///
static Constant *getSizeOf(const Type *Ty);
+ /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
+ /// return a pointer to a pointer of the array element type.
+ static Constant *getPtrPtrFromArrayPtr(Constant *C);
+
/// ConstantExpr::get - Return a binary or shift operator constant expression,
/// folding if possible.
///
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 71754fdac4b..ee60f804b3c 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1298,6 +1298,13 @@ Constant *ConstantExpr::getSizeOf(const Type *Ty) {
Type::ULongTy);
}
+Constant *ConstantExpr::getPtrPtrFromArrayPtr(Constant *C) {
+ // pointer from array is implemented as: getelementptr arr ptr, 0, 0
+ static std::vector<Constant*> Indices(2, ConstantUInt::get(Type::UIntTy, 0));
+
+ return ConstantExpr::getGetElementPtr(C, Indices);
+}
+
Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
Constant *C1, Constant *C2) {
if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)
OpenPOWER on IntegriCloud