mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-23 13:41:32 +00:00
Insert allocas as a contiguous block at the top of the entry block.
This minimizes the chance we accidentally get categorized as having a dynamic alloca.
This commit is contained in:
@ -682,6 +682,7 @@ pub struct LLVMModuleCodeGenerator {
|
|||||||
pub struct LLVMFunctionCodeGenerator {
|
pub struct LLVMFunctionCodeGenerator {
|
||||||
context: Option<Context>,
|
context: Option<Context>,
|
||||||
builder: Option<Builder>,
|
builder: Option<Builder>,
|
||||||
|
alloca_builder: Option<Builder>,
|
||||||
intrinsics: Option<Intrinsics>,
|
intrinsics: Option<Intrinsics>,
|
||||||
state: State,
|
state: State,
|
||||||
function: FunctionValue,
|
function: FunctionValue,
|
||||||
@ -706,12 +707,9 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn feed_local(&mut self, ty: WpType, n: usize) -> Result<(), CodegenError> {
|
fn feed_local(&mut self, ty: WpType, count: usize) -> Result<(), CodegenError> {
|
||||||
let param_len = self.num_params;
|
let param_len = self.num_params;
|
||||||
|
|
||||||
let mut local_idx = 0;
|
|
||||||
// let (count, ty) = local?;
|
|
||||||
let count = n;
|
|
||||||
let wasmer_ty = type_to_type(ty)?;
|
let wasmer_ty = type_to_type(ty)?;
|
||||||
|
|
||||||
let intrinsics = self.intrinsics.as_ref().unwrap();
|
let intrinsics = self.intrinsics.as_ref().unwrap();
|
||||||
@ -726,14 +724,22 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let builder = self.builder.as_ref().unwrap();
|
let builder = self.builder.as_ref().unwrap();
|
||||||
|
let alloca_builder = self.alloca_builder.as_ref().unwrap();
|
||||||
|
|
||||||
for _ in 0..count {
|
for local_idx in 0..count {
|
||||||
let alloca = builder.build_alloca(ty, &format!("local{}", param_len + local_idx));
|
let alloca =
|
||||||
|
alloca_builder.build_alloca(ty, &format!("local{}", param_len + local_idx));
|
||||||
builder.build_store(alloca, default_value);
|
builder.build_store(alloca, default_value);
|
||||||
|
if local_idx == 0 {
|
||||||
|
alloca_builder.position_before(
|
||||||
|
&alloca
|
||||||
|
.as_instruction()
|
||||||
|
.unwrap()
|
||||||
|
.get_next_instruction()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
self.locals.push(alloca);
|
self.locals.push(alloca);
|
||||||
local_idx += 1;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -7301,6 +7307,8 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
|
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
let entry_block = context.append_basic_block(&function, "entry");
|
let entry_block = context.append_basic_block(&function, "entry");
|
||||||
|
let alloca_builder = context.create_builder();
|
||||||
|
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");
|
||||||
builder.position_at_end(&return_block);
|
builder.position_at_end(&return_block);
|
||||||
@ -7322,20 +7330,23 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
.skip(1)
|
.skip(1)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, param)| {
|
.map(|(index, param)| {
|
||||||
//let ty = param.get_type();
|
|
||||||
let real_ty = func_sig.params()[index];
|
let real_ty = func_sig.params()[index];
|
||||||
let real_ty_llvm = type_to_llvm(&intrinsics, real_ty);
|
let real_ty_llvm = type_to_llvm(&intrinsics, real_ty);
|
||||||
|
let alloca =
|
||||||
let alloca = builder.build_alloca(real_ty_llvm, &format!("local{}", index));
|
alloca_builder.build_alloca(real_ty_llvm, &format!("local{}", index));
|
||||||
|
|
||||||
//if real_ty_llvm != ty {
|
|
||||||
builder.build_store(
|
builder.build_store(
|
||||||
alloca,
|
alloca,
|
||||||
builder.build_bitcast(param, real_ty_llvm, &state.var_name()),
|
builder.build_bitcast(param, real_ty_llvm, &state.var_name()),
|
||||||
);
|
);
|
||||||
/*} else {
|
if index == 0 {
|
||||||
builder.build_store(alloca, param);
|
alloca_builder.position_before(
|
||||||
}*/
|
&alloca
|
||||||
|
.as_instruction()
|
||||||
|
.unwrap()
|
||||||
|
.get_next_instruction()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
alloca
|
alloca
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -7347,6 +7358,7 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
state,
|
state,
|
||||||
context: Some(context),
|
context: Some(context),
|
||||||
builder: Some(builder),
|
builder: Some(builder),
|
||||||
|
alloca_builder: Some(alloca_builder),
|
||||||
intrinsics: Some(intrinsics),
|
intrinsics: Some(intrinsics),
|
||||||
function,
|
function,
|
||||||
func_sig: func_sig,
|
func_sig: func_sig,
|
||||||
|
Reference in New Issue
Block a user