[Mlir-commits] [mlir] 838fdef - [mlir][llvm] A DICompositeTypeAttr is also a DIScopeAttr.

Tobias Gysi llvmlistbot at llvm.org
Thu Jan 12 05:21:58 PST 2023


Author: Tobias Gysi
Date: 2023-01-12T14:21:21+01:00
New Revision: 838fdefc52d33ebe759f0325a67112222cf6c2c0

URL: https://github.com/llvm/llvm-project/commit/838fdefc52d33ebe759f0325a67112222cf6c2c0
DIFF: https://github.com/llvm/llvm-project/commit/838fdefc52d33ebe759f0325a67112222cf6c2c0.diff

LOG: [mlir][llvm] A DICompositeTypeAttr is also a DIScopeAttr.

A DICompositeTypeAttr is the MLIR counterpart of LLVMIR's
DICompositeType debug metadata node. It can be used to store debug
information associated to a class or struct type definition. Any class
member method then sets its scope to the parent DICompositeType. This
revision adds DICompositeTypeAttr to the list of DIScopeAttrs to
prevent verification failures for legal debug information. Additionally,
it adds a number of test cases.

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D141480

Added: 
    

Modified: 
    mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
    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/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 74cce2a9ae40a..2bf1cab8e8841 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -53,8 +53,9 @@ bool DINodeAttr::classof(Attribute attr) {
 //===----------------------------------------------------------------------===//
 
 bool DIScopeAttr::classof(Attribute attr) {
-  return llvm::isa<DICompileUnitAttr, DIFileAttr, DILexicalBlockAttr,
-                   DILexicalBlockFileAttr, DISubprogramAttr>(attr);
+  return llvm::isa<DICompileUnitAttr, DICompositeTypeAttr, DIFileAttr,
+                   DILexicalBlockAttr, DILexicalBlockFileAttr,
+                   DISubprogramAttr>(attr);
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index 4b16febc19a33..ff0364313a6fc 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -47,12 +47,10 @@
   elements = #llvm.di_subrange<count = 4>
 >
 
-// CHECK-DAG: #[[COMP2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type, name = "array2", file = #[[FILE]], scope = #[[FILE]], baseType = #[[INT0]], elements = #llvm.di_subrange<lowerBound = 0 : i64, upperBound = 4 : i64, stride = 1 : i64>>
+// CHECK-DAG: #[[COMP2:.*]] = #llvm.di_composite_type<tag = DW_TAG_class_type, name = "class_name", file = #[[FILE]], scope = #[[FILE]], flags = "TypePassByReference|NonTrivial">
 #comp2 = #llvm.di_composite_type<
-  tag = DW_TAG_array_type, name = "array2", file = #file,
-  scope = #file, baseType = #int0,
-  // Specify the subrange bounds.
-  elements = #llvm.di_subrange<lowerBound = 0, upperBound = 4, stride = 1>
+  tag = DW_TAG_class_type, name = "class_name", file = #file, scope = #file,
+  flags = "TypePassByReference|NonTrivial"
 >
 
 // CHECK-DAG: #[[SPTYPE0:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, argumentTypes = #[[INT0]], #[[PTR0]], #[[PTR1]], #[[COMP0:.*]], #[[COMP1:.*]], #[[COMP2:.*]]>
@@ -72,10 +70,10 @@
   file = #file, line = 3, scopeLine = 3, subprogramFlags = "Definition|Optimized", type = #spType0
 >
 
-// CHECK-DAG: #[[SP1:.*]] = #llvm.di_subprogram<compileUnit = #[[CU]], scope = #[[FILE]], name = "value", file = #[[FILE]], subprogramFlags = Definition, type = #[[SPTYPE1]]>
+// CHECK-DAG: #[[SP1:.*]] = #llvm.di_subprogram<compileUnit = #[[CU]], scope = #[[COMP2]], name = "value", file = #[[FILE]], subprogramFlags = Definition, type = #[[SPTYPE1]]>
 #sp1 = #llvm.di_subprogram<
   // Omit the optional linkageName parameter.
-  compileUnit = #cu, scope = #file, name = "value",
+  compileUnit = #cu, scope = #comp2, name = "value",
   file = #file, subprogramFlags = "Definition", type = #spType1
 >
 

diff  --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index 6e39f37f80970..4a8a43b392fee 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -269,3 +269,24 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 !7 = !DILocation(line: 1, column: 2, scope: !3)
 !8 = !DILocation(line: 2, column: 2, scope: !3)
 !9 = !DILocation(line: 3, column: 2, scope: !3)
+
+; // -----
+
+; CHECK-LABEL: @class_method
+define void @class_method(ptr %arg1) {
+  ; CHECK: llvm.return loc(#[[LOC:.+]])
+  ret void, !dbg !5
+}
+
+; CHECK: #[[COMP:.+]] = #llvm.di_composite_type<tag = DW_TAG_class_type, name = "class_name", file = #{{.*}}, line = 42, flags = "TypePassByReference|NonTrivial">
+; CHECK: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #[[COMP]], name = "class_method", file = #{{.*}}, subprogramFlags = Definition>
+; CHECK: #[[LOC]] = loc(fused<#[[SP]]>
+
+!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: "/")
+!3 = !DICompositeType(tag: DW_TAG_class_type, name: "class_name", file: !2, line: 42, flags: DIFlagTypePassByReference | DIFlagNonTrivial)
+!4 = distinct !DISubprogram(name: "class_method", scope: !3, file: !2, spFlags: DISPFlagDefinition, unit: !1)
+!5 = !DILocation(line: 1, column: 2, scope: !4)

diff  --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 61a6fa888d722..434207ec1e126 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -58,7 +58,7 @@ llvm.func @func_no_debug() {
   resultType = #si64, argumentTypes = #si64>
 #callee = #llvm.di_subprogram<
   // Omit the optional linkageName, line, and scopeLine parameters.
-  compileUnit = #cu, scope = #file, name = "callee",
+  compileUnit = #cu, scope = #composite, name = "callee",
   file = #file, subprogramFlags = "Definition", type = #calleeType
 >
 #fileScope = #llvm.di_lexical_block_file<scope = #sp, file = #file, discriminator = 0>
@@ -127,7 +127,7 @@ llvm.func @func_with_debug(%arg: i64) {
 
 // CHECK: ![[FUSEDWITH_LOC]] = !DILocation(line: 2, column: 4, scope: ![[FUSEDWITH_SCOPE:.*]], inlinedAt: ![[INLINE_LOC:.*]])
 // CHECK: ![[FUSEDWITH_SCOPE]] = !DILexicalBlockFile(scope: ![[CALLEE_LOC:.*]], file:
-// CHECK: ![[CALLEE_LOC]] = distinct !DISubprogram(name: "callee", scope: ![[CU_FILE_LOC]], file: ![[CU_FILE_LOC]], type: ![[CALLEE_TYPE:.*]], spFlags: DISPFlagDefinition, unit: ![[CU_LOC]])
+// CHECK: ![[CALLEE_LOC]] = distinct !DISubprogram(name: "callee", scope: ![[COMPOSITE_TYPE]], file: ![[CU_FILE_LOC]], type: ![[CALLEE_TYPE:.*]], spFlags: DISPFlagDefinition, unit: ![[CU_LOC]])
 // CHECK: ![[CALLEE_TYPE]] = !DISubroutineType(types: ![[CALLEE_ARGS:.*]])
 // CHECK: ![[CALLEE_ARGS]] = !{![[ARG_TYPE:.*]], ![[ARG_TYPE:.*]]}
 // CHECK: ![[INLINE_LOC]] = !DILocation(line: 28, column: 5,


        


More information about the Mlir-commits mailing list