about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-05-10 16:10:08 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-05-10 16:10:08 -0700
commitd6f1fcff6b056f1f0eb54989bbd2a68bf255ff22 (patch)
tree71317080577dd8cac3cb0e0ce48e58960a9d1e96 /src
parent813636d52e1d77785e4ec28c0fd5e5f513d2e020 (diff)
downloadrust-d6f1fcff6b056f1f0eb54989bbd2a68bf255ff22.tar.gz
rust-d6f1fcff6b056f1f0eb54989bbd2a68bf255ff22.zip
Add --time-llvm-passes.
Diffstat (limited to 'src')
-rw-r--r--src/comp/back/Link.rs16
-rw-r--r--src/comp/driver/rustc.rs7
-rw-r--r--src/comp/driver/session.rs1
-rw-r--r--src/comp/lib/llvm.rs6
-rw-r--r--src/rustllvm/RustWrapper.cpp12
-rw-r--r--src/rustllvm/rustllvm.def.in2
6 files changed, 40 insertions, 4 deletions
diff --git a/src/comp/back/Link.rs b/src/comp/back/Link.rs
index 15be6dc88de..50f10a804e2 100644
--- a/src/comp/back/Link.rs
+++ b/src/comp/back/Link.rs
@@ -75,11 +75,16 @@ mod Write {
     }
 
     fn run_passes(session.session sess, ModuleRef llmod, str output) {
-        link_intrinsics(sess, llmod);
 
-        auto pm = mk_pass_manager();
         auto opts = sess.get_opts();
 
+        if (opts.time_llvm_passes) {
+          llvm.LLVMRustEnableTimePasses();
+        }
+
+        link_intrinsics(sess, llmod);
+
+        auto pm = mk_pass_manager();
         auto td = mk_target_data(x86.get_data_layout());
         llvm.LLVMAddTargetData(td.lltd, pm.llpm);
 
@@ -165,6 +170,9 @@ mod Write {
                                          Str.buf(output),
                                          FileType);
             llvm.LLVMDisposeModule(llmod);
+            if (opts.time_llvm_passes) {
+              llvm.LLVMRustPrintPassTimings();
+            }
             ret;
         }
 
@@ -172,6 +180,10 @@ mod Write {
 
         llvm.LLVMWriteBitcodeToFile(llmod, Str.buf(output));
         llvm.LLVMDisposeModule(llmod);
+
+        if (opts.time_llvm_passes) {
+          llvm.LLVMRustPrintPassTimings();
+        }
     }
 }
 
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index cb8b676d517..9ac219e3711 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -157,6 +157,7 @@ options:
     -c                 compile and assemble, but do not link
     --save-temps       write intermediate files in addition to normal output
     --time-passes      time the individual phases of the compiler
+    --time-llvm-passes time the individual phases of the LLVM backend
     --sysroot <path>   override the system root (default: rustc's directory)
     --no-typestate     don't run the typestate pass (unsafe!)\n\n");
 }
@@ -209,8 +210,8 @@ fn main(vec[str] args) {
                     optflag("O"), optflag("shared"), optmulti("L"),
                     optflag("S"), optflag("c"), optopt("o"), optopt("g"),
                     optflag("save-temps"), optopt("sysroot"),
-                    optflag("time-passes"), optflag("no-typestate"),
-                    optflag("noverify"));
+                    optflag("time-passes"), optflag("time-llvm-passes"),
+                    optflag("no-typestate"), optflag("noverify"));
     auto binary = Vec.shift[str](args);
     auto match;
     alt (GetOpts.getopts(args, opts)) {
@@ -254,6 +255,7 @@ fn main(vec[str] args) {
     auto optimize = opt_present(match, "O");
     auto debuginfo = opt_present(match, "g");
     auto time_passes = opt_present(match, "time-passes");
+    auto time_llvm_passes = opt_present(match, "time-llvm-passes");
     auto run_typestate = !opt_present(match, "no-typestate");
     auto sysroot_opt = GetOpts.opt_maybe_str(match, "sysroot");
 
@@ -271,6 +273,7 @@ fn main(vec[str] args) {
              run_typestate = run_typestate,
              save_temps = save_temps,
              time_passes = time_passes,
+             time_llvm_passes = time_llvm_passes,
              output_type = output_type,
              library_search_paths = library_search_paths,
              sysroot = sysroot);
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index 644846d06b1..fd3e9b23596 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -32,6 +32,7 @@ type options = rec(bool shared,
                    bool run_typestate,
                    bool save_temps,
                    bool time_passes,
+                   bool time_llvm_passes,
                    back.Link.output_type output_type,
                    vec[str] library_search_paths,
                    str sysroot);
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs
index c4114261797..bc7338ffffc 100644
--- a/src/comp/lib/llvm.rs
+++ b/src/comp/lib/llvm.rs
@@ -872,6 +872,12 @@ native mod llvm = llvm_lib {
     fn LLVMRustConstSmallInt(TypeRef IntTy, uint N,
                              Bool SignExtend) -> ValueRef;
 
+    /** Turn on LLVM pass-timing. */
+    fn LLVMRustEnableTimePasses();
+
+    /** Print the pass timings since static dtors aren't picking them up. */
+    fn LLVMRustPrintPassTimings();
+
     /** Links LLVM modules together. `Src` is destroyed by this call and
         must never be referenced again. */
     fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool;
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index b57695199f9..2a3d8aeb79e 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -16,6 +16,8 @@
 #include "llvm/PassManager.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Timer.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetSelect.h"
 #include "llvm/Target/TargetRegistry.h"
@@ -121,3 +123,13 @@ extern "C" LLVMValueRef LLVMRustConstSmallInt(LLVMTypeRef IntTy, unsigned N,
                                               LLVMBool SignExtend) {
   return LLVMConstInt(IntTy, (unsigned long long)N, SignExtend);
 }
+
+extern bool llvm::TimePassesIsEnabled;
+extern "C" void LLVMRustEnableTimePasses() {
+  TimePassesIsEnabled = true;
+}
+
+extern "C" void LLVMRustPrintPassTimings() {
+  raw_fd_ostream OS (2, false); // stderr.
+  TimerGroup::printAll(OS);
+}
diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in
index 2da66c2408e..212c5be1ed4 100644
--- a/src/rustllvm/rustllvm.def.in
+++ b/src/rustllvm/rustllvm.def.in
@@ -1,9 +1,11 @@
 LLVMRustCreateMemoryBufferWithContentsOfFile
+LLVMRustEnableTimePasses
 LLVMRustWriteOutputFile
 LLVMRustGetLastError
 LLVMRustGetHostTriple
 LLVMRustConstSmallInt
 LLVMRustParseBitcode
+LLVMRustPrintPassTimings
 LLVMLinkModules
 LLVMCreateObjectFile
 LLVMDisposeObjectFile