diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Constants.h | 1 | ||||
-rw-r--r-- | include/llvm/InstrTypes.h | 21 | ||||
-rw-r--r-- | include/llvm/Support/ConstantFolder.h | 3 | ||||
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 6 | ||||
-rw-r--r-- | include/llvm/Support/NoFolder.h | 3 | ||||
-rw-r--r-- | include/llvm/Support/TargetFolder.h | 3 |
6 files changed, 37 insertions, 0 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 78b3ca83ea..30b48beb87 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -636,6 +636,7 @@ public: static Constant *getIntToPtr(Constant *C, const Type *Ty); static Constant *getBitCast (Constant *C, const Type *Ty); + static Constant* getNSWAdd(Constant* C1, Constant* C2); static Constant* getExactSDiv(Constant* C1, Constant* C2); /// Transparently provide more efficient getOperand methods. diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 9df99a7c6f..ce37521937 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -196,6 +196,27 @@ public: #include "llvm/Instruction.def" + /// CreateNSWAdd - Create an Add operator with the NSW flag set. + /// + static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2, + const Twine &Name = "") { + BinaryOperator *BO = CreateAdd(V1, V2, Name); + cast<AddOperator>(BO)->setHasNoSignedOverflow(true); + return BO; + } + static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2, + const Twine &Name, BasicBlock *BB) { + BinaryOperator *BO = CreateAdd(V1, V2, Name, BB); + cast<AddOperator>(BO)->setHasNoSignedOverflow(true); + return BO; + } + static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2, + const Twine &Name, Instruction *I) { + BinaryOperator *BO = CreateAdd(V1, V2, Name, I); + cast<AddOperator>(BO)->setHasNoSignedOverflow(true); + return BO; + } + /// CreateExactSDiv - Create an SDiv operator with the exact flag set. /// static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2, diff --git a/include/llvm/Support/ConstantFolder.h b/include/llvm/Support/ConstantFolder.h index 1b5b2b7745..ef70a898e4 100644 --- a/include/llvm/Support/ConstantFolder.h +++ b/include/llvm/Support/ConstantFolder.h @@ -35,6 +35,9 @@ public: Constant *CreateAdd(Constant *LHS, Constant *RHS) const { return ConstantExpr::getAdd(LHS, RHS); } + Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const { + return ConstantExpr::getNSWAdd(LHS, RHS); + } Constant *CreateFAdd(Constant *LHS, Constant *RHS) const { return ConstantExpr::getFAdd(LHS, RHS); } diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 89dd2953da..2e24d5ec1d 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -199,6 +199,12 @@ public: return Folder.CreateAdd(LC, RC); return Insert(BinaryOperator::CreateAdd(LHS, RHS), Name); } + Value *CreateNSWAdd(Value *LHS, Value *RHS, const char *Name = "") { + if (Constant *LC = dyn_cast<Constant>(LHS)) + if (Constant *RC = dyn_cast<Constant>(RHS)) + return Folder.CreateNSWAdd(LC, RC); + return Insert(BinaryOperator::CreateNSWAdd(LHS, RHS), Name); + } Value *CreateFAdd(Value *LHS, Value *RHS, const char *Name = "") { if (Constant *LC = dyn_cast<Constant>(LHS)) if (Constant *RC = dyn_cast<Constant>(RHS)) diff --git a/include/llvm/Support/NoFolder.h b/include/llvm/Support/NoFolder.h index 5333b87efd..4540f028ce 100644 --- a/include/llvm/Support/NoFolder.h +++ b/include/llvm/Support/NoFolder.h @@ -42,6 +42,9 @@ public: Value *CreateAdd(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateAdd(LHS, RHS); } + Value *CreateNSWAdd(Constant *LHS, Constant *RHS) const { + return BinaryOperator::CreateNSWAdd(LHS, RHS); + } Value *CreateFAdd(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateFAdd(LHS, RHS); } diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h index 2569cb9019..77533c00b1 100644 --- a/include/llvm/Support/TargetFolder.h +++ b/include/llvm/Support/TargetFolder.h @@ -51,6 +51,9 @@ public: Constant *CreateAdd(Constant *LHS, Constant *RHS) const { return Fold(ConstantExpr::getAdd(LHS, RHS)); } + Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const { + return Fold(ConstantExpr::getNSWAdd(LHS, RHS)); + } Constant *CreateFAdd(Constant *LHS, Constant *RHS) const { return Fold(ConstantExpr::getFAdd(LHS, RHS)); } |