aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Support
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support')
-rw-r--r--include/llvm/Support/ConstantFolder.h3
-rw-r--r--include/llvm/Support/IRBuilder.h16
-rw-r--r--include/llvm/Support/NoFolder.h3
-rw-r--r--include/llvm/Support/TargetFolder.h3
4 files changed, 21 insertions, 4 deletions
diff --git a/include/llvm/Support/ConstantFolder.h b/include/llvm/Support/ConstantFolder.h
index cb9b055..422d1ad 100644
--- a/include/llvm/Support/ConstantFolder.h
+++ b/include/llvm/Support/ConstantFolder.h
@@ -56,6 +56,9 @@ public:
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);
}
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index b2619a5..a8663d2 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -241,6 +241,12 @@ public:
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 @@ public:
/// 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 @@ public:
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);
}
};
diff --git a/include/llvm/Support/NoFolder.h b/include/llvm/Support/NoFolder.h
index e0fb9cd..b89c084 100644
--- a/include/llvm/Support/NoFolder.h
+++ b/include/llvm/Support/NoFolder.h
@@ -63,6 +63,9 @@ public:
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);
}
diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h
index cdcc4a8..900c326 100644
--- a/include/llvm/Support/TargetFolder.h
+++ b/include/llvm/Support/TargetFolder.h
@@ -72,6 +72,9 @@ public:
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));
}