Skip to content

Commit 6b34ba2

Browse files
committed
Update LLVM and jettison jit support
LLVM's JIT has been updated numerous times, and we haven't been tracking it at all. The existing LLVM glue code no longer compiles, and the JIT isn't used for anything currently. This also rebases out the FixedStackSegment support which we have added to LLVM. None of this is still in use by the compiler, and there's no need to keep this functionality around inside of LLVM. This is needed to unblock #10708 (where we're tripping an LLVM assertion).
1 parent b5bab85 commit 6b34ba2

File tree

10 files changed

+43
-463
lines changed

10 files changed

+43
-463
lines changed

src/librustc/back/link.rs

+28-141
Original file line numberDiff line numberDiff line change
@@ -82,111 +82,8 @@ pub fn WriteOutputFile(
8282
}
8383
}
8484

85-
pub mod jit {
86-
87-
use back::link::llvm_err;
88-
use driver::session::Session;
89-
use lib::llvm::llvm;
90-
use lib::llvm::{ModuleRef, ContextRef, ExecutionEngineRef};
91-
92-
use std::c_str::ToCStr;
93-
use std::cast;
94-
use std::local_data;
95-
use std::unstable::intrinsics;
96-
97-
struct LLVMJITData {
98-
ee: ExecutionEngineRef,
99-
llcx: ContextRef
100-
}
101-
102-
pub trait Engine {}
103-
impl Engine for LLVMJITData {}
104-
105-
impl Drop for LLVMJITData {
106-
fn drop(&mut self) {
107-
unsafe {
108-
llvm::LLVMDisposeExecutionEngine(self.ee);
109-
llvm::LLVMContextDispose(self.llcx);
110-
}
111-
}
112-
}
113-
114-
pub fn exec(sess: Session,
115-
c: ContextRef,
116-
m: ModuleRef,
117-
stacks: bool) {
118-
unsafe {
119-
let manager = llvm::LLVMRustPrepareJIT(intrinsics::morestack_addr());
120-
121-
// We need to tell JIT where to resolve all linked
122-
// symbols from. The equivalent of -lstd, -lcore, etc.
123-
// By default the JIT will resolve symbols from the extra and
124-
// core linked into rustc. We don't want that,
125-
// incase the user wants to use an older extra library.
126-
127-
// We custom-build a JIT execution engine via some rust wrappers
128-
// first. This wrappers takes ownership of the module passed in.
129-
let ee = llvm::LLVMRustBuildJIT(manager, m, stacks);
130-
if ee.is_null() {
131-
llvm::LLVMContextDispose(c);
132-
llvm_err(sess, ~"Could not create the JIT");
133-
}
134-
135-
// Next, we need to get a handle on the _rust_main function by
136-
// looking up it's corresponding ValueRef and then requesting that
137-
// the execution engine compiles the function.
138-
let fun = "_rust_main".with_c_str(|entry| {
139-
llvm::LLVMGetNamedFunction(m, entry)
140-
});
141-
if fun.is_null() {
142-
llvm::LLVMDisposeExecutionEngine(ee);
143-
llvm::LLVMContextDispose(c);
144-
llvm_err(sess, ~"Could not find _rust_main in the JIT");
145-
}
146-
147-
// Finally, once we have the pointer to the code, we can do some
148-
// closure magic here to turn it straight into a callable rust
149-
// closure
150-
let code = llvm::LLVMGetPointerToGlobal(ee, fun);
151-
assert!(!code.is_null());
152-
let func: extern "Rust" fn() = cast::transmute(code);
153-
func();
154-
155-
// Currently there is no method of re-using the executing engine
156-
// from LLVM in another call to the JIT. While this kinda defeats
157-
// the purpose of having a JIT in the first place, there isn't
158-
// actually much code currently which would re-use data between
159-
// different invocations of this. Additionally, the compilation
160-
// model currently isn't designed to support this scenario.
161-
//
162-
// We can't destroy the engine/context immediately here, however,
163-
// because of annihilation. The JIT code contains drop glue for any
164-
// types defined in the crate we just ran, and if any of those boxes
165-
// are going to be dropped during annihilation, the drop glue must
166-
// be run. Hence, we need to transfer ownership of this jit engine
167-
// to the caller of this function. To be convenient for now, we
168-
// shove it into TLS and have someone else remove it later on.
169-
let data = ~LLVMJITData { ee: ee, llcx: c };
170-
set_engine(data as ~Engine);
171-
}
172-
}
173-
174-
// The stage1 compiler won't work, but that doesn't really matter. TLS
175-
// changed only very recently to allow storage of owned values.
176-
local_data_key!(engine_key: ~Engine)
177-
178-
fn set_engine(engine: ~Engine) {
179-
local_data::set(engine_key, engine)
180-
}
181-
182-
pub fn consume_engine() -> Option<~Engine> {
183-
local_data::pop(engine_key)
184-
}
185-
}
186-
18785
pub mod write {
18886

189-
use back::link::jit;
19087
use back::link::{WriteOutputFile, output_type};
19188
use back::link::{output_type_assembly, output_type_bitcode};
19289
use back::link::{output_type_exe, output_type_llvm_assembly};
@@ -307,48 +204,38 @@ pub mod write {
307204
})
308205
}
309206

