[Mlir-commits] [mlir] 873ea45 - [mlir][llvm] Rename void debug type to null

Christian Ulmann llvmlistbot at llvm.org
Thu Feb 16 03:15:03 PST 2023


Author: Christian Ulmann
Date: 2023-02-16T12:13:24+01:00
New Revision: 873ea45115a8e5ed1065d6aaad8f41fe6120cac8

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

LOG: [mlir][llvm] Rename void debug type to null

This commit renames the "di_void_result_type" to "di_null_type" as LLVM
does use null not exclusively for void types. An added test demonstrates
this for variadic function declarations, whose DISubroutine indicates the
start of variadic types with `null`.

Reviewed By: gysit

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
    mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
    mlir/lib/Target/LLVMIR/DebugImporter.cpp
    mlir/lib/Target/LLVMIR/DebugTranslation.cpp
    mlir/lib/Target/LLVMIR/DebugTranslation.h
    mlir/test/Dialect/LLVMIR/debuginfo.mlir
    mlir/test/Dialect/LLVMIR/invalid.mlir
    mlir/test/Target/LLVMIR/Import/debug-info.ll
    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 a6d8c703baaf8..85526c4186e5c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -261,11 +261,11 @@ def LLVM_DITagParameter : LLVM_DIParameter<
 >;
 
 //===----------------------------------------------------------------------===//
-// DIVoidResultTypeAttr
+// DINullTypeAttr
 //===----------------------------------------------------------------------===//
 
-def LLVM_DIVoidResultTypeAttr : LLVM_Attr<"DIVoidResultType", "di_void_result_type",
-                                          /*traits=*/[], "DITypeAttr"> {
+def LLVM_DINullTypeAttr : LLVM_Attr<"DINullType", "di_null_type",
+                                    /*traits=*/[], "DITypeAttr"> {
   let parameters = (ins);
 }
 
@@ -442,7 +442,7 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
 def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
                                       /*traits=*/[], "DIScopeAttr"> {
   let parameters = (ins
-    "DICompileUnitAttr":$compileUnit,
+    OptionalParameter<"DICompileUnitAttr">:$compileUnit,
     "DIScopeAttr":$scope,
     "StringAttr":$name,
     OptionalParameter<"StringAttr">:$linkageName,
@@ -500,7 +500,6 @@ def LLVM_DISubroutineTypeAttr : LLVM_Attr<"DISubroutineType", "di_subroutine_typ
     }]>
   ];
   let assemblyFormat = "`<` struct(params) `>`";
