diff options
author | Dan Gohman <gohman@apple.com> | 2009-09-03 22:17:40 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-09-03 22:17:40 +0000 |
commit | e56a94ef91009ddb8d8b68783ff1650bcad3b326 (patch) | |
tree | 1c8c18901981239213e9c0c60e52786bd8916c38 /lib | |
parent | 5e41178a6ee9a0faa2c031811d32543d7e9d0aff (diff) |
Remove the API for creating ConstantExprs with the nsw, nuw, inbounds,
and exact flags. Because ConstantExprs are uniqued, creating an
expression with this flag causes all expressions with the same operands
to have the same flag, which may not be safe. Add, sub, mul, and sdiv
ConstantExprs are usually folded anyway, so the main interesting flag
here is inbounds, and the constant folder already knows how to set the
inbounds flag automatically in most cases, so there isn't an urgent need
for the API support.
This can be reconsidered in the future, but for now just removing these
API bits eliminates a source of potential trouble with little downside.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80959 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 18 | ||||
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 35 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 22 |
4 files changed, 13 insertions, 66 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 109eaad458..9bc0093881 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -203,15 +203,21 @@ static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps, if (Offset != 0) return 0; + // Create the GEP constant expr. + Constant *C = ConstantExpr::getGetElementPtr(Ptr, + &NewIdxs[0], NewIdxs.size()); + assert(cast<PointerType>(C->getType())->getElementType() == Ty && + "Computed GetElementPtr has unexpected type!"); + // If the base is the start of a GlobalVariable and all the array indices // remain in their static bounds, the GEP is inbounds. We can check that // all indices are in bounds by just checking the first index only - // because we've just normalized all the indices. - Constant *C = isa<GlobalVariable>(Ptr) && NewIdxs[0]->isNullValue() ? - ConstantExpr::getInBoundsGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()) : - ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()); - assert(cast<PointerType>(C->getType())->getElementType() == Ty && - "Computed GetElementPtr has unexpected type!"); + // because we've just normalized all the indices. We can mutate the + // Constant in place because we've proven that the indices are in bounds, + // so they'll always be in bounds. + if (isa<GlobalVariable>(Ptr) && NewIdxs[0]->isNullValue()) + if (GEPOperator *GEP = dyn_cast<GEPOperator>(C)) + GEP->setIsInBounds(true); // If we ended up indexing a member with a type that doesn't match // the type of what the original indices indexed, add a cast. diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 701a195f7f..a869467245 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -122,9 +122,7 @@ static Constant *FoldBitCast(LLVMContext &Context, } if (ElTy == DPTy->getElementType()) - // This GEP is inbounds because all indices are zero. - return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0], - IdxList.size()); + return ConstantExpr::getGetElementPtr(V, &IdxList[0], IdxList.size()); } // Handle casts from one vector constant to another. We know that the src diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 37efafc9b2..1ddc1e27b0 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -631,24 +631,6 @@ Constant* ConstantVector::get(Constant* const* Vals, unsigned NumVals) { return get(std::vector<Constant*>(Vals, Vals+NumVals)); } -Constant* ConstantExpr::getNSWAdd(Constant* C1, Constant* C2) { - Constant *C = getAdd(C1, C2); - // Set nsw attribute, assuming constant folding didn't eliminate the - // Add. - if (AddOperator *Add = dyn_cast<AddOperator>(C)) - Add->setHasNoSignedWrap(true); - return C; -} - -Constant* ConstantExpr::getExactSDiv(Constant* C1, Constant* C2) { - Constant *C = getSDiv(C1, C2); - // Set exact attribute, assuming constant folding didn't eliminate the - // SDiv. - if (SDivOperator *SDiv = dyn_cast<SDivOperator>(C)) - SDiv->setIsExact(true); - return C; -} - // Utility function for determining if a ConstantExpr is a CastOp or not. This // can't be inline because we don't want to #include Instruction.h into // Constant.h @@ -1491,28 +1473,11 @@ 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) { - Constant *Result = getGetElementPtr(C, Idxs, NumIdx); - // Set in bounds attribute, assuming constant folding didn't eliminate the - // GEP. - if (GEPOperator *GEP = dyn_cast<GEPOperator>(Result)) - GEP->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) { assert(LHS->getType() == RHS->getType()); diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 1dbf5c44ef..240b27af32 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -535,13 +535,6 @@ LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { unwrap<Constant>(RHSConstant))); } -LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, - LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getNSWAdd( - unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { return wrap(ConstantExpr::getFAdd( unwrap<Constant>(LHSConstant), @@ -583,13 +576,6 @@ LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { unwrap<Constant>(RHSConstant))); } -LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, - LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getExactSDiv( - unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { return wrap(ConstantExpr::getFDiv( unwrap<Constant>(LHSConstant), @@ -673,14 +659,6 @@ LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, NumIndices)); } -LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, - LLVMValueRef *ConstantIndices, - unsigned NumIndices) { - Constant* Val = unwrap<Constant>(ConstantVal); - Constant** Idxs = unwrap<Constant>(ConstantIndices, NumIndices); - return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, Idxs, NumIndices)); -} - LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { return wrap(ConstantExpr::getTrunc( unwrap<Constant>(ConstantVal), |