310-
if sess.opts.jit {
311-
// If we are using JIT, go ahead and create and execute the
312-
// engine now. JIT execution takes ownership of the module and
313-
// context, so don't dispose
314-
jit::exec(sess, llcx, llmod, true);
315-
} else {
316-
// Create a codegen-specific pass manager to emit the actual
317-
// assembly or object files. This may not end up getting used,
318-
// but we make it anyway for good measure.
319-
let cpm = llvm::LLVMCreatePassManager();
320-
llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod);
321-
llvm::LLVMRustAddLibraryInfo(cpm, llmod);
322-
323-
match output_type {
324-
output_type_none => {}
325-
output_type_bitcode => {
326-
output.with_c_str(|buf| {
327-
llvm::LLVMWriteBitcodeToFile(llmod, buf);
328-
})
329-
}
330-
output_type_llvm_assembly => {
331-
output.with_c_str(|output| {
332-
llvm::LLVMRustPrintModule(cpm, llmod, output)
333-
})
334-
}
335-
output_type_assembly => {
336-
WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::AssemblyFile);
337-
}
338-
output_type_exe | output_type_object => {
339-
WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::ObjectFile);
340-
}
207+
// Create a codegen-specific pass manager to emit the actual
208+
// assembly or object files. This may not end up getting used,
209+
// but we make it anyway for good measure.
210+
let cpm = llvm::LLVMCreatePassManager();
211+
llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod);
212+
llvm::LLVMRustAddLibraryInfo(cpm, llmod);
213+
214+
match output_type {
215+
output_type_none => {}
216+
output_type_bitcode => {
217+
output.with_c_str(|buf| {
218+
llvm::LLVMWriteBitcodeToFile(llmod, buf);
219+
})
220+
}
221+
output_type_llvm_assembly => {
222+
output.with_c_str(|output| {
223+
llvm::LLVMRustPrintModule(cpm, llmod, output)
224+
})
225+
}
226+
output_type_assembly => {
227+
WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::AssemblyFile);
228+
}
229+
output_type_exe | output_type_object => {
230+
WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::ObjectFile);
341231
}
342-
343-
llvm::LLVMDisposePassManager(cpm);
344232
}
345233

234+
llvm::LLVMDisposePassManager(cpm);
235+
346236
llvm::LLVMRustDisposeTargetMachine(tm);
347-
// the jit takes ownership of these two items
348-
if !sess.opts.jit {
349-
llvm::LLVMDisposeModule(llmod);
350-
llvm::LLVMContextDispose(llcx);
351-
}
237+
llvm::LLVMDisposeModule(llmod);
238+
llvm::LLVMContextDispose(llcx);
352239
if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); }
353240
}
354241
}

src/librustc/driver/driver.rs

-7
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,6 @@ pub fn stop_after_phase_5(sess: Session) -> bool {
419419
debug!("not building executable, returning early from compile_input");
420420
return true;
421421
}
422-
423-
if sess.opts.jit {
424-
debug!("running JIT, returning early from compile_input");
425-
return true;
426-
}
427422
return false;
428423
}
429424

