Skip to content

Commit b4422cc

Browse files
committed
Add a -O option and change the Makefile to use it.
1 parent ddf96ac commit b4422cc

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CFG_INFO := $(info cfg: building on $(CFG_OSTYPE) $(CFG_CPUTYPE))
1414
CFG_GCC_CFLAGS :=
1515
CFG_GCC_LINK_FLAGS :=
1616
CFG_BOOT_FLAGS := $(BOOT_FLAGS)
17-
CFG_RUSTC_FLAGS := -nowarn
17+
CFG_RUSTC_FLAGS := -nowarn -O
1818

1919
# On Darwin, we need to run dsymutil so the debugging information ends
2020
# up in the right place. On other platforms, it automatically gets

src/comp/driver/rustc.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impure fn compile_input(session.session sess,
5858
eval.env env,
5959
str input, str output,
6060
bool shared,
61+
bool optimize,
6162
vec[str] library_search_paths) {
6263
auto def = tup(0, 0);
6364
auto p = parser.new_parser(sess, env, def, input);
@@ -69,7 +70,7 @@ impure fn compile_input(session.session sess,
6970
auto type_cache = typeck_result._1;
7071
// FIXME: uncomment once typestate_check works
7172
// crate = typestate_check.check_crate(crate);
72-
trans.trans_crate(sess, crate, type_cache, output, shared);
73+
trans.trans_crate(sess, crate, type_cache, output, shared, optimize);
7374
}
7475

7576
impure fn pretty_print_input(session.session sess,
@@ -131,6 +132,9 @@ impure fn main(vec[str] args) {
131132
let bool pretty = false;
132133
let bool glue = false;
133134

135+
// FIXME: Maybe we should support -O0, -O1, -Os, etc
136+
let bool optimize = false;
137+
134138
auto i = 1u;
135139
auto len = _vec.len[str](args);
136140

@@ -140,6 +144,8 @@ impure fn main(vec[str] args) {
140144
if (_str.byte_len(arg) > 0u && arg.(0) == '-' as u8) {
141145
if (_str.eq(arg, "-nowarn")) {
142146
do_warn = false;
147+
} else if (_str.eq(arg, "-O")) {
148+
optimize = true;
143149
} else if (_str.eq(arg, "-glue")) {
144150
glue = true;
145151
} else if (_str.eq(arg, "-shared")) {
@@ -189,10 +195,10 @@ impure fn main(vec[str] args) {
189195
if (glue) {
190196
alt (output_file) {
191197
case (none[str]) {
192-
middle.trans.make_common_glue("glue.bc");
198+
middle.trans.make_common_glue("glue.bc", optimize);
193199
}
194200
case (some[str](?s)) {
195-
middle.trans.make_common_glue(s);
201+
middle.trans.make_common_glue(s, optimize);
196202
}
197203
}
198204
ret;
@@ -217,11 +223,11 @@ impure fn main(vec[str] args) {
217223
parts += vec(".bc");
218224
auto ofile = _str.concat(parts);
219225
compile_input(sess, env, ifile, ofile, shared,
220-
library_search_paths);
226+
optimize, library_search_paths);
221227
}
222228
case (some[str](?ofile)) {
223229
compile_input(sess, env, ifile, ofile, shared,
224-
library_search_paths);
230+
optimize, library_search_paths);
225231
}
226232
}
227233
}

src/comp/middle/trans.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7003,7 +7003,7 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
70037003
vec_append_glue = make_vec_append_glue(llmod, tn));
70047004
}
70057005

7006-
fn make_common_glue(str output) {
7006+
fn make_common_glue(str output, bool optimize) {
70077007
// FIXME: part of this is repetitive and is probably a good idea
70087008
// to autogen it, but things like the memcpy implementation are not
70097009
// and it might be better to just check in a .ll file.
@@ -7029,14 +7029,15 @@ fn make_common_glue(str output) {
70297029

70307030
trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn, llmod);
70317031

7032-
run_passes(llmod, true);
7032+
run_passes(llmod, optimize);
70337033

70347034
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
70357035
llvm.LLVMDisposeModule(llmod);
70367036
}
70377037

70387038
fn trans_crate(session.session sess, @ast.crate crate,
7039-
&ty.type_cache type_cache, str output, bool shared) {
7039+
&ty.type_cache type_cache, str output, bool shared,
7040+
bool optimize) {
70407041
auto llmod =
70417042
llvm.LLVMModuleCreateWithNameInContext(_str.buf("rust_out"),
70427043
llvm.LLVMGetGlobalContext());
@@ -7099,8 +7100,7 @@ fn trans_crate(session.session sess, @ast.crate crate,
70997100
// Translate the metadata.
71007101
middle.metadata.write_metadata(cx, crate);
71017102

7102-
// FIXME: Add an -O option
7103-
run_passes(llmod, true);
7103+
run_passes(llmod, optimize);
71047104

71057105
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
71067106
llvm.LLVMDisposeModule(llmod);

0 commit comments

Comments
 (0)