diff options
author | Dan Gohman <gohman@apple.com> | 2009-08-11 17:57:01 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-08-11 17:57:01 +0000 |
commit | e2574d3215c412a15763d26aee9aa5d856764c2c (patch) | |
tree | c5d94d9987841e646bbffadceb943480cd203296 /lib/VMCore | |
parent | 7cd0118c367314308cf94765ac12f81020a56271 (diff) | |
download | external_llvm-e2574d3215c412a15763d26aee9aa5d856764c2c.zip external_llvm-e2574d3215c412a15763d26aee9aa5d856764c2c.tar.gz external_llvm-e2574d3215c412a15763d26aee9aa5d856764c2c.tar.bz2 |
Add convenience functions for creating inbounds GEPs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78695 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Constants.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 2670965..89578fb 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1363,6 +1363,7 @@ Constant* ConstantExpr::getSizeOf(const Type* Ty) { Constant* ConstantExpr::getAlignOf(const Type* Ty) { // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1 + // Note that a non-inbounds gep is used, as null isn't within any object. const Type *AligningTy = StructType::get(Ty->getContext(), Type::Int8Ty, Ty, NULL); Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo()); @@ -1438,11 +1439,30 @@ 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) { + // 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(); + Constant *Result = getGetElementPtrTy(PointerType::get(Ty, As), C, + Idxs, NumIdx); + cast<GEPOperator>(Result)->setIsInBounds(true); + return Result; +} + Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs, unsigned NumIdx) { return getGetElementPtr(C, (Value* const *)Idxs, NumIdx); } +Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C, + Constant* const *Idxs, + unsigned NumIdx) { + return getInBoundsGetElementPtr(C, (Value* const *)Idxs, NumIdx); +} Constant * ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) { |