Skip to content

Commit e0185e7

Browse files
authored
feat: Optimize allocating immediate amounts of memory (#8579)
1 parent 0c54224 commit e0185e7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{
99
brillig_variable::{BrilligArray, BrilligVariable, BrilligVector, SingleAddrVariable},
1010
debug_show::DebugToString,
1111
registers::RegisterAllocator,
12-
BrilligContext, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE,
12+
BrilligContext, ReservedRegisters, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE,
1313
};
1414

1515
impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<F, Registers> {
@@ -20,9 +20,12 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<
2020
pointer_register: MemoryAddress,
2121
size: usize,
2222
) {
23-
let size_register = self.make_usize_constant_instruction(size.into());
24-
self.codegen_allocate_mem(pointer_register, size_register.address);
25-
self.deallocate_single_addr(size_register);
23+
self.load_free_memory_pointer_instruction(pointer_register);
24+
self.codegen_usize_op_in_place(
25+
ReservedRegisters::free_memory_pointer(),
26+
BrilligBinaryOp::Add,
27+
size,
28+
);
2629
}
2730

2831
/// Allocates an array of size contained in size_register and stores the

0 commit comments

Comments
 (0)