Pass function pointer directly rather than load/store into alloca

This commit is contained in:
Ayaz Hafiz 2023-07-07 11:46:07 -05:00
parent a123820b2b
commit 6ba6b04a17
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 3 additions and 14 deletions

View file

@ -1143,9 +1143,7 @@ pub(crate) fn build_exp_expr<'a, 'ctx>(
}
FunctionPointer { lambda_name } => {
let function_ptr_type =
fn_ptr::pointer_type_expecting_layout(env, layout_interner, layout);
let alloca = fn_ptr::build(env, *lambda_name, function_ptr_type);
let alloca = fn_ptr::build(env, *lambda_name);
alloca.into()
}
ErasedMake { value, callee } => {

View file

@ -63,19 +63,10 @@ pub fn pointer_type_expecting_layout<'a, 'ctx>(
pointer_type(env, layout_interner, function_pointer)
}
pub fn build<'a, 'ctx>(
env: &Env<'a, 'ctx, '_>,
lambda_name: LambdaName<'a>,
function_ptr_type: PointerType<'ctx>,
) -> BasicValueEnum<'ctx> {
let alloca = env
.builder
.build_alloca(function_ptr_type, "function_pointer_alloca");
pub fn build<'a, 'ctx>(env: &Env<'a, 'ctx, '_>, lambda_name: LambdaName<'a>) -> PointerValue<'ctx> {
let func_value: FunctionValue<'ctx> =
function_value_by_func_spec(env, FuncBorrowSpec::Erased, lambda_name.name());
env.builder
.build_store(alloca, func_value.as_global_value().as_pointer_value());
alloca.into()
func_value.as_global_value().as_pointer_value()
}
pub fn cast_to_function_ptr_type<'ctx>(