diff options
author | Stephen Tozer <stephen.tozer@sony.com> | 2024-06-11 13:11:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 13:11:41 +0100 |
commit | ca920bb6285e9995f5a202d040af79363e98ab28 (patch) | |
tree | 64e76df71f82dfdaa20fafe012201589d55a30b9 /mlir | |
parent | a141a28c0cf415d8ca410a636c3aacf3d683ab38 (diff) | |
download | llvm-ca920bb6285e9995f5a202d040af79363e98ab28.zip llvm-ca920bb6285e9995f5a202d040af79363e98ab28.tar.gz llvm-ca920bb6285e9995f5a202d040af79363e98ab28.tar.bz2 |
[MLIR][Flang][DebugInfo] Set debug info format in MLIR->IR translation (#95098)
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.
Diffstat (limited to 'mlir')
-rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 7b86b25..e1a60f1 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,9 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext, StringRef name) { m->getContext()->getOrLoadDialect<LLVM::LLVMDialect>(); auto llvmModule = std::make_unique<llvm::Module>(name, llvmContext); + // ModuleTranslation can currently only construct modules in the old debug + // info format, so set the flag accordingly. + llvmModule->setNewDbgInfoFormatFlag(false); if (auto dataLayoutAttr = m->getDiscardableAttr(LLVM::LLVMDialect::getDataLayoutAttrName())) { llvmModule->setDataLayout(cast<StringAttr>(dataLayoutAttr).getValue()); @@ -1867,6 +1872,11 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext, if (failed(translator.convertFunctions())) return nullptr; + // Once we've finished constructing elements in the module, we should convert + // it to use the debug info format desired by LLVM. + // See https://llvm.org/docs/RemoveDIsDebugInfo.html + translator.llvmModule->setIsNewDbgInfoFormat(UseNewDbgInfoFormat); + if (!disableVerification && llvm::verifyModule(*translator.llvmModule, &llvm::errs())) return nullptr; |