diff options
author | Chris Lattner <sabre@nondot.org> | 2011-02-10 07:01:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-02-10 07:01:55 +0000 |
commit | 81baf14fdfa29c22a08d609144c285169e23a247 (patch) | |
tree | bba3c5900147b7575bf52c6f20cf84fc1a383b2b /lib/VMCore | |
parent | 7a6aa1a3919af8ece92702c36dc552d81be9151a (diff) | |
download | external_llvm-81baf14fdfa29c22a08d609144c285169e23a247.zip external_llvm-81baf14fdfa29c22a08d609144c285169e23a247.tar.gz external_llvm-81baf14fdfa29c22a08d609144c285169e23a247.tar.bz2 |
switch the constantexpr, target folder, and IRBuilder interfaces
for NSW/NUW binops to follow the pattern of exact binops. This
allows someone to use Builder.CreateAdd(x, y, "tmp", MaybeNUW);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125270 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Constants.cpp | 91 |
1 files changed, 24 insertions, 67 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 4ce2af1..1cd6b0b 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -639,58 +639,6 @@ Constant *ConstantVector::get(Constant *const* Vals, unsigned NumVals) { return get(std::vector<Constant*>(Vals, Vals+NumVals)); } -Constant *ConstantExpr::getNSWNeg(Constant *C) { - assert(C->getType()->isIntOrIntVectorTy() && - "Cannot NEG a nonintegral value!"); - return getNSWSub(ConstantFP::getZeroValueForNegation(C->getType()), C); -} - -Constant *ConstantExpr::getNUWNeg(Constant *C) { - assert(C->getType()->isIntOrIntVectorTy() && - "Cannot NEG a nonintegral value!"); - return getNUWSub(ConstantFP::getZeroValueForNegation(C->getType()), C); -} - -Constant *ConstantExpr::getNSWAdd(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Add, C1, C2, - OverflowingBinaryOperator::NoSignedWrap); -} - -Constant *ConstantExpr::getNUWAdd(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Add, C1, C2, - OverflowingBinaryOperator::NoUnsignedWrap); -} - -Constant *ConstantExpr::getNSWSub(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Sub, C1, C2, - OverflowingBinaryOperator::NoSignedWrap); -} - -Constant *ConstantExpr::getNUWSub(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Sub, C1, C2, - OverflowingBinaryOperator::NoUnsignedWrap); -} - -Constant *ConstantExpr::getNSWMul(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Mul, C1, C2, - OverflowingBinaryOperator::NoSignedWrap); -} - -Constant *ConstantExpr::getNUWMul(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Mul, C1, C2, - OverflowingBinaryOperator::NoUnsignedWrap); -} - -Constant *ConstantExpr::getNSWShl(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Shl, C1, C2, - OverflowingBinaryOperator::NoSignedWrap); -} - -Constant *ConstantExpr::getNUWShl(Constant *C1, Constant *C2) { - return getTy(C1->getType(), Instruction::Shl, C1, C2, - OverflowingBinaryOperator::NoUnsignedWrap); -} - // 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 @@ -1823,20 +1771,17 @@ Constant *ConstantExpr::getExtractValue(Constant *Agg, return getExtractValueTy(ReqTy, Agg, IdxList, NumIdx); } -Constant *ConstantExpr::getNeg(Constant *C) { +Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) { assert(C->getType()->isIntOrIntVectorTy() && "Cannot NEG a nonintegral value!"); - return get(Instruction::Sub, - ConstantFP::getZeroValueForNegation(C->getType()), - C); + return getSub(ConstantFP::getZeroValueForNegation(C->getType()), + C, HasNUW, HasNSW); } Constant *ConstantExpr::getFNeg(Constant *C) { assert(C->getType()->isFPOrFPVectorTy() && "Cannot FNEG a non-floating-point value!"); - return get(Instruction::FSub, - ConstantFP::getZeroValueForNegation(C->getType()), - C); + return getFSub(ConstantFP::getZeroValueForNegation(C->getType()), C); } Constant *ConstantExpr::getNot(Constant *C) { @@ -1845,24 +1790,33 @@ Constant *ConstantExpr::getNot(Constant *C) { return get(Instruction::Xor, C, Constant::getAllOnesValue(C->getType())); } -Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) { - return get(Instruction::Add, C1, C2); +Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2, + bool HasNUW, bool HasNSW) { + unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) | + (HasNSW ? OverflowingBinaryOperator::NoSignedWrap : 0); + return get(Instruction::Add, C1, C2, Flags); } Constant *ConstantExpr::getFAdd(Constant *C1, Constant *C2) { return get(Instruction::FAdd, C1, C2); } -Constant *ConstantExpr::getSub(Constant *C1, Constant *C2) { - return get(Instruction::Sub, C1, C2); +Constant *ConstantExpr::getSub(Constant *C1, Constant *C2, + bool HasNUW, bool HasNSW) { + unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) | + (HasNSW ? OverflowingBinaryOperator::NoSignedWrap : 0); + return get(Instruction::Sub, C1, C2, Flags); } Constant *ConstantExpr::getFSub(Constant *C1, Constant *C2) { return get(Instruction::FSub, C1, C2); } -Constant *ConstantExpr::getMul(Constant *C1, Constant *C2) { - return get(Instruction::Mul, C1, C2); +Constant *ConstantExpr::getMul(Constant *C1, Constant *C2, + bool HasNUW, bool HasNSW) { + unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) | + (HasNSW ? OverflowingBinaryOperator::NoSignedWrap : 0); + return get(Instruction::Mul, C1, C2, Flags); } Constant *ConstantExpr::getFMul(Constant *C1, Constant *C2) { @@ -1907,8 +1861,11 @@ Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) { return get(Instruction::Xor, C1, C2); } -Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) { - return get(Instruction::Shl, C1, C2); +Constant *ConstantExpr::getShl(Constant *C1, Constant *C2, + bool HasNUW, bool HasNSW) { + unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) | + (HasNSW ? OverflowingBinaryOperator::NoSignedWrap : 0); + return get(Instruction::Shl, C1, C2, Flags); } Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2, bool isExact) { |