Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cranelift/filetests/src/function_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ impl TestFileCompiler {
.ok_or(anyhow!("Undeclared function {} found!", &func.name))?;

self.ctx.func = self.apply_func_rename(func, defined_func)?;
self.module
.define_function(defined_func.func_id, &mut self.ctx, ctrl_plane)?;
self.module.define_function_with_control_plane(
defined_func.func_id,
&mut self.ctx,
ctrl_plane,
)?;
self.module.clear_context(&mut self.ctx);
Ok(())
}
Expand Down
9 changes: 2 additions & 7 deletions cranelift/jit/examples/jit-minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ fn main() {
bcx.seal_all_blocks();
bcx.finalize();
}
let ctrl_plane = &mut Default::default();
module
.define_function(func_a, &mut ctx, ctrl_plane)
.unwrap();
module.define_function(func_a, &mut ctx).unwrap();
module.clear_context(&mut ctx);

ctx.func.signature = sig_b;
Expand All @@ -77,9 +74,7 @@ fn main() {
bcx.seal_all_blocks();
bcx.finalize();
}
module
.define_function(func_b, &mut ctx, ctrl_plane)
.unwrap();
module.define_function(func_b, &mut ctx).unwrap();
module.clear_context(&mut ctx);

// Perform linking.
Expand Down
2 changes: 1 addition & 1 deletion cranelift/jit/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl Module for JITModule {
})
}

fn define_function(
fn define_function_with_control_plane(
&mut self,
id: FuncId,
ctx: &mut cranelift_codegen::Context,
Expand Down
6 changes: 2 additions & 4 deletions cranelift/jit/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ fn define_simple_function(module: &mut JITModule) -> FuncId {
bcx.ins().return_(&[]);
}

module
.define_function(func_id, &mut ctx, &mut Default::default())
.unwrap();
module.define_function(func_id, &mut ctx).unwrap();

func_id
}
Expand Down Expand Up @@ -210,7 +208,7 @@ fn libcall_function() {
}

module
.define_function(func_id, &mut ctx, &mut Default::default())
.define_function_with_control_plane(func_id, &mut ctx, &mut Default::default())
.unwrap();

module.finalize_definitions().unwrap();
Expand Down
28 changes: 27 additions & 1 deletion cranelift/module/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,29 @@ pub trait Module {
///
/// Returns the size of the function's code and constant data.
///
/// Unlike [`define_function_with_control_plane`] this uses a default [`ControlPlane`] for
/// convenience.
///
/// Note: After calling this function the given `Context` will contain the compiled function.
///
/// [`define_function_with_control_plane`]: Self::define_function_with_control_plane
fn define_function(
&mut self,
func: FuncId,
ctx: &mut Context,
) -> ModuleResult<ModuleCompiledFunction> {
self.define_function_with_control_plane(func, ctx, &mut ControlPlane::default())
}

/// Define a function, producing the function body from the given `Context`.
///
/// Returns the size of the function's code and constant data.
///
/// Note: After calling this function the given `Context` will contain the compiled function.
fn define_function_with_control_plane(
&mut self,
func: FuncId,
ctx: &mut Context,
ctrl_plane: &mut ControlPlane,
) -> ModuleResult<ModuleCompiledFunction>;

Expand Down Expand Up @@ -762,9 +780,17 @@ impl<M: Module> Module for &mut M {
&mut self,
func: FuncId,
ctx: &mut Context,
) -> ModuleResult<ModuleCompiledFunction> {
(**self).define_function(func, ctx)
}

fn define_function_with_control_plane(
&mut self,
func: FuncId,
ctx: &mut Context,
ctrl_plane: &mut ControlPlane,
) -> ModuleResult<ModuleCompiledFunction> {
(**self).define_function(func, ctx, ctrl_plane)
(**self).define_function_with_control_plane(func, ctx, ctrl_plane)
}

fn define_function_bytes(
Expand Down
2 changes: 1 addition & 1 deletion cranelift/object/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Module for ObjectModule {
Ok(id)
}

fn define_function(
fn define_function_with_control_plane(
&mut self,
func_id: FuncId,
ctx: &mut cranelift_codegen::Context,
Expand Down
16 changes: 5 additions & 11 deletions cranelift/object/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use cranelift_codegen::ir::*;
use cranelift_codegen::isa::CallConv;
use cranelift_codegen::settings;
use cranelift_codegen::{ir::types::I16, Context};
use cranelift_control::ControlPlane;
use cranelift_entity::EntityRef;
use cranelift_frontend::*;
use cranelift_module::*;
Expand Down Expand Up @@ -32,7 +31,7 @@ fn error_on_incompatible_sig_in_declare_function() {
.unwrap(); // Make sure this is an error
}

fn define_simple_function(module: &mut ObjectModule, ctrl_plane: &mut ControlPlane) -> FuncId {
fn define_simple_function(module: &mut ObjectModule) -> FuncId {
let sig = Signature {
params: vec![],
returns: vec![],
Expand All @@ -53,17 +52,14 @@ fn define_simple_function(module: &mut ObjectModule, ctrl_plane: &mut ControlPla
bcx.ins().return_(&[]);
}

module
.define_function(func_id, &mut ctx, ctrl_plane)
.unwrap();
module.define_function(func_id, &mut ctx).unwrap();

func_id
}

#[test]
#[should_panic(expected = "Result::unwrap()` on an `Err` value: DuplicateDefinition(\"abc\")")]
fn panic_on_define_after_finalize() {
let ctrl_plane = &mut ControlPlane::default();
let flag_builder = settings::builder();
let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap();
let isa = isa_builder
Expand All @@ -72,8 +68,8 @@ fn panic_on_define_after_finalize() {
let mut module =
ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap());

define_simple_function(&mut module, ctrl_plane);
define_simple_function(&mut module, ctrl_plane);
define_simple_function(&mut module);
define_simple_function(&mut module);
}

#[test]
Expand Down Expand Up @@ -196,9 +192,7 @@ fn libcall_function() {
bcx.ins().return_(&[]);
}

module
.define_function(func_id, &mut ctx, &mut ControlPlane::default())
.unwrap();
module.define_function(func_id, &mut ctx).unwrap();

module.finish();
}
Expand Down
6 changes: 5 additions & 1 deletion cranelift/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ fn handle_module(
cranelift_module::Linkage::Export,
&context.func.signature,
)?;
module.define_function(fid, &mut context, &mut Default::default())?;
module.define_function_with_control_plane(
fid,
&mut context,
&mut Default::default(),
)?;
}

if options.print {
Expand Down