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

Tobias Gysi llvmlistbot at llvm.org
Sun Mar 24 02:26:14 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:

This is the minimal example I can come up with:
```
define void @class_field(ptr %arg1) !dbg !18 {
  ret void
}

declare void @llvm.dbg.value(metadata, metadata, metadata)

!llvm.dbg.cu = !{!1}
!llvm.module.flags = !{!0}
!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2)
!2 = !DIFile(filename: "debug-info.ll", directory: "/")


!3 = !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !2, line: 42, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !4)
!4 = !{!7, !8}

!5 = !DICompositeType(tag: DW_TAG_class_type, name: "B", scope: !3, file: !2, line: 42, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !9)
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, flags: DIFlagArtificial | DIFlagObjectPointer)
!7 = !DIDerivedType(tag: DW_TAG_member, name: "B:B1", file: !2, baseType: !5)
!8 = !DIDerivedType(tag: DW_TAG_member, name: "B:B2", file: !2, baseType: !5)
!9 = !{!7, !8}

!18 = distinct !DISubprogram(name: "A", scope: !3, file: !2, spFlags: DISPFlagDefinition, unit: !1)
```
When importing the B type declaration duplicates:
```
#di_composite_type3 = #llvm.di_composite_type<tag = DW_TAG_class_type, recId = distinct[1]<>, name = "B", file = #di_file, line = 42, scope = #di_composite_type, flags = "TypePassByReference|NonTrivial", elements = #di_derived_type, #di_derived_type1>
#di_composite_type4 = #llvm.di_composite_type<tag = DW_TAG_class_type, recId = distinct[2]<>, name = "B", file = #di_file, line = 42, scope = #di_composite_type, flags = "TypePassByReference|NonTrivial", elements = #di_derived_type2, #di_derived_type3>
```
Maybe it also makes sense to key the cache on the translation stack since the unboundSelfRefs are only really known after traversing the subtree if I understand correctly. Anyways I hope the example helps to clarify the problem!

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


More information about the Mlir-commits mailing list