mirror of
https://github.com/RPCS3/llvm.git
synced 2025-03-04 08:37:45 +00:00
[DomTree] Use a non-recursive DFS instead of a recursive one; NFC
Summary: The recursive DFS can stack overflow in pathological cases. Reviewers: kuhar Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D36442 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310383 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c9b3b5dd57
commit
0128b415ef
@ -433,34 +433,42 @@ struct SemiNCAInfo {
|
||||
const unsigned NCDLevel = NCD->getLevel();
|
||||
DEBUG(dbgs() << "Visiting " << BlockNamePrinter(TN) << "\n");
|
||||
|
||||
assert(TN->getBlock());
|
||||
for (const NodePtr Succ :
|
||||
ChildrenGetter<NodePtr, IsPostDom>::Get(TN->getBlock())) {
|
||||
const TreeNodePtr SuccTN = DT.getNode(Succ);
|
||||
assert(SuccTN && "Unreachable successor found at reachable insertion");
|
||||
const unsigned SuccLevel = SuccTN->getLevel();
|
||||
SmallVector<TreeNodePtr, 8> Stack = {TN};
|
||||
assert(TN->getBlock() && II.Visited.count(TN) && "Preconditions!");
|
||||
|
||||
DEBUG(dbgs() << "\tSuccessor " << BlockNamePrinter(Succ)
|
||||
<< ", level = " << SuccLevel << "\n");
|
||||
do {
|
||||
TreeNodePtr Next = Stack.pop_back_val();
|
||||
|
||||
// Succ dominated by subtree From -- not affected.
|
||||
// (Based on the lemma 2.5 from the second paper.)
|
||||
if (SuccLevel > RootLevel) {
|
||||
DEBUG(dbgs() << "\t\tDominated by subtree From\n");
|
||||
if (II.Visited.count(SuccTN) != 0) continue;
|
||||
for (const NodePtr Succ :
|
||||
ChildrenGetter<NodePtr, IsPostDom>::Get(Next->getBlock())) {
|
||||
const TreeNodePtr SuccTN = DT.getNode(Succ);
|
||||
assert(SuccTN && "Unreachable successor found at reachable insertion");
|
||||
const unsigned SuccLevel = SuccTN->getLevel();
|
||||
|
||||
DEBUG(dbgs() << "\t\tMarking visited not affected "
|
||||
<< BlockNamePrinter(Succ) << "\n");
|
||||
II.Visited.insert(SuccTN);
|
||||
II.VisitedNotAffectedQueue.push_back(SuccTN);
|
||||
VisitInsertion(DT, SuccTN, RootLevel, NCD, II);
|
||||
} else if ((SuccLevel > NCDLevel + 1) && II.Affected.count(SuccTN) == 0) {
|
||||
DEBUG(dbgs() << "\t\tMarking affected and adding "
|
||||
<< BlockNamePrinter(Succ) << " to a Bucket\n");
|
||||
II.Affected.insert(SuccTN);
|
||||
II.Bucket.push({SuccLevel, SuccTN});
|
||||
DEBUG(dbgs() << "\tSuccessor " << BlockNamePrinter(Succ)
|
||||
<< ", level = " << SuccLevel << "\n");
|
||||
|
||||
// Succ dominated by subtree From -- not affected.
|
||||
// (Based on the lemma 2.5 from the second paper.)
|
||||
if (SuccLevel > RootLevel) {
|
||||
DEBUG(dbgs() << "\t\tDominated by subtree From\n");
|
||||
if (II.Visited.count(SuccTN) != 0)
|
||||
continue;
|
||||
|
||||
DEBUG(dbgs() << "\t\tMarking visited not affected "
|
||||
<< BlockNamePrinter(Succ) << "\n");
|
||||
II.Visited.insert(SuccTN);
|
||||
II.VisitedNotAffectedQueue.push_back(SuccTN);
|
||||
Stack.push_back(SuccTN);
|
||||
} else if ((SuccLevel > NCDLevel + 1) &&
|
||||
II.Affected.count(SuccTN) == 0) {
|
||||
DEBUG(dbgs() << "\t\tMarking affected and adding "
|
||||
<< BlockNamePrinter(Succ) << " to a Bucket\n");
|
||||
II.Affected.insert(SuccTN);
|
||||
II.Bucket.push({SuccLevel, SuccTN});
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (!Stack.empty());
|
||||
}
|
||||
|
||||
// Updates immediate dominators and levels after insertion.
|
||||
|
Loading…
x
Reference in New Issue
Block a user