[mlir:LLVM] Fix translation of DISubRangeAttr to LLVM
authorRiver Riddle <riddleriver@gmail.com>
Fri, 4 Nov 2022 02:12:53 +0000 (19:12 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Sat, 5 Nov 2022 01:15:03 +0000 (18:15 -0700)
We were missing DISubRangeAttr in the type switch. This
also updates a few of the range parameters to be optional.

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.cpp
mlir/test/Target/LLVMIR/llvmir-debug.mlir

index 0c689d0..182704d 100644 (file)
@@ -334,9 +334,9 @@ def LLVM_DISubrangeAttr : LLVM_Attr<"DISubrange", "di_subrange", /*traits=*/[],
                                     "DINodeAttr"> {
   let parameters = (ins
     "IntegerAttr":$count,
-    "IntegerAttr":$lowerBound,
-    "IntegerAttr":$upperBound,
-    "IntegerAttr":$stride
+    OptionalParameter<"IntegerAttr">:$lowerBound,
+    OptionalParameter<"IntegerAttr">:$upperBound,
+    OptionalParameter<"IntegerAttr">:$stride
   );
   let assemblyFormat = "`<` struct(params) `>`";
 }
index 3927e81..74cce2a 100644 (file)
@@ -44,7 +44,8 @@ bool DINodeAttr::classof(Attribute attr) {
   return llvm::isa<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
                    DIDerivedTypeAttr, DIFileAttr, DILexicalBlockAttr,
                    DILexicalBlockFileAttr, DILocalVariableAttr,
-                   DISubprogramAttr, DISubroutineTypeAttr>(attr);
+                   DISubprogramAttr, DISubrangeAttr, DISubroutineTypeAttr>(
+      attr);
 }
 
 //===----------------------------------------------------------------------===//
@@ -61,7 +62,8 @@ bool DIScopeAttr::classof(Attribute attr) {
 //===----------------------------------------------------------------------===//
 
 bool DITypeAttr::classof(Attribute attr) {
-  return llvm::isa<DIBasicTypeAttr, DISubroutineTypeAttr>(attr);
+  return llvm::isa<DIBasicTypeAttr, DICompositeTypeAttr, DIDerivedTypeAttr,
+                   DISubroutineTypeAttr>(attr);
 }
 
 //===----------------------------------------------------------------------===//
index 6de8feb..3dbb3f7 100644 (file)
@@ -216,7 +216,7 @@ llvm::DINode *DebugTranslation::translate(DINodeAttr attr) {
           .Case<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
                 DIDerivedTypeAttr, DIFileAttr, DILexicalBlockAttr,
                 DILexicalBlockFileAttr, DILocalVariableAttr, DISubprogramAttr,
-                DISubroutineTypeAttr>(
+                DISubrangeAttr, DISubroutineTypeAttr>(
               [&](auto attr) { return translateImpl(attr); });
   attrToNode.insert({attr, node});
   return node;
index fd95e17..72f8f74 100644 (file)
@@ -27,7 +27,12 @@ llvm.func @func_no_debug() {
   sourceLanguage = DW_LANG_C, file = #file, producer = "MLIR",
   isOptimized = true, emissionKind = Full
 >
-#spType = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #si64>
+#composite = #llvm.di_composite_type<
+  tag = DW_TAG_structure_type, name = "composite", file = #file,
+  line = 0, sizeInBits = 0, alignInBits = 0,
+  elements = #llvm.di_subrange<count = 4>
+>
+#spType = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #si64, #composite>
 #sp = #llvm.di_subprogram<
   compileUnit = #cu, scope = #file, name = "intrinsics", linkageName = "intrinsics",
   file = #file, line = 3, scopeLine = 3, subprogramFlags = "Definition|Optimized", type = #spType
@@ -69,8 +74,11 @@ llvm.func @func_with_debug(%arg: i64) {
 
 // CHECK: ![[FUNC_LOC]] = distinct !DISubprogram(name: "intrinsics", linkageName: "intrinsics", scope: ![[CU_FILE_LOC]], file: ![[CU_FILE_LOC]], line: 3, type: ![[FUNC_TYPE:.*]], scopeLine: 3, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: ![[CU_LOC]])
 // CHECK: ![[FUNC_TYPE]] = !DISubroutineType(cc: DW_CC_normal, types: ![[ARG_TYPES:.*]])
-// CHECK: ![[ARG_TYPES]] = !{![[ARG_TYPE:.*]]}
+// CHECK: ![[ARG_TYPES]] = !{![[ARG_TYPE:.*]], ![[COMPOSITE_TYPE:.*]]}
 // CHECK: ![[ARG_TYPE]] = !DIBasicType(name: "si64", encoding: DW_ATE_signed)
+// CHECK: ![[COMPOSITE_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "composite", file: ![[CU_FILE_LOC]], elements: ![[COMPOSITE_ELEMENTS:.*]])
+// CHECK: ![[COMPOSITE_ELEMENTS]] = !{![[COMPOSITE_ELEMENT:.*]]}
+// CHECK: ![[COMPOSITE_ELEMENT]] = !DISubrange(count: 4)
 
 // CHECK: ![[VAR_LOC]] = !DILocalVariable(name: "arg", arg: 1, scope: ![[VAR_SCOPE:.*]], file: ![[CU_FILE_LOC]], line: 6, type: ![[ARG_TYPE]])
 // CHECK: ![[VAR_SCOPE]] = distinct !DILexicalBlockFile(scope: ![[FUNC_LOC]], file: ![[CU_FILE_LOC]], discriminator: 0)