Skip to content

Commit e910a24

Browse files
authored
Merge pull request rust-lang#1093 from bjorn3/use_new_module_interface
Use the new cranelift-module interface
2 parents 1cd63dc + 0a5968d commit e910a24

36 files changed

+220
-253
lines changed

Cargo.lock

Lines changed: 27 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime/", bran
1515
cranelift-simplejit = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", optional = true }
1616
cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" }
1717
target-lexicon = "0.11.0"
18-
gimli = { version = "0.21.0", default-features = false, features = ["write"]}
18+
gimli = { version = "0.22.0", default-features = false, features = ["write"]}
1919
object = { version = "0.21.1", default-features = false, features = ["std", "read_core", "write", "coff", "elf", "macho", "pe"] }
2020

2121
ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }

src/abi/comments.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use cranelift_codegen::entity::EntityRef;
1010
use crate::abi::pass_mode::*;
1111
use crate::prelude::*;
1212

13-
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Backend>) {
13+
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
1414
fx.add_global_comment(format!(
1515
"kind loc.idx param pass mode ty"
1616
));
1717
}
1818

1919
pub(super) fn add_arg_comment<'tcx>(
20-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
20+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
2121
kind: &str,
2222
local: Option<mir::Local>,
2323
local_field: Option<usize>,
@@ -54,15 +54,15 @@ pub(super) fn add_arg_comment<'tcx>(
5454
));
5555
}
5656

57-
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Backend>) {
57+
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
5858
fx.add_global_comment(String::new());
5959
fx.add_global_comment(format!(
6060
"kind local ty size align (abi,pref)"
6161
));
6262
}
6363

6464
pub(super) fn add_local_place_comments<'tcx>(
65-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
65+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
6666
place: CPlace<'tcx>,
6767
local: Local,
6868
) {

src/abi/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
238238
/// Instance must be monomorphized
239239
pub(crate) fn import_function<'tcx>(
240240
tcx: TyCtxt<'tcx>,
241-
module: &mut Module<impl Backend>,
241+
module: &mut impl Module,
242242
inst: Instance<'tcx>,
243243
) -> FuncId {
244244
let (name, sig) = get_function_name_and_sig(tcx, module.isa().triple(), inst, true);
@@ -247,7 +247,7 @@ pub(crate) fn import_function<'tcx>(
247247
.unwrap()
248248
}
249249

250-
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
250+
impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
251251
/// Instance must be monomorphized
252252
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
253253
let func_id = import_function(self.tcx, &mut self.cx.module, inst);
@@ -329,7 +329,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
329329

330330
/// Make a [`CPlace`] capable of holding value of the specified type.
331331
fn make_local_place<'tcx>(
332-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
332+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
333333
local: Local,
334334
layout: TyAndLayout<'tcx>,
335335
is_ssa: bool,
@@ -351,7 +351,7 @@ fn make_local_place<'tcx>(
351351
}
352352

353353
pub(crate) fn codegen_fn_prelude<'tcx>(
354-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
354+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
355355
start_block: Block,
356356
) {
357357
let ssa_analyzed = crate::analyze::analyze(fx);
@@ -488,7 +488,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
488488
}
489489

490490
pub(crate) fn codegen_terminator_call<'tcx>(
491-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
491+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
492492
span: Span,
493493
current_block: Block,
494494
func: &Operand<'tcx>,
@@ -701,7 +701,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
701701
}
702702

703703
pub(crate) fn codegen_drop<'tcx>(
704-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
704+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
705705
span: Span,
706706
drop_place: CPlace<'tcx>,
707707
) {

src/abi/pass_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>)
122122

123123
/// Get a set of values to be passed as function arguments.
124124
pub(super) fn adjust_arg_for_abi<'tcx>(
125-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
125+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
126126
arg: CValue<'tcx>,
127127
) -> EmptySinglePair<Value> {
128128
match get_pass_mode(fx.tcx, arg.layout()) {
@@ -142,7 +142,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
142142
/// Create a [`CValue`] containing the value of a function parameter adding clif function parameters
143143
/// as necessary.
144144
pub(super) fn cvalue_for_param<'tcx>(
145-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
145+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
146146
start_block: Block,
147147
#[cfg_attr(not(debug_assertions), allow(unused_variables))] local: Option<mir::Local>,
148148
#[cfg_attr(not(debug_assertions), allow(unused_variables))] local_field: Option<usize>,

src/abi/returning.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::abi::pass_mode::*;
44
use crate::prelude::*;
55

6-
fn return_layout<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> TyAndLayout<'tcx> {
6+
fn return_layout<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Module>) -> TyAndLayout<'tcx> {
77
fx.layout_of(fx.monomorphize(&fx.mir.local_decls[RETURN_PLACE].ty))
88
}
99

