diff --git a/include/llvm/Support/ConstantFolder.h b/include/llvm/Support/ConstantFolder.h index 699c6281b34..771784b4f9c 100644 --- a/include/llvm/Support/ConstantFolder.h +++ b/include/llvm/Support/ConstantFolder.h @@ -118,22 +118,36 @@ public: // Memory Instructions //===--------------------------------------------------------------------===// - Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx); + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size()); } - Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx); + Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const { + // This form of the function only exists to avoid ambiguous overload + // warnings about whether to convert Idx to ArrayRef or + // ArrayRef. + return ConstantExpr::getGetElementPtr(C, &Idx, 1); + } + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size()); } - Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx); + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(), + IdxList.size()); } - Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx); + Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const { + // This form of the function only exists to avoid ambiguous overload + // warnings about whether to convert Idx to ArrayRef or + // ArrayRef. + return ConstantExpr::getInBoundsGetElementPtr(C, &Idx, 1); + } + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(), + IdxList.size()); } //===--------------------------------------------------------------------===// diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index e166b199dd1..18a3fa39c42 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -774,8 +774,8 @@ public: if (!isa(*i)) break; if (i == IdxEnd) - return Insert(Folder.CreateGetElementPtr(PC, &IdxBegin[0], - IdxEnd - IdxBegin), + return Insert(Folder.CreateGetElementPtr(PC, makeArrayRef(IdxBegin, + IdxEnd)), Name); } return Insert(GetElementPtrInst::Create(Ptr, IdxBegin, IdxEnd), Name); @@ -792,8 +792,8 @@ public: break; if (i == IdxEnd) return Insert(Folder.CreateInBoundsGetElementPtr(PC, - &IdxBegin[0], - IdxEnd - IdxBegin), + makeArrayRef(IdxBegin, + IdxEnd)), Name); } return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxBegin, IdxEnd), @@ -802,20 +802,20 @@ public: Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") { if (Constant *PC = dyn_cast(Ptr)) if (Constant *IC = dyn_cast(Idx)) - return Insert(Folder.CreateGetElementPtr(PC, &IC, 1), Name); + return Insert(Folder.CreateGetElementPtr(PC, IC), Name); return Insert(GetElementPtrInst::Create(Ptr, Idx), Name); } Value *CreateInBoundsGEP(Value *Ptr, Value *Idx, const Twine &Name = "") { if (Constant *PC = dyn_cast(Ptr)) if (Constant *IC = dyn_cast(Idx)) - return Insert(Folder.CreateInBoundsGetElementPtr(PC, &IC, 1), Name); + return Insert(Folder.CreateInBoundsGetElementPtr(PC, IC), Name); return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name); } Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") { Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0); if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateGetElementPtr(PC, &Idx, 1), Name); + return Insert(Folder.CreateGetElementPtr(PC, Idx), Name); return Insert(GetElementPtrInst::Create(Ptr, &Idx, &Idx+1), Name); } @@ -824,7 +824,7 @@ public: Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0); if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1), Name); + return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name); return Insert(GetElementPtrInst::CreateInBounds(Ptr, &Idx, &Idx+1), Name); } @@ -836,7 +836,7 @@ public: }; if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateGetElementPtr(PC, Idxs, 2), Name); + return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name); return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name); } @@ -848,7 +848,7 @@ public: }; if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs, 2), Name); + return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name); return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name); } @@ -856,7 +856,7 @@ public: Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0); if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateGetElementPtr(PC, &Idx, 1), Name); + return Insert(Folder.CreateGetElementPtr(PC, Idx), Name); return Insert(GetElementPtrInst::Create(Ptr, &Idx, &Idx+1), Name); } @@ -865,7 +865,7 @@ public: Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0); if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1), Name); + return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name); return Insert(GetElementPtrInst::CreateInBounds(Ptr, &Idx, &Idx+1), Name); } @@ -877,7 +877,7 @@ public: }; if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateGetElementPtr(PC, Idxs, 2), Name); + return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name); return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name); } @@ -889,7 +889,7 @@ public: }; if (Constant *PC = dyn_cast(Ptr)) - return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs, 2), Name); + return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name); return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name); } diff --git a/include/llvm/Support/NoFolder.h b/include/llvm/Support/NoFolder.h index 28447f74973..7f14cd2bcd1 100644 --- a/include/llvm/Support/NoFolder.h +++ b/include/llvm/Support/NoFolder.h @@ -177,22 +177,23 @@ public: // Memory Instructions //===--------------------------------------------------------------------===// - Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx); + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size()); } - Instruction *CreateGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return GetElementPtrInst::Create(C, IdxList, IdxList+NumIdx); + Instruction *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return GetElementPtrInst::Create(C, IdxList.begin(), IdxList.end()); } - Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx); + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(), + IdxList.size()); } - Instruction *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return GetElementPtrInst::CreateInBounds(C, IdxList, IdxList+NumIdx); + Instruction *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return GetElementPtrInst::CreateInBounds(C, IdxList.begin(), IdxList.end()); } //===--------------------------------------------------------------------===// diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h index c13e7417395..2be8b74eb67 100644 --- a/include/llvm/Support/TargetFolder.h +++ b/include/llvm/Support/TargetFolder.h @@ -130,22 +130,32 @@ public: // Memory Instructions //===--------------------------------------------------------------------===// - Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx)); + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(), + IdxList.size())); } - Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx)); + Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const { + // This form of the function only exists to avoid ambiguous overload + // warnings about whether to convert Idx to ArrayRef or + // ArrayRef. + return Fold(ConstantExpr::getGetElementPtr(C, &Idx, 1)); + } + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(), + IdxList.size())); } - Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx)); + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(), + IdxList.size())); } - Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx)); + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(), + IdxList.size())); } //===--------------------------------------------------------------------===//