mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Have RocUnion::as_struct_value return an alloca instead
Saves a useless store/load.
This commit is contained in:
parent
0403509f64
commit
465cee053e
2 changed files with 14 additions and 24 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue