-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][nvlink-wrapper] Add support for opt-remarks command line options #145365
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
Conversation
This patch adds support for optimization record command line options to clang-nvlink-wrapper, fixing an issue where using -fsave-optimization-record with CUDA offloading would fail with "Unknown command line argument 'opt-remarks-format=yaml'".
Convert alias definitions to proper option definitions for opt-remarks-* options based on suggestions.
Convert alias definitions to proper option definitions for opt-remarks-* options based on suggestions.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Miguel Cárdenas (miguelcsx) ChangesProblemWhen using SolutionThis patch adds support for the standard optimization record command line options to Changes
TestingThe fix allows This change maintains backward compatibility and follows the existing pattern used by other LLVM linkers. Full diff: https://github.com/llvm/llvm-project/pull/145365.diff 2 Files Affected:
diff --git a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
index faf73a7c2f193..4b63971214f81 100644
--- a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
+++ b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
@@ -341,11 +341,16 @@ Expected<std::unique_ptr<lto::LTO>> createLTO(const ArgList &Args) {
Conf.CPU = Args.getLastArgValue(OPT_arch);
Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
- Conf.RemarksFilename = RemarksFilename;
- Conf.RemarksPasses = RemarksPasses;
- Conf.RemarksWithHotness = RemarksWithHotness;
+ Conf.RemarksFilename =
+ Args.getLastArgValue(OPT_opt_remarks_filename, RemarksFilename);
+ Conf.RemarksPasses =
+ Args.getLastArgValue(OPT_opt_remarks_filter, RemarksPasses);
+ Conf.RemarksFormat =
+ Args.getLastArgValue(OPT_opt_remarks_format, RemarksFormat);
+
+ Conf.RemarksWithHotness =
+ Args.hasArg(OPT_opt_remarks_with_hotness) || RemarksWithHotness;
Conf.RemarksHotnessThreshold = RemarksHotnessThreshold;
- Conf.RemarksFormat = RemarksFormat;
Conf.MAttrs = llvm::codegen::getMAttrs();
std::optional<CodeGenOptLevel> CGOptLevelOrNone =
diff --git a/clang/tools/clang-nvlink-wrapper/NVLinkOpts.td b/clang/tools/clang-nvlink-wrapper/NVLinkOpts.td
index 6de1a25c14f8b..7af35bf5989ec 100644
--- a/clang/tools/clang-nvlink-wrapper/NVLinkOpts.td
+++ b/clang/tools/clang-nvlink-wrapper/NVLinkOpts.td
@@ -72,6 +72,16 @@ def : Joined<["--", "-"], "plugin-opt=emit-llvm">,
Flags<[WrapperOnlyOption]>, Alias<lto_emit_llvm>;
def : Joined<["--", "-"], "plugin-opt=emit-asm">,
Flags<[WrapperOnlyOption]>, Alias<lto_emit_asm>;
+
+def opt_remarks_filename : Joined<["--", "-"], "plugin-opt=opt-remarks-filename=">,
+ Flags<[WrapperOnlyOption]>, HelpText<"YAML output file for optimization remarks">;
+def opt_remarks_format : Joined<["--", "-"], "plugin-opt=opt-remarks-format=">,
+ Flags<[WrapperOnlyOption]>, HelpText<"The format used for serializing remarks (default: YAML)">;
+def opt_remarks_filter : Joined<["--", "-"], "plugin-opt=opt-remarks-filter=">,
+ Flags<[WrapperOnlyOption]>, HelpText<"Regex for the passes that need to be serialized to the output file">;
+def opt_remarks_with_hotness : Flag<["--", "-"], "plugin-opt=opt-remarks-with-hotness">,
+ Flags<[WrapperOnlyOption]>, HelpText<"Include hotness information in the optimization remarks file">;
+
def plugin_opt : Joined<["--", "-"], "plugin-opt=">, Flags<[WrapperOnlyOption]>,
HelpText<"Options passed to LLVM, not including the Clang invocation. Use "
"'--plugin-opt=--help' for a list of options.">;
|
@josemonsalve2 @jhuber6 @jdoerfert I updated the branch with the upstream, and that closed my prev PR lol Here is again |
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.
Yeah, usually easier to do a force push if you plan on doing a rebase.
This one replaces #145200 which was closed due to some confusion. |
|
@miguelcsx Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…ons (llvm#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.
Problem
When using
-fsave-optimization-record
with offloading, the Clang driver passes optimization record options like-plugin-opt=opt-remarks-format=yaml
toclang-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.Changes
opt-remarks-filename
,opt-remarks-format
,opt-remarks-filter
, andopt-remarks-with-hotness
optionsplugin-opt=
aliases for these options to match what the Clang driver sendscreateLTO()
to use command line arguments when available, falling back to existing global variablesTesting
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.