Skip to content

Commit

Permalink
switch over to alloca expr
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jul 29, 2023
1 parent 911a9ce commit 4e1c61e
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 67 deletions.
1 change: 0 additions & 1 deletion crates/compiler/can/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ macro_rules! map_symbol_to_lowlevel_and_arity {
LowLevel::PtrStore => unimplemented!(),
LowLevel::PtrLoad => unimplemented!(),
LowLevel::PtrClearTagId => unimplemented!(),
LowLevel::Alloca => unimplemented!(),
LowLevel::RefCountIncRcPtr => unimplemented!(),
LowLevel::RefCountDecRcPtr=> unimplemented!(),
LowLevel::RefCountIncDataPtr => unimplemented!(),
Expand Down
4 changes: 0 additions & 4 deletions crates/compiler/gen_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,10 +1626,6 @@ trait Backend<'a> {
self.build_ptr_clear_tag_id(*sym, args[0]);
}

LowLevel::Alloca => {
self.build_alloca(*sym, Some(args[0]), arg_layouts[0]);
}

LowLevel::RefCountDecRcPtr => self.build_fn_call(
sym,
bitcode::UTILS_DECREF_RC_PTR.to_string(),
Expand Down
14 changes: 2 additions & 12 deletions crates/compiler/gen_llvm/src/llvm/lowlevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use crate::llvm::{
},
build::{
cast_basic_basic, complex_bitcast_check_size, create_entry_block_alloca,
entry_block_alloca_zerofill, function_value_by_func_spec, load_roc_value,
roc_function_call, tag_pointer_clear_tag_id, BuilderExt, FuncBorrowSpec, RocReturn,
function_value_by_func_spec, load_roc_value, roc_function_call, tag_pointer_clear_tag_id,
BuilderExt, FuncBorrowSpec, RocReturn,
},
build_list::{
list_append_unsafe, list_concat, list_drop_at, list_get_unsafe, list_len, list_map,
Expand Down Expand Up @@ -1331,16 +1331,6 @@ pub(crate) fn run_low_level<'a, 'ctx>(
tag_pointer_clear_tag_id(env, ptr.into_pointer_value()).into()
}

Alloca => {
arguments!(initial_value);

let ptr = entry_block_alloca_zerofill(env, initial_value.get_type(), "stack_value");

env.builder.build_store(ptr, initial_value);

ptr.into()
}

RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr | RefCountDecDataPtr => {
unreachable!("Not used in LLVM backend: {:?}", op);
}
Expand Down
36 changes: 0 additions & 36 deletions crates/compiler/gen_wasm/src/low_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,42 +1992,6 @@ impl<'a> LowLevelCall<'a> {
backend.code_builder.i32_const(-4); // 11111111...1100
backend.code_builder.i32_and();
}
Alloca => {
// Alloca : a -> Ptr a
let arg = self.arguments[0];
let arg_layout = backend.storage.symbol_layouts.get(&arg).unwrap();

let (size, alignment_bytes) = backend
.layout_interner
.stack_size_and_alignment(*arg_layout);

let (frame_ptr, offset) = backend
.storage
.allocate_anonymous_stack_memory(size, alignment_bytes);

// write the default value into the stack memory
backend.storage.copy_value_to_memory(
&mut backend.code_builder,
frame_ptr,
offset,
arg,
);

// create a local variable for the pointer
let ptr_local_id = match backend.storage.ensure_value_has_local(
&mut backend.code_builder,
self.ret_symbol,
self.ret_storage.clone(),
) {
StoredValue::Local { local_id, .. } => local_id,
_ => internal_error!("A pointer will always be an i32"),
};

backend.code_builder.get_local(frame_ptr);
backend.code_builder.i32_const(offset as i32);
backend.code_builder.i32_add();
backend.code_builder.set_local(ptr_local_id);
}

Hash => todo!("{:?}", self.lowlevel),

Expand Down
2 changes: 0 additions & 2 deletions crates/compiler/module/src/low_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub enum LowLevel {
PtrStore,
PtrLoad,
PtrClearTagId,
Alloca,
RefCountIncRcPtr,
RefCountDecRcPtr,
RefCountIncDataPtr,
Expand Down Expand Up @@ -237,7 +236,6 @@ macro_rules! map_symbol_to_lowlevel {
LowLevel::PtrStore => unimplemented!(),
LowLevel::PtrLoad => unimplemented!(),
LowLevel::PtrClearTagId => unimplemented!(),
LowLevel::Alloca => unimplemented!(),
LowLevel::RefCountIncRcPtr => unimplemented!(),
LowLevel::RefCountDecRcPtr=> unimplemented!(),
LowLevel::RefCountIncDataPtr => unimplemented!(),
Expand Down
1 change: 0 additions & 1 deletion crates/compiler/mono/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,6 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[Ownership] {
PtrStore => arena.alloc_slice_copy(&[owned, owned]),
PtrLoad => arena.alloc_slice_copy(&[owned]),
PtrCast => arena.alloc_slice_copy(&[owned]),
Alloca => arena.alloc_slice_copy(&[owned]),

PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr
| RefCountDecDataPtr | RefCountIsUnique => {
Expand Down
1 change: 0 additions & 1 deletion crates/compiler/mono/src/drop_specialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,6 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
PtrStore => RC::NoRc,
PtrLoad => RC::NoRc,
PtrCast => RC::NoRc,
Alloca => RC::NoRc,

PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr
| RefCountDecDataPtr | RefCountIsUnique => {
Expand Down
6 changes: 4 additions & 2 deletions crates/compiler/mono/src/inc_dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,10 @@ fn insert_refcount_operations_binding<'a>(
Expr::Reset { .. } | Expr::ResetRef { .. } => {
unreachable!("Reset(ref) should not exist at this point")
}
Expr::Alloca { .. } => {
unreachable!("Alloca should not exist at this point")
Expr::Alloca { initializer, .. } => {
let new_let = new_let!(stmt);

inc_owned!(initializer.as_ref().copied().into_iter(), new_let)
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions crates/compiler/mono/src/tail_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,10 @@ impl<'a> TrmcEnv<'a> {
.interner
.insert_direct_no_semantic(LayoutRepr::Ptr(return_layout));

let call = Call {
call_type: CallType::LowLevel {
op: LowLevel::Alloca,
update_mode: UpdateModeId::BACKEND_DUMMY,
},
arguments: arena.alloc([null_symbol]),
let ptr_null = Expr::Alloca {
initializer: Some(null_symbol),
element_layout: return_layout,
};

let ptr_null = Expr::Call(call);
let let_ptr = |next| Stmt::Let(initial_ptr_symbol, ptr_null, ptr_return_layout, next);

let joinpoint_id = JoinPointId(env.named_unique_symbol("trmc"));
Expand Down

0 comments on commit 4e1c61e

Please sign in to comment.