[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
Thu Mar 28 15:59:26 PDT 2019
mtrofin updated this revision to Diff 192736.
mtrofin added a comment.
- wording
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59967/new/
https://reviews.llvm.org/D59967
Files:
llvm/include/llvm/Analysis/LoopInfo.h
llvm/lib/Analysis/LoopInfo.cpp
Index: llvm/lib/Analysis/LoopInfo.cpp
===================================================================
--- llvm/lib/Analysis/LoopInfo.cpp
+++ llvm/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.
Index: llvm/include/llvm/Analysis/LoopInfo.h
===================================================================
--- llvm/include/llvm/Analysis/LoopInfo.h
+++ llvm/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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59967.192736.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190328/56a46b6b/attachment.bin>
More information about the llvm-commits
mailing list