[PATCH] D36442: [DomTree] Use a non-recursive DFS instead of a recursive one; NFC
Sanjoy Das via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 10:20:04 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310383: [DomTree] Use a non-recursive DFS instead of a recursive one; NFC (authored by sanjoy).
Changed prior to commit:
https://reviews.llvm.org/D36442?vs=110134&id=110225#toc
Repository:
rL LLVM
https://reviews.llvm.org/D36442
Files:
llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
Index: llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
===================================================================
--- llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
+++ llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
@@ -433,34 +433,42 @@
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();
-
- 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);
- 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});
+ SmallVector<TreeNodePtr, 8> Stack = {TN};
+ assert(TN->getBlock() && II.Visited.count(TN) && "Preconditions!");
+
+ do {
+ TreeNodePtr Next = Stack.pop_back_val();
+
+ 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() << "\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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36442.110225.patch
Type: text/x-patch
Size: 3285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170808/d007a32d/attachment.bin>
More information about the llvm-commits
mailing list