Skip to content

Commit f8bf57d

Browse files
committed
rustc: Leak the LLVM module and context. rust-lang#3552
1 parent 2c0f9bd commit f8bf57d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/librustc/back/link.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,12 @@ pub mod write {
392392
}
393393
// Clean up and return
394394

395-
llvm::LLVMDisposeModule(llmod);
396-
llvm::LLVMContextDispose(llcx);
395+
// Save some time by not destroying the LLVM module
396+
if !sess.opts.leak_llvm {
397+
llvm::LLVMDisposeModule(llmod);
398+
llvm::LLVMContextDispose(llcx);
399+
}
400+
397401
if sess.time_llvm_passes() {
398402
llvm::LLVMRustPrintPassTimings();
399403
}
@@ -413,8 +417,12 @@ pub mod write {
413417
}
414418
}
415419

416-
llvm::LLVMDisposeModule(llmod);
417-
llvm::LLVMContextDispose(llcx);
420+
// Save some time by not destroying the LLVM module
421+
if !sess.opts.leak_llvm {
422+
llvm::LLVMDisposeModule(llmod);
423+
llvm::LLVMContextDispose(llcx);
424+
}
425+
418426
if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); }
419427
}
420428
}

src/librustc/driver/driver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ pub fn build_session_options(binary: @str,
762762
parse_only: parse_only,
763763
no_trans: no_trans,
764764
debugging_opts: debugging_opts,
765-
android_cross_path: android_cross_path
765+
android_cross_path: android_cross_path,
766+
leak_llvm: true
766767
};
767768
return sopts;
768769
}

src/librustc/driver/session.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ pub struct options {
166166
no_trans: bool,
167167
debugging_opts: uint,
168168
android_cross_path: Option<~str>,
169+
// Destroying the LLVM module takes significant time. Standalone rustc
170+
// will just leak it to save precious seconds.
171+
leak_llvm: bool
169172
}
170173

171174
pub struct crate_metadata {
@@ -350,6 +353,7 @@ pub fn basic_options() -> @options {
350353
no_trans: false,
351354
debugging_opts: 0u,
352355
android_cross_path: None,
356+
leak_llvm: false
353357
}
354358
}
355359

0 commit comments

Comments
 (0)