-  let genVerifyDecl = 1;
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 8e749259dad94..1bb0f6a9438d8 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -42,7 +42,7 @@ void LLVMDialect::registerAttributes() {
 //===----------------------------------------------------------------------===//
 
 bool DINodeAttr::classof(Attribute attr) {
-  return llvm::isa<DIVoidResultTypeAttr, DIBasicTypeAttr, DICompileUnitAttr,
+  return llvm::isa<DINullTypeAttr, DIBasicTypeAttr, DICompileUnitAttr,
                    DICompositeTypeAttr, DIDerivedTypeAttr, DIFileAttr,
                    DILexicalBlockAttr, DILexicalBlockFileAttr,
                    DILocalVariableAttr, DISubprogramAttr, DISubrangeAttr,
@@ -71,27 +71,10 @@ bool DILocalScopeAttr::classof(Attribute attr) {
 //===----------------------------------------------------------------------===//
 
 bool DITypeAttr::classof(Attribute attr) {
-  return llvm::isa<DIVoidResultTypeAttr, DIBasicTypeAttr, DICompositeTypeAttr,
+  return llvm::isa<DINullTypeAttr, DIBasicTypeAttr, DICompositeTypeAttr,
                    DIDerivedTypeAttr, DISubroutineTypeAttr>(attr);
 }
 
-//===----------------------------------------------------------------------===//
-// DISubroutineTypeAttr
-//===----------------------------------------------------------------------===//
-
-LogicalResult
-DISubroutineTypeAttr::verify(function_ref<InFlightDiagnostic()> emitError,
-                             unsigned int callingConventions,
-                             ArrayRef<DITypeAttr> types) {
-  ArrayRef<DITypeAttr> argumentTypes =
-      types.empty() ? types : types.drop_front();
-  if (llvm::any_of(argumentTypes, [](DITypeAttr type) {
-        return type.isa<DIVoidResultTypeAttr>();
-      }))
-    return emitError() << "expected subroutine to have non-void argument types";
-  return success();
-}
-
 //===----------------------------------------------------------------------===//
 // MemoryEffectsAttr
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index ee152f75432fa..ec3d202790d5d 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2759,7 +2759,7 @@ struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
 
   AliasResult getAlias(Attribute attr, raw_ostream &os) const override {
     return TypeSwitch<Attribute, AliasResult>(attr)
-        .Case<DIVoidResultTypeAttr, DIBasicTypeAttr, DICompileUnitAttr,
+        .Case<DINullTypeAttr, DIBasicTypeAttr, DICompileUnitAttr,
               DICompositeTypeAttr, DIDerivedTypeAttr, DIFileAttr,
               DILexicalBlockAttr, DILexicalBlockFileAttr, DILocalVariableAttr,
               DISubprogramAttr, DISubroutineTypeAttr, LoopAnnotationAttr,

diff  --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index cbb6754ea44d4..d6ddd6efd1495 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -151,11 +151,11 @@ DebugImporter::translateImpl(llvm::DISubroutineType *node) {
   SmallVector<DITypeAttr> types;
   for (llvm::DIType *type : node->getTypeArray()) {
     if (!type) {
-      // A nullptr entry at the beginning of the subroutine types list models a
-      // void result type. Translate the nullptr to an explicit
-      // DIVoidResultTypeAttr since the attribute list cannot contain a nullptr
-      // entry.
-      types.push_back(DIVoidResultTypeAttr::get(context));
+      // A nullptr entry may appear at the beginning or the end of the
+      // subroutine types list modeling either a void result type or the type of
+      // a variadic argument. Translate the nullptr to an explicit
+      // DINullTypeAttr since the attribute list cannot contain a nullptr entry.
+      types.push_back(DINullTypeAttr::get(context));
       continue;
     }
     types.push_back(translate(type));

diff  --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index fd80a773df8e7..9b13e81ace67f 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -88,10 +88,11 @@ void DebugTranslation::translate(LLVMFuncOp func, llvm::Function &llvmFunc) {
 // Attributes
 //===----------------------------------------------------------------------===//
 
-llvm::DIType *DebugTranslation::translateImpl(DIVoidResultTypeAttr attr) {
-  // A DIVoidResultTypeAttr at the beginning of the subroutine types list models
-  // a void result type. Translate the explicit DIVoidResultTypeAttr to a
-  // nullptr since LLVM IR metadata does not have an explicit void result type
+llvm::DIType *DebugTranslation::translateImpl(DINullTypeAttr attr) {
+  // A DINullTypeAttr at the beginning of the subroutine types list models
+  // a void result type. If it is at the end, it models a variadic function.
+  // Translate the explicit DINullTypeAttr to a nullptr since LLVM IR metadata
+  // does not have an explicit void result type nor a variadic type
   // representation.
   return nullptr;
 }
@@ -234,7 +235,7 @@ llvm::DINode *DebugTranslation::translate(DINodeAttr attr) {
 
   llvm::DINode *node =
       TypeSwitch<DINodeAttr, llvm::DINode *>(attr)
-          .Case<DIVoidResultTypeAttr, DIBasicTypeAttr, DICompileUnitAttr,
+          .Case<DINullTypeAttr, DIBasicTypeAttr, DICompileUnitAttr,
                 DICompositeTypeAttr, DIDerivedTypeAttr, DIFileAttr,
                 DILexicalBlockAttr, DILexicalBlockFileAttr, DILocalVariableAttr,
                 DISubprogramAttr, DISubrangeAttr, DISubroutineTypeAttr>(

diff  --git a/mlir/lib/Target/LLVMIR/DebugTranslation.h b/mlir/lib/Target/LLVMIR/DebugTranslation.h
index b62bd2bab4cea..17bc35c8ab44d 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.h
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.h
@@ -61,7 +61,7 @@ class DebugTranslation {
   llvm::DIFile *translateFile(StringRef fileName);
 
   /// Translate the given attribute to the corresponding llvm debug metadata.
-  llvm::DIType *translateImpl(DIVoidResultTypeAttr attr);
+  llvm::DIType *translateImpl(DINullTypeAttr attr);
   llvm::DIBasicType *translateImpl(DIBasicTypeAttr attr);
   llvm::DICompileUnit *translateImpl(DICompileUnitAttr attr);
   llvm::DICompositeType *translateImpl(DICompositeTypeAttr attr);

diff  --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index 4e13c5e01f2a3..d7123d971a68f 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -9,8 +9,8 @@
   isOptimized = true, emissionKind = Full
 >
 
-// CHECK-DAG: #[[VOID:.*]] = #llvm.di_void_result_type
-#void = #llvm.di_void_result_type
+// CHECK-DAG: #[[NULL:.*]] = #llvm.di_null_type
+#null = #llvm.di_null_type
 
 // CHECK-DAG: #[[INT0:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int0">
 #int0 = #llvm.di_basic_type<
@@ -56,9 +56,9 @@
   flags = "TypePassByReference|NonTrivial"
 >
 
-// CHECK-DAG: #[[SPTYPE0:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #[[VOID]], #[[INT0]], #[[PTR0]], #[[PTR1]], #[[COMP0:.*]], #[[COMP1:.*]], #[[COMP2:.*]]>
+// CHECK-DAG: #[[SPTYPE0:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #[[NULL]], #[[INT0]], #[[PTR0]], #[[PTR1]], #[[COMP0:.*]], #[[COMP1:.*]], #[[COMP2:.*]]>
 #spType0 = #llvm.di_subroutine_type<
-  callingConvention = DW_CC_normal, types = #void, #int0, #ptr0, #ptr1, #comp0, #comp1, #comp2
+  callingConvention = DW_CC_normal, types = #null, #int0, #ptr0, #ptr1, #comp0, #comp1, #comp2
 >
 
 // CHECK-DAG: #[[SPTYPE1:.*]] = #llvm.di_subroutine_type<types = #[[INT1]], #[[INT1]]>

diff  --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 256a509049252..664a9136f69a9 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -1300,12 +1300,6 @@ func.func @extract_scalable_from_fixed_length_vector(%arg0 : vector<16xf32>) {
 
 // -----
 
-#void = #llvm.di_void_result_type
-// expected-error at below {{expected subroutine to have non-void argument types}}
-#void_argument_type = #llvm.di_subroutine_type<types = #void, #void>
-
-// -----
-
 func.func @invalid_bitcast_ptr_to_i64(%arg : !llvm.ptr) {
   // expected-error at +1 {{can only cast pointers from and to pointers}}
   %1 = llvm.bitcast %arg : !llvm.ptr to i64

diff  --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index 588eea590de34..6dc5463006aee 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -112,10 +112,10 @@ define i32 @lexical_block_file(i32 %arg1) {
 
 ; // -----
 
-; CHECK-DAG: #[[VOID:.+]] = #llvm.di_void_result_type
+; CHECK-DAG: #[[NULL:.+]] = #llvm.di_null_type
 ; CHECK-DAG: #[[INT1:.+]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int1">
 ; CHECK-DAG: #[[INT2:.+]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int2", sizeInBits = 32, encoding = DW_ATE_signed>
-; CHECK-DAG: #llvm.di_subroutine_type<types = #[[VOID]], #[[INT1]], #[[INT2]]>
+; CHECK-DAG: #llvm.di_subroutine_type<types = #[[NULL]], #[[INT1]], #[[INT2]]>
 
 define void @basic_type() !dbg !3 {
   ret void
@@ -328,3 +328,19 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 !7 = !DILocalVariable(scope: !8, name: "class_field", file: !2, type: !5);
 !8 = distinct !DISubprogram(name: "class_field", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1)
 !9 = !DILocation(line: 1, column: 2, scope: !8)
+
+; // -----
+
+; CHECK-DAG: #[[NULL:.+]] = #llvm.di_null_type
+; CHECK-DAG: #llvm.di_subroutine_type<types = #[[NULL]], #[[NULL]]>
+
+declare !dbg !3 void @variadic_func()
+
+!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 = !DISubprogram(name: "variadic_func", scope: !2, file: !2, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, type: !4)
+!4 = !DISubroutineType(types: !5)
+!5 = !{null, null}

diff  --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 50d18eb2dd5fe..8b5a9f29864da 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -48,8 +48,8 @@ llvm.func @func_no_debug() {
   baseType = #si64, flags = Vector,
   elements = #llvm.di_subrange<lowerBound = 0, upperBound = 4, stride = 1>
 >
-#void = #llvm.di_void_result_type
-#spType0 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #void, #si64, #ptr, #named, #composite, #vector>
+#null = #llvm.di_null_type
+#spType0 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #null, #si64, #ptr, #named, #composite, #vector>
 #sp0 = #llvm.di_subprogram<
   compileUnit = #cu, scope = #file, name = "func_with_debug", linkageName = "func_with_debug",
   file = #file, line = 3, scopeLine = 3, subprogramFlags = "Definition|Optimized", type = #spType0


        


More information about the Mlir-commits mailing list