[Mlir-commits] [mlir] [RemoveDIs][MLIR] Don't process debug records in the LLVM-IR translator (PR #89735)

Stephen Tozer llvmlistbot at llvm.org
Tue Apr 23 03:44:10 PDT 2024


https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/89735

We are almost ready to enable the use of debug records everywhere in LLVM by default; part of the prep-work for this means ensuring that every tool supports them. Every tool in the `llvm/` project supports them, front-ends that use the `DIBuilder` will support them, and as far as I can tell, the only other tool in the LLVM repo that needs to support them but doesn't is `mlir-translate`. This patch trivially unblocks them by converting from debug records to debug intrinsics before translating a module. 

The steps for adding real support for debug records are probably quite simple:

1. Iterate over debug records at the same time as iterating over instructions. The list of debug records that precede an instruction `I` are obtained from `I.getDbgRecordRange()`, so these can be processed immediately before processing `I`. Debug records have all the same fields and methods as debug intrinsics, so porting logic should generally be trivial.
2. Build debug records using the DIBuilder rather than the IRBuilder; the latter will only produce debug intrinsics, while the former will produce either debug records or debug intrinsics according to the debug info format of the target module.

These are changes that I _may_ be able to implement in time, but for the moment since there's not a huge advantage to support for debug records AFAICT (since we're translating out of the IR module, meaning there's no advantage to records over intrinsics), the simple pre-translate conversion should suffice for now.

>From 8bc4704d70b303f28f8648486bd0ab743f74f391 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Tue, 23 Apr 2024 11:05:28 +0100
Subject: [PATCH] Don't process debug records in the MLIR converter

---
 mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp     | 4 ++++
 mlir/test/Target/LLVMIR/Import/import-failure.ll | 8 ++++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index 101add70c51e29..7e2da1e0303c74 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -56,6 +56,10 @@ void registerFromLLVMIRTranslation() {
         if (llvm::verifyModule(*llvmModule, &llvm::errs()))
           return nullptr;
 
+        // Debug records are not currently supported in the LLVM IR translator.
+        if (llvmModule->IsNewDbgInfoFormat)
+          llvmModule->convertFromNewDbgValues();
+
         return translateLLVMIRToModule(std::move(llvmModule), context,
                                        emitExpensiveWarnings,
                                        dropDICompositeTypeElements);
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index 3f4efab70e1c02..9c24ed2b75746b 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -64,12 +64,12 @@ define void @unhandled_intrinsic() gc "example" {
 declare void @llvm.dbg.value(metadata, metadata, metadata)
 
 ; CHECK:      import-failure.ll
-; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata !DIArgList(i64 %{{.*}}, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value))
+; CHECK-SAME: warning: dropped intrinsic: tail call void @llvm.dbg.value(metadata !DIArgList(i64 %{{.*}}, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value))
 ; CHECK:      import-failure.ll
-; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression())
+; CHECK-SAME: warning: dropped intrinsic: tail call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression())
 define void @unsupported_argument(i64 %arg1) {
-  call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !5
-  call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5
+  tail call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !5
+  tail call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5
   ret void
 }
 



More information about the Mlir-commits mailing list