diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td @@ -175,12 +175,12 @@ LLVM_DITagParameter:$tag, "StringAttr":$name, OptionalParameter<"DIFileAttr">:$file, - "uint32_t":$line, + OptionalParameter<"uint32_t">:$line, OptionalParameter<"DIScopeAttr">:$scope, OptionalParameter<"DITypeAttr">:$baseType, OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags, - "uint64_t":$sizeInBits, - "uint64_t":$alignInBits, + OptionalParameter<"uint64_t">:$sizeInBits, + OptionalParameter<"uint64_t">:$alignInBits, OptionalArrayRefParameter<"DINodeAttr">:$elements ); let assemblyFormat = "`<` struct(params) `>`"; @@ -197,9 +197,9 @@ LLVM_DITagParameter:$tag, OptionalParameter<"StringAttr">:$name, "DITypeAttr":$baseType, - "uint64_t":$sizeInBits, - "uint32_t":$alignInBits, - "uint64_t":$offsetInBits + OptionalParameter<"uint64_t">:$sizeInBits, + OptionalParameter<"uint32_t">:$alignInBits, + OptionalParameter<"uint64_t">:$offsetInBits ); let assemblyFormat = "`<` struct(params) `>`"; } @@ -228,8 +228,8 @@ let parameters = (ins "DIScopeAttr":$scope, OptionalParameter<"DIFileAttr">:$file, - "unsigned":$line, - "unsigned":$column + OptionalParameter<"unsigned">:$line, + OptionalParameter<"unsigned">:$column ); let builders = [ AttrBuilderWithInferredContext<(ins @@ -307,8 +307,8 @@ "StringAttr":$name, OptionalParameter<"StringAttr">:$linkageName, "DIFileAttr":$file, - "unsigned":$line, - "unsigned":$scopeLine, + OptionalParameter<"unsigned">:$line, + OptionalParameter<"unsigned">:$scopeLine, "DISubprogramFlags":$subprogramFlags, OptionalParameter<"DISubroutineTypeAttr">:$type ); diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir --- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir +++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir @@ -21,38 +21,36 @@ sizeInBits = 32, encoding = DW_ATE_signed > -// CHECK-DAG: #[[PTR0:.*]] = #llvm.di_derived_type +// CHECK-DAG: #[[PTR0:.*]] = #llvm.di_derived_type #ptr0 = #llvm.di_derived_type< tag = DW_TAG_pointer_type, baseType = #int0, - sizeInBits = 0, alignInBits = 0, offsetInBits = 0 + sizeInBits = 64, alignInBits = 32, offsetInBits = 4 > -// CHECK-DAG: #[[PTR1:.*]] = #llvm.di_derived_type +// CHECK-DAG: #[[PTR1:.*]] = #llvm.di_derived_type #ptr1 = #llvm.di_derived_type< // Specify the name parameter. - tag = DW_TAG_pointer_type, name = "ptr1", baseType = #int0, - sizeInBits = 64, alignInBits = 32, offsetInBits = 4 + tag = DW_TAG_pointer_type, name = "ptr1", baseType = #int0 > // CHECK-DAG: #[[COMP0:.*]] = #llvm.di_composite_type #comp0 = #llvm.di_composite_type< - // Omit optional parameters. tag = DW_TAG_array_type, name = "array0", line = 10, sizeInBits = 128, alignInBits = 32 > -// CHECK-DAG: #[[COMP1:.*]] = #llvm.di_composite_type> +// CHECK-DAG: #[[COMP1:.*]] = #llvm.di_composite_type> #comp1 = #llvm.di_composite_type< tag = DW_TAG_array_type, name = "array1", file = #file, - line = 0, scope = #file, baseType = #int0, sizeInBits = 0, alignInBits = 0, + scope = #file, baseType = #int0, // Specify the subrange count. elements = #llvm.di_subrange > -// CHECK-DAG: #[[COMP2:.*]] = #llvm.di_composite_type> +// CHECK-DAG: #[[COMP2:.*]] = #llvm.di_composite_type> #comp2 = #llvm.di_composite_type< tag = DW_TAG_array_type, name = "array2", file = #file, - line = 0, scope = #file, baseType = #int0, sizeInBits = 0, alignInBits = 0, + scope = #file, baseType = #int0, // Specify the subrange bounds. elements = #llvm.di_subrange > @@ -74,23 +72,29 @@ file = #file, line = 3, scopeLine = 3, subprogramFlags = "Definition|Optimized", type = #spType0 > -// CHECK-DAG: #[[SP1:.*]] = #llvm.di_subprogram +// CHECK-DAG: #[[SP1:.*]] = #llvm.di_subprogram #sp1 = #llvm.di_subprogram< // Omit the optional linkageName parameter. compileUnit = #cu, scope = #file, name = "value", - file = #file, line = 4, scopeLine = 4, subprogramFlags = "Definition", type = #spType1 + file = #file, subprogramFlags = "Definition", type = #spType1 > -// CHECK-DAG: #[[VAR0:.*]] = #llvm.di_local_variable +// CHECK-DAG: #[[BLOCK0:.*]] = #llvm.di_lexical_block +#block0 = #llvm.di_lexical_block + +// CHECK-DAG: #[[BLOCK1:.*]] = #llvm.di_lexical_block +#block1 = #llvm.di_lexical_block + +// CHECK-DAG: #[[VAR0:.*]] = #llvm.di_local_variable #var0 = #llvm.di_local_variable< - scope = #sp0, name = "alloc", file = #file, + scope = #block0, name = "alloc", file = #file, line = 6, arg = 1, alignInBits = 32, type = #int0 > -// CHECK-DAG: #[[VAR1:.*]] = #llvm.di_local_variable +// CHECK-DAG: #[[VAR1:.*]] = #llvm.di_local_variable #var1 = #llvm.di_local_variable< // Omit the optional parameters. - scope = #sp1, name = "arg" + scope = #block1, name = "arg" > // CHECK: llvm.func @addr(%[[ARG:.*]]: i64) diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll --- a/mlir/test/Target/LLVMIR/Import/debug-info.ll +++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll @@ -38,8 +38,8 @@ !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 = distinct !DISubprogram(name: "instruction_loc", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1) -!4 = distinct !DISubprogram(name: "callee", scope: !2, file: !2, line: 43, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "instruction_loc", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) +!4 = distinct !DISubprogram(name: "callee", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) !5 = !DILocation(line: 1, column: 2, scope: !3) !6 = !DILocation(line: 2, column: 2, scope: !3) !7 = !DILocation(line: 7, column: 4, scope: !4, inlinedAt: !6) @@ -48,7 +48,7 @@ ; CHECK: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/"> ; CHECK: #[[SP:.+]] = #llvm.di_subprogram +; CHECK: #[[$LB0:.+]] = #llvm.di_lexical_block ; CHECK: #[[$LB1:.+]] = #llvm.di_lexical_block ; CHECK-LABEL: @lexical_block @@ -69,7 +69,7 @@ !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 = distinct !DISubprogram(name: "lexical_block", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "lexical_block", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) !4 = !DILexicalBlock(scope: !3) !5 = !DILexicalBlock(scope: !3, file: !2, line: 2, column: 2) !6 = !DILocation(line: 1, column: 2, scope: !4) @@ -100,7 +100,7 @@ !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 = distinct !DISubprogram(name: "lexical_block_file", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "lexical_block_file", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) !4 = !DILexicalBlockFile(scope: !3, discriminator: 0) !5 = !DILexicalBlockFile(scope: !3, file: !2, discriminator: 0) !6 = !DILocation(line: 1, column: 2, scope: !4) @@ -121,7 +121,7 @@ !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 = distinct !DISubprogram(name: "basic_type", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1, type: !4) +!3 = distinct !DISubprogram(name: "basic_type", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1, type: !4) !4 = !DISubroutineType(types: !5) !5 = !{null, !6, !7} !6 = !DIBasicType(name: "int1") @@ -130,7 +130,7 @@ ; // ----- ; CHECK: #[[INT:.+]] = #llvm.di_basic_type -; CHECK: #[[PTR1:.+]] = #llvm.di_derived_type +; CHECK: #[[PTR1:.+]] = #llvm.di_derived_type ; CHECK: #[[PTR2:.+]] = #llvm.di_derived_type ; CHECK: #llvm.di_subroutine_type @@ -143,7 +143,7 @@ !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 = distinct !DISubprogram(name: "derived_type", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1, type: !4) +!3 = distinct !DISubprogram(name: "derived_type", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1, type: !4) !4 = !DISubroutineType(types: !5) !5 = !{null, !7, !8} !6 = !DIBasicType(name: "int") @@ -155,9 +155,9 @@ ; CHECK-DAG: #[[INT:.+]] = #llvm.di_basic_type ; CHECK-DAG: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/"> ; CHECK-DAG: #[[COMP1:.+]] = #llvm.di_composite_type -; CHECK-DAG: #[[COMP2:.+]] = #llvm.di_composite_type<{{.*}}, file = #[[FILE]], line = 0, scope = #[[FILE]], baseType = #[[INT]], sizeInBits = 0, alignInBits = 0> -; CHECK-DAG: #[[COMP3:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, {{.*}}, elements = #llvm.di_subrange> -; CHECK-DAG: #[[COMP4:.+]] = #llvm.di_composite_type<{{.*}}, elements = #llvm.di_subrange> +; CHECK-DAG: #[[COMP2:.+]] = #llvm.di_composite_type<{{.*}}, file = #[[FILE]], scope = #[[FILE]], baseType = #[[INT]]> +; CHECK-DAG: #[[COMP3:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, elements = #llvm.di_subrange> +; CHECK-DAG: #[[COMP4:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, elements = #llvm.di_subrange> ; CHECK-DAG: #llvm.di_subroutine_type define void @composite_type() !dbg !3 { @@ -169,7 +169,7 @@ !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 = distinct !DISubprogram(name: "composite_type", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1, type: !4) +!3 = distinct !DISubprogram(name: "composite_type", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1, type: !4) !4 = !DISubroutineType(types: !5) !5 = !{null, !7, !8, !9, !10} !6 = !DIBasicType(name: "int") @@ -206,7 +206,7 @@ ; // ----- -; CHECK: #[[$SP:.+]] = #llvm.di_subprogram +; CHECK: #[[$SP:.+]] = #llvm.di_subprogram ; CHECK-LABEL: @func_loc define void @func_loc() !dbg !3 { @@ -219,7 +219,7 @@ !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 = distinct !DISubprogram(name: "func_loc", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "func_loc", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) ; // ----- @@ -259,7 +259,7 @@ !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 = distinct !DISubprogram(name: "intrinsic", scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "intrinsic", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) !4 = !DIBasicType(name: "int") !5 = !DILocalVariable(scope: !3, name: "arg", file: !2, line: 1, arg: 1, align: 32, type: !4); !6 = !DILocalVariable(scope: !3, name: "arg") diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir --- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir +++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir @@ -28,12 +28,11 @@ > #ptr = #llvm.di_derived_type< tag = DW_TAG_pointer_type, baseType = #si32, - sizeInBits = 64, alignInBits = 0, offsetInBits = 0 + sizeInBits = 64, alignInBits = 32, offsetInBits = 8 > #named = #llvm.di_derived_type< // Specify the name parameter. - tag = DW_TAG_pointer_type, name = "named", baseType = #si32, - sizeInBits = 64, alignInBits = 0, offsetInBits = 0 + tag = DW_TAG_pointer_type, name = "named", baseType = #si32 > #cu = #llvm.di_compile_unit< sourceLanguage = DW_LANG_C, file = #file, producer = "MLIR", @@ -41,12 +40,12 @@ > #composite = #llvm.di_composite_type< tag = DW_TAG_structure_type, name = "composite", file = #file, - line = 0, sizeInBits = 0, alignInBits = 0, + line = 42, sizeInBits = 64, alignInBits = 32, elements = #llvm.di_subrange > #vector = #llvm.di_composite_type< tag = DW_TAG_array_type, name = "array", file = #file, - line = 0, baseType = #si64, sizeInBits = 0, alignInBits = 0, flags = Vector, + baseType = #si64, flags = Vector, elements = #llvm.di_subrange > #spType = #llvm.di_subroutine_type @@ -58,13 +57,14 @@ // Omit the optional callingConvention parameter but specify a result type. resultType = #si64, argumentTypes = #si64> #callee = #llvm.di_subprogram< - // Omit the linkageName parameter. + // Omit the optional linkageName, line, and scopeLine parameters. compileUnit = #cu, scope = #file, name = "callee", - file = #file, line = 4, scopeLine = 4, subprogramFlags = "Definition", type = #calleeType + file = #file, subprogramFlags = "Definition", type = #calleeType > #fileScope = #llvm.di_lexical_block_file -#variable = #llvm.di_local_variable -#variableAddr = #llvm.di_local_variable +#blockScope = #llvm.di_lexical_block +#variable = #llvm.di_local_variable +#variableAddr = #llvm.di_local_variable // CHECK-LABEL: define void @func_with_debug( // CHECK-SAME: i64 %[[ARG:.*]]) !dbg ![[FUNC_LOC:[0-9]+]] @@ -105,19 +105,20 @@ // CHECK: ![[FUNC_TYPE]] = !DISubroutineType(cc: DW_CC_normal, types: ![[FUNC_ARGS:.*]]) // CHECK: ![[FUNC_ARGS]] = !{null, ![[ARG_TYPE:.*]], ![[PTR_TYPE:.*]], ![[NAMED_TYPE:.*]], ![[COMPOSITE_TYPE:.*]], ![[VECTOR_TYPE:.*]]} // CHECK: ![[ARG_TYPE]] = !DIBasicType(name: "si64") -// CHECK: ![[PTR_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BASE_TYPE:.*]], size: 64) +// CHECK: ![[PTR_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BASE_TYPE:.*]], size: 64, align: 32, offset: 8) // CHECK: ![[BASE_TYPE]] = !DIBasicType(name: "si32", size: 32, encoding: DW_ATE_signed) -// CHECK: ![[NAMED_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "named", baseType: ![[BASE_TYPE:.*]], size: 64) -// CHECK: ![[COMPOSITE_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "composite", file: ![[CU_FILE_LOC]], elements: ![[COMPOSITE_ELEMENTS:.*]]) +// CHECK: ![[NAMED_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "named", baseType: ![[BASE_TYPE:.*]]) +// CHECK: ![[COMPOSITE_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "composite", file: ![[CU_FILE_LOC]], line: 42, size: 64, align: 32, elements: ![[COMPOSITE_ELEMENTS:.*]]) // CHECK: ![[COMPOSITE_ELEMENTS]] = !{![[COMPOSITE_ELEMENT:.*]]} // CHECK: ![[COMPOSITE_ELEMENT]] = !DISubrange(count: 4) // CHECK: ![[VECTOR_TYPE]] = !DICompositeType(tag: DW_TAG_array_type, name: "array", file: ![[CU_FILE_LOC]], baseType: ![[ARG_TYPE]], flags: DIFlagVector, elements: ![[VECTOR_ELEMENTS:.*]]) // CHECK: ![[VECTOR_ELEMENTS]] = !{![[VECTOR_ELEMENT:.*]]} // CHECK: ![[VECTOR_ELEMENT]] = !DISubrange(lowerBound: 0, upperBound: 4, stride: 1) -// CHECK: ![[VAR_LOC]] = !DILocalVariable(name: "arg", arg: 1, scope: ![[VAR_SCOPE:.*]], file: ![[CU_FILE_LOC]], line: 6, type: ![[ARG_TYPE]]) +// CHECK: ![[VAR_LOC]] = !DILocalVariable(name: "arg", arg: 1, scope: ![[VAR_SCOPE:.*]], file: ![[CU_FILE_LOC]], line: 6, type: ![[ARG_TYPE]], align: 32) // CHECK: ![[VAR_SCOPE]] = distinct !DILexicalBlockFile(scope: ![[FUNC_LOC]], file: ![[CU_FILE_LOC]], discriminator: 0) -// CHECK: ![[ADDR_LOC]] = !DILocalVariable(name: "alloc", scope: ![[VAR_SCOPE:.*]]) +// CHECK: ![[ADDR_LOC]] = !DILocalVariable(name: "alloc", scope: ![[BLOCK_LOC:.*]]) +// CHECK: ![[BLOCK_LOC]] = distinct !DILexicalBlock(scope: ![[FUNC_LOC]]) // CHECK-DAG: ![[CALLSITE_LOC]] = !DILocation(line: 3, column: 4, // CHECK-DAG: ![[FILE_LOC]] = !DILocation(line: 1, column: 2, @@ -126,7 +127,7 @@ // 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]], line: 4, type: ![[CALLEE_TYPE:.*]], scopeLine: 4, spFlags: DISPFlagDefinition, unit: ![[CU_LOC]]) +// 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_TYPE]] = !DISubroutineType(types: ![[CALLEE_ARGS:.*]]) // CHECK: ![[CALLEE_ARGS]] = !{![[ARG_TYPE:.*]], ![[ARG_TYPE:.*]]} // CHECK: ![[INLINE_LOC]] = !DILocation(line: 28, column: 5,