Skip to content

Commit e80acd4

Browse files
authored
[clang][nvlink-wrapper] Add support for opt-remarks command line options (#145365)
## Problem When using `-fsave-optimization-record` with offloading, the Clang driver passes optimization record options like `-plugin-opt=opt-remarks-format=yaml` to `clang-nvlink-wrapper`. However, the wrapper doesn't recognize these options, causing compilation to fail. ## Solution This patch adds support for the standard optimization record command line options to `clang-nvlink-wrapper`, matching the interface provided by LLD and gold-plugin as documented in the [LLVM Remarks documentation](https://llvm.org/docs/Remarks.html). ## Changes - **NVLinkOpts.td**: Added definitions for `opt-remarks-filename`, `opt-remarks-format`, `opt-remarks-filter`, and `opt-remarks-with-hotness` options - **NVLinkOpts.td**: Added `plugin-opt=` aliases for these options to match what the Clang driver sends - **ClangNVLinkWrapper.cpp**: Updated `createLTO()` to use command line arguments when available, falling back to existing global variables ## Testing The fix allows `-fsave-optimization-record` to work correctly with offloading, generating optimization records during the LTO phase without throwing unknown argument errors. This change maintains backward compatibility and follows the existing pattern used by other LLVM linkers.
1 parent 0f173a0 commit e80acd4

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,16 @@ Expected<std::unique_ptr<lto::LTO>> createLTO(const ArgList &Args) {
341341
Conf.CPU = Args.getLastArgValue(OPT_arch);
342342
Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
343343

344-
Conf.RemarksFilename = RemarksFilename;
345-
Conf.RemarksPasses = RemarksPasses;
346-
Conf.RemarksWithHotness = RemarksWithHotness;
344+
Conf.RemarksFilename =
345+
Args.getLastArgValue(OPT_opt_remarks_filename, RemarksFilename);
346+
Conf.RemarksPasses =
347+
Args.getLastArgValue(OPT_opt_remarks_filter, RemarksPasses);
348+
Conf.RemarksFormat =
349+
Args.getLastArgValue(OPT_opt_remarks_format, RemarksFormat);
350+
351+
Conf.RemarksWithHotness =
352+
Args.hasArg(OPT_opt_remarks_with_hotness) || RemarksWithHotness;
347353
Conf.RemarksHotnessThreshold = RemarksHotnessThreshold;
348-
Conf.RemarksFormat = RemarksFormat;
349354

350355
Conf.MAttrs = llvm::codegen::getMAttrs();
351356
std::optional<CodeGenOptLevel> CGOptLevelOrNone =

clang/tools/clang-nvlink-wrapper/NVLinkOpts.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def : Joined<["--", "-"], "plugin-opt=emit-llvm">,
7272
Flags<[WrapperOnlyOption]>, Alias<lto_emit_llvm>;
7373
def : Joined<["--", "-"], "plugin-opt=emit-asm">,
7474
Flags<[WrapperOnlyOption]>, Alias<lto_emit_asm>;
75+
76+
def opt_remarks_filename : Joined<["--", "-"], "plugin-opt=opt-remarks-filename=">,
77+
Flags<[WrapperOnlyOption]>, HelpText<"YAML output file for optimization remarks">;
78+
def opt_remarks_format : Joined<["--", "-"], "plugin-opt=opt-remarks-format=">,
79+
Flags<[WrapperOnlyOption]>, HelpText<"The format used for serializing remarks (default: YAML)">;
80+
def opt_remarks_filter : Joined<["--", "-"], "plugin-opt=opt-remarks-filter=">,
81+
Flags<[WrapperOnlyOption]>, HelpText<"Regex for the passes that need to be serialized to the output file">;
82+
def opt_remarks_with_hotness : Flag<["--", "-"], "plugin-opt=opt-remarks-with-hotness">,
83+
Flags<[WrapperOnlyOption]>, HelpText<"Include hotness information in the optimization remarks file">;
84+
7585
def plugin_opt : Joined<["--", "-"], "plugin-opt=">, Flags<[WrapperOnlyOption]>,
7686
HelpText<"Options passed to LLVM, not including the Clang invocation. Use "
7787
"'--plugin-opt=--help' for a list of options.">;

0 commit comments

Comments
 (0)