OptLevel changes. Accepts levels 0 to 3 only. '-O' is synonym for --OptLevel=2.
This commit is contained in:
parent
0a74ffaea3
commit
31d65453d4
3 changed files with 55 additions and 18 deletions
|
|
@ -101,7 +101,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,
|
||||
|
|
@ -121,22 +121,26 @@ mod write {
|
|||
// -Os, etc
|
||||
// FIXME3: Should we expose and use the pass lists used by the opt
|
||||
// tool?
|
||||
if (opts.optimize) {
|
||||
if (opts.optimize != 0u) {
|
||||
auto fpm = mk_pass_manager();
|
||||
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
|
||||
llvm::LLVMAddStandardFunctionPasses(fpm.llpm, 2u);
|
||||
llvm::LLVMRunPassManager(fpm.llpm, llmod);
|
||||
|
||||
// TODO: On -O3, use 275 instead of 225 for the inlining
|
||||
// threshold.
|
||||
let uint threshold = 225u;
|
||||
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
|
||||
// optimization level
|
||||
opts.optimize,
|
||||
False, // optimize for size
|
||||
True, // unit-at-a-time
|
||||
True, // unroll loops
|
||||
True, // simplify lib calls
|
||||
True, // have exceptions
|
||||
threshold); // inline threshold
|
||||
}
|
||||
|
||||
if (opts.verify) {
|
||||
|
|
|
|||
|
|
@ -165,7 +165,8 @@ 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
|
||||
-O equivalent to --OptLevel=2
|
||||
-S compile only; do not assemble or link
|
||||
-c compile and assemble, but do not link
|
||||
--emit-llvm produce an LLVM bitcode file
|
||||
|
|
@ -228,8 +229,9 @@ fn main(vec[str] args) {
|
|||
optflag("glue"), optflag("emit-llvm"),
|
||||
optflag("pretty"), optflag("typed-pretty"),
|
||||
optflag("ls"), optflag("parse-only"),
|
||||
optflag("O"), optflag("shared"), optmulti("L"),
|
||||
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
|
||||
optflag("O"), optopt("OptLevel"),
|
||||
optflag("shared"), optmulti("L"),
|
||||
optflag("S"), optflag("c"), optopt("o"), optopt("g"),
|
||||
optflag("save-temps"), optopt("sysroot"),
|
||||
optflag("stats"),
|
||||
optflag("time-passes"), optflag("time-llvm-passes"),
|
||||
|
|
@ -276,8 +278,6 @@ 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 stats = opt_present(match, "stats");
|
||||
auto time_passes = opt_present(match, "time-passes");
|
||||
|
|
@ -285,6 +285,39 @@ fn main(vec[str] args) {
|
|||
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, "O")) {
|
||||
optLevel = 2u;
|
||||
if (opt_present(match, "OptLevel")) {
|
||||
log
|
||||
("error: -O and --OptLevel both provided");
|
||||
fail;
|
||||
}
|
||||
}
|
||||
|
||||
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); }
|
||||
|
|
@ -293,7 +326,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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue