From d69dad9a9078195929ded12ec96db50b3b528a96 Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Tue, 10 May 2011 01:17:32 -0600 Subject: [PATCH] OptLevel changes. Accepts levels 0 to 3 only. '-O' is no longer accepted. --- Makefile.in | 2 +- src/comp/back/Link.rs | 33 +++++++++++++++------------------ src/comp/driver/rustc.rs | 32 +++++++++++++++++++++++++++----- src/comp/driver/session.rs | 2 +- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/Makefile.in b/Makefile.in index c32ac1e498670..7930cc9bd882b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,7 +15,7 @@ ifdef CFG_DISABLE_OPTIMIZE $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE)) CFG_RUSTC_FLAGS := else - CFG_RUSTC_FLAGS := -O + CFG_RUSTC_FLAGS := --OptLevel=2 endif ifdef SAVE_TEMPS diff --git a/src/comp/back/Link.rs b/src/comp/back/Link.rs index 15be6dc88de7f..e7f1c128ba891 100644 --- a/src/comp/back/Link.rs +++ b/src/comp/back/Link.rs @@ -91,7 +91,7 @@ mod Write { if (opts.save_temps) { alt (opts.output_type) { case (output_type_bitcode) { - if (opts.optimize) { + if (opts.optimize != 0u) { auto filename = mk_intermediate_name(output, "no-opt.bc"); llvm.LLVMWriteBitcodeToFile(llmod, @@ -105,28 +105,25 @@ mod Write { } } - // FIXME: This is mostly a copy of the bits of opt's -O2 that are - // available in the C api. - // FIXME2: We might want to add optimization levels like -O1, -O2, - // -Os, etc - // FIXME3: Should we expose and use the pass lists used by the opt - // tool? - if (opts.optimize) { + // FIXME: LTO? + if (opts.optimize != 0u) { + let uint threshold = 225u; auto fpm = mk_pass_manager(); llvm.LLVMAddTargetData(td.lltd, fpm.llpm); - llvm.LLVMAddStandardFunctionPasses(fpm.llpm, 2u); + llvm.LLVMAddStandardFunctionPasses(fpm.llpm, opts.optimize); llvm.LLVMRunPassManager(fpm.llpm, llmod); - // TODO: On -O3, use 275 instead of 225 for the inlining - // threshold. + if (opts.optimize == 3u) { + threshold = 275u; + } llvm.LLVMAddStandardModulePasses(pm.llpm, - 2u, // optimization level - False, // optimize for size - True, // unit-at-a-time - True, // unroll loops - True, // simplify lib calls - True, // have exceptions - 225u); // inlining threshold + opts.optimize,// opt level + False, // opt for size + True, // unit-at-a-time + True, // unroll loops + True, // simplifyLibCalls + True, // have exceptions + threshold); // inline threshold } if (opts.verify) { diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index cb8b676d51789..03020faa98010 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -152,7 +152,7 @@ options: --depend print dependencies, in makefile-rule form --parse-only parse only; do not compile, assemble, or link -g produce debug info - -O optimize + --OptLevel= optimize with possible levels 0-3 -S compile only; do not assemble or link -c compile and assemble, but do not link --save-temps write intermediate files in addition to normal output @@ -206,7 +206,7 @@ fn main(vec[str] args) { optflag("v"), optflag("version"), optflag("glue"), optflag("pretty"), optflag("ls"), optflag("parse-only"), - optflag("O"), optflag("shared"), optmulti("L"), + optopt("OptLevel"), optflag("shared"), optmulti("L"), optflag("S"), optflag("c"), optopt("o"), optopt("g"), optflag("save-temps"), optopt("sysroot"), optflag("time-passes"), optflag("no-typestate"), @@ -250,13 +250,35 @@ fn main(vec[str] args) { auto verify = !opt_present(match, "noverify"); auto save_temps = opt_present(match, "save-temps"); - // FIXME: Maybe we should support -O0, -O1, -Os, etc - auto optimize = opt_present(match, "O"); auto debuginfo = opt_present(match, "g"); auto time_passes = opt_present(match, "time-passes"); auto run_typestate = !opt_present(match, "no-typestate"); auto sysroot_opt = GetOpts.opt_maybe_str(match, "sysroot"); + let uint optLevel = 0u; + if (opt_present(match, "OptLevel")) { + auto opt = GetOpts.opt_maybe_str(match, "OptLevel"); + alt (opt) { + case (some[str](?s)) { + alt (s) { + case ("0") { optLevel = 0u; } + case ("1") { optLevel = 1u; } + case ("2") { optLevel = 2u; } + case ("3") { optLevel = 3u; } + case (_) { + log + ("error: optimization level needs to be between 0-3"); + fail; + } + } + } + case (none[str]) { + log("error: expected optimization level after --OptLevel="); + fail; + } + } + } + auto sysroot; alt (sysroot_opt) { case (none[str]) { sysroot = get_default_sysroot(binary); } @@ -265,7 +287,7 @@ fn main(vec[str] args) { let @session.options sopts = @rec(shared = shared, - optimize = optimize, + optimize = optLevel, debuginfo = debuginfo, verify = verify, run_typestate = run_typestate, diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index 644846d06b14b..a03b276806359 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -26,7 +26,7 @@ type config = rec(os os, ty_mach float_type); type options = rec(bool shared, - bool optimize, + uint optimize, bool debuginfo, bool verify, bool run_typestate,