]> git.lizzy.rs Git - rust.git/commitdiff
Save bitcode before LTO when -C save-temps is given
authorSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 21 Sep 2015 15:33:17 +0000 (00:33 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 21 Sep 2015 15:33:17 +0000 (00:33 +0900)
src/librustc_trans/back/lto.rs
src/librustc_trans/back/write.rs

index 00439c1fd5878ae46cb5829dc0929b24bbbeb406..ba6ec895a8e12e356d23f3094ad5e99a9cfb9ddc 100644 (file)
@@ -15,6 +15,7 @@
 use llvm::archive_ro::ArchiveRO;
 use llvm::{ModuleRef, TargetMachineRef, True, False};
 use rustc::util::common::time;
+use rustc::util::common::path2cstr;
 use back::write::{ModuleConfig, with_llvm_pmb};
 
 use libc;
@@ -24,7 +25,9 @@
 
 pub fn run(sess: &session::Session, llmod: ModuleRef,
            tm: TargetMachineRef, reachable: &[String],
-           config: &ModuleConfig) {
+           config: &ModuleConfig,
+           name_extra: &str,
+           output_names: &config::OutputFilenames) {
     if sess.opts.cg.prefer_dynamic {
         sess.err("cannot prefer dynamic linking when performing LTO");
         sess.note("only 'staticlib' and 'bin' outputs are supported with LTO");
@@ -124,6 +127,14 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
         }
     }
 
+    if sess.opts.cg.save_temps {
+        let path = output_names.with_extension(&format!("{}.no-opt.lto.bc", name_extra));
+        let cstr = path2cstr(&path);
+        unsafe {
+            llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
+        }
+    }
+
     // Now we have one massive module inside of llmod. Time to run the
     // LTO-specific optimization passes that LLVM provides.
     //
index d75f2fcf126a941084612637d6237ba555b1d8f0..94e2891f40fa070d262de6674e241281e015ce59 100644 (file)
@@ -496,7 +496,8 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
         match cgcx.lto_ctxt {
             Some((sess, reachable)) if sess.lto() =>  {
                 time(sess.time_passes(), "all lto passes", ||
-                     lto::run(sess, llmod, tm, reachable, &config));
+                     lto::run(sess, llmod, tm, reachable, &config,
+                              &name_extra, &output_names));
 
                 if config.emit_lto_bc {
                     let name = format!("{}.lto.bc", name_extra);