diff options
| author | Mircea Trofin <mtrofin@google.com> | 2019-03-29 17:39:17 +0000 |
|---|---|---|
| committer | Mircea Trofin <mtrofin@google.com> | 2019-03-29 17:39:17 +0000 |
| commit | b27d0fd0bfde0d5b9745334a93c37fb81f87bae7 (patch) | |
| tree | 07c4acbce5f0f27f1d07e7c5e51d8bd9f153f650 | |
| parent | fe59e14031a948f0711d0e7042417670a14e2db2 (diff) | |
| download | bcm5719-llvm-b27d0fd0bfde0d5b9745334a93c37fb81f87bae7.tar.gz bcm5719-llvm-b27d0fd0bfde0d5b9745334a93c37fb81f87bae7.zip | |
[llvm][NFC] Factor out logic for getting incoming & back Loop edges
Reviewers: davidxl
Reviewed By: davidxl
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59967
llvm-svn: 357284
| -rw-r--r-- | llvm/include/llvm/Analysis/LoopInfo.h | 5 | ||||
| -rw-r--r-- | llvm/lib/Analysis/LoopInfo.cpp | 23 |
2 files changed, 23 insertions, 5 deletions
diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index 0899630fe8e..f62f2004e10 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -521,6 +521,11 @@ public: /// 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; diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 9518c6e551c..6b93234b487 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -109,24 +109,37 @@ bool Loop::makeLoopInvariant(Instruction *I, bool &Changed, 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. |

