about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorZack Corr <zack@z0w0.me>2012-08-25 14:54:30 +1000
committerBrian Anderson <banderson@mozilla.com>2012-08-31 16:20:35 -0700
commitd7aa9918ef1673edcef261da41075203de5b15b3 (patch)
tree7dc7164676cbbf0cd18a56c6e67ad3bfebd2a7d7 /src/rustc
parent97bb812238b859db453cf935373f32ff2afa7887 (diff)
downloadrust-d7aa9918ef1673edcef261da41075203de5b15b3.tar.gz
rust-d7aa9918ef1673edcef261da41075203de5b15b3.zip
Add experimental JIT compiler
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/back/link.rs26
-rw-r--r--src/rustc/driver/driver.rs6
-rw-r--r--src/rustc/driver/rustc.rs1
-rw-r--r--src/rustc/driver/session.rs2
-rw-r--r--src/rustc/lib/llvm.rs6
5 files changed, 39 insertions, 2 deletions
diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs
index a81755be933..04c38c11d62 100644
--- a/src/rustc/back/link.rs
+++ b/src/rustc/back/link.rs
@@ -76,6 +76,7 @@ mod write {
         // Generate a pre-optimization intermediate file if -save-temps was
         // specified.
 
+
         if opts.save_temps {
             match opts.output_type {
               output_type_bitcode => {
@@ -135,7 +136,7 @@ mod write {
             llvm::LLVMPassManagerBuilderDispose(MPMB);
         }
         if !sess.no_verify() { llvm::LLVMAddVerifierPass(pm.llpm); }
-        if is_object_or_assembly_or_exe(opts.output_type) {
+        if is_object_or_assembly_or_exe(opts.output_type) || opts.jit {
             let LLVMOptNone       = 0 as c_int; // -O0
             let LLVMOptLess       = 1 as c_int; // -O1
             let LLVMOptDefault    = 2 as c_int; // -O2, -Os
@@ -148,6 +149,29 @@ mod write {
               session::Aggressive => LLVMOptAggressive
             };
 
+            if opts.jit {
+                // If we are using JIT, go ahead and create and
+                // execute the engine now.
+
+                /*llvm::LLVMAddBasicAliasAnalysisPass(pm.llpm);
+                llvm::LLVMAddInstructionCombiningPass(pm.llpm);
+                llvm::LLVMAddReassociatePass(pm.llpm);
+                llvm::LLVMAddGVNPass(pm.llpm);
+                llvm::LLVMAddCFGSimplificationPass(pm.llpm);*/
+
+                // JIT execution takes ownership of the module,
+                // so don't dispose and return.
+
+                if !llvm::LLVMRustJIT(pm.llpm,
+                                      llmod,
+                                      CodeGenOptLevel,
+                                      true) {
+                    llvm_err(sess, ~"Could not JIT");
+                }
+                if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); }
+                return;
+            }
+
             let mut FileType;
             if opts.output_type == output_type_object ||
                    opts.output_type == output_type_exe {
diff --git a/src/rustc/driver/driver.rs b/src/rustc/driver/driver.rs
index c9be01f4d56..2d5b36debaa 100644
--- a/src/rustc/driver/driver.rs
+++ b/src/rustc/driver/driver.rs
@@ -259,7 +259,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
 
     let stop_after_codegen =
         sess.opts.output_type != link::output_type_exe ||
-            sess.opts.static && sess.building_library;
+        (sess.opts.static && sess.building_library)    ||
+        sess.opts.jit;
 
     if stop_after_codegen { return {crate: crate, tcx: Some(ty_cx)}; }
 
@@ -483,6 +484,7 @@ fn build_session_options(matches: getopts::Matches,
         llvm::LLVMSetDebug(1);
     }
 
+    let jit = opt_present(matches, ~"jit");
     let output_type =
         if parse_only || no_trans {
             link::output_type_none
@@ -545,6 +547,7 @@ fn build_session_options(matches: getopts::Matches,
           extra_debuginfo: extra_debuginfo,
           lint_opts: lint_opts,
           save_temps: save_temps,
+          jit: jit,
           output_type: output_type,
           addl_lib_search_paths: addl_lib_search_paths,
           maybe_sysroot: sysroot_opt,
@@ -620,6 +623,7 @@ fn opts() -> ~[getopts::Opt] {
           optopt(~"o"), optopt(~"out-dir"), optflag(~"xg"),
           optflag(~"c"), optflag(~"g"), optflag(~"save-temps"),
           optopt(~"sysroot"), optopt(~"target"),
+          optflag(~"jit"),
 
           optmulti(~"W"), optmulti(~"warn"),
           optmulti(~"A"), optmulti(~"allow"),
diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs
index d1929a68629..42982550325 100644
--- a/src/rustc/driver/rustc.rs
+++ b/src/rustc/driver/rustc.rs
@@ -42,6 +42,7 @@ Options:
     -L <path>          Add a directory to the library search path
     --lib              Compile a library crate
     --ls               List the symbols defined by a compiled library crate
+    --jit              Execute using JIT (experimental)
     --no-trans         Run all passes except translation; no output
     -O                 Equivalent to --opt-level=2
     -o <filename>      Write output to <filename>
diff --git a/src/rustc/driver/session.rs b/src/rustc/driver/session.rs
index 59c4e5697ad..47aa3019de1 100644
--- a/src/rustc/driver/session.rs
+++ b/src/rustc/driver/session.rs
@@ -108,6 +108,7 @@ type options =
      extra_debuginfo: bool,
      lint_opts: ~[(lint::lint, lint::level)],
      save_temps: bool,
+     jit: bool,
      output_type: back::link::output_type,
      addl_lib_search_paths: ~[Path],
      maybe_sysroot: Option<Path>,
@@ -249,6 +250,7 @@ fn basic_options() -> @options {
         extra_debuginfo: false,
         lint_opts: ~[],
         save_temps: false,
+        jit: false,
         output_type: link::output_type_exe,
         addl_lib_search_paths: ~[],
         maybe_sysroot: None,
diff --git a/src/rustc/lib/llvm.rs b/src/rustc/lib/llvm.rs
index 1440a654a89..5c8bab166ec 100644
--- a/src/rustc/lib/llvm.rs
+++ b/src/rustc/lib/llvm.rs
@@ -986,6 +986,12 @@ extern mod llvm {
         call. */
     fn LLVMRustGetLastError() -> *c_char;
 
+    /** JIT the module. **/
+    fn LLVMRustJIT(PM: PassManagerRef,
+                   M: ModuleRef,
+                   OptLevel: c_int,
+                   EnableSegmentedStacks: bool) -> bool;
+
     /** Parses the bitcode in the given memory buffer. */
     fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;