[PATCH] D59967: [llvm][NFC] Factor out logic for getting incoming & back Loop edges

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 10:40:29 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL357284: [llvm][NFC] Factor out logic for getting incoming & back Loop edges (authored by mtrofin, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59967?vs=192736&id=192861#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59967/new/

https://reviews.llvm.org/D59967

Files:
  llvm/trunk/include/llvm/Analysis/LoopInfo.h
  llvm/trunk/lib/Analysis/LoopInfo.cpp


Index: llvm/trunk/include/llvm/Analysis/LoopInfo.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h
@@ -521,6 +521,11 @@
   ///
   PHINode *getCanonicalInductionVariable() const;
 
+  /// Obtain the unique incoming and back edge. Return false if they are
+  /// non-unique or the loop is dead; otherwise, return true.
+  bool getIncomingAndBackEdge(BasicBlock *&Incoming,
+                              BasicBlock *&Backedge) const;
+
   /// Return true if the Loop is in LCSSA form.
   bool isLCSSAForm(DominatorTree &DT) const;
 
Index: llvm/trunk/lib/Analysis/LoopInfo.cpp
===================================================================
--- llvm/trunk/lib/Analysis/LoopInfo.cpp
+++ llvm/trunk/lib/Analysis/LoopInfo.cpp
@@ -109,24 +109,37 @@
   return true;
 }
 
-PHINode *Loop::getCanonicalInductionVariable() const {
+bool Loop::getIncomingAndBackEdge(BasicBlock *&Incoming,
+                                  BasicBlock *&Backedge) const {
   BasicBlock *H = getHeader();
 
-  BasicBlock *Incoming = nullptr, *Backedge = nullptr;
+  Incoming = nullptr;
+  Backedge = nullptr;
   pred_iterator PI = pred_begin(H);
   assert(PI != pred_end(H) && "Loop must have at least one backedge!");
   Backedge = *PI++;
   if (PI == pred_end(H))
-    return nullptr; // dead loop
+    return false; // dead loop
   Incoming = *PI++;
   if (PI != pred_end(H))
-    return nullptr; // multiple backedges?
+    return false; // multiple backedges?
 
   if (contains(Incoming)) {
     if (contains(Backedge))
-      return nullptr;
+      return false;
     std::swap(Incoming, Backedge);
   } else if (!contains(Backedge))
+    return false;
+
+  assert(Incoming && Backedge && "expected non-null incoming and backedges");
+  return true;
+}
+
+PHINode *Loop::getCanonicalInductionVariable() const {
+  BasicBlock *H = getHeader();
+
+  BasicBlock *Incoming = nullptr, *Backedge = nullptr;
+  if (!getIncomingAndBackEdge(Incoming, Backedge))
     return nullptr;
 
   // Loop over all of the PHI nodes, looking for a canonical indvar.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59967.192861.patch
Type: text/x-patch
Size: 2143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190329/e1a4f56f/attachment.bin>


More information about the llvm-commits mailing list