[Mlir-commits] [mlir] e83446f - [mlir:LLVM] Fix translation of DISubRangeAttr to LLVM

River Riddle llvmlistbot at llvm.org
Fri Nov 4 18:26:51 PDT 2022


Author: River Riddle
Date: 2022-11-04T18:15:03-07:00
New Revision: e83446f43b23cf4a4274cb3bde09883dcd9f7b4d

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

LOG: [mlir:LLVM] Fix translation of DISubRangeAttr to LLVM

We were missing DISubRangeAttr in the type switch. This
also updates a few of the range parameters to be optional.

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 0c689d0019f45..182704defcc64 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -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) `>`";
 }

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 3927e8169c0f4..74cce2a9ae40a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -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);
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 6de8febdd56a8..3dbb3f719e5b3 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -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;

diff  --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index fd95e176e1941..72f8f746b9769 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -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)


        


More information about the Mlir-commits mailing list