-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang] Remove hardcoded bits from AddDebugInfo. #89231
Conversation
This PR adds following options to the AddDebugInfo pass. 1. IsOptimized flag. 2. Level of debug info to generate. 3. Name of the source file This enables us to remove the hard coded values from the code. It also allows us to test the pass with different options. The tests have been modified to take advantage of that. The calling convention flag and producer name have also been improved.
@llvm/pr-subscribers-flang-fir-hlfir Author: None (abidh) ChangesThis PR adds following options to the AddDebugInfo pass.
This enables us to remove the hard coded values from the code. It also allows us to test the pass with different options. The tests have been modified to take advantage of that. The calling convention flag and producer name have also been improved. Full diff: https://github.com/llvm/llvm-project/pull/89231.diff 8 Files Affected:
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h
index d8840d9e967b48..ea004c2d5d6da2 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -48,6 +48,7 @@ namespace fir {
#define GEN_PASS_DECL_ALGEBRAICSIMPLIFICATION
#define GEN_PASS_DECL_POLYMORPHICOPCONVERSION
#define GEN_PASS_DECL_OPENACCDATAOPERANDCONVERSION
+#define GEN_PASS_DECL_ADDDEBUGINFO
#include "flang/Optimizer/Transforms/Passes.h.inc"
std::unique_ptr<mlir::Pass> createAbstractResultOnFuncOptPass();
@@ -67,7 +68,8 @@ std::unique_ptr<mlir::Pass> createMemoryAllocationPass();
std::unique_ptr<mlir::Pass> createStackArraysPass();
std::unique_ptr<mlir::Pass> createAliasTagsPass();
std::unique_ptr<mlir::Pass> createSimplifyIntrinsicsPass();
-std::unique_ptr<mlir::Pass> createAddDebugInfoPass();
+std::unique_ptr<mlir::Pass>
+createAddDebugInfoPass(fir::AddDebugInfoOptions options = {});
std::unique_ptr<mlir::Pass> createLoopVersioningPass();
std::unique_ptr<mlir::Pass>
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index bfc0db8124af21..86c762b129d7d7 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -210,6 +210,25 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> {
let dependentDialects = [
"fir::FIROpsDialect", "mlir::func::FuncDialect", "mlir::LLVM::LLVMDialect"
];
+ let options = [
+ Option<"debugLevel", "debug-level",
+ "mlir::LLVM::DIEmissionKind",
+ /*default=*/"mlir::LLVM::DIEmissionKind::Full",
+ "debug level",
+ [{::llvm::cl::values(
+ clEnumValN(mlir::LLVM::DIEmissionKind::Full, "Full", "Emit full debug info"),
+ clEnumValN(mlir::LLVM::DIEmissionKind::LineTablesOnly, "LineTablesOnly", "Emit line tables only"),
+ clEnumValN(mlir::LLVM::DIEmissionKind::None, "None", "Emit no debug information")
+ )}]
+ >,
+ Option<"isOptimized", "is-optimized",
+ "bool", /*default=*/"false",
+ "is optimized.">,
+ Option<"inputFilename", "file-name",
+ "std::string",
+ /*default=*/"std::string{}",
+ "name of the input source file">,
+ ];
}
// This needs to be a "mlir::ModuleOp" pass, because it inserts simplified
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index ea297fb337a2c8..5e0479c40c945a 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -155,9 +155,27 @@ inline void addTargetRewritePass(mlir::PassManager &pm) {
});
}
-inline void addDebugInfoPass(mlir::PassManager &pm) {
- addPassConditionally(
- pm, disableDebugInfo, [&]() { return fir::createAddDebugInfoPass(); });
+inline mlir::LLVM::DIEmissionKind getEmissionKind(
+ llvm::codegenoptions::DebugInfoKind kind) {
+ switch (kind) {
+ case llvm::codegenoptions::DebugInfoKind::FullDebugInfo:
+ return mlir::LLVM::DIEmissionKind::Full;
+ case llvm::codegenoptions::DebugInfoKind::DebugLineTablesOnly:
+ return mlir::LLVM::DIEmissionKind::LineTablesOnly;
+ default:
+ return mlir::LLVM::DIEmissionKind::None;
+ }
+}
+
+inline void addDebugInfoPass(mlir::PassManager &pm,
+ llvm::codegenoptions::DebugInfoKind debugLevel,
+ llvm::OptimizationLevel optLevel, llvm::StringRef inputFilename) {
+ fir::AddDebugInfoOptions options;
+ options.debugLevel = getEmissionKind(debugLevel);
+ options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
+ options.inputFilename = inputFilename;
+ addPassConditionally(pm, disableDebugInfo,
+ [&]() { return fir::createAddDebugInfoPass(options); });
}
inline void addFIRToLLVMPass(
@@ -283,12 +301,13 @@ inline void createOpenMPFIRPassPipeline(
}
#if !defined(FLANG_EXCLUDE_CODEGEN)
-inline void createDebugPasses(
- mlir::PassManager &pm, llvm::codegenoptions::DebugInfoKind debugLevel) {
+inline void createDebugPasses(mlir::PassManager &pm,
+ llvm::codegenoptions::DebugInfoKind debugLevel,
+ llvm::OptimizationLevel OptLevel, llvm::StringRef inputFilename) {
// Currently only -g1, -g, -gline-tables-only supported
switch (debugLevel) {
case llvm::codegenoptions::DebugLineTablesOnly:
- addDebugInfoPass(pm);
+ addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename);
return;
case llvm::codegenoptions::NoDebugInfo:
return;
@@ -296,13 +315,13 @@ inline void createDebugPasses(
// TODO: Add cases and passes for other debug options.
// All other debug options not implemented yet, currently emits warning
// and generates as much debug information as possible.
- addDebugInfoPass(pm);
+ addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename);
return;
}
}
-inline void createDefaultFIRCodeGenPassPipeline(
- mlir::PassManager &pm, MLIRToLLVMPassPipelineConfig config) {
+inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
+ MLIRToLLVMPassPipelineConfig config, llvm::StringRef inputFilename = {}) {
fir::addBoxedProcedurePass(pm);
pm.addNestedPass<mlir::func::FuncOp>(
fir::createAbstractResultOnFuncOptPass());
@@ -310,7 +329,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
fir::addCodeGenRewritePass(pm);
fir::addTargetRewritePass(pm);
fir::addExternalNameConversionPass(pm, config.Underscoring);
- fir::createDebugPasses(pm, config.DebugInfo);
+ fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
if (config.VScaleMin != 0)
pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, config.VScaleMax}));
@@ -344,15 +363,16 @@ inline void createDefaultFIRCodeGenPassPipeline(
/// \param pm - MLIR pass manager that will hold the pipeline definition
/// \param optLevel - optimization level used for creating FIR optimization
/// passes pipeline
-inline void createMLIRToLLVMPassPipeline(
- mlir::PassManager &pm, const MLIRToLLVMPassPipelineConfig &config) {
+inline void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
+ const MLIRToLLVMPassPipelineConfig &config,
+ llvm::StringRef inputFilename = {}) {
fir::createHLFIRToFIRPassPipeline(pm, config.OptLevel);
// Add default optimizer pass pipeline.
fir::createDefaultFIROptimizerPassPipeline(pm, config);
// Add codegen pass pipeline.
- fir::createDefaultFIRCodeGenPassPipeline(pm, config);
+ fir::createDefaultFIRCodeGenPassPipeline(pm, config, inputFilename);
}
#undef FLANG_EXCLUDE_CODEGEN
#endif
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 8f251997ed401b..d91846dde95a83 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -809,7 +809,7 @@ void CodeGenAction::generateLLVMIR() {
}
// Create the pass pipeline
- fir::createMLIRToLLVMPassPipeline(pm, config);
+ fir::createMLIRToLLVMPassPipeline(pm, config, getCurrentFile());
(void)mlir::applyPassManagerCLOptions(pm);
// run the pass manager
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index 4ca33806612876..69c7e1f40e7d0a 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -11,12 +11,14 @@
/// This pass populates some debug information for the module and functions.
//===----------------------------------------------------------------------===//
+#include "flang/Common/Version.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Dialect/FIROps.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/Dialect/Support/FIRContext.h"
+#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Transforms/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -28,12 +30,12 @@
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
namespace fir {
#define GEN_PASS_DEF_ADDDEBUGINFO
-#define GEN_PASS_DECL_ADDDEBUGINFO
#include "flang/Optimizer/Transforms/Passes.h.inc"
} // namespace fir
@@ -43,6 +45,7 @@ namespace {
class AddDebugInfoPass : public fir::impl::AddDebugInfoBase<AddDebugInfoPass> {
public:
+ AddDebugInfoPass(fir::AddDebugInfoOptions options) : Base(options) {}
void runOnOperation() override;
};
@@ -52,21 +55,40 @@ void AddDebugInfoPass::runOnOperation() {
mlir::ModuleOp module = getOperation();
mlir::MLIRContext *context = &getContext();
mlir::OpBuilder builder(context);
- std::string inputFilePath("-");
- if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>())
- inputFilePath = fileLoc.getFilename().getValue();
+ llvm::StringRef fileName;
+ std::string filePath;
+ // We need 2 type of file paths here.
+ // 1. Name of the file as was presented to compiler. This can be absolute
+ // or relative to 2.
+ // 2. Current working directory
+ //
+ // We are also dealing with 2 different situations below. One is normal
+ // compilation where we will have a value in 'inputFilename' and we can
+ // obtain the current directory using 'current_path'.
+ // The 2nd case is when this pass is invoked directly from 'fir-opt' tool.
+ // In that case, 'inputFilename' may be empty. Location embedded in the
+ // module will be used to get file name and its directory.
+ if (inputFilename.empty()) {
+ if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>()) {
+ fileName = llvm::sys::path::filename(fileLoc.getFilename().getValue());
+ filePath = llvm::sys::path::parent_path(fileLoc.getFilename().getValue());
+ } else
+ fileName = "-";
+ } else {
+ fileName = inputFilename;
+ llvm::SmallString<256> cwd;
+ if (!llvm::sys::fs::current_path(cwd))
+ filePath = cwd.str();
+ }
- auto getFileAttr = [context](llvm::StringRef path) -> mlir::LLVM::DIFileAttr {
- return mlir::LLVM::DIFileAttr::get(context, llvm::sys::path::filename(path),
- llvm::sys::path::parent_path(path));
- };
-
- mlir::LLVM::DIFileAttr fileAttr = getFileAttr(inputFilePath);
- mlir::StringAttr producer = mlir::StringAttr::get(context, "Flang");
+ mlir::LLVM::DIFileAttr fileAttr =
+ mlir::LLVM::DIFileAttr::get(context, fileName, filePath);
+ mlir::StringAttr producer =
+ mlir::StringAttr::get(context, Fortran::common::getFlangFullVersion());
mlir::LLVM::DICompileUnitAttr cuAttr = mlir::LLVM::DICompileUnitAttr::get(
mlir::DistinctAttr::create(mlir::UnitAttr::get(context)),
llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer,
- /*isOptimized=*/false, mlir::LLVM::DIEmissionKind::LineTablesOnly);
+ isOptimized, debugLevel);
module.walk([&](mlir::func::FuncOp funcOp) {
mlir::Location l = funcOp->getLoc();
@@ -75,12 +97,14 @@ void AddDebugInfoPass::runOnOperation() {
if (l.dyn_cast<mlir::FusedLoc>())
return;
- llvm::StringRef funcFilePath;
- if (l.dyn_cast<mlir::FileLineColLoc>())
- funcFilePath =
- l.dyn_cast<mlir::FileLineColLoc>().getFilename().getValue();
- else
- funcFilePath = inputFilePath;
+ unsigned int CC = (funcOp.getName() == fir::NameUniquer::doProgramEntry())
+ ? llvm::dwarf::getCallingConvention("DW_CC_program")
+ : llvm::dwarf::getCallingConvention("DW_CC_normal");
+
+ if (auto funcLoc = l.dyn_cast<mlir::FileLineColLoc>()) {
+ fileName = llvm::sys::path::filename(funcLoc.getFilename().getValue());
+ filePath = llvm::sys::path::parent_path(funcLoc.getFilename().getValue());
+ }
mlir::StringAttr funcName =
mlir::StringAttr::get(context, funcOp.getName());
@@ -88,30 +112,31 @@ void AddDebugInfoPass::runOnOperation() {
context, llvm::dwarf::DW_TAG_base_type, "void", /*sizeInBits=*/0,
/*encoding=*/1);
mlir::LLVM::DISubroutineTypeAttr subTypeAttr =
- mlir::LLVM::DISubroutineTypeAttr::get(
- context, llvm::dwarf::getCallingConvention("DW_CC_normal"),
- {bT, bT});
- mlir::LLVM::DIFileAttr funcFileAttr = getFileAttr(funcFilePath);
+ mlir::LLVM::DISubroutineTypeAttr::get(context, CC, {bT, bT});
+ mlir::LLVM::DIFileAttr funcFileAttr =
+ mlir::LLVM::DIFileAttr::get(context, fileName, filePath);
// Only definitions need a distinct identifier and a compilation unit.
mlir::DistinctAttr id;
mlir::LLVM::DICompileUnitAttr compilationUnit;
- auto subprogramFlags = mlir::LLVM::DISubprogramFlags::Optimized;
+ mlir::LLVM::DISubprogramFlags subprogramFlags =
+ mlir::LLVM::DISubprogramFlags{};
+ if (isOptimized)
+ subprogramFlags = mlir::LLVM::DISubprogramFlags::Optimized;
if (!funcOp.isExternal()) {
id = mlir::DistinctAttr::create(mlir::UnitAttr::get(context));
compilationUnit = cuAttr;
- subprogramFlags =
- subprogramFlags | mlir::LLVM::DISubprogramFlags::Definition;
+ subprogramFlags = mlir::LLVM::DISubprogramFlags::Definition;
}
auto spAttr = mlir::LLVM::DISubprogramAttr::get(
context, id, compilationUnit, fileAttr, funcName, funcName,
- funcFileAttr,
- /*line=*/1,
- /*scopeline=*/1, subprogramFlags, subTypeAttr);
+ funcFileAttr, /*line=*/1, /*scopeline=*/1, subprogramFlags,
+ subTypeAttr);
funcOp->setLoc(builder.getFusedLoc({funcOp->getLoc()}, spAttr));
});
}
-std::unique_ptr<mlir::Pass> fir::createAddDebugInfoPass() {
- return std::make_unique<AddDebugInfoPass>();
+std::unique_ptr<mlir::Pass>
+fir::createAddDebugInfoPass(fir::AddDebugInfoOptions options) {
+ return std::make_unique<AddDebugInfoPass>(options);
}
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index d55655c53906e6..fc08d67540ceb0 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -35,6 +35,7 @@ add_flang_library(FIRTransforms
FIRDialect
FIRDialectSupport
FIRSupport
+ FortranCommon
HLFIRDialect
MLIRAffineUtils
MLIRFuncDialect
diff --git a/flang/test/Transforms/debug-line-table-inc-file.fir b/flang/test/Transforms/debug-line-table-inc-file.fir
index be4f005bf664ac..dc75482d4f8a7f 100644
--- a/flang/test/Transforms/debug-line-table-inc-file.fir
+++ b/flang/test/Transforms/debug-line-table-inc-file.fir
@@ -1,5 +1,5 @@
-// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
+// RUN: fir-opt --add-debug-info="debug-level=LineTablesOnly" --mlir-print-debuginfo %s | FileCheck %s
// REQUIRES: system-linux
// Test for included functions that have a different debug location than the current file
@@ -30,7 +30,7 @@ module attributes {} {
// CHECK: #[[MODULE_LOC]] = loc("{{.*}}simple.f90":0:0)
// CHECK: #[[LOC_INC_FILE:.*]] = loc("{{.*}}inc.f90":1:1)
// CHECK: #[[LOC_FILE:.*]] = loc("{{.*}}simple.f90":3:1)
-// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
+// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "flang{{.*}}", isOptimized = false, emissionKind = LineTablesOnly>
// CHECK: #[[DI_SP_INC:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QPsinc", linkageName = "_QPsinc", file = #[[DI_INC_FILE]], {{.*}}>
// CHECK: #[[DI_SP:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QQmain", linkageName = "_QQmain", file = #[[DI_FILE]], {{.*}}>
// CHECK: #[[FUSED_LOC_INC_FILE]] = loc(fused<#[[DI_SP_INC]]>[#[[LOC_INC_FILE]]])
diff --git a/flang/test/Transforms/debug-line-table.fir b/flang/test/Transforms/debug-line-table.fir
index 0ba88d3d9f7fa2..3b3a39174df094 100644
--- a/flang/test/Transforms/debug-line-table.fir
+++ b/flang/test/Transforms/debug-line-table.fir
@@ -1,5 +1,7 @@
-// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
+// RUN: fir-opt --add-debug-info="debug-level=Full" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=FULL
+// RUN: fir-opt --add-debug-info="debug-level=LineTablesOnly" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=LINETABLE
+// RUN: fir-opt --add-debug-info="is-optimized=true" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=OPT
module attributes { fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", llvm.target_triple = "aarch64-unknown-linux-gnu"} {
func.func @_QPsb() {
@@ -22,7 +24,9 @@ module attributes { fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.dat
// CHECK: #[[MODULE_LOC]] = loc("[[DIR_NAME]]/[[FILE_NAME]]":1:1)
// CHECK: #[[SB_LOC]] = loc("./simple.f90":2:1)
// CHECK: #[[DECL_LOC:.*]] = loc("./simple.f90":10:1)
-// CHECK: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
+// FULL: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang{{.*}}", isOptimized = false, emissionKind = Full>
+// OPT: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang{{.*}}", isOptimized = true, emissionKind = Full>
+// LINETABLE: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang{{.*}}", isOptimized = false, emissionKind = LineTablesOnly>
// CHECK: #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_basic_type, #di_basic_type>
// CHECK: #[[SB_SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "[[SB_NAME]]", linkageName = "[[SB_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
// CHECK: #[[DECL_SUBPROGRAM:.*]] = #llvm.di_subprogram<scope = #di_file, name = "[[DECL_NAME]]", linkageName = "[[DECL_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Optimized, type = #di_subroutine_type>
|
@llvm/pr-subscribers-flang-driver Author: None (abidh) ChangesThis PR adds following options to the AddDebugInfo pass.
This enables us to remove the hard coded values from the code. It also allows us to test the pass with different options. The tests have been modified to take advantage of that. The calling convention flag and producer name have also been improved. Full diff: https://github.com/llvm/llvm-project/pull/89231.diff 8 Files Affected:
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h
index d8840d9e967b48..ea004c2d5d6da2 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -48,6 +48,7 @@ namespace fir {
#define GEN_PASS_DECL_ALGEBRAICSIMPLIFICATION
#define GEN_PASS_DECL_POLYMORPHICOPCONVERSION
#define GEN_PASS_DECL_OPENACCDATAOPERANDCONVERSION
+#define GEN_PASS_DECL_ADDDEBUGINFO
#include "flang/Optimizer/Transforms/Passes.h.inc"
std::unique_ptr<mlir::Pass> createAbstractResultOnFuncOptPass();
@@ -67,7 +68,8 @@ std::unique_ptr<mlir::Pass> createMemoryAllocationPass();
std::unique_ptr<mlir::Pass> createStackArraysPass();
std::unique_ptr<mlir::Pass> createAliasTagsPass();
std::unique_ptr<mlir::Pass> createSimplifyIntrinsicsPass();
-std::unique_ptr<mlir::Pass> createAddDebugInfoPass();
+std::unique_ptr<mlir::Pass>
+createAddDebugInfoPass(fir::AddDebugInfoOptions options = {});
std::unique_ptr<mlir::Pass> createLoopVersioningPass();
std::unique_ptr<mlir::Pass>
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index bfc0db8124af21..86c762b129d7d7 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -210,6 +210,25 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> {
let dependentDialects = [
"fir::FIROpsDialect", "mlir::func::FuncDialect", "mlir::LLVM::LLVMDialect"
];
+ let options = [
+ Option<"debugLevel", "debug-level",
+ "mlir::LLVM::DIEmissionKind",
+ /*default=*/"mlir::LLVM::DIEmissionKind::Full",
+ "debug level",
+ [{::llvm::cl::values(
+ clEnumValN(mlir::LLVM::DIEmissionKind::Full, "Full", "Emit full debug info"),
+ clEnumValN(mlir::LLVM::DIEmissionKind::LineTablesOnly, "LineTablesOnly", "Emit line tables only"),
+ clEnumValN(mlir::LLVM::DIEmissionKind::None, "None", "Emit no debug information")
+ )}]
+ >,
+ Option<"isOptimized", "is-optimized",
+ "bool", /*default=*/"false",
+ "is optimized.">,
+ Option<"inputFilename", "file-name",
+ "std::string",
+ /*default=*/"std::string{}",
+ "name of the input source file">,
+ ];
}
// This needs to be a "mlir::ModuleOp" pass, because it inserts simplified
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index ea297fb337a2c8..5e0479c40c945a 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -155,9 +155,27 @@ inline void addTargetRewritePass(mlir::PassManager &pm) {
});
}
-inline void addDebugInfoPass(mlir::PassManager &pm) {
- addPassConditionally(
- pm, disableDebugInfo, [&]() { return fir::createAddDebugInfoPass(); });
+inline mlir::LLVM::DIEmissionKind getEmissionKind(
+ llvm::codegenoptions::DebugInfoKind kind) {
+ switch (kind) {
+ case llvm::codegenoptions::DebugInfoKind::FullDebugInfo:
+ return mlir::LLVM::DIEmissionKind::Full;
+ case llvm::codegenoptions::DebugInfoKind::DebugLineTablesOnly:
+ return mlir::LLVM::DIEmissionKind::LineTablesOnly;
+ default:
+ return mlir::LLVM::DIEmissionKind::None;
+ }
+}
+
+inline void addDebugInfoPass(mlir::PassManager &pm,
+ llvm::codegenoptions::DebugInfoKind debugLevel,
+ llvm::OptimizationLevel optLevel, llvm::StringRef inputFilename) {
+ fir::AddDebugInfoOptions options;
+ options.debugLevel = getEmissionKind(debugLevel);
+ options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
+ options.inputFilename = inputFilename;
+ addPassConditionally(pm, disableDebugInfo,
+ [&]() { return fir::createAddDebugInfoPass(options); });
}
inline void addFIRToLLVMPass(
@@ -283,12 +301,13 @@ inline void createOpenMPFIRPassPipeline(
}
#if !defined(FLANG_EXCLUDE_CODEGEN)
-inline void createDebugPasses(
- mlir::PassManager &pm, llvm::codegenoptions::DebugInfoKind debugLevel) {
+inline void createDebugPasses(mlir::PassManager &pm,
+ llvm::codegenoptions::DebugInfoKind debugLevel,
+ llvm::OptimizationLevel OptLevel, llvm::StringRef inputFilename) {
// Currently only -g1, -g, -gline-tables-only supported
switch (debugLevel) {
case llvm::codegenoptions::DebugLineTablesOnly:
- addDebugInfoPass(pm);
+ addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename);
return;
case llvm::codegenoptions::NoDebugInfo:
return;
@@ -296,13 +315,13 @@ inline void createDebugPasses(
// TODO: Add cases and passes for other debug options.
// All other debug options not implemented yet, currently emits warning
// and generates as much debug information as possible.
- addDebugInfoPass(pm);
+ addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename);
return;
}
}
-inline void createDefaultFIRCodeGenPassPipeline(
- mlir::PassManager &pm, MLIRToLLVMPassPipelineConfig config) {
+inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
+ MLIRToLLVMPassPipelineConfig config, llvm::StringRef inputFilename = {}) {
fir::addBoxedProcedurePass(pm);
pm.addNestedPass<mlir::func::FuncOp>(
fir::createAbstractResultOnFuncOptPass());
@@ -310,7 +329,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
fir::addCodeGenRewritePass(pm);
fir::addTargetRewritePass(pm);
fir::addExternalNameConversionPass(pm, config.Underscoring);
- fir::createDebugPasses(pm, config.DebugInfo);
+ fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
if (config.VScaleMin != 0)
pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, config.VScaleMax}));
@@ -344,15 +363,16 @@ inline void createDefaultFIRCodeGenPassPipeline(
/// \param pm - MLIR pass manager that will hold the pipeline definition
/// \param optLevel - optimization level used for creating FIR optimization
/// passes pipeline
-inline void createMLIRToLLVMPassPipeline(
- mlir::PassManager &pm, const MLIRToLLVMPassPipelineConfig &config) {
+inline void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
+ const MLIRToLLVMPassPipelineConfig &config,
+ llvm::StringRef inputFilename = {}) {
fir::createHLFIRToFIRPassPipeline(pm, config.OptLevel);
// Add default optimizer pass pipeline.
fir::createDefaultFIROptimizerPassPipeline(pm, config);
// Add codegen pass pipeline.
- fir::createDefaultFIRCodeGenPassPipeline(pm, config);
+ fir::createDefaultFIRCodeGenPassPipeline(pm, config, inputFilename);
}
#undef FLANG_EXCLUDE_CODEGEN
#endif
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 8f251997ed401b..d91846dde95a83 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -809,7 +809,7 @@ void CodeGenAction::generateLLVMIR() {
}
// Create the pass pipeline
- fir::createMLIRToLLVMPassPipeline(pm, config);
+ fir::createMLIRToLLVMPassPipeline(pm, config, getCurrentFile());
(void)mlir::applyPassManagerCLOptions(pm);
// run the pass manager
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index 4ca33806612876..69c7e1f40e7d0a 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -11,12 +11,14 @@
/// This pass populates some debug information for the module and functions.
//===----------------------------------------------------------------------===//
+#include "flang/Common/Version.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Dialect/FIROps.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/Dialect/Support/FIRContext.h"
+#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Transforms/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -28,12 +30,12 @@
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
namespace fir {
#define GEN_PASS_DEF_ADDDEBUGINFO
-#define GEN_PASS_DECL_ADDDEBUGINFO
#include "flang/Optimizer/Transforms/Passes.h.inc"
} // namespace fir
@@ -43,6 +45,7 @@ namespace {
class AddDebugInfoPass : public fir::impl::AddDebugInfoBase<AddDebugInfoPass> {
public:
+ AddDebugInfoPass(fir::AddDebugInfoOptions options) : Base(options) {}
void runOnOperation() override;
};
@@ -52,21 +55,40 @@ void AddDebugInfoPass::runOnOperation() {
mlir::ModuleOp module = getOperation();
mlir::MLIRContext *context = &getContext();
mlir::OpBuilder builder(context);
- std::string inputFilePath("-");
- if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>())
- inputFilePath = fileLoc.getFilename().getValue();
+ llvm::StringRef fileName;
+ std::string filePath;
+ // We need 2 type of file paths here.
+ // 1. Name of the file as was presented to compiler. This can be absolute
+ // or relative to 2.
+ // 2. Current working directory
+ //
+ // We are also dealing with 2 different situations below. One is normal
+ // compilation where we will have a value in 'inputFilename' and we can
+ // obtain the current directory using 'current_path'.
+ // The 2nd case is when this pass is invoked directly from 'fir-opt' tool.
+ // In that case, 'inputFilename' may be empty. Location embedded in the
+ // module will be used to get file name and its directory.
+ if (inputFilename.empty()) {
+ if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>()) {
+ fileName = llvm::sys::path::filename(fileLoc.getFilename().getValue());
+ filePath = llvm::sys::path::parent_path(fileLoc.getFilename().getValue());
+ } else
+ fileName = "-";
+ } else {
+ fileName = inputFilename;
+ llvm::SmallString<256> cwd;
+ if (!llvm::sys::fs::current_path(cwd))
+ filePath = cwd.str();
+ }
- auto getFileAttr = [context](llvm::StringRef path) -> mlir::LLVM::DIFileAttr {
- return mlir::LLVM::DIFileAttr::get(context, llvm::sys::path::filename(path),
- llvm::sys::path::parent_path(path));
- };
-
- mlir::LLVM::DIFileAttr fileAttr = getFileAttr(inputFilePath);
- mlir::StringAttr producer = mlir::StringAttr::get(context, "Flang");
+ mlir::LLVM::DIFileAttr fileAttr =
+ mlir::LLVM::DIFileAttr::get(context, fileName, filePath);
+ mlir::StringAttr producer =
+ mlir::StringAttr::get(context, Fortran::common::getFlangFullVersion());
mlir::LLVM::DICompileUnitAttr cuAttr = mlir::LLVM::DICompileUnitAttr::get(
mlir::DistinctAttr::create(mlir::UnitAttr::get(context)),
llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer,
- /*isOptimized=*/false, mlir::LLVM::DIEmissionKind::LineTablesOnly);
+ isOptimized, debugLevel);
module.walk([&](mlir::func::FuncOp funcOp) {
mlir::Location l = funcOp->getLoc();
@@ -75,12 +97,14 @@ void AddDebugInfoPass::runOnOperation() {
if (l.dyn_cast<mlir::FusedLoc>())
return;
- llvm::StringRef funcFilePath;
- if (l.dyn_cast<mlir::FileLineColLoc>())
- funcFilePath =
- l.dyn_cast<mlir::FileLineColLoc>().getFilename().getValue();
- else
- funcFilePath = inputFilePath;
+ unsigned int CC = (funcOp.getName() == fir::NameUniquer::doProgramEntry())
+ ? llvm::dwarf::getCallingConvention("DW_CC_program")
+ : llvm::dwarf::getCallingConvention("DW_CC_normal");
+
+ if (auto funcLoc = l.dyn_cast<mlir::FileLineColLoc>()) {
+ fileName = llvm::sys::path::filename(funcLoc.getFilename().getValue());
+ filePath = llvm::sys::path::parent_path(funcLoc.getFilename().getValue());
+ }
mlir::StringAttr funcName =
mlir::StringAttr::get(context, funcOp.getName());
@@ -88,30 +112,31 @@ void AddDebugInfoPass::runOnOperation() {
context, llvm::dwarf::DW_TAG_base_type, "void", /*sizeInBits=*/0,
/*encoding=*/1);
mlir::LLVM::DISubroutineTypeAttr subTypeAttr =
- mlir::LLVM::DISubroutineTypeAttr::get(
- context, llvm::dwarf::getCallingConvention("DW_CC_normal"),
- {bT, bT});
- mlir::LLVM::DIFileAttr funcFileAttr = getFileAttr(funcFilePath);
+ mlir::LLVM::DISubroutineTypeAttr::get(context, CC, {bT, bT});
+ mlir::LLVM::DIFileAttr funcFileAttr =
+ mlir::LLVM::DIFileAttr::get(context, fileName, filePath);
// Only definitions need a distinct identifier and a compilation unit.
mlir::DistinctAttr id;
mlir::LLVM::DICompileUnitAttr compilationUnit;
- auto subprogramFlags = mlir::LLVM::DISubprogramFlags::Optimized;
+ mlir::LLVM::DISubprogramFlags subprogramFlags =
+ mlir::LLVM::DISubprogramFlags{};
+ if (isOptimized)
+ subprogramFlags = mlir::LLVM::DISubprogramFlags::Optimized;
if (!funcOp.isExternal()) {
id = mlir::DistinctAttr::create(mlir::UnitAttr::get(context));
compilationUnit = cuAttr;
- subprogramFlags =
- subprogramFlags | mlir::LLVM::DISubprogramFlags::Definition;
+ subprogramFlags = mlir::LLVM::DISubprogramFlags::Definition;
}
auto spAttr = mlir::LLVM::DISubprogramAttr::get(
context, id, compilationUnit, fileAttr, funcName, funcName,
- funcFileAttr,
- /*line=*/1,
- /*scopeline=*/1, subprogramFlags, subTypeAttr);
+ funcFileAttr, /*line=*/1, /*scopeline=*/1, subprogramFlags,
+ subTypeAttr);
funcOp->setLoc(builder.getFusedLoc({funcOp->getLoc()}, spAttr));
});
}
-std::unique_ptr<mlir::Pass> fir::createAddDebugInfoPass() {
- return std::make_unique<AddDebugInfoPass>();
+std::unique_ptr<mlir::Pass>
+fir::createAddDebugInfoPass(fir::AddDebugInfoOptions options) {
+ return std::make_unique<AddDebugInfoPass>(options);
}
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index d55655c53906e6..fc08d67540ceb0 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -35,6 +35,7 @@ add_flang_library(FIRTransforms
FIRDialect
FIRDialectSupport
FIRSupport
+ FortranCommon
HLFIRDialect
MLIRAffineUtils
MLIRFuncDialect
diff --git a/flang/test/Transforms/debug-line-table-inc-file.fir b/flang/test/Transforms/debug-line-table-inc-file.fir
index be4f005bf664ac..dc75482d4f8a7f 100644
--- a/flang/test/Transforms/debug-line-table-inc-file.fir
+++ b/flang/test/Transforms/debug-line-table-inc-file.fir
@@ -1,5 +1,5 @@
-// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
+// RUN: fir-opt --add-debug-info="debug-level=LineTablesOnly" --mlir-print-debuginfo %s | FileCheck %s
// REQUIRES: system-linux
// Test for included functions that have a different debug location than the current file
@@ -30,7 +30,7 @@ module attributes {} {
// CHECK: #[[MODULE_LOC]] = loc("{{.*}}simple.f90":0:0)
// CHECK: #[[LOC_INC_FILE:.*]] = loc("{{.*}}inc.f90":1:1)
// CHECK: #[[LOC_FILE:.*]] = loc("{{.*}}simple.f90":3:1)
-// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
+// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "flang{{.*}}", isOptimized = false, emissionKind = LineTablesOnly>
// CHECK: #[[DI_SP_INC:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QPsinc", linkageName = "_QPsinc", file = #[[DI_INC_FILE]], {{.*}}>
// CHECK: #[[DI_SP:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QQmain", linkageName = "_QQmain", file = #[[DI_FILE]], {{.*}}>
// CHECK: #[[FUSED_LOC_INC_FILE]] = loc(fused<#[[DI_SP_INC]]>[#[[LOC_INC_FILE]]])
diff --git a/flang/test/Transforms/debug-line-table.fir b/flang/test/Transforms/debug-line-table.fir
index 0ba88d3d9f7fa2..3b3a39174df094 100644
--- a/flang/test/Transforms/debug-line-table.fir
+++ b/flang/test/Transforms/debug-line-table.fir
@@ -1,5 +1,7 @@
-// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
+// RUN: fir-opt --add-debug-info="debug-level=Full" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=FULL
+// RUN: fir-opt --add-debug-info="debug-level=LineTablesOnly" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=LINETABLE
+// RUN: fir-opt --add-debug-info="is-optimized=true" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=OPT
module attributes { fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", llvm.target_triple = "aarch64-unknown-linux-gnu"} {
func.func @_QPsb() {
@@ -22,7 +24,9 @@ module attributes { fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.dat
// CHECK: #[[MODULE_LOC]] = loc("[[DIR_NAME]]/[[FILE_NAME]]":1:1)
// CHECK: #[[SB_LOC]] = loc("./simple.f90":2:1)
// CHECK: #[[DECL_LOC:.*]] = loc("./simple.f90":10:1)
-// CHECK: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
+// FULL: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang{{.*}}", isOptimized = false, emissionKind = Full>
+// OPT: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang{{.*}}", isOptimized = true, emissionKind = Full>
+// LINETABLE: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang{{.*}}", isOptimized = false, emissionKind = LineTablesOnly>
// CHECK: #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_basic_type, #di_basic_type>
// CHECK: #[[SB_SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "[[SB_NAME]]", linkageName = "[[SB_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
// CHECK: #[[DECL_SUBPROGRAM:.*]] = #llvm.di_subprogram<scope = #di_file, name = "[[DECL_NAME]]", linkageName = "[[DECL_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Optimized, type = #di_subroutine_type>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! My main comment is that I do not get why you need to pass the filename from the driver, it was not hardcoded since it came from the module location which is created in lowering from the source file name.
} else { | ||
fileName = inputFilename; | ||
llvm::SmallString<256> cwd; | ||
if (!llvm::sys::fs::current_path(cwd)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't current_path
the working directory where the compiler is being run? If so, that could be different from the file directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I explained in my earlier comment, DWARF
requires working directory.
// We are also dealing with 2 different situations below. One is normal | ||
// compilation where we will have a value in 'inputFilename' and we can | ||
// obtain the current directory using 'current_path'. | ||
// The 2nd case is when this pass is invoked directly from 'fir-opt' tool. | ||
// In that case, 'inputFilename' may be empty. Location embedded in the | ||
// module will be used to get file name and its directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not always using the module location since it must have been provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In ideal case, we would like it to be the current working directory as I explained above. But we don't have that information in 2nd case so using parent directory is sort of a compromise.
The name and path field in the DICompileUnit are used to set the
Please also see the example below. It demonstrates where the gfortran was invoked from and what we get in the
|
llvm::StringRef fileName; | ||
std::string filePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does DWARF support paths with wide characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DWARF
has DW_AT_use_UTF8
attribute which can be used to say that program entities and filenames use UTF-8
representation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that some of the functions in llvm::sys::fs
represent paths as Twine
s so I guess a std::string
should be good enough for now. Off the top of my head, I can't think of a reason why a std::string
can't store a UTF8 string (::size() might be confusing, but that shouldn't matter here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining. I understand now that the pervious debug info was incorrect with regard to the build directory:
/home/haqadeer/build$ gfortran ../src/test.f90
DW_AT_name ("test.f90")
DW_AT_comp_dir ("/home/src")
Too bad there is no equivalent of std::filesystem::relative in llvm filesystem, this would have allowed to easily compute the inputFileName from the mlir location and current working directory without an extra pass option (there is not usages of std::filesystem in LLVM outside of libcxx and some tests, so probably best to not introduce it just for this).
Thank you for this work @abidh! Do you know or have some pointers to how Clang handles |
+1. I tried to use |
I have seen that I am not sure whether
This probably does not answer your question. I will try to dig more. |
This PR adds following options to the AddDebugInfo pass.
This enables us to remove the hard coded values from the code. It also allows us to test the pass with different options. The tests have been modified to take advantage of that.
The calling convention flag and producer name have also been improved.