[Mlir-commits] [flang] [mlir] [MLIR][Flang][DebugInfo] Set debug info format in MLIR->IR translation (PR #95098)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jun 11 04:42:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
Author: Stephen Tozer (SLTozer)
<details>
<summary>Changes</summary>
MLIR's LLVM dialect does not internally support debug records, only converting to/from debug intrinsics. To smooth the transition from intrinsics to records, there is a step prior to IR->MLIR translation that switches the IR module to intrinsic-form; this patch adds the equivalent conversion to record-form at MLIR->IR translation, and also modifies the flang front end to use the WriteNewDbgInfoFormat flag when it is emitting LLVM IR.
---
Full diff: https://github.com/llvm/llvm-project/pull/95098.diff
2 Files Affected:
- (modified) flang/lib/Frontend/FrontendActions.cpp (+7)
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+5)
``````````diff
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index b1b6391f1439c..585177b5c7647 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -50,6 +50,7 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
+#include "llvm/IR/DebugProgramInstruction.h"
#include "llvm/IR/LLVMRemarkStreamer.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Verifier.h"
@@ -81,6 +82,8 @@ using namespace Fortran::frontend;
llvm::PassPluginLibraryInfo get##Ext##PluginInfo();
#include "llvm/Support/Extension.def"
+extern llvm::cl::opt<bool> WriteNewDbgInfoFormat;
+
/// Save the given \c mlirModule to a temporary .mlir file, in a location
/// decided by the -save-temps flag. No files are produced if the flag is not
/// specified.
@@ -1271,6 +1274,10 @@ void CodeGenAction::executeAction() {
runOptimizationPipeline(ci.isOutputStreamNull() ? *os : ci.getOutputStream());
if (action == BackendActionTy::Backend_EmitLL) {
+ llvm::ScopedDbgInfoFormatSetter FormatSetter(*llvmModule,
+ WriteNewDbgInfoFormat);
+ if (WriteNewDbgInfoFormat)
+ llvmModule->removeDebugIntrinsicDeclarations();
llvmModule->print(ci.isOutputStreamNull() ? *os : ci.getOutputStream(),
/*AssemblyAnnotationWriter=*/nullptr);
return;
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 7b86b250c294b..a5c8c26483edf 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -64,6 +64,8 @@ using namespace mlir;
using namespace mlir::LLVM;
using namespace mlir::LLVM::detail;
+extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
+
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
namespace {
@@ -1789,6 +1791,7 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
StringRef name) {
m->getContext()->getOrLoadDialect<LLVM::LLVMDialect>();
auto llvmModule = std::make_unique<llvm::Module>(name, llvmContext);
+ llvmModule->setNewDbgInfoFormatFlag(false);
if (auto dataLayoutAttr =
m->getDiscardableAttr(LLVM::LLVMDialect::getDataLayoutAttrName())) {
llvmModule->setDataLayout(cast<StringAttr>(dataLayoutAttr).getValue());
@@ -1867,6 +1870,8 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
if (failed(translator.convertFunctions()))
return nullptr;
+ translator.llvmModule->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
+
if (!disableVerification &&
llvm::verifyModule(*translator.llvmModule, &llvm::errs()))
return nullptr;
``````````
</details>
https://github.com/llvm/llvm-project/pull/95098
More information about the Mlir-commits
mailing list