[PATCH] D74691: add some pattern to containsCycle

omar ahmed via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 16 07:25:28 PST 2020


omarahmed created this revision.
omarahmed added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a reviewer: sstefan1.
Herald added a project: LLVM.

Merge branch 'master' of https://github.com/llvm/llvm-project

add some pattern to containsCycle


Repository:
  rG LLVM Github Monorepo

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
@@ -2368,15 +2368,27 @@
 
 // Helper function that checks whether a function has any cycle.
 // TODO: Replace with more efficent code
-static bool containsCycle(Function &F) {
+static bool containsCycle(Function &F,Attributor &A) {
   SmallPtrSet<BasicBlock *, 32> Visited;
 
   // 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))
+      if (Visited.count(SuccBB)){
+        ScalarEvolution *SE =
+          A.getInfoCache().getAnalysisResultForFunction<ScalarEvolutionAnalysis>(F);
+
+        LoopInfo *LI = 
+          A.getInfoCache().getAnalysisResultForFunction<LoopAnalysis>(F);
+
+        if(LI->isLoopHeader(BB)){
+          Loop *L = LI->getLoopFor(BB);
+          if(SE->getSmallConstantMaxTripCount(L)) return false;
+          return true;
+        }
         return true;
+      }
     }
   }
   return false;
@@ -2386,8 +2398,8 @@
 // endless loop
 // FIXME: Any cycle is regarded as endless loop for now.
 //        We have to allow some patterns.
-static bool containsPossiblyEndlessLoop(Function *F) {
-  return !F || !F->hasExactDefinition() || containsCycle(*F);
+static bool containsPossiblyEndlessLoop(Function *F,Attributor &A) {  
+  return !F || !F->hasExactDefinition() || containsCycle(*F,A);
 }
 
 struct AAWillReturnImpl : public AAWillReturn {
@@ -2398,7 +2410,7 @@
     AAWillReturn::initialize(A);
 
     Function *F = getAssociatedFunction();
-    if (containsPossiblyEndlessLoop(F))
+    if (containsPossiblyEndlessLoop(F,A))
       indicatePessimisticFixpoint();
   }
 
@@ -7374,7 +7386,7 @@
     for (Instruction *I : OpcodeInstMap[Opcode]) {
       // Skip dead instructions.
       if (A && A->isAssumedDead(IRPosition::value(*I), QueryingAA, LivenessAA,
-                                CheckBBLivenessOnly))
+				 CheckBBLivenessOnly))
         continue;
 
       if (!Pred(*I))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74691.244875.patch
Type: text/x-patch
Size: 2182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200216/aeac6f92/attachment.bin>


More information about the llvm-commits mailing list