[llvm-commits] [llvm] r78682 - in /llvm/trunk: include/llvm/Constants.h include/llvm/InstrTypes.h include/llvm/Support/ConstantFolder.h include/llvm/Support/IRBuilder.h include/llvm/Support/NoFolder.h include/llvm/Support/TargetFolder.h lib/VMCore/Constants.cpp
Dan Gohman
gohman at apple.com
Tue Aug 11 10:05:25 PDT 2009
Author: djg
Date: Tue Aug 11 12:05:24 2009
New Revision: 78682
URL: http://llvm.org/viewvc/llvm-project?rev=78682&view=rev
Log:
Add convenience functions for creating exact sdiv operators, and
use them in CreatePtrDiff.
Modified:
llvm/trunk/include/llvm/Constants.h
llvm/trunk/include/llvm/InstrTypes.h
llvm/trunk/include/llvm/Support/ConstantFolder.h
llvm/trunk/include/llvm/Support/IRBuilder.h
llvm/trunk/include/llvm/Support/NoFolder.h
llvm/trunk/include/llvm/Support/TargetFolder.h
llvm/trunk/lib/VMCore/Constants.cpp
Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Tue Aug 11 12:05:24 2009
@@ -636,6 +636,8 @@
static Constant *getIntToPtr(Constant *C, const Type *Ty);
static Constant *getBitCast (Constant *C, const Type *Ty);
+ static Constant* getExactSDiv(Constant* C1, Constant* C2);
+
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
Modified: llvm/trunk/include/llvm/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InstrTypes.h?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/InstrTypes.h Tue Aug 11 12:05:24 2009
@@ -18,6 +18,7 @@
#include "llvm/Instruction.h"
#include "llvm/OperandTraits.h"
+#include "llvm/Operator.h"
#include "llvm/DerivedTypes.h"
namespace llvm {
@@ -195,6 +196,27 @@
#include "llvm/Instruction.def"
+ /// CreateExactSDiv - Create an SDiv operator with the exact flag set.
+ ///
+ static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
+ const Twine &Name = "") {
+ BinaryOperator *BO = CreateSDiv(V1, V2, Name);
+ cast<SDivOperator>(BO)->setIsExact(true);
+ return BO;
+ }
+ static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
+ const Twine &Name, BasicBlock *BB) {
+ BinaryOperator *BO = CreateSDiv(V1, V2, Name, BB);
+ cast<SDivOperator>(BO)->setIsExact(true);
+ return BO;
+ }
+ static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
+ const Twine &Name, Instruction *I) {
+ BinaryOperator *BO = CreateSDiv(V1, V2, Name, I);
+ cast<SDivOperator>(BO)->setIsExact(true);
+ return BO;
+ }
+
/// Helper functions to construct and inspect unary operations (NEG and NOT)
/// via binary operators SUB and XOR:
///
Modified: llvm/trunk/include/llvm/Support/ConstantFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantFolder.h?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ConstantFolder.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantFolder.h Tue Aug 11 12:05:24 2009
@@ -56,6 +56,9 @@
Constant *CreateSDiv(Constant *LHS, Constant *RHS) const {
return ConstantExpr::getSDiv(LHS, RHS);
}
+ Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
+ return ConstantExpr::getExactSDiv(LHS, RHS);
+ }
Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
return ConstantExpr::getFDiv(LHS, RHS);
}
Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Aug 11 12:05:24 2009
@@ -241,6 +241,12 @@
return Folder.CreateSDiv(LC, RC);
return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
}
+ Value *CreateExactSDiv(Value *LHS, Value *RHS, const char *Name = "") {
+ if (Constant *LC = dyn_cast<Constant>(LHS))
+ if (Constant *RC = dyn_cast<Constant>(RHS))
+ return Folder.CreateExactSDiv(LC, RC);
+ return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
+ }
Value *CreateFDiv(Value *LHS, Value *RHS, const char *Name = "") {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
@@ -719,7 +725,9 @@
/// CreatePtrDiff - Return the i64 difference between two pointer values,
/// dividing out the size of the pointed-to objects. This is intended to
- /// implement C-style pointer subtraction.
+ /// implement C-style pointer subtraction. As such, the pointers must be
+ /// appropriately aligned for their element types and pointing into the
+ /// same object.
Value *CreatePtrDiff(Value *LHS, Value *RHS, const char *Name = "") {
assert(LHS->getType() == RHS->getType() &&
"Pointer subtraction operand types must match!");
@@ -727,9 +735,9 @@
Value *LHS_int = CreatePtrToInt(LHS, Type::Int64Ty);
Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
Value *Difference = CreateSub(LHS_int, RHS_int);
- return CreateSDiv(Difference,
- ConstantExpr::getSizeOf(ArgType->getElementType()),
- Name);
+ return CreateExactSDiv(Difference,
+ ConstantExpr::getSizeOf(ArgType->getElementType()),
+ Name);
}
};
Modified: llvm/trunk/include/llvm/Support/NoFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/NoFolder.h?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/NoFolder.h (original)
+++ llvm/trunk/include/llvm/Support/NoFolder.h Tue Aug 11 12:05:24 2009
@@ -63,6 +63,9 @@
Value *CreateSDiv(Constant *LHS, Constant *RHS) const {
return BinaryOperator::CreateSDiv(LHS, RHS);
}
+ Value *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
+ return BinaryOperator::CreateExactSDiv(LHS, RHS);
+ }
Value *CreateFDiv(Constant *LHS, Constant *RHS) const {
return BinaryOperator::CreateFDiv(LHS, RHS);
}
Modified: llvm/trunk/include/llvm/Support/TargetFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetFolder.h?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/TargetFolder.h (original)
+++ llvm/trunk/include/llvm/Support/TargetFolder.h Tue Aug 11 12:05:24 2009
@@ -72,6 +72,9 @@
Constant *CreateSDiv(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getSDiv(LHS, RHS));
}
+ Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
+ return Fold(ConstantExpr::getExactSDiv(LHS, RHS));
+ }
Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getFDiv(LHS, RHS));
}
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=78682&r1=78681&r2=78682&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Aug 11 12:05:24 2009
@@ -605,6 +605,12 @@
return get(std::vector<Constant*>(Vals, Vals+NumVals));
}
+Constant* ConstantExpr::getExactSDiv(Constant* C1, Constant* C2) {
+ Constant *C = getSDiv(C1, C2);
+ cast<SDivOperator>(C)->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
More information about the llvm-commits
mailing list