Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ fn compile_func(
context,
registry,
module,
&pre_entry_block,
block,
location,
metadata,
Expand Down Expand Up @@ -724,6 +725,7 @@ fn compile_func(
context,
registry,
module,
&pre_entry_block,
block,
location,
metadata,
Expand Down
9 changes: 7 additions & 2 deletions src/libfuncs/felt252_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ pub fn build_squash<'ctx, 'this>(
.to_native_assert_error("runtime library should be available")?;

let range_check_ptr =
entry.alloca1(context, location, IntegerType::new(context, 64).into(), 0)?;
helper
.init_block()
.alloca1(context, location, IntegerType::new(context, 64).into(), 0)?;
entry.store(context, location, range_check_ptr, range_check)?;
let gas_ptr = entry.alloca1(context, location, IntegerType::new(context, 64).into(), 0)?;
let gas_ptr =
helper
.init_block()
.alloca1(context, location, IntegerType::new(context, 64).into(), 0)?;
entry.store(context, location, gas_ptr, gas)?;

runtime_bindings.dict_squash(
Expand Down
10 changes: 8 additions & 2 deletions src/libfuncs/qm31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,14 @@ pub fn build_binary_op<'ctx, 'this>(
let lhs = entry.arg(0)?;
let rhs = entry.arg(1)?;

let lhs_ptr = entry.alloca1(context, location, qm31_ty, get_integer_layout(31).align())?;
let rhs_ptr = entry.alloca1(context, location, qm31_ty, get_integer_layout(31).align())?;
let lhs_ptr =
helper
.init_block()
.alloca1(context, location, qm31_ty, get_integer_layout(31).align())?;
let rhs_ptr =
helper
.init_block()
.alloca1(context, location, qm31_ty, get_integer_layout(31).align())?;

entry.store(context, location, lhs_ptr, lhs)?;
entry.store(context, location, rhs_ptr, rhs)?;
Expand Down
5 changes: 4 additions & 1 deletion src/libfuncs/squashed_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ pub fn build_into_entries<'ctx, 'this>(
&info.branch_signatures()[0].vars[0].ty,
)?;
// Alloc the necessary memory
let array_ptr = entry.alloca1(context, location, array_ty, array_layout.align())?;
let array_ptr =
helper
.init_block()
.alloca1(context, location, array_ty, array_layout.align())?;

// Runtime function that creates the array with its content
metadata
Expand Down
17 changes: 11 additions & 6 deletions src/metadata/runtime_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ impl RuntimeBindingsMeta {
pub fn libfunc_qm31_bin_op<'c, 'a>(
&mut self,
context: &'c Context,
module: &Module,
helper: &LibfuncHelper<'c, 'a>,
block: &'a Block<'c>,
lhs_ptr: Value<'c, '_>,
rhs_ptr: Value<'c, '_>,
Expand All @@ -741,20 +741,25 @@ impl RuntimeBindingsMeta {
'c: 'a,
{
let qm31_ty = llvm::r#type::array(IntegerType::new(context, 31).into(), 4);
let res_ptr = block.alloca1(context, location, qm31_ty, get_integer_layout(31).align())?;
let res_ptr = helper.init_block().alloca1(
context,
location,
qm31_ty,
get_integer_layout(31).align(),
)?;

let function = match op {
QM31BinaryOperator::Add => {
self.build_function(context, module, block, location, RuntimeBinding::QM31Add)?
self.build_function(context, helper, block, location, RuntimeBinding::QM31Add)?
}
QM31BinaryOperator::Sub => {
self.build_function(context, module, block, location, RuntimeBinding::QM31Sub)?
self.build_function(context, helper, block, location, RuntimeBinding::QM31Sub)?
}
QM31BinaryOperator::Mul => {
self.build_function(context, module, block, location, RuntimeBinding::QM31Mul)?
self.build_function(context, helper, block, location, RuntimeBinding::QM31Mul)?
}
QM31BinaryOperator::Div => {
self.build_function(context, module, block, location, RuntimeBinding::QM31Div)?
self.build_function(context, helper, block, location, RuntimeBinding::QM31Div)?
}
};

Expand Down
7 changes: 5 additions & 2 deletions src/utils/trace_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use cairo_lang_sierra::{
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use melior::{
helpers::LlvmBlockExt,
ir::{BlockRef, Location, Module, Value, ValueLike},
ir::{Block, BlockRef, Location, Module, Value, ValueLike},
Context,
};

Expand All @@ -88,6 +88,7 @@ pub fn build_state_snapshot(
context: &Context,
registry: &ProgramRegistry<CoreType, CoreLibfunc>,
module: &Module,
init_block: &Block,
block: &BlockRef,
location: Location,
metadata: &mut MetadataStorage,
Expand All @@ -103,7 +104,9 @@ pub fn build_state_snapshot(

let layout = value_type.layout(registry).unwrap();

let value_ptr = block
// Allocas must live in the init block so that they are not executed on every loop
// iteration, which would grow the stack unboundedly.
let value_ptr = init_block
.alloca1(context, location, value.r#type(), layout.align())
.unwrap();
block.store(context, location, value_ptr, *value).unwrap();
Expand Down
Loading