[Mlir-commits] [mlir] 3cc2710 - [MLIR][Flang][DebugInfo] Convert debug format in MLIR translators

Stephen Tozer llvmlistbot at llvm.org
Tue Jun 11 05:49:55 PDT 2024


Author: Stephen Tozer
Date: 2024-06-11T13:48:41+01:00
New Revision: 3cc2710e0dd53bb82742904fa13014018a1137ed

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

LOG: [MLIR][Flang][DebugInfo] Convert debug format in MLIR translators

Following from the previous commit, this patch converts to the
appropriate debug info format before printing LLVM IR.

See: https://github.com/llvm/llvm-project/pull/95098

Added: 
    

Modified: 
    flang/lib/Frontend/FrontendActions.cpp
    mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
    mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index a4db944e8c0ab..a74d2be9be3b1 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1276,6 +1276,7 @@ void CodeGenAction::executeAction() {
   if (action == BackendActionTy::Backend_EmitLL) {
     // When printing LLVM IR, we should convert the module to the debug info
     // format that LLVM expects us to print.
+    // See https://llvm.org/docs/RemoveDIsDebugInfo.html
     llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
                                                  WriteNewDbgInfoFormat);
     if (WriteNewDbgInfoFormat)

diff  --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
index 4558893779534..be3b36c762055 100644
--- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
@@ -16,9 +16,12 @@
 #include "mlir/Target/LLVMIR/Dialect/All.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Tools/mlir-translate/Translation.h"
+#include "llvm/IR/DebugProgramInstruction.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 
+extern llvm::cl::opt<bool> WriteNewDbgInfoFormat;
+
 using namespace mlir;
 
 namespace mlir {
@@ -31,6 +34,13 @@ void registerToLLVMIRTranslation() {
         if (!llvmModule)
           return failure();
 
+        // When printing LLVM IR, we should convert the module to the debug info
+        // format that LLVM expects us to print.
+        // See https://llvm.org/docs/RemoveDIsDebugInfo.html
+        llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
+                                                     WriteNewDbgInfoFormat);
+        if (WriteNewDbgInfoFormat)
+          llvmModule->removeDebugIntrinsicDeclarations();
         llvmModule->print(output, nullptr);
         return success();
       },

diff  --git a/mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp b/mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp
index 57e7d658fb501..813b4960faa94 100644
--- a/mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp
+++ b/mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp
@@ -22,6 +22,9 @@
 #include "mlir/Tools/mlir-translate/Translation.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/IR/DebugProgramInstruction.h"
+
+extern llvm::cl::opt<bool> WriteNewDbgInfoFormat;
 
 using namespace mlir;
 
@@ -122,6 +125,13 @@ void registerTestToLLVMIR() {
         if (!llvmModule)
           return failure();
 
+        // When printing LLVM IR, we should convert the module to the debug info
+        // format that LLVM expects us to print.
+        // See https://llvm.org/docs/RemoveDIsDebugInfo.html
+        llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
+                                                     WriteNewDbgInfoFormat);
+        if (WriteNewDbgInfoFormat)
+          llvmModule->removeDebugIntrinsicDeclarations();
         llvmModule->print(output, nullptr);
         return success();
       },


        


More information about the Mlir-commits mailing list