[Mlir-commits] [mlir] [MLIR][LLVM] Support Recursive DITypes (PR #80251)
Tobias Gysi
llvmlistbot at llvm.org
Sun Mar 10 08:48:03 PDT 2024
================
@@ -247,12 +244,43 @@ DINodeAttr DebugImporter::translate(llvm::DINode *node) {
if (DINodeAttr attr = nodeToAttr.lookup(node))
return attr;
- // Return nullptr if a cyclic dependency is detected since the same node is
- // being traversed twice. This check avoids infinite recursion if the debug
- // metadata contains cycles.
- if (!translationStack.insert(node))
- return nullptr;
- auto guard = llvm::make_scope_exit([&]() { translationStack.pop_back(); });
+ // If the node type is capable of being recursive, check if it's seen before.
+ auto recSelfCtor = getRecSelfConstructor(node);
+ if (recSelfCtor) {
+ // If a cyclic dependency is detected since the same node is being traversed
+ // twice, emit a recursive self type, and mark the duplicate node on the
+ // translationStack so it can emit a recursive decl type.
+ auto [iter, inserted] = translationStack.try_emplace(node, nullptr);
+ if (!inserted) {
+ // The original node may have already been assigned a recursive ID from
+ // a different self-reference. Use that if possible.
+ DistinctAttr recId = iter->second;
+ if (!recId) {
+ recId = DistinctAttr::create(UnitAttr::get(context));
+ iter->second = recId;
+ }
+ unboundRecursiveSelfRefs.back().insert(recId);
+
+ return cast<DINodeAttr>(recSelfCtor(recId));
----------------
gysit wrote:
```suggestion
unboundRecursiveSelfRefs.back().insert(recId);
return cast<DINodeAttr>(recSelfCtor(recId));
```
ultra nit:
https://github.com/llvm/llvm-project/pull/80251
More information about the Mlir-commits
mailing list