Skip to content

Commit 3cc2710

Browse files
committed
[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: #95098
1 parent 460408f commit 3cc2710

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

flang/lib/Frontend/FrontendActions.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ void CodeGenAction::executeAction() {
12761276
if (action == BackendActionTy::Backend_EmitLL) {
12771277
// When printing LLVM IR, we should convert the module to the debug info
12781278
// format that LLVM expects us to print.
1279+
// See https://llvm.org/docs/RemoveDIsDebugInfo.html
12791280
llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
12801281
WriteNewDbgInfoFormat);
12811282
if (WriteNewDbgInfoFormat)

mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
#include "mlir/Target/LLVMIR/Dialect/All.h"
1717
#include "mlir/Target/LLVMIR/Export.h"
1818
#include "mlir/Tools/mlir-translate/Translation.h"
19+
#include "llvm/IR/DebugProgramInstruction.h"
1920
#include "llvm/IR/LLVMContext.h"
2021
#include "llvm/IR/Module.h"
2122

23+
extern llvm::cl::opt<bool> WriteNewDbgInfoFormat;
24+
2225
using namespace mlir;
2326

2427
namespace mlir {
@@ -31,6 +34,13 @@ void registerToLLVMIRTranslation() {
3134
if (!llvmModule)
3235
return failure();
3336

37+
// When printing LLVM IR, we should convert the module to the debug info
38+
// format that LLVM expects us to print.
39+
// See https://llvm.org/docs/RemoveDIsDebugInfo.html
40+
llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
41+
WriteNewDbgInfoFormat);
42+
if (WriteNewDbgInfoFormat)
43+
llvmModule->removeDebugIntrinsicDeclarations();
3444
llvmModule->print(output, nullptr);
3545
return success();
3646
},

mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "mlir/Tools/mlir-translate/Translation.h"
2323
#include "llvm/ADT/StringSwitch.h"
2424
#include "llvm/ADT/TypeSwitch.h"
25+
#include "llvm/IR/DebugProgramInstruction.h"
26+
27+
extern llvm::cl::opt<bool> WriteNewDbgInfoFormat;
2528

2629
using namespace mlir;
2730

@@ -122,6 +125,13 @@ void registerTestToLLVMIR() {
122125
if (!llvmModule)
123126
return failure();
124127

128+
// When printing LLVM IR, we should convert the module to the debug info
129+
// format that LLVM expects us to print.
130+
// See https://llvm.org/docs/RemoveDIsDebugInfo.html
131+
llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
132+
WriteNewDbgInfoFormat);
133+
if (WriteNewDbgInfoFormat)
134+
llvmModule->removeDebugIntrinsicDeclarations();
125135
llvmModule->print(output, nullptr);
126136
return success();
127137
},

0 commit comments

Comments
 (0)