aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorTyker <tyker1@outlook.com>2020-06-15 10:57:17 +0200
committerTyker <tyker1@outlook.com>2020-06-16 13:12:35 +0200
commit90c50cad1983c5e29107a78382dead0fe2a9562c (patch)
tree331b2424a6da7c0cc44386883befeb21f009bc8c /llvm/lib/IR
parent740575dc232b25de0a4bedb41e825ee2e5a056ea (diff)
downloadllvm-90c50cad1983c5e29107a78382dead0fe2a9562c.zip
llvm-90c50cad1983c5e29107a78382dead0fe2a9562c.tar.gz
llvm-90c50cad1983c5e29107a78382dead0fe2a9562c.tar.bz2
[AssumeBundles] add cannonicalisation to the assume builder
Summary: this reduces significantly the number of assumes generated without aftecting too much the information that is preserved. this improves the compile-time cost of enable-knowledge-retention significantly. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: hiraditya, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79650
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Operator.cpp27
-rw-r--r--llvm/lib/IR/Value.cpp10
2 files changed, 34 insertions, 3 deletions
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index baf3a05..df6f08d 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -31,6 +31,33 @@ Type *GEPOperator::getResultElementType() const {
return cast<GetElementPtrConstantExpr>(this)->getResultElementType();
}
+Align GEPOperator::getMaxPreservedAlignment(const DataLayout &DL) const {
+ /// compute the worse possible offset for every level of the GEP et accumulate
+ /// the minimum alignment into Result.
+
+ Align Result = Align(llvm::Value::MaximumAlignment);
+ for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this);
+ GTI != GTE; ++GTI) {
+ int64_t Offset = 1;
+ ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
+
+ if (StructType *STy = GTI.getStructTypeOrNull()) {
+ const StructLayout *SL = DL.getStructLayout(STy);
+ Offset = SL->getElementOffset(OpC->getZExtValue());
+ } else {
+ assert(GTI.isSequential() && "should be sequencial");
+ /// If the index isn't know we take 1 because it is the index that will
+ /// give the worse alignment of the offset.
+ int64_t ElemCount = 1;
+ if (OpC)
+ ElemCount = OpC->getZExtValue();
+ Offset = DL.getTypeAllocSize(GTI.getIndexedType()) * ElemCount;
+ }
+ Result = Align(MinAlign(Offset, Result.value()));
+ }
+ return Result;
+}
+
bool GEPOperator::accumulateConstantOffset(
const DataLayout &DL, APInt &Offset,
function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 70d4012..78c12f4 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -516,7 +516,9 @@ enum PointerStripKind {
};
template <PointerStripKind StripKind>
-static const Value *stripPointerCastsAndOffsets(const Value *V) {
+static const Value *stripPointerCastsAndOffsets(
+ const Value *V,
+ function_ref<void(const Value *)> Func = [](const Value *) {}) {
if (!V->getType()->isPointerTy())
return V;
@@ -526,6 +528,7 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {
Visited.insert(V);
do {
+ Func(V);
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
switch (StripKind) {
case PSK_ZeroIndices:
@@ -667,8 +670,9 @@ const Value *Value::stripAndAccumulateConstantOffsets(
return V;
}
-const Value *Value::stripInBoundsOffsets() const {
- return stripPointerCastsAndOffsets<PSK_InBounds>(this);
+const Value *
+Value::stripInBoundsOffsets(function_ref<void(const Value *)> Func) const {
+ return stripPointerCastsAndOffsets<PSK_InBounds>(this, Func);
}
uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,