@@ -751,7 +746,6 @@ pub fn build_session_options(binary: @str,
751746
} else { No }
752747
};
753748
let gc = debugging_opts & session::gc != 0;
754-
let jit = debugging_opts & session::jit != 0;
755749
let extra_debuginfo = debugging_opts & session::extra_debug_info != 0;
756750
let debuginfo = debugging_opts & session::debug_info != 0 ||
757751
extra_debuginfo;
@@ -802,7 +796,6 @@ pub fn build_session_options(binary: @str,
802796
extra_debuginfo: extra_debuginfo,
803797
lint_opts: lint_opts,
804798
save_temps: save_temps,
805-
jit: jit,
806799
output_type: output_type,
807800
addl_lib_search_paths: @mut addl_lib_search_paths,
808801
ar: ar,

src/librustc/driver/session.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,18 @@ pub static count_type_sizes: uint = 1 << 14;
5555
pub static meta_stats: uint = 1 << 15;
5656
pub static no_opt: uint = 1 << 16;
5757
pub static gc: uint = 1 << 17;
58-
pub static jit: uint = 1 << 18;
59-
pub static debug_info: uint = 1 << 19;
60-
pub static extra_debug_info: uint = 1 << 20;
61-
pub static print_link_args: uint = 1 << 21;
62-
pub static no_debug_borrows: uint = 1 << 22;
63-
pub static lint_llvm: uint = 1 << 23;
64-
pub static print_llvm_passes: uint = 1 << 24;
65-
pub static no_vectorize_loops: uint = 1 << 25;
66-
pub static no_vectorize_slp: uint = 1 << 26;
67-
pub static no_prepopulate_passes: uint = 1 << 27;
68-
pub static use_softfp: uint = 1 << 28;
69-
pub static gen_crate_map: uint = 1 << 29;
70-
pub static prefer_dynamic: uint = 1 << 30;
58+
pub static debug_info: uint = 1 << 18;
59+
pub static extra_debug_info: uint = 1 << 19;
60+
pub static print_link_args: uint = 1 << 20;
61+
pub static no_debug_borrows: uint = 1 << 21;
62+
pub static lint_llvm: uint = 1 << 22;
63+
pub static print_llvm_passes: uint = 1 << 23;
64+
pub static no_vectorize_loops: uint = 1 << 24;
65+
pub static no_vectorize_slp: uint = 1 << 25;
66+
pub static no_prepopulate_passes: uint = 1 << 26;
67+
pub static use_softfp: uint = 1 << 27;
68+
pub static gen_crate_map: uint = 1 << 28;
69+
pub static prefer_dynamic: uint = 1 << 29;
7170

7271
pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
7372
~[("verbose", "in general, enable more debug printouts", verbose),
@@ -95,7 +94,6 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
9594
("no-opt", "do not optimize, even if -O is passed", no_opt),
9695
("print-link-args", "Print the arguments passed to the linker", print_link_args),
9796
("gc", "Garbage collect shared data (experimental)", gc),
98-
("jit", "Execute using JIT (experimental)", jit),
9997
("extra-debug-info", "Extra debugging info (experimental)",
10098
extra_debug_info),
10199
("debug-info", "Produce debug info (experimental)", debug_info),
@@ -146,7 +144,6 @@ pub struct options {
146144
extra_debuginfo: bool,
147145
lint_opts: ~[(lint::lint, lint::level)],
148146
save_temps: bool,
149-
jit: bool,
150147
output_type: back::link::output_type,
151148
addl_lib_search_paths: @mut HashSet<Path>, // This is mutable for rustpkg, which
152149
// updates search paths based on the
@@ -370,7 +367,6 @@ pub fn basic_options() -> @options {
370367
extra_debuginfo: false,
371368
lint_opts: ~[],
372369
save_temps: false,
373-
jit: false,
374370
output_type: link::output_type_exe,
375371
addl_lib_search_paths: @mut HashSet::new(),
376372
ar: None,

src/librustc/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
363363
let _finally = finally { ch: ch };
364364

365365
f(demitter);
366-
367-
// Due reasons explain in #7732, if there was a jit execution context it
368-
// must be consumed and passed along to our parent task.
369-
back::link::jit::consume_engine()
370366
}) {
371367
result::Ok(_) => { /* fallthrough */ }
372368
result::Err(_) => {

src/librustc/lib/llvm.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1441,18 +1441,6 @@ pub mod llvm {
14411441
call. */
14421442
pub fn LLVMRustGetLastError() -> *c_char;
14431443

1444-
/** Prepare the JIT. Returns a memory manager that can load crates. */
1445-
pub fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1446-
1447-
/** Load a crate into the memory manager. */
1448-
pub fn LLVMRustLoadCrate(MM: *(), Filename: *c_char) -> bool;
1449-
1450-
/** Execute the JIT engine. */
1451-
pub fn LLVMRustBuildJIT(MM: *(),
1452-
M: ModuleRef,
1453-
EnableSegmentedStacks: bool)
1454-
-> ExecutionEngineRef;
1455-
14561444
/// Print the pass timings since static dtors aren't picking them up.
14571445
pub fn LLVMRustPrintPassTimings();
14581446

src/llvm

Submodule llvm updated 2522 files

src/rustllvm/PassWrapper.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ LLVMRustCreateTargetMachine(const char *triple,
8181
TargetOptions Options;
8282
Options.NoFramePointerElim = true;
8383
Options.EnableSegmentedStacks = EnableSegmentedStacks;
84-
Options.FixedStackSegmentSize = 2 * 1024 * 1024; // XXX: This is too big.
8584
Options.FloatABIType =
8685
(Trip.getEnvironment() == Triple::GNUEABIHF) ? FloatABI::Hard :
8786
FloatABI::Default;

0 commit comments

Comments
 (0)