Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/Passes/Pipelines.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void addCompilerGeneratedNamesConversionPass(mlir::PassManager &pm);
void addDebugInfoPass(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel optLevel,
llvm::StringRef inputFilename);
llvm::StringRef inputFilename, int32_t dwarfVersion);

void addFIRToLLVMPass(mlir::PassManager &pm,
const MLIRToLLVMPassPipelineConfig &config);
Expand Down Expand Up @@ -158,7 +158,7 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
void createDebugPasses(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel OptLevel,
llvm::StringRef inputFilename);
llvm::StringRef inputFilename, int32_t dwarfVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please give dwarfVersion a default value in the declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you kindly describe what problem do you see because the version have a default value both in pass declaration and in opts.


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 @@ -242,6 +242,10 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> {
"std::string",
/*default=*/"std::string{}",
"name of the input source file">,
Option<"dwarfVersion", "dwarf-version",
"int32_t",
/*default=*/"0",
"dwarf version">,
];
}

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 @@ -108,6 +108,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
InstrumentFunctionEntry = "__cyg_profile_func_enter";
InstrumentFunctionExit = "__cyg_profile_func_exit";
}
DwarfVersion = opts.DwarfVersion;
}

llvm::OptimizationLevel OptLevel; ///< optimisation level
Expand Down Expand Up @@ -143,6 +144,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
Fortran::frontend::CodeGenOptions::ComplexRangeKind ComplexRange =
Fortran::frontend::CodeGenOptions::ComplexRangeKind::
CX_Full; ///< Method for calculating complex number division
int32_t DwarfVersion = 0; ///< Version of DWARF debug info to generate
};

struct OffloadModuleOpts {
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0");
diags.Report(debugWarning) << arg->getValue();
}
// The default value of 2 here is to match clang.
opts.DwarfVersion =
getLastArgIntValue(args, clang::driver::options::OPT_dwarf_version_EQ,
/*Default=*/2, diags);
/*Default=*/0, diags);
}
return true;
}
Expand Down
10 changes: 6 additions & 4 deletions flang/lib/Optimizer/Passes/Pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ getEmissionKind(llvm::codegenoptions::DebugInfoKind kind) {
void addDebugInfoPass(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel optLevel,
llvm::StringRef inputFilename) {
llvm::StringRef inputFilename, int32_t dwarfVersion) {
fir::AddDebugInfoOptions options;
options.debugLevel = getEmissionKind(debugLevel);
options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
options.inputFilename = inputFilename;
options.dwarfVersion = dwarfVersion;
addPassConditionally(pm, disableDebugInfo,
[&]() { return fir::createAddDebugInfoPass(options); });
}
Expand Down Expand Up @@ -333,9 +334,9 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
void createDebugPasses(mlir::PassManager &pm,
llvm::codegenoptions::DebugInfoKind debugLevel,
llvm::OptimizationLevel OptLevel,
llvm::StringRef inputFilename) {
llvm::StringRef inputFilename, int32_t dwarfVersion) {
if (debugLevel != llvm::codegenoptions::NoDebugInfo)
addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename);
addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename, dwarfVersion);
}

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

