[PATCH] D47087: [ScopHelper] Cache ScopExpander results.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 18 14:29:59 PDT 2018
efriedma created this revision.
efriedma added reviewers: grosser, Meinersbur.
Herald added a subscriber: javed.absar.
A naive SCEV visitor not linear in the number of SCEV expressions. For an expression like x*x, "x" will be visited twice. If x is itself an expression like x*x, that will be visited twice, etc, and the overall runtime is O(2^N) in the number of SCEV expressions.
To prevent this from happening, add a cache, so we only visit each SCEV expression once.
Not sure this is the best solution. Maybe we can instead check whether the SCEV is scop-invariant (in which case we never need to map the value). But we don't have a utility for that at the moment.
Repository:
rPLO Polly
https://reviews.llvm.org/D47087
Files:
lib/Support/ScopHelper.cpp
Index: lib/Support/ScopHelper.cpp
===================================================================
--- lib/Support/ScopHelper.cpp
+++ lib/Support/ScopHelper.cpp
@@ -249,13 +249,25 @@
return Expander.expandCodeFor(E, Ty, I);
}
+ const SCEV *visit(const SCEV *E) {
+ // Cache the expansion results for intermediate SCEV expressions. A SCEV
+ // expression can refer to an operand multiple times (e.g. "x*x), so
+ // a naive visitor takes exponential time.
+ if (SCEVCache.count(E))
+ return SCEVCache[E];
+ const SCEV *Result = SCEVVisitor::visit(E);
+ SCEVCache[E] = Result;
+ return Result;
+ }
+
private:
SCEVExpander Expander;
ScalarEvolution &SE;
const char *Name;
const Region &R;
ValueMapT *VMap;
BasicBlock *RTCBB;
+ DenseMap<const SCEV *, const SCEV *> SCEVCache;
const SCEV *visitGenericInst(const SCEVUnknown *E, Instruction *Inst,
Instruction *IP) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47087.147585.patch
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180518/1e82f4e2/attachment.bin>
More information about the llvm-commits
mailing list