Skip to content

Commit 921fd5c

Browse files
committed
auto merge of #10758 : alexcrichton/rust/upgrade-llvm, r=thestinger
This upgrades LLVM in order to make progress on #10708, and it's also been awhile since we last upgraded! The contentious point of this upgrade is that all JIT support has been removed because LLVM is changing it and we're not keeping up with it.
2 parents b5bab85 + 88e64b9 commit 921fd5c

17 files changed

+60
-571
lines changed

mk/llvm.mk

+3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ endif
3737
# dependencies. In these cases, commit a change that touches
3838
# the stamp in the source dir.
3939
$$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
40+
@$$(call E, make: cleaning llvm)
4041
$(Q)$(MAKE) clean-llvm
42+
@$$(call E, make: done cleaning llvm)
43+
@mkdir -p $$(CFG_LLVM_INST_DIR_$(1))/bin
4144
touch $$@
4245

4346
endef

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/back/upcall.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,10 @@ use middle::trans::type_::Type;
1515
use lib::llvm::{ModuleRef, ValueRef};
1616

1717
pub struct Upcalls {
18-
trace: ValueRef,
1918
rust_personality: ValueRef,
20-
reset_stack_limit: ValueRef
2119
}
2220

2321
macro_rules! upcall (
24-
(fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
25-
let fn_ty = Type::func([ $($arg),* ], &$ret);
26-
base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty)
27-
});
28-
(nothrow fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
29-
let fn_ty = Type::func([ $($arg),* ], &$ret);
30-
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
31-
base::set_no_unwind(decl);
32-
decl
33-
});
3422
(nothrow fn $name:ident -> $ret:expr) => ({
3523
let fn_ty = Type::func([], &$ret);
3624
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
@@ -39,13 +27,9 @@ macro_rules! upcall (
3927
})
4028
)
4129

42-
pub fn declare_upcalls(targ_cfg: @session::config, llmod: ModuleRef) -> @Upcalls {
43-
let opaque_ptr = Type::i8().ptr_to();
44-
let int_ty = Type::int(targ_cfg.arch);
45-
30+
pub fn declare_upcalls(_targ_cfg: @session::config,
31+
llmod: ModuleRef) -> @Upcalls {
4632
@Upcalls {
47-
trace: upcall!(fn trace(opaque_ptr, opaque_ptr, int_ty) -> Type::void()),
4833
rust_personality: upcall!(nothrow fn rust_personality -> Type::i32()),
49-
reset_stack_limit: upcall!(nothrow fn reset_stack_limit -> Type::void())
5034
}
5135
}

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

+22-29
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,28 @@ pub static time_llvm_passes: uint = 1 << 3;
4444
pub static trans_stats: uint = 1 << 4;
4545
pub static asm_comments: uint = 1 << 5;
4646
pub static no_verify: uint = 1 << 6;
47-
pub static trace: uint = 1 << 7;
48-
pub static coherence: uint = 1 << 8;
49-
pub static borrowck_stats: uint = 1 << 9;
50-
pub static borrowck_note_pure: uint = 1 << 10;
51-
pub static borrowck_note_loan: uint = 1 << 11;
52-
pub static no_landing_pads: uint = 1 << 12;
53-
pub static debug_llvm: uint = 1 << 13;
54-
pub static count_type_sizes: uint = 1 << 14;
55-
pub static meta_stats: uint = 1 << 15;
56-
pub static no_opt: uint = 1 << 16;
57-
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;
47+
pub static coherence: uint = 1 << 7;
48+
pub static borrowck_stats: uint = 1 << 8;
49+
pub static borrowck_note_pure: uint = 1 << 9;
50+
pub static borrowck_note_loan: uint = 1 << 10;
51+
pub static no_landing_pads: uint = 1 << 11;
52+
pub static debug_llvm: uint = 1 << 12;
53+
pub static count_type_sizes: uint = 1 << 13;
54+
pub static meta_stats: uint = 1 << 14;
55+
pub static no_opt: uint = 1 << 15;
56+
pub static gc: uint = 1 << 16;
57+
pub static debug_info: uint = 1 << 17;
58+
pub static extra_debug_info: uint = 1 << 18;
59+
pub static print_link_args: uint = 1 << 19;
60+
pub static no_debug_borrows: uint = 1 << 20;
61+
pub static lint_llvm: uint = 1 << 21;
62+
pub static print_llvm_passes: uint = 1 << 22;
63+
pub static no_vectorize_loops: uint = 1 << 23;
64+
pub static no_vectorize_slp: uint = 1 << 24;
65+
pub static no_prepopulate_passes: uint = 1 << 25;
66+
pub static use_softfp: uint = 1 << 26;
67+
pub static gen_crate_map: uint = 1 << 27;
68+
pub static prefer_dynamic: uint = 1 << 28;
7169

7270
pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
7371
~[("verbose", "in general, enable more debug printouts", verbose),
@@ -79,7 +77,6 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
7977
("trans-stats", "gather trans statistics", trans_stats),
8078
("asm-comments", "generate comments into the assembly (may change behavior)", asm_comments),
8179
("no-verify", "skip LLVM verification", no_verify),
82-
("trace", "emit trace logs", trace),
8380
("coherence", "perform coherence checking", coherence),
8481
("borrowck-stats", "gather borrowck statistics", borrowck_stats),
8582
("borrowck-note-pure", "note where purity is req'd",
@@ -95,7 +92,6 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
9592
("no-opt", "do not optimize, even if -O is passed", no_opt),
9693
("print-link-args", "Print the arguments passed to the linker", print_link_args),
9794
("gc", "Garbage collect shared data (experimental)", gc),
98-
("jit", "Execute using JIT (experimental)", jit),
9995
("extra-debug-info", "Extra debugging info (experimental)",
10096
extra_debug_info),
10197
("debug-info", "Produce debug info (experimental)", debug_info),
@@ -146,7 +142,6 @@ pub struct options {
146142
extra_debuginfo: bool,
147143
lint_opts: ~[(lint::lint, lint::level)],
148144
save_temps: bool,
149-
jit: bool,
150145
output_type: back::link::output_type,
151146
addl_lib_search_paths: @mut HashSet<Path>, // This is mutable for rustpkg, which
152147
// updates search paths based on the
@@ -311,7 +306,6 @@ impl Session_ {
311306
pub fn asm_comments(&self) -> bool { self.debugging_opt(asm_comments) }
312307
pub fn no_verify(&self) -> bool { self.debugging_opt(no_verify) }
313308
pub fn lint_llvm(&self) -> bool { self.debugging_opt(lint_llvm) }
314-
pub fn trace(&self) -> bool { self.debugging_opt(trace) }
315309
pub fn coherence(&self) -> bool { self.debugging_opt(coherence) }
316310
pub fn borrowck_stats(&self) -> bool { self.debugging_opt(borrowck_stats) }
317311
pub fn borrowck_note_pure(&self) -> bool {
@@ -370,7 +364,6 @@ pub fn basic_options() -> @options {
370364
extra_debuginfo: false,
371365
lint_opts: ~[],
372366
save_temps: false,
373-
jit: false,
374367
output_type: link::output_type_exe,
375368
addl_lib_search_paths: @mut HashSet::new(),
376369
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

0 commit comments

Comments
 (0)