about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-05-19 12:46:10 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-05-19 12:46:10 -0700
commit31d65453d47f243635ea17563db6b2c1127e9836 (patch)
treed63a3d6512237883b35b908c756177fb241f3e1c /src/comp
parent0a74ffaea336177ab65b92d578a187d1388857e3 (diff)
downloadrust-31d65453d47f243635ea17563db6b2c1127e9836.tar.gz
rust-31d65453d47f243635ea17563db6b2c1127e9836.zip
OptLevel changes. Accepts levels 0 to 3 only. '-O' is synonym for --OptLevel=2.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/back/link.rs26
-rw-r--r--src/comp/driver/rustc.rs45
-rw-r--r--src/comp/driver/session.rs2
3 files changed, 55 insertions, 18 deletions
diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs
index 09a4079b1f8..d0e6b5a7c6f 100644
--- a/src/comp/back/link.rs
+++ b/src/comp/back/link.rs
@@ -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) {
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 456cb0faa4c..0ce20eb2f15 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -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,
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index 88d0fcfb6c7..d943c151c6d 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,