Have RocUnion::as_struct_value return an alloca instead

Saves a useless store/load.
This commit is contained in:
Ayaz Hafiz 2023-06-16 17:54:17 -05:00
parent 0403509f64
commit 465cee053e
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 14 additions and 24 deletions

View file

@ -1616,24 +1616,16 @@ fn build_tag<'a, 'ctx>(
let roc_union =
RocUnion::tagged_from_slices(layout_interner, env.context, tags, env.target_info);
let value = roc_union.as_struct_value(
env,
layout_interner,
data,
data_layout_repr,
Some(tag_id as _),
);
let alloca = create_entry_block_alloca(
env,
parent,
value.get_type().into(),
"non_recursive_tag_alloca",
);
env.builder.build_store(alloca, value);
alloca.into()
roc_union
.as_struct_alloca(
env,
layout_interner,
data,
data_layout_repr,
Some(tag_id as _),
)
.into()
}
UnionLayout::Recursive(tags) => {
debug_assert!(union_size > 1);
@ -1755,7 +1747,7 @@ fn build_tag<'a, 'ctx>(
let data = RocStruct::build(env, layout_interner, data_layout_repr, scope, arguments);
let value =
roc_union.as_struct_value(env, layout_interner, data, data_layout_repr, None);
roc_union.as_struct_alloca(env, layout_interner, data, data_layout_repr, None);
env.builder.build_store(data_ptr, value);

View file

@ -3,7 +3,7 @@ use crate::llvm::memcpy::build_memcpy;
use bumpalo::collections::Vec as AVec;
use inkwell::context::Context;
use inkwell::types::{BasicType, BasicTypeEnum, FloatType, IntType, StructType};
use inkwell::values::StructValue;
use inkwell::values::PointerValue;
use inkwell::AddressSpace;
use roc_builtins::bitcode::{FloatWidth, IntWidth};
use roc_mono::layout::{
@ -407,14 +407,14 @@ impl<'ctx> RocUnion<'ctx> {
width
}
pub fn as_struct_value<'a, 'env>(
pub fn as_struct_alloca<'a, 'env>(
&self,
env: &Env<'a, 'ctx, 'env>,
layout_interner: &STLayoutInterner<'a>,
data: RocStruct<'ctx>,
data_layout: LayoutRepr<'a>,
tag_id: Option<usize>,
) -> StructValue<'ctx> {
) -> PointerValue<'ctx> {
debug_assert_eq!(tag_id.is_some(), self.tag_type.is_some());
let tag_alloca = env.builder.build_alloca(self.struct_type(), "tag_alloca");
@ -483,9 +483,7 @@ impl<'ctx> RocUnion<'ctx> {
env.builder.build_store(tag_id_ptr, tag_id);
}
env.builder
.new_build_load(self.struct_type(), tag_alloca, "load_tag")
.into_struct_value()
tag_alloca
}
}