[Mlir-commits] [mlir] [MLIR] Improve translation of DISubrange. (PR #93689)

Christian Ulmann llvmlistbot at llvm.org
Wed May 29 09:24:35 PDT 2024


================
@@ -217,21 +217,34 @@ DISubprogramAttr DebugImporter::translateImpl(llvm::DISubprogram *node) {
 }
 
 DISubrangeAttr DebugImporter::translateImpl(llvm::DISubrange *node) {
-  auto getIntegerAttrOrNull = [&](llvm::DISubrange::BoundType data) {
-    if (auto *constInt = llvm::dyn_cast_or_null<llvm::ConstantInt *>(data))
+  auto getAttrOrNull =
+      [&](llvm::DISubrange::BoundType data) -> mlir::Attribute {
+    if (data.isNull())
+      return nullptr;
+
+    if (auto *constInt = llvm::dyn_cast<llvm::ConstantInt *>(data)) {
       return IntegerAttr::get(IntegerType::get(context, 64),
                               constInt->getSExtValue());
-    return IntegerAttr();
+    } else if (auto *expr = llvm::dyn_cast<llvm::DIExpression *>(data)) {
+      return translateExpression(expr);
+    } else if (auto *var = llvm::dyn_cast<llvm::DIVariable *>(data)) {
+      if (auto *local = llvm::dyn_cast<llvm::DILocalVariable>(var))
+        return translate(local);
+      else if (auto *global = llvm::dyn_cast<llvm::DIGlobalVariable>(var))
+        return translate(global);
+      llvm_unreachable("Unknown variable type");
+    }
+    llvm_unreachable("Unknown DISubrange::BoundType");
   };
-  IntegerAttr count = getIntegerAttrOrNull(node->getCount());
-  IntegerAttr upperBound = getIntegerAttrOrNull(node->getUpperBound());
+  auto count = getAttrOrNull(node->getCount());
+  auto upperBound = getAttrOrNull(node->getUpperBound());
----------------
Dinistro wrote:

Nit: Only use `auto` when the type is mentioned on the RHS or too complex to write out (iterators, ranges, template mess, etc.)

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


More information about the Mlir-commits mailing list