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

Tobias Gysi llvmlistbot at llvm.org
Wed Feb 28 11:13:23 PST 2024


================
@@ -200,22 +208,66 @@ DebugTranslation::translateImpl(DIGlobalVariableAttr attr) {
       attr.getIsDefined(), nullptr, nullptr, attr.getAlignInBits(), nullptr);
 }
 
+llvm::DIType *DebugTranslation::translateImpl(DIRecursiveTypeAttr attr) {
+  if (attr.isRecSelf()) {
+    auto *iter = recursiveTypeMap.find(attr.getId());
+    assert(iter != recursiveTypeMap.end() && "unbound DI recursive self type");
+    return iter->second;
+  }
+
+  size_t recursiveStackSize = recursiveTypeMap.size();
+  auto setRecursivePlaceholderFn = [&](llvm::DIType *node) {
+    auto [iter, inserted] = recursiveTypeMap.try_emplace(attr.getId(), node);
+    assert(inserted && "illegal reuse of recursive id");
+  };
+
+  llvm::DIType *node =
+      TypeSwitch<DITypeAttr, llvm::DIType *>(attr.getBaseType())
+          .Case<DICompositeTypeAttr>([&](auto attr) {
+            return translateImpl(attr, setRecursivePlaceholderFn);
----------------
gysit wrote:

Did you consider to split the translateImpl in two function calls? E.g. one that computes the paceholder type without elements and one that adds the translated elements? The translateImpl could then use these two helper functions without the callback, while this function could call the two helper functions and in-between store the place holder on the stack. I hope this is understandable/makes sense I am starting to get tired...

It feels like this is a bit more direct than the extra setRecursivePlaceholderFn parameter. 

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


More information about the Mlir-commits mailing list