[llvm] [MachineOutliner] Leaf Descendants (PR #90275)

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 16:22:34 PDT 2024


================
@@ -105,6 +114,71 @@ void SuffixTree::setSuffixIndices() {
   }
 }
 
+void SuffixTree::setLeafNodes() {
+  // A stack that keeps track of nodes to visit for post-order DFS traversal.
+  SmallVector<SuffixTreeNode *> ToVisit;
+  ToVisit.push_back(Root);
+
+  // This keeps track of the index of the next leaf node to be added to
+  // the LeafNodes vector of the suffix tree.
+  unsigned LeafCounter = 0;
+
+  // This keeps track of nodes whose children have been added to the stack.
+  // The value is a pair, representing a node's first and last children.
+  DenseMap<SuffixTreeInternalNode *,
+           std::pair<SuffixTreeNode *, SuffixTreeNode *>>
+      ChildrenMap;
+
+  // Traverse the tree in post-order.
+  while (!ToVisit.empty()) {
+    SuffixTreeNode *CurrNode = ToVisit.back();
----------------
kyulee-com wrote:

```suggestion
    SuffixTreeNode *CurrNode = ToVisit. pop_back_val();
```
Then you can delete the following line.


https://github.com/llvm/llvm-project/pull/90275


More information about the llvm-commits mailing list