Skip to content
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

OptLevel changes. Accepts levels 0 to 3 only. '-O' is no longer accepted. #357

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 15 additions & 18 deletions src/comp/back/Link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
32 changes: 27 additions & 5 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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); }
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/comp/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down