[mlir][llvm] Rename void debug type to null
authorChristian Ulmann <christian.ulmann@nextsilicon.com>
Thu, 16 Feb 2023 10:36:34 +0000 (11:36 +0100)
committerChristian Ulmann <christian.ulmann@nextsilicon.com>
Thu, 16 Feb 2023 11:13:24 +0000 (12:13 +0100)
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

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

index a6d8c70..85526c4 100644 (file)
@@ -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;
 }
 
 //===----------------------------------------------------------------------===//
index 8e74925..1bb0f6a 100644 (file)
@@ -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,28 +71,11 @@ 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
 //===----------------------------------------------------------------------===//
 
index ee152f7..ec3d202 100644 (file)
@@ -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,
index cbb6754..d6ddd6e 100644 (file)
@@ -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));
index fd80a77..9b13e81 100644 (file)
@@ -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>(
index b62bd2b..17bc35c 100644 (file)
@@ -61,7 +61,7 @@ private:
   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);
index 4e13c5e..d7123d9 100644 (file)
@@ -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]]>
index 256a509..664a913 100644 (file)
@@ -1300,12 +1300,6 @@ func.func @extract_scalable_from_fixed_length_vector(%arg0 : vector<16xf32>) {
 
 // -----
 
-#void = #llvm.di_void_result_type
-// expected-error@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@+1 {{can only cast pointers from and to pointers}}
   %1 = llvm.bitcast %arg : !llvm.ptr to i64
index 588eea5..6dc5463 100644 (file)
@@ -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}
index 50d18eb..8b5a9f2 100644 (file)
@@ -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