forked from OSchip/llvm-project
[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
This commit is contained in:
parent
fe59e14031
commit
b27d0fd0bf
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue