Skip to content

Commit

Permalink
revise alloca at function entry later
Browse files Browse the repository at this point in the history
Signed-off-by: Cyrill Leutwiler <[email protected]>
  • Loading branch information
xermicus committed Sep 16, 2024
1 parent 616f044 commit 72d9583
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Entry {
"input_pointer_casted",
)?;

let length_pointer = context.build_alloca(context.xlen_type(), "len_ptr");
let length_pointer = context.build_alloca_at_entry(context.xlen_type(), "len_ptr");
let length_pointer_casted = context.builder.build_ptr_to_int(
length_pointer.value,
context.xlen_type(),
Expand Down
17 changes: 8 additions & 9 deletions crates/llvm-context/src/polkavm/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ where
0 => FunctionReturn::none(),
1 => {
self.set_basic_block(entry_block);
let pointer = self.build_alloca_internal(self.word_type(), "return_pointer");
let pointer = self.build_alloca(self.word_type(), "return_pointer");
FunctionReturn::primitive(pointer)
}
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
Expand All @@ -452,7 +452,7 @@ where
}
size => {
self.set_basic_block(entry_block);
let pointer = self.build_alloca_internal(
let pointer = self.build_alloca(
self.structure_type(
vec![self.word_type().as_basic_type_enum(); size].as_slice(),
),
Expand Down Expand Up @@ -596,7 +596,7 @@ where
}

/// Builds an aligned stack allocation at the function entry.
pub fn build_alloca<T: BasicType<'ctx> + Clone + Copy>(
pub fn build_alloca_at_entry<T: BasicType<'ctx> + Clone + Copy>(
&self,
r#type: T,
name: &str,
Expand All @@ -609,17 +609,16 @@ where
None => self.builder().position_at_end(entry_block),
}

let pointer = self.build_alloca_internal(r#type, name);
let pointer = self.build_alloca(r#type, name);

self.set_basic_block(current_block);
return pointer;
}

/// Builds a stack allocation and sets the alignment.
///
/// Stack allocations should always happen at the function prelude.
/// Only use this when the position is guaranteed to be at the entry!
fn build_alloca_internal<T: BasicType<'ctx> + Clone + Copy>(
/// Builds an aligned stack allocation at the current position.
/// Use this if [`build_alloca_at_entry`] might change program semantics.
/// Otherwise, alloca should always be built at the function prelude!
pub fn build_alloca<T: BasicType<'ctx> + Clone + Copy>(
&self,
r#type: T,
name: &str,
Expand Down

0 comments on commit 72d9583

Please sign in to comment.