[PATCH] D74691: [Attributor] add some pattern to containsCycle
omar ahmed via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 19 03:31:09 PST 2020
omarahmed updated this revision to Diff 245368.
omarahmed added a comment.
it's a bit messy but is the approach right
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74691/new/
https://reviews.llvm.org/D74691
Files:
llvm/lib/Transforms/IPO/Attributor.cpp
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2369,14 +2369,42 @@
// Helper function that checks whether a function has any cycle.
// TODO: Replace with more efficent code
static bool containsCycle(Function &F) {
- SmallPtrSet<BasicBlock *, 32> Visited;
+ bool noAnalysis = false;
- // Traverse BB by dfs and check whether successor is already visited.
- for (BasicBlock *BB : depth_first(&F)) {
- Visited.insert(BB);
- for (auto *SuccBB : successors(BB)) {
- if (Visited.count(SuccBB))
- return true;
+ ScalarEvolution *SE =
+ A.getInfoCache().getAnalysisResultForFunction<ScalarEvolutionAnalysis>(F);
+ LoopInfo *LI = A.getInfoCache().getAnalysisResultForFunction<LoopAnalysis>(F);
+
+ if (!LI || !SE) {
+ noAnalysis = true;
+ }
+
+ for (scc_iterator<Function *> I = scc_begin(&F), IE = scc_end(&F); I != IE;
+ ++I) {
+ const std::vector<BasicBlock *> &SCCBBs = *I;
+ // when noAnalysis available then check only if the SCC has loop or not
+ if (noAnalysis) {
+ if (I.hasLoop()) return true;
+ continue;
+ }
+ // when current SCC has a single block with no loop continue to the next SCC
+ if (!I.hasLoop()) continue;
+
+ std::vector<BasicBlock *>::const_iterator BBI = SCCBBs.begin();
+ Loop *L = LI->getLoopFor(*BBI);
+ if (!L) {
+ return true;
+ }
+ if (L->getNumBlocks() > SCCBBs.size()) return true;
+ if (L->getNumBlocks() == SCCBBs.size()) {
+ if (!SE->getSmallConstantMaxTripCount(L)) return true;
+ continue;
+ }
+ L = L->getParentLoop();
+ if (L->getNumBlocks() > SCCBBs.size()) return true;
+ if (L->getNumBlocks() == SCCBBs.size()) {
+ if (!SE->getSmallConstantMaxTripCount(L)) return true;
+ continue;
}
}
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74691.245368.patch
Type: text/x-patch
Size: 1932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200219/a53d2c0e/attachment.bin>
More information about the llvm-commits
mailing list