[Mlir-commits] [mlir] [MLIR][LLVM] Support Recursive DITypes (PR #80251)

Tobias Gysi llvmlistbot at llvm.org
Sat Mar 23 12:56:25 PDT 2024


================
@@ -289,7 +316,19 @@ DINodeAttr DebugImporter::translate(llvm::DINode *node) {
     return nullptr;
   };
   if (DINodeAttr attr = translateNode(node)) {
-    nodeToAttr.insert({node, attr});
+    // If this node was marked as recursive, set its recId.
+    if (auto recType = dyn_cast<DIRecursiveTypeAttrInterface>(attr)) {
+      if (DistinctAttr recId = translationStack.lookup(node)) {
+        attr = cast<DINodeAttr>(recType.withRecId(recId));
+        // Remove the unbound recursive ID from the set of unbound self
+        // references in the translation stack.
+        unboundRecursiveSelfRefs.back().erase(recId);
+      }
+    }
+
+    // Only cache fully self-contained nodes.
+    if (unboundRecursiveSelfRefs.back().empty())
----------------
gysit wrote:

Yes I was thinking of the last example you posted with the nested cycles. I am not 100% sure if this is what we are seeing though our input is 1.6gb of ir...

What I tried though is the following hack:
```
      if (DistinctAttr recId = translationStack.lookup(node)) {
        attr = cast<DINodeAttr>(recType.withRecId(recId));
        // Remove the unbound recursive ID from the set of unbound self
        // references in the translation stack.
        unboundRecursiveSelfRefs.back().erase(recId);

        if (!unboundRecursiveSelfRefs.back().empty()) {
          DINodeAttr containedAttr = nullptr;
          for (auto &[unboundSelfRefs, attr] : unboundAttrCache[node]) {
            if (unboundSelfRefs == unboundRecursiveSelfRefs.back())
              containedAttr = attr;
          }
          if (!containedAttr)
            unboundAttrCache[node].emplace_back(unboundRecursiveSelfRefs.back(),
                                                attr);

          if (containedAttr) {
            attr = containedAttr;
          }
        }
      }
    }
```
So essentially I cache previous instances of a recursive attribute declaration with the corresponding unbounded self refs and then always return an attribute from the cache... This solves the IR size problem but not the compilation time problem since the traversal is unchanged. I am not really sure the IR is correct but at least it imports and exports... 


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


More information about the Mlir-commits mailing list