@@ -22,7 +22,7 @@ pub(crate) fn can_return_to_ssa_var<'tcx>(
2222
/// Return a place where the return value of the current function can be written to. If necessary
2323
/// this adds an extra parameter pointing to where the return value needs to be stored.
2424
pub(super) fn codegen_return_param<'tcx>(
25-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
25+
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
2626
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
2727
start_block: Block,
2828
) -> CPlace<'tcx> {
@@ -66,11 +66,11 @@ pub(super) fn codegen_return_param<'tcx>(
6666

6767
/// Invokes the closure with if necessary a value representing the return pointer. When the closure
6868
/// returns the call return value(s) if any are written to the correct place.
69-
pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
70-
fx: &mut FunctionCx<'_, 'tcx, B>,
69+
pub(super) fn codegen_with_call_return_arg<'tcx, M: Module, T>(
70+
fx: &mut FunctionCx<'_, 'tcx, M>,
7171
fn_sig: FnSig<'tcx>,
7272
ret_place: Option<CPlace<'tcx>>,
73-
f: impl FnOnce(&mut FunctionCx<'_, 'tcx, B>, Option<Value>) -> (Inst, T),
73+
f: impl FnOnce(&mut FunctionCx<'_, 'tcx, M>, Option<Value>) -> (Inst, T),
7474
) -> (Inst, T) {
7575
let ret_layout = fx.layout_of(fn_sig.output());
7676

@@ -110,7 +110,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
110110
}
111111

112112
/// Codegen a return instruction with the right return value(s) if any.
113-
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Backend>) {
113+
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Module>) {
114114
match get_pass_mode(fx.tcx, return_layout(fx)) {
115115
PassMode::NoPass | PassMode::ByRef { size: Some(_) } => {
116116
fx.bcx.ins().return_(&[]);

src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
99
/// Returns whether an allocator shim was created
1010
pub(crate) fn codegen(
1111
tcx: TyCtxt<'_>,
12-
module: &mut Module<impl Backend + 'static>,
12+
module: &mut impl Module,
1313
unwind_context: &mut UnwindContext<'_>,
1414
) -> bool {
1515
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| {
@@ -27,7 +27,7 @@ pub(crate) fn codegen(
2727
}
2828

2929
fn codegen_inner(
30-
module: &mut Module<impl Backend + 'static>,
30+
module: &mut impl Module,
3131
unwind_context: &mut UnwindContext<'_>,
3232
kind: AllocatorKind,
3333
) {

src/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) enum SsaKind {
1111
Ssa,
1212
}
1313

14-
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind> {
14+
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, SsaKind> {
1515
let mut flag_map = fx
1616
.mir
1717
.local_decls

src/atomic_shim.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
1111
libc::PTHREAD_MUTEX_INITIALIZER;
1212

1313
pub(crate) fn init_global_lock(
14-
module: &mut Module<impl Backend>,
14+
module: &mut impl Module,
1515
bcx: &mut FunctionBuilder<'_>,
1616
use_jit: bool,
1717
) {
@@ -24,13 +24,13 @@ pub(crate) fn init_global_lock(
2424

2525
let mut data_ctx = DataContext::new();
2626
data_ctx.define_zeroinit(1024); // 1024 bytes should be big enough on all platforms.
27+
data_ctx.set_align(16);
2728
let atomic_mutex = module
2829
.declare_data(
2930
"__cg_clif_global_atomic_mutex",
3031
Linkage::Export,
3132
true,
3233
false,
33-
Some(16),
3434
)
3535
.unwrap();
3636
module.define_data(atomic_mutex, &data_ctx).unwrap();
@@ -67,7 +67,7 @@ pub(crate) fn init_global_lock(
6767
}
6868

6969
pub(crate) fn init_global_lock_constructor(
70-
module: &mut Module<impl Backend>,
70+
module: &mut impl Module,
7171
constructor_name: &str,
7272
) -> FuncId {
7373
let sig = Signature::new(CallConv::SystemV);
@@ -101,7 +101,7 @@ pub(crate) fn init_global_lock_constructor(
101101
init_func_id
102102
}
103103

104-
pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
104+
pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Module>) {
105105
let atomic_mutex = fx
106106
.cx
107107
.module
@@ -110,7 +110,6 @@ pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
110110
Linkage::Import,
111111
true,
112112
false,
113-
None,
114113
)
115114
.unwrap();
116115

@@ -144,7 +143,7 @@ pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
144143
fx.bcx.ins().call(pthread_mutex_lock, &[atomic_mutex]);
145144
}
146145

147-
pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
146+
pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Module>) {
148147
let atomic_mutex = fx
149148
.cx
150149
.module
@@ -153,7 +152,6 @@ pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
153152
Linkage::Import,
154153
true,
155154
false,
156-
None,
157155
)
158156
.unwrap();
159157

0 commit comments

Comments
 (0)