Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flang/include/flang/Optimizer/Passes/Pipelines.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
void createDebugPasses(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel OptLevel,
llvm::StringRef inputFilename, int32_t dwarfVersion);
llvm::StringRef inputFilename, int32_t dwarfVersion,
llvm::StringRef splitDwarfFile);

void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
MLIRToLLVMPassPipelineConfig config,
Expand Down
4 changes: 4 additions & 0 deletions flang/include/flang/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> {
"int32_t",
/*default=*/"0",
"dwarf version">,
Option<"splitDwarfFile", "split-dwarf-file",
"std::string", /*default=*/"std::string{}",
"Name of the split dwarf file">

];
}

Expand Down
2 changes: 2 additions & 0 deletions flang/include/flang/Tools/CrossToolHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
InstrumentFunctionExit = "__cyg_profile_func_exit";
}
DwarfVersion = opts.DwarfVersion;
SplitDwarfFile = opts.SplitDwarfFile;
}

llvm::OptimizationLevel OptLevel; ///< optimisation level
Expand Down Expand Up @@ -146,6 +147,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
Fortran::frontend::CodeGenOptions::ComplexRangeKind::
CX_Full; ///< Method for calculating complex number division
int32_t DwarfVersion = 0; ///< Version of DWARF debug info to generate
std::string SplitDwarfFile = ""; ///< File name for the split debug info
};

struct OffloadModuleOpts {
Expand Down
12 changes: 8 additions & 4 deletions flang/lib/Optimizer/Passes/Pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ getEmissionKind(llvm::codegenoptions::DebugInfoKind kind) {
void addDebugInfoPass(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel optLevel,
llvm::StringRef inputFilename, int32_t dwarfVersion) {
llvm::StringRef inputFilename, int32_t dwarfVersion,
llvm::StringRef splitDwarfFile) {
fir::AddDebugInfoOptions options;
options.debugLevel = getEmissionKind(debugLevel);
options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
options.inputFilename = inputFilename;
options.dwarfVersion = dwarfVersion;
options.splitDwarfFile = splitDwarfFile;
addPassConditionally(pm, disableDebugInfo,
[&]() { return fir::createAddDebugInfoPass(options); });
}
Expand Down Expand Up @@ -340,9 +342,11 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
void createDebugPasses(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel OptLevel,
llvm::StringRef inputFilename, int32_t dwarfVersion) {
llvm::StringRef inputFilename, int32_t dwarfVersion,
llvm::StringRef splitDwarfFile) {
if (debugLevel != llvm::codegenoptions::NoDebugInfo)
addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename, dwarfVersion);
addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename, dwarfVersion,
splitDwarfFile);
}

void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
Expand All @@ -360,7 +364,7 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
fir::addExternalNameConversionPass(pm, config.Underscoring);
fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename,
config.DwarfVersion);
config.DwarfVersion, config.SplitDwarfFile);
fir::addTargetRewritePass(pm);
fir::addCompilerGeneratedNamesConversionPass(pm);

Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ void AddDebugInfoPass::runOnOperation() {
llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer,
isOptimized, debugLevel,
/*nameTableKind=*/mlir::LLVM::DINameTableKind::Default,
/*splitDebugFilename=*/mlir::StringAttr());
splitDwarfFile.empty() ? mlir::StringAttr()
: mlir::StringAttr::get(context, splitDwarfFile));

module.walk([&](mlir::func::FuncOp funcOp) {
handleFuncOp(funcOp, fileAttr, cuAttr, typeGen, &symbolTable);
Expand Down
26 changes: 17 additions & 9 deletions flang/test/Integration/debug-split-dwarf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@

! Testing to ensure that setting only -split-dwarf-file allows to place
! .dwo sections into regular output object.
! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \
! RUN: -split-dwarf-file %t.o -emit-obj -o %t.o %s
! RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=DWO %s
! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \
! RUN: -split-dwarf-file %t.o -emit-obj -o %t.o %s
! RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=DWO %s

! Testing to ensure that setting both -split-dwarf-file and -split-dwarf-output
! does not place .dwo sections into regular output object but in a separate
! file.
! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \
! RUN: -split-dwarf-file %t.dwo -split-dwarf-output %t.dwo -emit-obj -o %t.o %s
! RUN: llvm-readobj -S %t.dwo | FileCheck --check-prefix=DWO %s
! RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=SPLIT %s
! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \
! RUN: -split-dwarf-file %t.dwo -split-dwarf-output %t.dwo -emit-obj -o %t.o %s
! RUN: llvm-readobj -S %t.dwo | FileCheck --check-prefix=DWO %s
! RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=SPLIT %s

! DWO: .dwo
! SPLIT-NOT: .dwo
! Test that splitDebugFilename field of the DICompileUnit get correctly
! generated.
! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \
! RUN: -split-dwarf-file %t.test_dwo -split-dwarf-output %t.test_dwo \
! RUN: -emit-llvm %s -o - | FileCheck --check-prefix=CU %s

! DWO: .dwo
! SPLIT-NOT: .dwo
! CU: !DICompileUnit
! CU-SAME: splitDebugFilename: "{{.*}}test_dwo"

program test
end program test
12 changes: 12 additions & 0 deletions flang/test/Transforms/debug-split-dwarf.fir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: fir-opt --add-debug-info="split-dwarf-file=test.dwo" \
// RUN: --mlir-print-debuginfo %s -o - | FileCheck %s

module {
func.func @test() {
return
} loc(#loc1)
}
#loc1 = loc("test.f90":15:1)

// CHECK: llvm.di_compile_unit
// CHECK-SAME: splitDebugFilename = "test.dwo"