Skip to content

Commit c218816

Browse files
authored
[flang][debug] Generate splitDebugFilename field in DICompileUnitAttr. (#161214)
This PR builds on #160540 and allows us to set the `splitDebugFilename` field in `DICompileUnitAttr`. The changes are mostly mechanical. I saw some spurious white space in a test that I have cleaned up.
1 parent e485d5e commit c218816

File tree

7 files changed

+47
-15
lines changed

7 files changed

+47
-15
lines changed

flang/include/flang/Optimizer/Passes/Pipelines.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
158158
void createDebugPasses(mlir::PassManager &pm,
159159
llvm::codegenoptions::DebugInfoKind debugLevel,
160160
llvm::OptimizationLevel OptLevel,
161-
llvm::StringRef inputFilename, int32_t dwarfVersion);
161+
llvm::StringRef inputFilename, int32_t dwarfVersion,
162+
llvm::StringRef splitDwarfFile);
162163

163164
void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
164165
MLIRToLLVMPassPipelineConfig config,

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> {
246246
"int32_t",
247247
/*default=*/"0",
248248
"dwarf version">,
249+
Option<"splitDwarfFile", "split-dwarf-file",
250+
"std::string", /*default=*/"std::string{}",
251+
"Name of the split dwarf file">
252+
249253
];
250254
}
251255

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
109109
InstrumentFunctionExit = "__cyg_profile_func_exit";
110110
}
111111
DwarfVersion = opts.DwarfVersion;
112+
SplitDwarfFile = opts.SplitDwarfFile;
112113
}
113114

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

151153
struct OffloadModuleOpts {

flang/lib/Optimizer/Passes/Pipelines.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ getEmissionKind(llvm::codegenoptions::DebugInfoKind kind) {
9595
void addDebugInfoPass(mlir::PassManager &pm,
9696
llvm::codegenoptions::DebugInfoKind debugLevel,
9797
llvm::OptimizationLevel optLevel,
98-
llvm::StringRef inputFilename, int32_t dwarfVersion) {
98+
llvm::StringRef inputFilename, int32_t dwarfVersion,
99+
llvm::StringRef splitDwarfFile) {
99100
fir::AddDebugInfoOptions options;
100101
options.debugLevel = getEmissionKind(debugLevel);
101102
options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
102103
options.inputFilename = inputFilename;
103104
options.dwarfVersion = dwarfVersion;
105+
options.splitDwarfFile = splitDwarfFile;
104106
addPassConditionally(pm, disableDebugInfo,
105107
[&]() { return fir::createAddDebugInfoPass(options); });
106108
}
@@ -340,9 +342,11 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
340342
void createDebugPasses(mlir::PassManager &pm,
341343
llvm::codegenoptions::DebugInfoKind debugLevel,
342344
llvm::OptimizationLevel OptLevel,
343-
llvm::StringRef inputFilename, int32_t dwarfVersion) {
345+
llvm::StringRef inputFilename, int32_t dwarfVersion,
346+
llvm::StringRef splitDwarfFile) {
344347
if (debugLevel != llvm::codegenoptions::NoDebugInfo)
345-
addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename, dwarfVersion);
348+
addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename, dwarfVersion,
349+
splitDwarfFile);
346350
}
347351

348352
void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
@@ -360,7 +364,7 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
360364
pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
361365
fir::addExternalNameConversionPass(pm, config.Underscoring);
362366
fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename,
363-
config.DwarfVersion);
367+
config.DwarfVersion, config.SplitDwarfFile);
364368
fir::addTargetRewritePass(pm);
365369
fir::addCompilerGeneratedNamesConversionPass(pm);
366370

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ void AddDebugInfoPass::runOnOperation() {
696696
llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer,
697697
isOptimized, debugLevel,
698698
/*nameTableKind=*/mlir::LLVM::DINameTableKind::Default,
699-
/*splitDebugFilename=*/mlir::StringAttr());
699+
splitDwarfFile.empty() ? mlir::StringAttr()
700+
: mlir::StringAttr::get(context, splitDwarfFile));
700701

701702
module.walk([&](mlir::func::FuncOp funcOp) {
702703
handleFuncOp(funcOp, fileAttr, cuAttr, typeGen, &symbolTable);

flang/test/Integration/debug-split-dwarf.f90

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22

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

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

17-
! DWO: .dwo
18-
! SPLIT-NOT: .dwo
17+
! Test that splitDebugFilename field of the DICompileUnit get correctly
18+
! generated.
19+
! RUN: %flang_fc1 -debug-info-kind=standalone -triple x86_64-unknown-linux \
20+
! RUN: -split-dwarf-file %t.test_dwo -split-dwarf-output %t.test_dwo \
21+
! RUN: -emit-llvm %s -o - | FileCheck --check-prefix=CU %s
22+
23+
! DWO: .dwo
24+
! SPLIT-NOT: .dwo
25+
! CU: !DICompileUnit
26+
! CU-SAME: splitDebugFilename: "{{.*}}test_dwo"
1927

2028
program test
2129
end program test
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: fir-opt --add-debug-info="split-dwarf-file=test.dwo" \
2+
// RUN: --mlir-print-debuginfo %s -o - | FileCheck %s
3+
4+
module {
5+
func.func @test() {
6+
return
7+
} loc(#loc1)
8+
}
9+
#loc1 = loc("test.f90":15:1)
10+
11+
// CHECK: llvm.di_compile_unit
12+
// CHECK-SAME: splitDebugFilename = "test.dwo"

0 commit comments

Comments
 (0)