[Mlir-commits] [mlir] 7e9d7db - [mlir][LLVM] Add support for DIModule metadata
Christian Ulmann
llvmlistbot at llvm.org
Thu Aug 3 00:49:29 PDT 2023
Author: Christian Ulmann
Date: 2023-08-03T07:46:51Z
New Revision: 7e9d7db407209306660db3208fa9e9c4608eb863
URL: https://github.com/llvm/llvm-project/commit/7e9d7db407209306660db3208fa9e9c4608eb863
DIFF: https://github.com/llvm/llvm-project/commit/7e9d7db407209306660db3208fa9e9c4608eb863.diff
LOG: [mlir][LLVM] Add support for DIModule metadata
This commit adds a DIModuleAttr to the set of debug info attributes and
extends the LLVM IR import and export to support it.
DIModule metadata is missing in the LLVM LangRef and cannot be produced
from C or C++ input. So far, we only observed classic flang producing
such DI metadata.
Reviewed By: zero9178
Differential Revision: https://reviews.llvm.org/D156969
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Target/LLVMIR/DebugImporter.cpp
mlir/lib/Target/LLVMIR/DebugImporter.h
mlir/lib/Target/LLVMIR/DebugTranslation.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.h
mlir/test/Dialect/LLVMIR/debuginfo.mlir
mlir/test/Target/LLVMIR/Import/debug-info.ll
mlir/test/Target/LLVMIR/llvmir-debug.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index f58fab881d572a..2443b23e42e43c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -470,6 +470,26 @@ def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
let assemblyFormat = "`<` struct(params) `>`";
}
+//===----------------------------------------------------------------------===//
+// DIModuleAttr
+//===----------------------------------------------------------------------===//
+
+def LLVM_DIModuleAttr : LLVM_Attr<"DIModule", "di_module",
+ /*traits=*/[], "DIScopeAttr"> {
+ let parameters = (ins
+ OptionalParameter<"DIFileAttr">:$file,
+ OptionalParameter<"DIScopeAttr">:$scope,
+ OptionalParameter<"StringAttr">:$name,
+ OptionalParameter<"StringAttr">:$configMacros,
+ OptionalParameter<"StringAttr">:$includePath,
+ OptionalParameter<"StringAttr">:$apinotes,
+ OptionalParameter<"unsigned">:$line,
+ OptionalParameter<"bool">:$isDecl
+ );
+
+ let assemblyFormat = "`<` struct(params) `>`";
+}
+
//===----------------------------------------------------------------------===//
// DINamespaceAttr
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 6e255153f51b24..3d45ab8fac4d70 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -45,9 +45,9 @@ bool DINodeAttr::classof(Attribute attr) {
return llvm::isa<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
DIDerivedTypeAttr, DIFileAttr, DILabelAttr,
DILexicalBlockAttr, DILexicalBlockFileAttr,
- DILocalVariableAttr, DINamespaceAttr, DINullTypeAttr,
- DISubprogramAttr, DISubrangeAttr, DISubroutineTypeAttr>(
- attr);
+ DILocalVariableAttr, DIModuleAttr, DINamespaceAttr,
+ DINullTypeAttr, DISubprogramAttr, DISubrangeAttr,
+ DISubroutineTypeAttr>(attr);
}
//===----------------------------------------------------------------------===//
@@ -56,7 +56,7 @@ bool DINodeAttr::classof(Attribute attr) {
bool DIScopeAttr::classof(Attribute attr) {
return llvm::isa<DICompileUnitAttr, DICompositeTypeAttr, DIFileAttr,
- DILocalScopeAttr, DINamespaceAttr>(attr);
+ DILocalScopeAttr, DIModuleAttr, DINamespaceAttr>(attr);
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index eaad4c7a3af5fb..2d04aab307d748 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2819,12 +2819,12 @@ struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
.Case<AccessGroupAttr, AliasScopeAttr, AliasScopeDomainAttr,
DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
DIDerivedTypeAttr, DIFileAttr, DILabelAttr, DILexicalBlockAttr,
- DILexicalBlockFileAttr, DILocalVariableAttr, DINamespaceAttr,
- DINullTypeAttr, DISubprogramAttr, DISubroutineTypeAttr,
- LoopAnnotationAttr, LoopVectorizeAttr, LoopInterleaveAttr,
- LoopUnrollAttr, LoopUnrollAndJamAttr, LoopLICMAttr,
- LoopDistributeAttr, LoopPipelineAttr, LoopPeeledAttr,
- LoopUnswitchAttr, TBAARootAttr, TBAATagAttr,
+ DILexicalBlockFileAttr, DILocalVariableAttr, DIModuleAttr,
+ DINamespaceAttr, DINullTypeAttr, DISubprogramAttr,
+ DISubroutineTypeAttr, LoopAnnotationAttr, LoopVectorizeAttr,
+ LoopInterleaveAttr, LoopUnrollAttr, LoopUnrollAndJamAttr,
+ LoopLICMAttr, LoopDistributeAttr, LoopPipelineAttr,
+ LoopPeeledAttr, LoopUnswitchAttr, TBAARootAttr, TBAATagAttr,
TBAATypeDescriptorAttr>([&](auto attr) {
os << decltype(attr)::getMnemonic();
return AliasResult::OverridableAlias;
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index fbd2324fd9ed31..693f948ce7e027 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -118,6 +118,16 @@ DIScopeAttr DebugImporter::translateImpl(llvm::DIScope *node) {
return cast<DIScopeAttr>(translate(static_cast<llvm::DINode *>(node)));
}
+DIModuleAttr DebugImporter::translateImpl(llvm::DIModule *node) {
+ return DIModuleAttr::get(
+ context, translate(node->getFile()), translate(node->getScope()),
+ getStringAttrOrNull(node->getRawName()),
+ getStringAttrOrNull(node->getRawConfigurationMacros()),
+ getStringAttrOrNull(node->getRawIncludePath()),
+ getStringAttrOrNull(node->getRawAPINotesFile()), node->getLineNo(),
+ node->getIsDecl());
+}
+
DINamespaceAttr DebugImporter::translateImpl(llvm::DINamespace *node) {
return DINamespaceAttr::get(context, getStringAttrOrNull(node->getRawName()),
translate(node->getScope()),
@@ -214,10 +224,12 @@ DINodeAttr DebugImporter::translate(llvm::DINode *node) {
return translateImpl(casted);
if (auto *casted = dyn_cast<llvm::DILocalVariable>(node))
return translateImpl(casted);
- if (auto *casted = dyn_cast<llvm::DISubprogram>(node))
+ if (auto *casted = dyn_cast<llvm::DIModule>(node))
return translateImpl(casted);
if (auto *casted = dyn_cast<llvm::DINamespace>(node))
return translateImpl(casted);
+ if (auto *casted = dyn_cast<llvm::DISubprogram>(node))
+ return translateImpl(casted);
if (auto *casted = dyn_cast<llvm::DISubrange>(node))
return translateImpl(casted);
if (auto *casted = dyn_cast<llvm::DISubroutineType>(node))
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.h b/mlir/lib/Target/LLVMIR/DebugImporter.h
index f75f09e3357d9e..5c07ec82d0191b 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.h
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.h
@@ -62,9 +62,10 @@ class DebugImporter {
DILexicalBlockAttr translateImpl(llvm::DILexicalBlock *node);
DILexicalBlockFileAttr translateImpl(llvm::DILexicalBlockFile *node);
DILocalVariableAttr translateImpl(llvm::DILocalVariable *node);
+ DIModuleAttr translateImpl(llvm::DIModule *node);
+ DINamespaceAttr translateImpl(llvm::DINamespace *node);
DIScopeAttr translateImpl(llvm::DIScope *node);
DISubprogramAttr translateImpl(llvm::DISubprogram *node);
- DINamespaceAttr translateImpl(llvm::DINamespace *node);
DISubrangeAttr translateImpl(llvm::DISubrange *node);
DISubroutineTypeAttr translateImpl(llvm::DISubroutineType *node);
DITypeAttr translateImpl(llvm::DIType *node);
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index b76a48eb02dca9..ca5dde7a9376e2 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -221,6 +221,15 @@ llvm::DISubprogram *DebugTranslation::translateImpl(DISubprogramAttr attr) {
translate(attr.getCompileUnit()));
}
+llvm::DIModule *DebugTranslation::translateImpl(DIModuleAttr attr) {
+ return llvm::DIModule::get(
+ llvmCtx, translate(attr.getFile()), translate(attr.getScope()),
+ getMDStringOrNull(attr.getName()),
+ getMDStringOrNull(attr.getConfigMacros()),
+ getMDStringOrNull(attr.getIncludePath()),
+ getMDStringOrNull(attr.getApinotes()), attr.getLine(), attr.getIsDecl());
+}
+
llvm::DINamespace *DebugTranslation::translateImpl(DINamespaceAttr attr) {
return llvm::DINamespace::get(llvmCtx, translate(attr.getScope()),
getMDStringOrNull(attr.getName()),
@@ -266,9 +275,9 @@ llvm::DINode *DebugTranslation::translate(DINodeAttr attr) {
TypeSwitch<DINodeAttr, llvm::DINode *>(attr)
.Case<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
DIDerivedTypeAttr, DIFileAttr, DILabelAttr, DILexicalBlockAttr,
- DILexicalBlockFileAttr, DILocalVariableAttr, DINamespaceAttr,
- DINullTypeAttr, DISubprogramAttr, DISubrangeAttr,
- DISubroutineTypeAttr>(
+ DILexicalBlockFileAttr, DILocalVariableAttr, DIModuleAttr,
+ DINamespaceAttr, DINullTypeAttr, DISubprogramAttr,
+ DISubrangeAttr, DISubroutineTypeAttr>(
[&](auto attr) { return translateImpl(attr); });
attrToNode.insert({attr, node});
return node;
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.h b/mlir/lib/Target/LLVMIR/DebugTranslation.h
index 5f93882c65d44c..d22c3d80dafd5f 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.h
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.h
@@ -72,9 +72,10 @@ class DebugTranslation {
llvm::DILexicalBlockFile *translateImpl(DILexicalBlockFileAttr attr);
llvm::DILocalScope *translateImpl(DILocalScopeAttr attr);
llvm::DILocalVariable *translateImpl(DILocalVariableAttr attr);
+ llvm::DIModule *translateImpl(DIModuleAttr attr);
+ llvm::DINamespace *translateImpl(DINamespaceAttr attr);
llvm::DIScope *translateImpl(DIScopeAttr attr);
llvm::DISubprogram *translateImpl(DISubprogramAttr attr);
- llvm::DINamespace *translateImpl(DINamespaceAttr attr);
llvm::DISubrange *translateImpl(DISubrangeAttr attr);
llvm::DISubroutineType *translateImpl(DISubroutineTypeAttr attr);
llvm::DIType *translateImpl(DITypeAttr attr);
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index dde22bc5717165..5f7b1acff6bbe9 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -102,10 +102,17 @@
file = #file, subprogramFlags = "Definition", type = #spType1
>
-// CHECK-DAG: #[[SP2:.*]] = #llvm.di_subprogram<compileUnit = #[[CU]], scope = #[[FILE]], name = "value", file = #[[FILE]], subprogramFlags = Definition, type = #[[SPTYPE2]]>
+// CHECK-DAG: #[[MODULE:.*]] = #llvm.di_module<file = #[[FILE]], scope = #[[FILE]], name = "module", configMacros = "bar", includePath = "/", apinotes = "/", line = 42, isDecl = true>
+#module = #llvm.di_module<
+ file = #file, scope = #file, name = "module",
+ configMacros = "bar", includePath = "/",
+ apinotes = "/", line = 42, isDecl = true
+>
+
+// CHECK-DAG: #[[SP2:.*]] = #llvm.di_subprogram<compileUnit = #[[CU]], scope = #[[MODULE]], name = "value", file = #[[FILE]], subprogramFlags = Definition, type = #[[SPTYPE2]]>
#sp2 = #llvm.di_subprogram<
// Omit the optional linkageName parameter.
- compileUnit = #cu, scope = #file, name = "value",
+ compileUnit = #cu, scope = #module, name = "value",
file = #file, subprogramFlags = "Definition", type = #spType2
>
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index 4f20fa92f4aef9..1e2fecbdbe931d 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -464,3 +464,24 @@ define void @noname_subprogram(ptr %arg) !dbg !8 {
!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2)
!2 = !DIFile(filename: "debug-info.ll", directory: "/")
!8 = distinct !DISubprogram(scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1);
+
+; // -----
+
+; CHECK: #[[MODULE:.+]] = #llvm.di_module<
+; CHECK-SAME: file = #{{.*}}, scope = #{{.*}}, name = "module",
+; CHECK-SAME: configMacros = "bar", includePath = "/",
+; CHECK-SAME: apinotes = "/", line = 42, isDecl = true
+; CHECK-SAME: >
+; CHECK: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #[[MODULE]], name = "func_in_module"
+
+define void @func_in_module(ptr %arg) !dbg !8 {
+ ret void
+}
+
+!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: "/")
+!8 = distinct !DISubprogram(name: "func_in_module", scope: !10, file: !2, unit: !1);
+!10 = !DIModule(scope: !2, name: "module", configMacros: "bar", includePath: "/", apinotes: "/", file: !2, line: 42, isDecl: true)
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 4ea6ab1e1d6ecf..9156c3a1bbbb49 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -73,10 +73,14 @@ llvm.func @func_no_debug() {
#variable = #llvm.di_local_variable<scope = #fileScope, name = "arg", file = #file, line = 6, arg = 1, alignInBits = 32, type = #si64>
#variableAddr = #llvm.di_local_variable<scope = #blockScope, name = "alloc">
#noNameVariable = #llvm.di_local_variable<scope = #blockScope>
-
+#module = #llvm.di_module<
+ file = #file, scope = #file, name = "module",
+ configMacros = "bar", includePath = "/",
+ apinotes = "/", line = 42, isDecl = true
+>
#spType1 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal>
#sp1 = #llvm.di_subprogram<
- compileUnit = #cu, scope = #file, name = "empty_types",
+ compileUnit = #cu, scope = #module, name = "empty_types",
file = #file, subprogramFlags = "Definition", type = #spType1
>
@@ -153,7 +157,8 @@ llvm.func @empty_types() {
// CHECK: ![[CALLEE_ARGS]] = !{![[ARG_TYPE:.*]], ![[ARG_TYPE:.*]]}
// CHECK: ![[INLINE_LOC]] = !DILocation(line: 28, column: 5,
-// CHECK: ![[EMPTY_TYPES_LOC]] = distinct !DISubprogram(name: "empty_types", scope: ![[CU_FILE_LOC]], file: ![[CU_FILE_LOC]], type: ![[EMPTY_TYPES_TYPE:.*]], spFlags: DISPFlagDefinition
+// CHECK: ![[EMPTY_TYPES_LOC]] = distinct !DISubprogram(name: "empty_types", scope: ![[MODULE:.*]], file: ![[CU_FILE_LOC]], type: ![[EMPTY_TYPES_TYPE:.*]], spFlags: DISPFlagDefinition
+// CHECK: ![[MODULE]] = !DIModule(scope: ![[CU_FILE_LOC]], name: "module", configMacros: "bar", includePath: "/", apinotes: "/", file: ![[CU_FILE_LOC]], line: 42, isDecl: true)
// CHECK: ![[EMPTY_TYPES_TYPE]] = !DISubroutineType(cc: DW_CC_normal, types: ![[EMPTY_TYPES_ARGS:.*]])
// CHECK: ![[EMPTY_TYPES_ARGS]] = !{}
More information about the Mlir-commits
mailing list