[PATCH] D102796: [SCEV] Cache operands used in BEInfo
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 25 12:03:57 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6300c37a461b: [SCEV] Cache operands used in BEInfo (NFC) (authored by nikic).
Changed prior to commit:
https://reviews.llvm.org/D102796?vs=346525&id=347752#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102796/new/
https://reviews.llvm.org/D102796
Files:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7392,18 +7392,8 @@
return MaxOrZero && !any_of(ExitNotTaken, PredicateNotAlwaysTrue);
}
-bool ScalarEvolution::BackedgeTakenInfo::hasOperand(const SCEV *S,
- ScalarEvolution *SE) const {
- if (getConstantMax() && getConstantMax() != SE->getCouldNotCompute() &&
- SE->hasOperand(getConstantMax(), S))
- return true;
-
- for (auto &ENT : ExitNotTaken)
- if (ENT.ExactNotTaken != SE->getCouldNotCompute() &&
- SE->hasOperand(ENT.ExactNotTaken, S))
- return true;
-
- return false;
+bool ScalarEvolution::BackedgeTakenInfo::hasOperand(const SCEV *S) const {
+ return Operands.contains(S);
}
ScalarEvolution::ExitLimit::ExitLimit(const SCEV *E)
@@ -7445,6 +7435,19 @@
"No point in having a non-constant max backedge taken count!");
}
+class SCEVRecordOperands {
+ SmallPtrSetImpl<const SCEV *> &Operands;
+
+public:
+ SCEVRecordOperands(SmallPtrSetImpl<const SCEV *> &Operands)
+ : Operands(Operands) {}
+ bool follow(const SCEV *S) {
+ Operands.insert(S);
+ return true;
+ }
+ bool isDone() { return false; }
+};
+
/// Allocate memory for BackedgeTakenInfo and copy the not-taken count of each
/// computable exit into a persistent ExitNotTakenInfo array.
ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo(
@@ -7473,6 +7476,14 @@
assert((isa<SCEVCouldNotCompute>(ConstantMax) ||
isa<SCEVConstant>(ConstantMax)) &&
"No point in having a non-constant max backedge taken count!");
+
+ SCEVRecordOperands RecordOperands(Operands);
+ SCEVTraversal<SCEVRecordOperands> ST(RecordOperands);
+ if (!isa<SCEVCouldNotCompute>(ConstantMax))
+ ST.visitAll(ConstantMax);
+ for (auto &ENT : ExitNotTaken)
+ if (!isa<SCEVCouldNotCompute>(ENT.ExactNotTaken))
+ ST.visitAll(ENT.ExactNotTaken);
}
/// Compute the number of times the backedge of the specified loop will execute.
@@ -12627,7 +12638,7 @@
[S, this](DenseMap<const Loop *, BackedgeTakenInfo> &Map) {
for (auto I = Map.begin(), E = Map.end(); I != E;) {
BackedgeTakenInfo &BEInfo = I->second;
- if (BEInfo.hasOperand(S, this))
+ if (BEInfo.hasOperand(S))
Map.erase(I++);
else
++I;
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1390,6 +1390,9 @@
/// True iff the backedge is taken either exactly Max or zero times.
bool MaxOrZero = false;
+ /// SCEV expressions used in any of the ExitNotTakenInfo counts.
+ SmallPtrSet<const SCEV *, 4> Operands;
+
bool isComplete() const { return IsComplete; }
const SCEV *getConstantMax() const { return ConstantMax; }
@@ -1458,7 +1461,7 @@
/// Return true if any backedge taken count expressions refer to the given
/// subexpression.
- bool hasOperand(const SCEV *S, ScalarEvolution *SE) const;
+ bool hasOperand(const SCEV *S) const;
};
/// Cache the backedge-taken count of the loops for this function as they
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102796.347752.patch
Type: text/x-patch
Size: 3366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210525/1e4cfd6b/attachment.bin>
More information about the llvm-commits
mailing list