From 1dbf0df996bba398a70abccc714b1a9652330014 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Mon, 7 Feb 2011 09:21:52 +0000 Subject: [PATCH] Add IRBuilder methods for creating an exact udiv, like for exact sdiv. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125002 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InstrTypes.h | 21 +++++++++++++++++++++ include/llvm/Operator.h | 2 +- include/llvm/Support/ConstantFolder.h | 3 +++ include/llvm/Support/IRBuilder.h | 6 ++++++ include/llvm/Support/NoFolder.h | 3 +++ include/llvm/Support/TargetFolder.h | 3 +++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 1bb50b78fae..1d9dab78082 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -321,6 +321,27 @@ public: return BO; } + /// CreateExactUDiv - Create a UDiv operator with the exact flag set. + /// + static BinaryOperator *CreateExactUDiv(Value *V1, Value *V2, + const Twine &Name = "") { + BinaryOperator *BO = CreateUDiv(V1, V2, Name); + BO->setIsExact(true); + return BO; + } + static BinaryOperator *CreateExactUDiv(Value *V1, Value *V2, + const Twine &Name, BasicBlock *BB) { + BinaryOperator *BO = CreateUDiv(V1, V2, Name, BB); + BO->setIsExact(true); + return BO; + } + static BinaryOperator *CreateExactUDiv(Value *V1, Value *V2, + const Twine &Name, Instruction *I) { + BinaryOperator *BO = CreateUDiv(V1, V2, Name, I); + BO->setIsExact(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/Operator.h b/include/llvm/Operator.h index 288edf12244..eaa28ad47fa 100644 --- a/include/llvm/Operator.h +++ b/include/llvm/Operator.h @@ -228,7 +228,7 @@ public: } }; -/// UDivOperator - An Operator with opcode Instruction::SDiv. +/// UDivOperator - An Operator with opcode Instruction::UDiv. /// class UDivOperator : public PossiblyExactOperator { public: diff --git a/include/llvm/Support/ConstantFolder.h b/include/llvm/Support/ConstantFolder.h index ea6c5fd82a0..93adb3a403d 100644 --- a/include/llvm/Support/ConstantFolder.h +++ b/include/llvm/Support/ConstantFolder.h @@ -72,6 +72,9 @@ public: Constant *CreateUDiv(Constant *LHS, Constant *RHS) const { return ConstantExpr::getUDiv(LHS, RHS); } + Constant *CreateExactUDiv(Constant *LHS, Constant *RHS) const { + return ConstantExpr::getExactUDiv(LHS, RHS); + } Constant *CreateSDiv(Constant *LHS, Constant *RHS) const { return ConstantExpr::getSDiv(LHS, RHS); } diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index e6c3cd8905b..981a92ab3e7 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -527,6 +527,12 @@ public: return Insert(Folder.CreateUDiv(LC, RC), Name); return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name); } + Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") { + if (Constant *LC = dyn_cast(LHS)) + if (Constant *RC = dyn_cast(RHS)) + return Insert(Folder.CreateExactUDiv(LC, RC), Name); + return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name); + } Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "") { if (Constant *LC = dyn_cast(LHS)) if (Constant *RC = dyn_cast(RHS)) diff --git a/include/llvm/Support/NoFolder.h b/include/llvm/Support/NoFolder.h index 37ad27fe4b3..d7b5b42924c 100644 --- a/include/llvm/Support/NoFolder.h +++ b/include/llvm/Support/NoFolder.h @@ -77,6 +77,9 @@ public: Instruction *CreateUDiv(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateUDiv(LHS, RHS); } + Instruction *CreateExactUDiv(Constant *LHS, Constant *RHS) const { + return BinaryOperator::CreateExactUDiv(LHS, RHS); + } Instruction *CreateSDiv(Constant *LHS, Constant *RHS) const { return BinaryOperator::CreateSDiv(LHS, RHS); } diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h index d34f35fe0d2..138885d48d1 100644 --- a/include/llvm/Support/TargetFolder.h +++ b/include/llvm/Support/TargetFolder.h @@ -85,6 +85,9 @@ public: Constant *CreateUDiv(Constant *LHS, Constant *RHS) const { return Fold(ConstantExpr::getUDiv(LHS, RHS)); } + Constant *CreateExactUDiv(Constant *LHS, Constant *RHS) const { + return Fold(ConstantExpr::getExactUDiv(LHS, RHS)); + } Constant *CreateSDiv(Constant *LHS, Constant *RHS) const { return Fold(ConstantExpr::getSDiv(LHS, RHS)); } -- 2.34.1