[llvm-branch-commits] [mlir] [flang] [MLIR][LLVM] Add distinct identifier to the DISubprogram attribute (PR #77093)

Tobias Gysi via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 5 06:03:21 PST 2024


================
@@ -66,12 +66,28 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
       LLVM::DISubroutineTypeAttr::get(context, llvm::dwarf::DW_CC_normal, {});
 
   StringAttr funcNameAttr = llvmFunc.getNameAttr();
-  auto subprogramAttr = LLVM::DISubprogramAttr::get(
-      context, compileUnitAttr, fileAttr, funcNameAttr, funcNameAttr, fileAttr,
-      /*line=*/line,
-      /*scopeline=*/col,
-      LLVM::DISubprogramFlags::Definition | LLVM::DISubprogramFlags::Optimized,
-      subroutineTypeAttr);
+  mlir::LLVM::DISubprogramAttr subprogramAttr;
+  // Only definitions need a distinct identifier and a compilation unit.
+  if (!llvmFunc.isExternal()) {
+    auto id = DistinctAttr::create(UnitAttr::get(context));
+    subprogramAttr =
+        LLVM::DISubprogramAttr::get(context, id, compileUnitAttr, fileAttr,
+                                    funcNameAttr, funcNameAttr, fileAttr,
+                                    /*line=*/line,
+                                    /*scopeline=*/col,
+                                    LLVM::DISubprogramFlags::Definition |
+                                        LLVM::DISubprogramFlags::Optimized,
+                                    subroutineTypeAttr);
+  } else {
+    subprogramAttr = LLVM::DISubprogramAttr::get(
+        context, DistinctAttr(), LLVM::DICompileUnitAttr(), fileAttr,
+        funcNameAttr, funcNameAttr, fileAttr,
+        /*line=*/line,
+        /*scopeline=*/col,
+        LLVM::DISubprogramFlags::Definition |
+            LLVM::DISubprogramFlags::Optimized,
+        subroutineTypeAttr);
----------------
gysit wrote:

nit: maybe consider hoisting the actual builder call outside the if else using some extra variables for the fields that differ?

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


More information about the llvm-branch-commits mailing list