mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-30 10:21:20 +00:00
Merge #1322
1322: inkwell::Builder is a per-function notion, remove it from LLVMModuleCodeGenerator. r=nlewycky a=nlewycky This also removes it from the API to generate trampolines, which makes sense because those produce new functions, so it can produce a new builder for the new function. Co-authored-by: Nick Lewycky <nick@wasmer.io> Co-authored-by: nlewycky <nick@wasmer.io>
This commit is contained in:
commit
c6dc793924
@ -954,7 +954,6 @@ pub unsafe extern "C" fn callback_trampoline(
|
|||||||
|
|
||||||
pub struct LLVMModuleCodeGenerator<'ctx> {
|
pub struct LLVMModuleCodeGenerator<'ctx> {
|
||||||
context: Option<&'ctx Context>,
|
context: Option<&'ctx Context>,
|
||||||
builder: Option<Builder<'ctx>>,
|
|
||||||
intrinsics: Option<Intrinsics<'ctx>>,
|
intrinsics: Option<Intrinsics<'ctx>>,
|
||||||
functions: Vec<LLVMFunctionCodeGenerator<'ctx>>,
|
functions: Vec<LLVMFunctionCodeGenerator<'ctx>>,
|
||||||
signatures: Map<SigIndex, FunctionType<'ctx>>,
|
signatures: Map<SigIndex, FunctionType<'ctx>>,
|
||||||
@ -8619,7 +8618,6 @@ impl From<LoadError> for CodegenError {
|
|||||||
impl Drop for LLVMModuleCodeGenerator<'_> {
|
impl Drop for LLVMModuleCodeGenerator<'_> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Ensure that all members of the context are dropped before we drop the context.
|
// Ensure that all members of the context are dropped before we drop the context.
|
||||||
drop(self.builder.take());
|
|
||||||
drop(self.intrinsics.take());
|
drop(self.intrinsics.take());
|
||||||
self.functions.clear();
|
self.functions.clear();
|
||||||
self.signatures.clear();
|
self.signatures.clear();
|
||||||
@ -8698,8 +8696,6 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
|||||||
module.set_target(&target);
|
module.set_target(&target);
|
||||||
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
||||||
|
|
||||||
let builder = context.create_builder();
|
|
||||||
|
|
||||||
let intrinsics = Intrinsics::declare(&module, &context);
|
let intrinsics = Intrinsics::declare(&module, &context);
|
||||||
|
|
||||||
let personality_func = module.add_function(
|
let personality_func = module.add_function(
|
||||||
@ -8710,7 +8706,6 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
|||||||
|
|
||||||
LLVMModuleCodeGenerator {
|
LLVMModuleCodeGenerator {
|
||||||
context: Some(context),
|
context: Some(context),
|
||||||
builder: Some(builder),
|
|
||||||
intrinsics: Some(intrinsics),
|
intrinsics: Some(intrinsics),
|
||||||
module: ManuallyDrop::new(Rc::new(RefCell::new(module))),
|
module: ManuallyDrop::new(Rc::new(RefCell::new(module))),
|
||||||
functions: vec![],
|
functions: vec![],
|
||||||
@ -8740,15 +8735,10 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
|||||||
_loc: WasmSpan,
|
_loc: WasmSpan,
|
||||||
) -> Result<&mut LLVMFunctionCodeGenerator<'ctx>, CodegenError> {
|
) -> Result<&mut LLVMFunctionCodeGenerator<'ctx>, CodegenError> {
|
||||||
// Creates a new function and returns the function-scope code generator for it.
|
// Creates a new function and returns the function-scope code generator for it.
|
||||||
let (context, builder, intrinsics) = match self.functions.last_mut() {
|
let (context, intrinsics) = match self.functions.last_mut() {
|
||||||
Some(x) => (
|
Some(x) => (x.context.take().unwrap(), x.intrinsics.take().unwrap()),
|
||||||
x.context.take().unwrap(),
|
|
||||||
x.builder.take().unwrap(),
|
|
||||||
x.intrinsics.take().unwrap(),
|
|
||||||
),
|
|
||||||
None => (
|
None => (
|
||||||
self.context.take().unwrap(),
|
self.context.take().unwrap(),
|
||||||
self.builder.take().unwrap(),
|
|
||||||
self.intrinsics.take().unwrap(),
|
self.intrinsics.take().unwrap(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -8766,6 +8756,7 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
|||||||
alloca_builder.position_at_end(entry_block);
|
alloca_builder.position_at_end(entry_block);
|
||||||
|
|
||||||
let return_block = context.append_basic_block(*function, "return");
|
let return_block = context.append_basic_block(*function, "return");
|
||||||
|
let builder = context.create_builder();
|
||||||
builder.position_at_end(return_block);
|
builder.position_at_end(return_block);
|
||||||
|
|
||||||
let phis: SmallVec<[PhiValue; 1]> = func_sig
|
let phis: SmallVec<[PhiValue; 1]> = func_sig
|
||||||
@ -8851,20 +8842,14 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
|||||||
),
|
),
|
||||||
CodegenError,
|
CodegenError,
|
||||||
> {
|
> {
|
||||||
let (context, builder, intrinsics) = match self.functions.last_mut() {
|
let (context, intrinsics) = match self.functions.last_mut() {
|
||||||
Some(x) => (
|
Some(x) => (x.context.take().unwrap(), x.intrinsics.take().unwrap()),
|
||||||
x.context.take().unwrap(),
|
|
||||||
x.builder.take().unwrap(),
|
|
||||||
x.intrinsics.take().unwrap(),
|
|
||||||
),
|
|
||||||
None => (
|
None => (
|
||||||
self.context.take().unwrap(),
|
self.context.take().unwrap(),
|
||||||
self.builder.take().unwrap(),
|
|
||||||
self.intrinsics.take().unwrap(),
|
self.intrinsics.take().unwrap(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
self.context = Some(context);
|
self.context = Some(context);
|
||||||
self.builder = Some(builder);
|
|
||||||
self.intrinsics = Some(intrinsics);
|
self.intrinsics = Some(intrinsics);
|
||||||
|
|
||||||
generate_trampolines(
|
generate_trampolines(
|
||||||
@ -8872,7 +8857,6 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
|||||||
&self.signatures,
|
&self.signatures,
|
||||||
&self.module.borrow_mut(),
|
&self.module.borrow_mut(),
|
||||||
self.context.as_ref().unwrap(),
|
self.context.as_ref().unwrap(),
|
||||||
self.builder.as_ref().unwrap(),
|
|
||||||
self.intrinsics.as_ref().unwrap(),
|
self.intrinsics.as_ref().unwrap(),
|
||||||
)
|
)
|
||||||
.map_err(|e| CodegenError {
|
.map_err(|e| CodegenError {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::intrinsics::Intrinsics;
|
use crate::intrinsics::Intrinsics;
|
||||||
use inkwell::{
|
use inkwell::{
|
||||||
builder::Builder,
|
|
||||||
context::Context,
|
context::Context,
|
||||||
module::{Linkage, Module},
|
module::{Linkage, Module},
|
||||||
types::{BasicType, FunctionType},
|
types::{BasicType, FunctionType},
|
||||||
@ -18,7 +17,6 @@ pub fn generate_trampolines<'ctx>(
|
|||||||
signatures: &SliceMap<SigIndex, FunctionType<'ctx>>,
|
signatures: &SliceMap<SigIndex, FunctionType<'ctx>>,
|
||||||
module: &Module<'ctx>,
|
module: &Module<'ctx>,
|
||||||
context: &'ctx Context,
|
context: &'ctx Context,
|
||||||
builder: &Builder<'ctx>,
|
|
||||||
intrinsics: &Intrinsics<'ctx>,
|
intrinsics: &Intrinsics<'ctx>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
for (sig_index, sig) in info.signatures.iter() {
|
for (sig_index, sig) in info.signatures.iter() {
|
||||||
@ -42,7 +40,7 @@ pub fn generate_trampolines<'ctx>(
|
|||||||
Some(Linkage::External),
|
Some(Linkage::External),
|
||||||
);
|
);
|
||||||
|
|
||||||
generate_trampoline(trampoline_func, sig, context, builder, intrinsics)?;
|
generate_trampoline(trampoline_func, sig, context, intrinsics)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -51,10 +49,10 @@ fn generate_trampoline<'ctx>(
|
|||||||
trampoline_func: FunctionValue,
|
trampoline_func: FunctionValue,
|
||||||
func_sig: &FuncSig,
|
func_sig: &FuncSig,
|
||||||
context: &'ctx Context,
|
context: &'ctx Context,
|
||||||
builder: &Builder<'ctx>,
|
|
||||||
intrinsics: &Intrinsics<'ctx>,
|
intrinsics: &Intrinsics<'ctx>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let entry_block = context.append_basic_block(trampoline_func, "entry");
|
let entry_block = context.append_basic_block(trampoline_func, "entry");
|
||||||
|
let builder = context.create_builder();
|
||||||
builder.position_at_end(entry_block);
|
builder.position_at_end(entry_block);
|
||||||
|
|
||||||
let (vmctx_ptr, func_ptr, args_ptr, returns_ptr) = match trampoline_func.get_params().as_slice()
|
let (vmctx_ptr, func_ptr, args_ptr, returns_ptr) = match trampoline_func.get_params().as_slice()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user