-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Perform LTO optimisations with wasm-ld + -Clinker-plugin-lto #118378
Merged
bors
merged 1 commit into
rust-lang:master
from
cormacrelf:bugfix/linker-plugin-lto-wasm
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1302,6 +1302,8 @@ impl<'a> Linker for WasmLd<'a> { | |||||
} | ||||||
|
||||||
fn optimize(&mut self) { | ||||||
// The -O flag is, as of late 2023, only used for merging of strings and debuginfo, and | ||||||
// only differentiates -O0 and -O1. It does not apply to LTO. | ||||||
self.cmd.arg(match self.sess.opts.optimize { | ||||||
OptLevel::No => "-O0", | ||||||
OptLevel::Less => "-O1", | ||||||
|
@@ -1354,7 +1356,31 @@ impl<'a> Linker for WasmLd<'a> { | |||||
fn subsystem(&mut self, _subsystem: &str) {} | ||||||
|
||||||
fn linker_plugin_lto(&mut self) { | ||||||
// Do nothing for now | ||||||
match self.sess.opts.cg.linker_plugin_lto { | ||||||
LinkerPluginLto::Disabled => { | ||||||
// Nothing to do | ||||||
} | ||||||
LinkerPluginLto::LinkerPluginAuto => { | ||||||
self.push_linker_plugin_lto_args(); | ||||||
} | ||||||
LinkerPluginLto::LinkerPlugin(_) => { | ||||||
self.push_linker_plugin_lto_args(); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
impl<'a> WasmLd<'a> { | ||||||
fn push_linker_plugin_lto_args(&mut self) { | ||||||
let opt_level = match self.sess.opts.optimize { | ||||||
config::OptLevel::No => "O0", | ||||||
config::OptLevel::Less => "O1", | ||||||
config::OptLevel::Default => "O2", | ||||||
config::OptLevel::Aggressive => "O3", | ||||||
// wasm-ld only handles integer LTO opt levels. Use O2 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
config::OptLevel::Size | config::OptLevel::SizeMin => "O2", | ||||||
}; | ||||||
self.cmd.arg(&format!("--lto-{opt_level}")); | ||||||
} | ||||||
} | ||||||
|
||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
push_linker_plugin_lto_args
could then be inlined and removed.Upd: the match on
self.sess.opts.optimize
could be kept separate function, though, it is shared betweenfn optimize
andfn linker_plugin_lto
.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.
I intentionally left them separate.
--lto-O*
args may change to support Os and Oz in future. (Especially with those being the most popular opt levels for webassembly.) If that happens, adding Os/Oz to a shared match statement would break the normalfn optimize
that controls merging sections only, unrelated to LLVM.push_linker_plugin_lto_args
could be inlined, but I was going to do another PR that puts warnings in one of the match arms but not the other.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.
Ok.