Skip to content

Commit dc18321

Browse files
committed
Don't run passes again on JIT code
These passes are already run beforehand, no need to do them twice.
1 parent 079ffa3 commit dc18321

File tree

3 files changed

+17
-51
lines changed

3 files changed

+17
-51
lines changed

src/librustc/back/link.rs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,21 @@ pub mod jit {
102102
use back::link::llvm_err;
103103
use driver::session::Session;
104104
use lib::llvm::llvm;
105-
use lib::llvm::{ModuleRef, PassManagerRef, ContextRef};
105+
use lib::llvm::{ModuleRef, ContextRef};
106106
use metadata::cstore;
107107

108108
use core::cast;
109-
use core::libc::c_int;
110109
use core::ptr;
111110
use core::str;
112-
113-
pub mod rusti {
114-
#[nolink]
115-
#[abi = "rust-intrinsic"]
116-
pub extern "rust-intrinsic" {
117-
pub fn morestack_addr() -> *();
118-
}
119-
}
120-
121-
pub struct Closure {
122-
code: *(),
123-
env: *(),
124-
}
111+
use core::sys;
112+
use core::unstable::intrinsics;
125113

126114
pub fn exec(sess: Session,
127-
pm: PassManagerRef,
128115
c: ContextRef,
129116
m: ModuleRef,
130-
opt: c_int,
131117
stacks: bool) {
132118
unsafe {
133-
let manager = llvm::LLVMRustPrepareJIT(rusti::morestack_addr());
119+
let manager = llvm::LLVMRustPrepareJIT(intrinsics::morestack_addr());
134120

135121
// We need to tell JIT where to resolve all linked
136122
// symbols from. The equivalent of -lstd, -lcore, etc.
@@ -156,7 +142,7 @@ pub mod jit {
156142

157143
// We custom-build a JIT execution engine via some rust wrappers
158144
// first. This wrappers takes ownership of the module passed in.
159-
let ee = llvm::LLVMRustBuildJIT(manager, pm, m, opt, stacks);
145+
let ee = llvm::LLVMRustBuildJIT(manager, m, stacks);
160146
if ee.is_null() {
161147
llvm::LLVMContextDispose(c);
162148
llvm_err(sess, ~"Could not create the JIT");
@@ -179,7 +165,7 @@ pub mod jit {
179165
// closure
180166
let code = llvm::LLVMGetPointerToGlobal(ee, fun);
181167
assert!(!code.is_null());
182-
let closure = Closure {
168+
let closure = sys::Closure {
183169
code: code,
184170
env: ptr::null()
185171
};
@@ -282,7 +268,17 @@ pub mod write {
282268
debug!("Running Module Optimization Pass");
283269
mpm.run(llmod);
284270

285-
if is_object_or_assembly_or_exe(output_type) || opts.jit {
271+
if opts.jit {
272+
// If we are using JIT, go ahead and create and execute the
273+
// engine now. JIT execution takes ownership of the module and
274+
// context, so don't dispose and return.
275+
jit::exec(sess, llcx, llmod, true);
276+
277+
if sess.time_llvm_passes() {
278+
llvm::LLVMRustPrintPassTimings();
279+
}
280+
return;
281+
} else if is_object_or_assembly_or_exe(output_type) {
286282
let LLVMOptNone = 0 as c_int; // -O0
287283
let LLVMOptLess = 1 as c_int; // -O1
288284
let LLVMOptDefault = 2 as c_int; // -O2, -Os
@@ -295,20 +291,6 @@ pub mod write {
295291
session::Aggressive => LLVMOptAggressive
296292
};
297293

298-
if opts.jit {
299-
// If we are using JIT, go ahead and create and
300-
// execute the engine now.
301-
// JIT execution takes ownership of the module,
302-
// so don't dispose and return.
303-
304-
jit::exec(sess, pm.llpm, llcx, llmod, CodeGenOptLevel, true);
305-
306-
if sess.time_llvm_passes() {
307-
llvm::LLVMRustPrintPassTimings();
308-
}
309-
return;
310-
}
311-
312294
let FileType;
313295
if output_type == output_type_object ||
314296
output_type == output_type_exe {

src/librustc/lib/llvm.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,9 +1828,7 @@ pub mod llvm {
18281828
/** Execute the JIT engine. */
18291829
#[fast_ffi]
18301830
pub unsafe fn LLVMRustBuildJIT(MM: *(),
1831-
PM: PassManagerRef,
18321831
M: ModuleRef,
1833-
OptLevel: c_int,
18341832
EnableSegmentedStacks: bool) -> ExecutionEngineRef;
18351833

18361834
/** Parses the bitcode in the given memory buffer. */

src/rustllvm/RustWrapper.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ LLVMRustLoadCrate(void* mem, const char* crate) {
331331

332332
extern "C" LLVMExecutionEngineRef
333333
LLVMRustBuildJIT(void* mem,
334-
LLVMPassManagerRef PMR,
335334
LLVMModuleRef M,
336-
CodeGenOpt::Level OptLevel,
337335
bool EnableSegmentedStacks) {
338336

339337
InitializeNativeTarget();
@@ -346,25 +344,13 @@ LLVMRustBuildJIT(void* mem,
346344
Options.JITEmitDebugInfo = true;
347345
Options.NoFramePointerElim = true;
348346
Options.EnableSegmentedStacks = EnableSegmentedStacks;
349-
PassManager *PM = unwrap<PassManager>(PMR);
350347
RustMCJITMemoryManager* MM = (RustMCJITMemoryManager*) mem;
351-
352348
assert(MM);
353349

354-
PM->add(createBasicAliasAnalysisPass());
355-
PM->add(createInstructionCombiningPass());
356-
PM->add(createReassociatePass());
357-
PM->add(createGVNPass());
358-
PM->add(createCFGSimplificationPass());
359-
PM->add(createFunctionInliningPass());
360-
PM->add(createPromoteMemoryToRegisterPass());
361-
PM->run(*unwrap(M));
362-
363350
ExecutionEngine* EE = EngineBuilder(unwrap(M))
364351
.setErrorStr(&Err)
365352
.setTargetOptions(Options)
366353
.setJITMemoryManager(MM)
367-
.setOptLevel(OptLevel)
368354
.setUseMCJIT(true)
369355
.setAllocateGVsWithCode(false)
370356
.create();

0 commit comments

Comments
 (0)