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
18 changes: 18 additions & 0 deletions compiler/noirc_evaluator/src/brillig/brillig_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ use super::{
};
use crate::{errors::InternalError, ssa::ir::function::Function};

/// Generates a complete Brillig entry point artifact for a given SSA-level [Function], linking all dependencies.
///
/// This function is responsible for generating a final Brillig artifact corresponding to a compiled SSA [Function].
/// It sets up the entry point context, registers input/output parameters, and recursively resolves and links
/// all transitive Brillig function dependencies.
///
/// # Parameters
/// - func: The SSA [Function] to compile as the entry point.
/// - arguments: Brillig-compatible [BrilligParameter] inputs to the function
/// - brillig: The [context structure][Brillig] of all known Brillig artifacts for dependency resolution.
/// - options: Brillig compilation options (e.g., debug trace settings).
///
/// # Returns
/// - Ok([GeneratedBrillig]): Fully linked artifact for the entry point that can be executed as a Brillig program.
/// - Err([InternalError]): If linking fails to find a dependency
///
/// # Panics
/// - If the global memory size for the function has not been precomputed.
pub(crate) fn gen_brillig_for(
func: &Function,
arguments: Vec<BrilligParameter>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Codegen for native (black box) function calls.
use acvm::{
AcirField,
acir::{
Expand Down Expand Up @@ -424,6 +425,8 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString, Registers: Re
}
}

/// Converts a Brillig array or vector into a heap-allocated [HeapVector]
/// suitable for use as an input to a Brillig [BlackBoxOp].
fn convert_array_or_vector<F: AcirField + DebugToString, Registers: RegisterAllocator>(
brillig_context: &mut BrilligContext<F, Registers>,
array_or_vector: BrilligVariable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
//! This module handles allocation, tracking, and lifetime management of variables
//! within a Brillig compiled SSA basic block.
//!
//! [BlockVariables] maintains a set of SSA [ValueId]s that are live and available
//! during the compilation of a single SSA block into Brillig instructions. It cooperates
//! with the [FunctionContext] to manage the mapping from SSA values to [BrilligVariable]s
//! and with the [BrilligContext] for allocating registers.
//!
//! Variables are:
//! - Allocated when first defined in a block (if not already global or hoisted to the global space).
//! - Cached for reuse to avoid redundant register allocation.
//! - Deallocated explicitly when no longer needed (as determined by SSA liveness).
use acvm::FieldElement;
use fxhash::FxHashSet as HashSet;

Expand All @@ -19,6 +31,15 @@ use crate::{

use super::brillig_fn::FunctionContext;

/// Tracks SSA variables that are live and usable during Brillig compilation of a block.
///
/// This structure is meant to be instantiated per SSA basic block and initialized using the
/// the set of live variables that must be available at the block's entry.
///
/// It implements:
/// - A set of active [ValueId]s that are allocated and usable.
/// - The interface to define new variables as needed for instructions within the block.
/// - Utilities to remove, check, and retrieve variables during Brillig codegen.
#[derive(Debug, Default)]
pub(crate) struct BlockVariables {
available_variables: HashSet<ValueId>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Codegen for converting SSA globals to Brillig bytecode.
use std::collections::{BTreeMap, BTreeSet};

use acvm::FieldElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Codegen for converting SSA slice intrinsic functions to Brillig bytecode.
use acvm::acir::brillig::MemoryAddress;

use crate::brillig::brillig_ir::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use super::{
};

impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<F, Registers> {
// impl<F: AcirField + DebugToString> BrilligContext<F, Stack> {
pub(crate) fn codegen_call(
&mut self,
func_id: FunctionId,
Expand Down
Loading