[flang-commits] [flang] [mlir] [MLIR][LLVM] Add DebugNameTableKind to DICompileUnit (PR #87974)
Billy Zhu via flang-commits
flang-commits at lists.llvm.org
Mon Apr 8 08:57:20 PDT 2024
https://github.com/zyx-billy updated https://github.com/llvm/llvm-project/pull/87974
>From 087ad7c69647cfb1c8143885d85c74cd80e65c95 Mon Sep 17 00:00:00 2001
From: Billy Zhu <billyzhu at modular.com>
Date: Fri, 5 Apr 2024 17:35:57 -0700
Subject: [PATCH 1/2] handle debug NameTableKind
---
.../Transforms/AddDebugFoundation.cpp | 2 +-
mlir/include/mlir-c/Dialect/LLVM.h | 10 +++++++++-
.../mlir/Dialect/LLVMIR/LLVMAttrDefs.td | 15 +++++++++++++-
mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td | 20 +++++++++++++++++++
mlir/lib/CAPI/Dialect/LLVM.cpp | 6 ++++--
.../Transforms/DIScopeForLLVMFuncOp.cpp | 4 ++--
mlir/lib/Target/LLVMIR/DebugImporter.cpp | 6 +++++-
mlir/lib/Target/LLVMIR/DebugTranslation.cpp | 5 ++++-
mlir/test/CAPI/llvm.c | 6 +++---
mlir/test/Target/LLVMIR/Import/debug-info.ll | 4 ++--
mlir/test/Target/LLVMIR/llvmir-debug.mlir | 5 +++--
11 files changed, 67 insertions(+), 16 deletions(-)
diff --git a/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp b/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp
index 7a6f58066722d5..678fbf6a7d23ba 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp
@@ -65,7 +65,7 @@ void AddDebugFoundationPass::runOnOperation() {
mlir::LLVM::DIFileAttr fileAttr = getFileAttr(inputFilePath);
mlir::StringAttr producer = mlir::StringAttr::get(context, "Flang");
mlir::LLVM::DICompileUnitAttr cuAttr = mlir::LLVM::DICompileUnitAttr::get(
- context, mlir::DistinctAttr::create(mlir::UnitAttr::get(context)),
+ mlir::DistinctAttr::create(mlir::UnitAttr::get(context)),
llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer,
/*isOptimized=*/false, mlir::LLVM::DIEmissionKind::LineTablesOnly);
diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index 4f1d646f5bc831..bd9b7dd26f5e9e 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -257,11 +257,19 @@ enum MlirLLVMDIEmissionKind {
};
typedef enum MlirLLVMDIEmissionKind MlirLLVMDIEmissionKind;
+enum MlirLLVMDINameTableKind {
+ MlirLLVMDINameTableKindDefault = 0,
+ MlirLLVMDINameTableKindGNU = 1,
+ MlirLLVMDINameTableKindNone = 2,
+ MlirLLVMDINameTableKindApple = 3,
+};
+typedef enum MlirLLVMDINameTableKind MlirLLVMDINameTableKind;
+
/// Creates a LLVM DICompileUnit attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(
MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,
MlirAttribute file, MlirAttribute producer, bool isOptimized,
- MlirLLVMDIEmissionKind emissionKind);
+ MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind);
/// Creates a LLVM DIFlags attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 91bd3702f93b97..604cef042e47f9 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -350,8 +350,21 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", "di_compile_unit",
"DIFileAttr":$file,
OptionalParameter<"StringAttr">:$producer,
"bool":$isOptimized,
- "DIEmissionKind":$emissionKind
+ "DIEmissionKind":$emissionKind,
+ DefaultValuedParameter<
+ "DINameTableKind", "DINameTableKind::Default">:$nameTableKind
);
+ let builders = [
+ AttrBuilderWithInferredContext<(ins
+ "DistinctAttr":$id, "unsigned":$sourceLanguage, "DIFileAttr":$file,
+ "StringAttr":$producer, "bool":$isOptimized,
+ "DIEmissionKind":$emissionKind,
+ CArg<"DINameTableKind", "DINameTableKind::Default">:$nameTableKind
+ ), [{
+ return $_get(id.getContext(), id, sourceLanguage, file, producer,
+ isOptimized, emissionKind, nameTableKind);
+ }]>
+ ];
let assemblyFormat = "`<` struct(params) `>`";
}
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
index 04d797031245e3..a93964abcb42e7 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
@@ -393,6 +393,26 @@ def DIFlags : I32BitEnumAttr<
let printBitEnumPrimaryGroups = 1;
}
+//===----------------------------------------------------------------------===//
+// DINameTableKind
+//===----------------------------------------------------------------------===//
+
+def LLVM_DINameTableDefault : I64EnumAttrCase<"Default", 0>;
+def LLVM_DINameTableGNU : I64EnumAttrCase<"GNU", 1>;
+def LLVM_DINameTableNone : I64EnumAttrCase<"None", 2>;
+def LLVM_DINameTableApple : I64EnumAttrCase<"Apple", 3>;
+
+def LLVM_DINameTableKind : I64EnumAttr<
+ "DINameTableKind",
+ "LLVM debug name table kind", [
+ LLVM_DINameTableDefault,
+ LLVM_DINameTableGNU,
+ LLVM_DINameTableNone,
+ LLVM_DINameTableApple,
+ ]> {
+ let cppNamespace = "::mlir::LLVM";
+}
+
//===----------------------------------------------------------------------===//
// DISubprogramFlags
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index 71f2b73dd73bca..4669c40f843d94 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -206,11 +206,13 @@ MlirAttribute
mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id,
unsigned int sourceLanguage, MlirAttribute file,
MlirAttribute producer, bool isOptimized,
- MlirLLVMDIEmissionKind emissionKind) {
+ MlirLLVMDIEmissionKind emissionKind,
+ MlirLLVMDINameTableKind nameTableKind) {
return wrap(DICompileUnitAttr::get(
unwrap(ctx), cast<DistinctAttr>(unwrap(id)), sourceLanguage,
cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)),
- isOptimized, DIEmissionKind(emissionKind)));
+ isOptimized, DIEmissionKind(emissionKind),
+ DINameTableKind(nameTableKind)));
}
MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
index 2960cc6220d9f5..395ff6ed1e48ea 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
@@ -115,8 +115,8 @@ struct DIScopeForLLVMFuncOp
}
compileUnitAttr = LLVM::DICompileUnitAttr::get(
- context, DistinctAttr::create(UnitAttr::get(context)),
- llvm::dwarf::DW_LANG_C, fileAttr, StringAttr::get(context, "MLIR"),
+ DistinctAttr::create(UnitAttr::get(context)), llvm::dwarf::DW_LANG_C,
+ fileAttr, StringAttr::get(context, "MLIR"),
/*isOptimized=*/true, LLVM::DIEmissionKind::LineTablesOnly);
}
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index 3dc2d4e3a7509f..95b1474eef79a0 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -56,10 +56,14 @@ DIBasicTypeAttr DebugImporter::translateImpl(llvm::DIBasicType *node) {
DICompileUnitAttr DebugImporter::translateImpl(llvm::DICompileUnit *node) {
std::optional<DIEmissionKind> emissionKind =
symbolizeDIEmissionKind(node->getEmissionKind());
+ std::optional<DINameTableKind> nameTableKind = symbolizeDINameTableKind(
+ static_cast<
+ std::underlying_type_t<llvm::DICompileUnit::DebugNameTableKind>>(
+ node->getNameTableKind()));
return DICompileUnitAttr::get(
context, getOrCreateDistinctID(node), node->getSourceLanguage(),
translate(node->getFile()), getStringAttrOrNull(node->getRawProducer()),
- node->isOptimized(), emissionKind.value());
+ node->isOptimized(), emissionKind.value(), nameTableKind.value());
}
DICompositeTypeAttr DebugImporter::translateImpl(llvm::DICompositeType *node) {
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index f6e05e25ace6ae..46e2e7f2ba5dc4 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -104,7 +104,10 @@ llvm::DICompileUnit *DebugTranslation::translateImpl(DICompileUnitAttr attr) {
attr.getIsOptimized(),
/*Flags=*/"", /*RV=*/0, /*SplitName=*/{},
static_cast<llvm::DICompileUnit::DebugEmissionKind>(
- attr.getEmissionKind()));
+ attr.getEmissionKind()),
+ 0, true, false,
+ static_cast<llvm::DICompileUnit::DebugNameTableKind>(
+ attr.getNameTableKind()));
}
/// Returns a new `DINodeT` that is either distinct or not, depending on
diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index 9c3c7da46c4cd8..25f900e521cf99 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -264,9 +264,9 @@ static void testDebugInfoAttributes(MlirContext ctx) {
// CHECK: #llvm.di_file<"foo" in "bar">
mlirAttributeDump(file);
- MlirAttribute compile_unit =
- mlirLLVMDICompileUnitAttrGet(ctx, id, LLVMDWARFSourceLanguageC99, file,
- foo, false, MlirLLVMDIEmissionKindFull);
+ MlirAttribute compile_unit = mlirLLVMDICompileUnitAttrGet(
+ ctx, id, LLVMDWARFSourceLanguageC99, file, foo, false,
+ MlirLLVMDIEmissionKindFull, MlirLLVMDINameTableKindDefault);
// CHECK: #llvm.di_compile_unit<{{.*}}>
mlirAttributeDump(compile_unit);
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index e2ef94617dd7d3..245cf300d2c1af 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -197,7 +197,7 @@ define void @composite_type() !dbg !3 {
; // -----
; CHECK-DAG: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/">
-; CHECK-DAG: #[[CU:.+]] = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #[[FILE]], isOptimized = false, emissionKind = None>
+; CHECK-DAG: #[[CU:.+]] = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #[[FILE]], isOptimized = false, emissionKind = None, nameTableKind = None>
; Verify an empty subroutine types list is supported.
; CHECK-DAG: #[[SP_TYPE:.+]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal>
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[CU]], scope = #[[FILE]], name = "subprogram", linkageName = "subprogram", file = #[[FILE]], line = 42, scopeLine = 42, subprogramFlags = Definition, type = #[[SP_TYPE]]>
@@ -209,7 +209,7 @@ define void @subprogram() !dbg !3 {
!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)
+!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, nameTableKind: None)
!2 = !DIFile(filename: "debug-info.ll", directory: "/")
!3 = distinct !DISubprogram(name: "subprogram", linkageName: "subprogram", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1, type: !4)
!4 = !DISubroutineType(cc: DW_CC_normal, types: !5)
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index c4ca0e83f81ee3..f4c18bf6bd53c0 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -37,7 +37,8 @@ llvm.func @func_no_debug() {
>
#cu = #llvm.di_compile_unit<
id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #file,
- producer = "MLIR", isOptimized = true, emissionKind = Full
+ producer = "MLIR", isOptimized = true, emissionKind = Full,
+ nameTableKind = None
>
#composite = #llvm.di_composite_type<
tag = DW_TAG_structure_type, name = "composite", file = #file,
@@ -127,7 +128,7 @@ llvm.func @empty_types() {
llvm.return
} loc(fused<#sp1>["foo.mlir":2:1])
-// CHECK: ![[CU_LOC:.*]] = distinct !DICompileUnit(language: DW_LANG_C, file: ![[CU_FILE_LOC:.*]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+// CHECK: ![[CU_LOC:.*]] = distinct !DICompileUnit(language: DW_LANG_C, file: ![[CU_FILE_LOC:.*]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, nameTableKind: None)
// CHECK: ![[CU_FILE_LOC]] = !DIFile(filename: "foo.mlir", directory: "/test/")
// CHECK: ![[FUNC_LOC]] = distinct !DISubprogram(name: "func_with_debug", linkageName: "func_with_debug", scope: ![[NESTED_NAMESPACE:.*]], file: ![[CU_FILE_LOC]], line: 3, type: ![[FUNC_TYPE:.*]], scopeLine: 3, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: ![[CU_LOC]])
>From 93ca8a289d837d9c3976e533f59edcdf6c267bc0 Mon Sep 17 00:00:00 2001
From: Billy Zhu <billyzhu at modular.com>
Date: Mon, 8 Apr 2024 17:55:10 +0200
Subject: [PATCH 2/2] use OptionalParameter instead of default
---
mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 604cef042e47f9..cc849cb7c978d7 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -351,8 +351,7 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", "di_compile_unit",
OptionalParameter<"StringAttr">:$producer,
"bool":$isOptimized,
"DIEmissionKind":$emissionKind,
- DefaultValuedParameter<
- "DINameTableKind", "DINameTableKind::Default">:$nameTableKind
+ OptionalParameter<"DINameTableKind">:$nameTableKind
);
let builders = [
AttrBuilderWithInferredContext<(ins
More information about the flang-commits
mailing list