Expand Down
14 changes: 13 additions & 1 deletion flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,19 @@ void AddDebugInfoPass::runOnOperation() {
signalPassFailure();
return;
}
mlir::OpBuilder builder(context);
if (dwarfVersion > 0) {
mlir::OpBuilder::InsertionGuard guard(builder);
builder.setInsertionPointToEnd(module.getBody());
llvm::SmallVector<mlir::Attribute> moduleFlags;
mlir::IntegerType int32Ty = mlir::IntegerType::get(context, 32);
moduleFlags.push_back(builder.getAttr<mlir::LLVM::ModuleFlagAttr>(
mlir::LLVM::ModFlagBehavior::Max,
mlir::StringAttr::get(context, "Dwarf Version"),
mlir::IntegerAttr::get(int32Ty, dwarfVersion)));
mlir::LLVM::ModuleFlagsOp::create(builder, module.getLoc(),
builder.getArrayAttr(moduleFlags));
}
fir::DebugTypeGenerator typeGen(module, &symbolTable, *dl);
// We need 2 type of file paths here.
// 1. Name of the file as was presented to compiler. This can be absolute
Expand Down Expand Up @@ -686,7 +699,6 @@ void AddDebugInfoPass::runOnOperation() {
module.walk([&](mlir::func::FuncOp funcOp) {
handleFuncOp(funcOp, fileAttr, cuAttr, typeGen, &symbolTable);
});
mlir::OpBuilder builder(context);
// We have processed all function. Attach common block variables to the
// global that represent the storage.
for (auto [global, exprs] : globalToGlobalExprsMap) {
Expand Down
24 changes: 24 additions & 0 deletions flang/test/Integration/debug-dwarf-flags.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone -dwarf-version=5 %s \
! RUN: -o - | FileCheck --check-prefix=CHECK-DWARF5 %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only -dwarf-version=5 \
! RUN: %s -o - | FileCheck --check-prefix=CHECK-DWARF5 %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone -dwarf-version=4 %s \
! RUN: -o - | FileCheck --check-prefix=CHECK-DWARF4 %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone -dwarf-version=3 %s \
! RUN: -o - | FileCheck --check-prefix=CHECK-DWARF3 %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone -dwarf-version=2 %s \
! RUN: -o - | FileCheck --check-prefix=CHECK-DWARF2 %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o -\
! RUN: | FileCheck --check-prefix=CHECK-WITHOUT-VERSION %s
! RUN: %flang_fc1 -emit-llvm -dwarf-version=5 %s -o - \
! RUN: | FileCheck --check-prefix=CHECK-WITHOUT-DEBUG-KIND %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like both CHECK-WITHOUT-VERSION and CHECK-WITHOUT-DEBUG-KIND check for the absence of "Dwarf version" in the output. We can probably just use CHECK-WITHOUT-VERSION here to eliminate redundant check prefixes.

Suggested change
! RUN: | FileCheck --check-prefix=CHECK-WITHOUT-DEBUG-KIND %s
! RUN: | FileCheck --check-prefix=CHECK-WITHOUT-VERSION %s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


program test
end program test

! CHECK-DWARF5: !{i32 7, !"Dwarf Version", i32 5}
! CHECK-DWARF4: !{i32 7, !"Dwarf Version", i32 4}
! CHECK-DWARF3: !{i32 7, !"Dwarf Version", i32 3}
! CHECK-DWARF2: !{i32 7, !"Dwarf Version", i32 2}
! CHECK-WITHOUT-VERSION-NOT: "Dwarf Version"
! CHECK-WITHOUT-DEBUG-KIND-NOT: "Dwarf Version"
22 changes: 22 additions & 0 deletions flang/test/Transforms/debug-dwarf-version.fir
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unnecessary empty line at start of file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

// RUN: fir-opt --add-debug-info="dwarf-version=5" --mlir-print-debuginfo %s \
// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
// RUN: fir-opt --add-debug-info="dwarf-version=4" --mlir-print-debuginfo %s \
// RUN: | FileCheck --check-prefix=CHECK-DWARF4 %s
// RUN: fir-opt --add-debug-info="dwarf-version=3" --mlir-print-debuginfo %s \
// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
// RUN: fir-opt --add-debug-info="dwarf-version=2" --mlir-print-debuginfo %s \
// RUN: | FileCheck --check-prefix=CHECK-DWARF2 %s
// RUN: fir-opt --add-debug-info= --mlir-print-debuginfo %s \
// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-VERSION %s
// REQUIRES: system-linux

module {
} loc(#loc)
#loc = loc("simple.f90":0:0)

// CHECK-DWARF5: llvm.module_flags [#llvm.mlir.module_flag<max, "Dwarf Version", 5 : i32>]
// CHECK-DWARF4: llvm.module_flags [#llvm.mlir.module_flag<max, "Dwarf Version", 4 : i32>]
// CHECK-DWARF3: llvm.module_flags [#llvm.mlir.module_flag<max, "Dwarf Version", 3 : i32>]
// CHECK-DWARF2: llvm.module_flags [#llvm.mlir.module_flag<max, "Dwarf Version", 2 : i32>]
// CHECK-WITHOUT-VERSION-NOT: llvm.module_flags