Skip to content

Commit 6b501d7

Browse files
committed
---
yaml --- r: 2651 b: refs/heads/master c: 31d6545 h: refs/heads/master i: 2649: f14fc7a 2647: 6bda5e6 v: v3
1 parent b6f9709 commit 6b501d7

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0a74ffaea336177ab65b92d578a187d1388857e3
2+
refs/heads/master: 31d65453d47f243635ea17563db6b2c1127e9836

trunk/src/comp/back/link.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod write {
101101
if (opts.save_temps) {
102102
alt (opts.output_type) {
103103
case (output_type_bitcode) {
104-
if (opts.optimize) {
104+
if (opts.optimize != 0u) {
105105
auto filename = mk_intermediate_name(output,
106106
"no-opt.bc");
107107
llvm::LLVMWriteBitcodeToFile(llmod,
@@ -121,22 +121,26 @@ mod write {
121121
// -Os, etc
122122
// FIXME3: Should we expose and use the pass lists used by the opt
123123
// tool?
124-
if (opts.optimize) {
124+
if (opts.optimize != 0u) {
125125
auto fpm = mk_pass_manager();
126126
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
127127
llvm::LLVMAddStandardFunctionPasses(fpm.llpm, 2u);
128128
llvm::LLVMRunPassManager(fpm.llpm, llmod);
129129

130-
// TODO: On -O3, use 275 instead of 225 for the inlining
131-
// threshold.
130+
let uint threshold = 225u;
131+
if (opts.optimize == 3u) {
132+
threshold = 275u;
133+
}
134+
132135
llvm::LLVMAddStandardModulePasses(pm.llpm,
133-
2u, // optimization level
134-
False, // optimize for size
135-
True, // unit-at-a-time
136-
True, // unroll loops
137-
True, // simplify lib calls
138-
True, // have exceptions
139-
225u); // inlining threshold
136+
// optimization level
137+
opts.optimize,
138+
False, // optimize for size
139+
True, // unit-at-a-time
140+
True, // unroll loops
141+
True, // simplify lib calls
142+
True, // have exceptions
143+
threshold); // inline threshold
140144
}
141145

142146
if (opts.verify) {

trunk/src/comp/driver/rustc.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ options:
165165
--depend print dependencies, in makefile-rule form
166166
--parse-only parse only; do not compile, assemble, or link
167167
-g produce debug info
168-
-O optimize
168+
--OptLevel= optimize with possible levels 0-3
169+
-O equivalent to --OptLevel=2
169170
-S compile only; do not assemble or link
170171
-c compile and assemble, but do not link
171172
--emit-llvm produce an LLVM bitcode file
@@ -228,8 +229,9 @@ fn main(vec[str] args) {
228229
optflag("glue"), optflag("emit-llvm"),
229230
optflag("pretty"), optflag("typed-pretty"),
230231
optflag("ls"), optflag("parse-only"),
231-
optflag("O"), optflag("shared"), optmulti("L"),
232-
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
232+
optflag("O"), optopt("OptLevel"),
233+
optflag("shared"), optmulti("L"),
234+
optflag("S"), optflag("c"), optopt("o"), optopt("g"),
233235
optflag("save-temps"), optopt("sysroot"),
234236
optflag("stats"),
235237
optflag("time-passes"), optflag("time-llvm-passes"),
@@ -276,15 +278,46 @@ fn main(vec[str] args) {
276278

277279
auto verify = !opt_present(match, "noverify");
278280
auto save_temps = opt_present(match, "save-temps");
279-
// FIXME: Maybe we should support -O0, -O1, -Os, etc
280-
auto optimize = opt_present(match, "O");
281281
auto debuginfo = opt_present(match, "g");
282282
auto stats = opt_present(match, "stats");
283283
auto time_passes = opt_present(match, "time-passes");
284284
auto time_llvm_passes = opt_present(match, "time-llvm-passes");
285285
auto run_typestate = !opt_present(match, "no-typestate");
286286
auto sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
287287

288+
let uint optLevel = 0u;
289+
if (opt_present(match, "O")) {
290+
optLevel = 2u;
291+
if (opt_present(match, "OptLevel")) {
292+
log
293+
("error: -O and --OptLevel both provided");
294+
fail;
295+
}
296+
}
297+
298+
if (opt_present(match, "OptLevel")) {
299+
auto opt = getopts::opt_maybe_str(match, "OptLevel");
300+
alt (opt) {
301+
case (some[str](?s)) {
302+
alt (s) {
303+
case ("0") { optLevel = 0u; }
304+
case ("1") { optLevel = 1u; }
305+
case ("2") { optLevel = 2u; }
306+
case ("3") { optLevel = 3u; }
307+
case (_) {
308+
log
309+
("error: optimization level needs to be between 0-3");
310+
fail;
311+
}
312+
}
313+
}
314+
case (none[str]) {
315+
log("error: expected optimization level after --OptLevel=");
316+
fail;
317+
}
318+
}
319+
}
320+
288321
auto sysroot;
289322
alt (sysroot_opt) {
290323
case (none[str]) { sysroot = get_default_sysroot(binary); }
@@ -293,7 +326,7 @@ fn main(vec[str] args) {
293326

294327
let @session::options sopts =
295328
@rec(shared = shared,
296-
optimize = optimize,
329+
optimize = optLevel,
297330
debuginfo = debuginfo,
298331
verify = verify,
299332
run_typestate = run_typestate,

trunk/src/comp/driver/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type config = rec(os os,
2626
ty_mach float_type);
2727

2828
type options = rec(bool shared,
29-
bool optimize,
29+
uint optimize,
3030
bool debuginfo,
3131
bool verify,
3232
bool run_typestate,

0 commit comments

Comments
 (0)