Make -O
mean -C opt-level=3
This commit is contained in:
parent
c241e14650
commit
2966256133
13 changed files with 39 additions and 34 deletions
|
@ -289,7 +289,7 @@ fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
|
|||
flags_builder.set("opt_level", "none").unwrap();
|
||||
}
|
||||
OptLevel::Less
|
||||
| OptLevel::Default
|
||||
| OptLevel::More
|
||||
| OptLevel::Size
|
||||
| OptLevel::SizeMin
|
||||
| OptLevel::Aggressive => {
|
||||
|
|
|
@ -476,7 +476,7 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
|
|||
Some(level) => match level {
|
||||
OptLevel::No => OptimizationLevel::None,
|
||||
OptLevel::Less => OptimizationLevel::Limited,
|
||||
OptLevel::Default => OptimizationLevel::Standard,
|
||||
OptLevel::More => OptimizationLevel::Standard,
|
||||
OptLevel::Aggressive => OptimizationLevel::Aggressive,
|
||||
OptLevel::Size | OptLevel::SizeMin => OptimizationLevel::Limited,
|
||||
},
|
||||
|
|
|
@ -141,7 +141,7 @@ fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm::
|
|||
match cfg {
|
||||
No => (llvm::CodeGenOptLevel::None, llvm::CodeGenOptSizeNone),
|
||||
Less => (llvm::CodeGenOptLevel::Less, llvm::CodeGenOptSizeNone),
|
||||
Default => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone),
|
||||
More => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone),
|
||||
Aggressive => (llvm::CodeGenOptLevel::Aggressive, llvm::CodeGenOptSizeNone),
|
||||
Size => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeDefault),
|
||||
SizeMin => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeAggressive),
|
||||
|
@ -153,7 +153,7 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
|
|||
match cfg {
|
||||
No => llvm::PassBuilderOptLevel::O0,
|
||||
Less => llvm::PassBuilderOptLevel::O1,
|
||||
Default => llvm::PassBuilderOptLevel::O2,
|
||||
More => llvm::PassBuilderOptLevel::O2,
|
||||
Aggressive => llvm::PassBuilderOptLevel::O3,
|
||||
Size => llvm::PassBuilderOptLevel::Os,
|
||||
SizeMin => llvm::PassBuilderOptLevel::Oz,
|
||||
|
|
|
@ -410,7 +410,7 @@ impl<'a> GccLinker<'a> {
|
|||
let opt_level = match self.sess.opts.optimize {
|
||||
config::OptLevel::No => "O0",
|
||||
config::OptLevel::Less => "O1",
|
||||
config::OptLevel::Default | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
|
||||
config::OptLevel::More | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
|
||||
config::OptLevel::Aggressive => "O3",
|
||||
};
|
||||
|
||||
|
@ -685,7 +685,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
|
||||
// GNU-style linkers support optimization with -O. GNU ld doesn't
|
||||
// need a numeric argument, but other linkers do.
|
||||
if self.sess.opts.optimize == config::OptLevel::Default
|
||||
if self.sess.opts.optimize == config::OptLevel::More
|
||||
|| self.sess.opts.optimize == config::OptLevel::Aggressive
|
||||
{
|
||||
self.link_arg("-O1");
|
||||
|
@ -1213,7 +1213,7 @@ impl<'a> Linker for EmLinker<'a> {
|
|||
self.cc_arg(match self.sess.opts.optimize {
|
||||
OptLevel::No => "-O0",
|
||||
OptLevel::Less => "-O1",
|
||||
OptLevel::Default => "-O2",
|
||||
OptLevel::More => "-O2",
|
||||
OptLevel::Aggressive => "-O3",
|
||||
OptLevel::Size => "-Os",
|
||||
OptLevel::SizeMin => "-Oz",
|
||||
|
@ -1384,7 +1384,7 @@ impl<'a> Linker for WasmLd<'a> {
|
|||
self.link_arg(match self.sess.opts.optimize {
|
||||
OptLevel::No => "-O0",
|
||||
OptLevel::Less => "-O1",
|
||||
OptLevel::Default => "-O2",
|
||||
OptLevel::More => "-O2",
|
||||
OptLevel::Aggressive => "-O3",
|
||||
// Currently LLD doesn't support `Os` and `Oz`, so pass through `O2`
|
||||
// instead.
|
||||
|
@ -1451,7 +1451,7 @@ impl<'a> WasmLd<'a> {
|
|||
let opt_level = match self.sess.opts.optimize {
|
||||
config::OptLevel::No => "O0",
|
||||
config::OptLevel::Less => "O1",
|
||||
config::OptLevel::Default => "O2",
|
||||
config::OptLevel::More => "O2",
|
||||
config::OptLevel::Aggressive => "O3",
|
||||
// wasm-ld only handles integer LTO opt levels. Use O2
|
||||
config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
|
||||
|
@ -1525,7 +1525,7 @@ impl<'a> Linker for L4Bender<'a> {
|
|||
fn optimize(&mut self) {
|
||||
// GNU-style linkers support optimization with -O. GNU ld doesn't
|
||||
// need a numeric argument, but other linkers do.
|
||||
if self.sess.opts.optimize == config::OptLevel::Default
|
||||
if self.sess.opts.optimize == config::OptLevel::More
|
||||
|| self.sess.opts.optimize == config::OptLevel::Aggressive
|
||||
{
|
||||
self.link_arg("-O1");
|
||||
|
@ -1929,7 +1929,7 @@ impl<'a> Linker for LlbcLinker<'a> {
|
|||
match self.sess.opts.optimize {
|
||||
OptLevel::No => "-O0",
|
||||
OptLevel::Less => "-O1",
|
||||
OptLevel::Default => "-O2",
|
||||
OptLevel::More => "-O2",
|
||||
OptLevel::Aggressive => "-O3",
|
||||
OptLevel::Size => "-Os",
|
||||
OptLevel::SizeMin => "-Oz",
|
||||
|
@ -2006,7 +2006,7 @@ impl<'a> Linker for BpfLinker<'a> {
|
|||
self.link_arg(match self.sess.opts.optimize {
|
||||
OptLevel::No => "-O0",
|
||||
OptLevel::Less => "-O1",
|
||||
OptLevel::Default => "-O2",
|
||||
OptLevel::More => "-O2",
|
||||
OptLevel::Aggressive => "-O3",
|
||||
OptLevel::Size => "-Os",
|
||||
OptLevel::SizeMin => "-Oz",
|
||||
|
|
|
@ -236,7 +236,7 @@ impl ModuleConfig {
|
|||
// Copy what clang does by turning on loop vectorization at O2 and
|
||||
// slp vectorization at O3.
|
||||
vectorize_loop: !sess.opts.cg.no_vectorize_loops
|
||||
&& (sess.opts.optimize == config::OptLevel::Default
|
||||
&& (sess.opts.optimize == config::OptLevel::More
|
||||
|| sess.opts.optimize == config::OptLevel::Aggressive),
|
||||
vectorize_slp: !sess.opts.cg.no_vectorize_slp
|
||||
&& sess.opts.optimize == config::OptLevel::Aggressive,
|
||||
|
@ -260,7 +260,7 @@ impl ModuleConfig {
|
|||
MergeFunctions::Trampolines | MergeFunctions::Aliases => {
|
||||
use config::OptLevel::*;
|
||||
match sess.opts.optimize {
|
||||
Aggressive | Default | SizeMin | Size => true,
|
||||
Aggressive | More | SizeMin | Size => true,
|
||||
Less | No => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1054,12 +1054,12 @@ pub(crate) fn provide(providers: &mut Providers) {
|
|||
config::OptLevel::No => return config::OptLevel::No,
|
||||
// If globally optimise-speed is already specified, just use that level.
|
||||
config::OptLevel::Less => return config::OptLevel::Less,
|
||||
config::OptLevel::Default => return config::OptLevel::Default,
|
||||
config::OptLevel::More => return config::OptLevel::More,
|
||||
config::OptLevel::Aggressive => return config::OptLevel::Aggressive,
|
||||
// If globally optimize-for-size has been requested, use -O2 instead (if optimize(size)
|
||||
// are present).
|
||||
config::OptLevel::Size => config::OptLevel::Default,
|
||||
config::OptLevel::SizeMin => config::OptLevel::Default,
|
||||
config::OptLevel::Size => config::OptLevel::More,
|
||||
config::OptLevel::SizeMin => config::OptLevel::More,
|
||||
};
|
||||
|
||||
let defids = tcx.collect_and_partition_mono_items(cratenum).all_mono_items;
|
||||
|
|
|
@ -49,8 +49,7 @@ impl<'tcx> crate::MirPass<'tcx> for Inline {
|
|||
match sess.mir_opt_level() {
|
||||
0 | 1 => false,
|
||||
2 => {
|
||||
(sess.opts.optimize == OptLevel::Default
|
||||
|| sess.opts.optimize == OptLevel::Aggressive)
|
||||
(sess.opts.optimize == OptLevel::More || sess.opts.optimize == OptLevel::Aggressive)
|
||||
&& sess.opts.incremental == None
|
||||
}
|
||||
_ => true,
|
||||
|
|
|
@ -86,12 +86,18 @@ pub enum CFProtection {
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Hash, HashStable_Generic)]
|
||||
pub enum OptLevel {
|
||||
No, // -O0
|
||||
Less, // -O1
|
||||
Default, // -O2
|
||||
Aggressive, // -O3
|
||||
Size, // -Os
|
||||
SizeMin, // -Oz
|
||||
/// `-Copt-level=0`
|
||||
No,
|
||||
/// `-Copt-level=1`
|
||||
Less,
|
||||
/// `-Copt-level=2`
|
||||
More,
|
||||
/// `-Copt-level=3` / `-O`
|
||||
Aggressive,
|
||||
/// `-Copt-level=s`
|
||||
Size,
|
||||
/// `-Copt-level=z`
|
||||
SizeMin,
|
||||
}
|
||||
|
||||
/// This is what the `LtoCli` values get mapped to after resolving defaults and
|
||||
|
@ -1253,7 +1259,7 @@ impl Options {
|
|||
Some(setting) => setting,
|
||||
None => match self.optimize {
|
||||
OptLevel::No | OptLevel::Less | OptLevel::Size | OptLevel::SizeMin => true,
|
||||
OptLevel::Default | OptLevel::Aggressive => false,
|
||||
OptLevel::More | OptLevel::Aggressive => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1572,7 +1578,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
|||
stack-protector-strategies|link-args|deployment-target]",
|
||||
),
|
||||
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
|
||||
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=2", ""),
|
||||
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
|
||||
opt(Stable, Opt, "o", "", "Write output to <filename>", "FILENAME"),
|
||||
opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
|
||||
opt(
|
||||
|
@ -2127,12 +2133,12 @@ fn parse_opt_level(
|
|||
})
|
||||
.max();
|
||||
if max_o > max_c {
|
||||
OptLevel::Default
|
||||
OptLevel::Aggressive
|
||||
} else {
|
||||
match cg.opt_level.as_ref() {
|
||||
"0" => OptLevel::No,
|
||||
"1" => OptLevel::Less,
|
||||
"2" => OptLevel::Default,
|
||||
"2" => OptLevel::More,
|
||||
"3" => OptLevel::Aggressive,
|
||||
"s" => OptLevel::Size,
|
||||
"z" => OptLevel::SizeMin,
|
||||
|
|
|
@ -368,7 +368,7 @@ This flag controls the optimization level.
|
|||
* `s`: optimize for binary size.
|
||||
* `z`: optimize for binary size, but also turn off loop vectorization.
|
||||
|
||||
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`.
|
||||
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=3`.
|
||||
|
||||
The default is `0`.
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ A synonym for [`-C debuginfo=2`](codegen-options/index.md#debuginfo).
|
|||
<a id="option-o-optimize"></a>
|
||||
## `-O`: optimize your code
|
||||
|
||||
A synonym for [`-C opt-level=2`](codegen-options/index.md#opt-level).
|
||||
A synonym for [`-C opt-level=3`](codegen-options/index.md#opt-level).
|
||||
|
||||
<a id="option-o-output"></a>
|
||||
## `-o`: filename of the output
|
||||
|
|
|
@ -84,7 +84,7 @@ impl Rustc {
|
|||
self
|
||||
}
|
||||
|
||||
/// Specify default optimization level `-O` (alias for `-C opt-level=2`).
|
||||
/// Specify default optimization level `-O` (alias for `-C opt-level=3`).
|
||||
pub fn opt(&mut self) -> &mut Self {
|
||||
self.cmd.arg("-O");
|
||||
self
|
||||
|
|
|
@ -32,7 +32,7 @@ Options:
|
|||
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
|
||||
Compiler information to print on stdout
|
||||
-g Equivalent to -C debuginfo=2
|
||||
-O Equivalent to -C opt-level=2
|
||||
-O Equivalent to -C opt-level=3
|
||||
-o FILENAME Write output to <filename>
|
||||
--out-dir DIR Write output to compiler-chosen filename in <dir>
|
||||
--explain OPT Provide a detailed explanation of an error message
|
||||
|
|
|
@ -32,7 +32,7 @@ Options:
|
|||
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
|
||||
Compiler information to print on stdout
|
||||
-g Equivalent to -C debuginfo=2
|
||||
-O Equivalent to -C opt-level=2
|
||||
-O Equivalent to -C opt-level=3
|
||||
-o FILENAME Write output to <filename>
|
||||
--out-dir DIR Write output to compiler-chosen filename in <dir>
|
||||
--explain OPT Provide a detailed explanation of an error message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue