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

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


================
@@ -241,30 +313,35 @@ void SuffixTree::RepeatedSubstringIterator::advance() {
     // it's too short, we'll quit.
     unsigned Length = Curr->getConcatLen();
 
-    // Iterate over each child, saving internal nodes for visiting, and
-    // leaf nodes' SuffixIdx in RepeatedSubstringStarts. Internal nodes
-    // represent individual strings, which may repeat.
-    for (auto &ChildPair : Curr->Children) {
+    // Iterate over each child, saving internal nodes for visiting.
+    // Internal nodes represent individual strings, which may repeat.
+    for (auto &ChildPair : Curr->Children)
       // Save all of this node's children for processing.
       if (auto *InternalChild =
-              dyn_cast<SuffixTreeInternalNode>(ChildPair.second)) {
+              dyn_cast<SuffixTreeInternalNode>(ChildPair.second))
         InternalNodesToVisit.push_back(InternalChild);
-        continue;
-      }
-
-      if (Length < MinLength)
-        continue;
 
-      // Have an occurrence of a potentially repeated string. Save it.
-      auto *Leaf = cast<SuffixTreeLeafNode>(ChildPair.second);
-      RepeatedSubstringStarts.push_back(Leaf->getSuffixIdx());
-    }
+    // If length of repeated substring is below threshold, then skip it.
+    if (Length < MinLength)
+      continue;
 
     // The root never represents a repeated substring. If we're looking at
     // that, then skip it.
     if (Curr->isRoot())
       continue;
 
+    // Collect leaf children or leaf descendants by OutlinerLeafDescendants.
+    if (!OutlinerLeafDescendants) {
+      for (auto &ChildPair : Curr->Children)
+        if (auto *Leaf = dyn_cast<SuffixTreeLeafNode>(ChildPair.second))
+          RepeatedSubstringStarts.push_back(Leaf->getSuffixIdx());
+    } else {
+      LeafDescendants.assign(LeafNodes.begin() + Curr->getLeftLeafIdx(),
----------------
kyulee-com wrote:

You might need to clean up `LeafDescendants` early in the loop when the candidates are bailed out.
Instead of using this extra copy, can we simply do this way?
```
    for (unsigned I = Curr->getLeftLeafIdx(); I <= Curr->getRightLeafIdx(); ++I)
        RepeatedSubstringStarts.push_back(LeafNodes[I]->getSuffixIdx());
```


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


More information about the llvm-commits mailing list