mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
change incref to use the zig builtin
This commit is contained in:
parent
56dc503d11
commit
ef49d5714b
2 changed files with 21 additions and 32 deletions
|
@ -266,6 +266,7 @@ pub fn gen_from_mono_module_llvm(
|
||||||
|| name.starts_with("roc_builtins.dec")
|
|| name.starts_with("roc_builtins.dec")
|
||||||
|| name.starts_with("list.RocList")
|
|| name.starts_with("list.RocList")
|
||||||
|| name.starts_with("dict.RocDict")
|
|| name.starts_with("dict.RocDict")
|
||||||
|
|| name.contains("incref")
|
||||||
|| name.contains("decref")
|
|| name.contains("decref")
|
||||||
{
|
{
|
||||||
function.add_attribute(AttributeLoc::Function, enum_attr);
|
function.add_attribute(AttributeLoc::Function, enum_attr);
|
||||||
|
|
|
@ -125,38 +125,7 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn increment<'a, 'env>(&self, amount: IntValue<'ctx>, env: &Env<'a, 'ctx, 'env>) {
|
fn increment<'a, 'env>(&self, amount: IntValue<'ctx>, env: &Env<'a, 'ctx, 'env>) {
|
||||||
let refcount = self.get_refcount(env);
|
incref_pointer(env, self.value, amount);
|
||||||
let builder = env.builder;
|
|
||||||
let refcount_type = env.ptr_int();
|
|
||||||
|
|
||||||
let is_static_allocation = builder.build_int_compare(
|
|
||||||
IntPredicate::EQ,
|
|
||||||
refcount,
|
|
||||||
refcount_type.const_int(REFCOUNT_MAX as u64, false),
|
|
||||||
"refcount_max_check",
|
|
||||||
);
|
|
||||||
|
|
||||||
let block = env.builder.get_insert_block().expect("to be in a function");
|
|
||||||
let parent = block.get_parent().unwrap();
|
|
||||||
|
|
||||||
let modify_block = env
|
|
||||||
.context
|
|
||||||
.append_basic_block(parent, "inc_refcount_modify");
|
|
||||||
let cont_block = env.context.append_basic_block(parent, "inc_refcount_cont");
|
|
||||||
|
|
||||||
env.builder
|
|
||||||
.build_conditional_branch(is_static_allocation, cont_block, modify_block);
|
|
||||||
|
|
||||||
{
|
|
||||||
env.builder.position_at_end(modify_block);
|
|
||||||
|
|
||||||
let incremented = builder.build_int_add(refcount, amount, "increment_refcount");
|
|
||||||
self.set_refcount(env, incremented);
|
|
||||||
|
|
||||||
env.builder.build_unconditional_branch(cont_block);
|
|
||||||
}
|
|
||||||
|
|
||||||
env.builder.position_at_end(cont_block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decrement<'a, 'env>(&self, env: &Env<'a, 'ctx, 'env>, layout: &Layout<'a>) {
|
pub fn decrement<'a, 'env>(&self, env: &Env<'a, 'ctx, 'env>, layout: &Layout<'a>) {
|
||||||
|
@ -232,6 +201,25 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn incref_pointer<'a, 'ctx, 'env>(
|
||||||
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
|
pointer: PointerValue<'ctx>,
|
||||||
|
amount: IntValue<'ctx>,
|
||||||
|
) {
|
||||||
|
call_void_bitcode_fn(
|
||||||
|
env,
|
||||||
|
&[
|
||||||
|
env.builder.build_bitcast(
|
||||||
|
pointer,
|
||||||
|
env.ptr_int().ptr_type(AddressSpace::Generic),
|
||||||
|
"to_isize_ptr",
|
||||||
|
),
|
||||||
|
amount.into(),
|
||||||
|
],
|
||||||
|
roc_builtins::bitcode::UTILS_INCREF,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn decref_pointer<'a, 'ctx, 'env>(
|
fn decref_pointer<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
pointer: PointerValue<'ctx>,
|
pointer: PointerValue<'ctx>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue