Skip to content

Commit

Permalink
chore(ssa): Remove dead code + modify visibility of modules to match …
Browse files Browse the repository at this point in the history
…usage (#786)

* make all modules not needed outside of SSA private

* Remove dead code

* document `as_u32` and link to issue about its soundness
  • Loading branch information
kevaundray authored Feb 9, 2023
1 parent 71b179c commit f979918
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ impl SsaContext {
None
}
}
//blocks/////////////////////////

pub fn try_get_block_mut(&mut self, id: BlockId) -> Option<&mut block::BasicBlock> {
self.blocks.get_mut(id.0)
}
Expand Down
1 change: 0 additions & 1 deletion crates/noirc_evaluator/src/ssa/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ fn get_load_max(
max_map: &mut HashMap<NodeId, BigUint>,
value_map: &HashMap<NodeId, NodeId>,
array: ArrayId,
// obj_type: ObjectType,
) -> BigUint {
if let Some(&value) = ctx.get_indexed_value(array, address) {
return get_obj_max_value(ctx, value, max_map, value_map);
Expand Down
5 changes: 4 additions & 1 deletion crates/noirc_evaluator/src/ssa/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ impl Memory {
self.last_adr += len;
id
}

/// Coerces a FieldElement into a u32
/// By taking its value modulo 2^32
///
/// See issue #785 on whether this is safe
pub fn as_u32(value: FieldElement) -> u32 {
let big_v = BigUint::from_bytes_be(&value.to_be_bytes());
let mut modulus = BigUint::from(2_u32);
Expand Down
24 changes: 12 additions & 12 deletions crates/noirc_evaluator/src/ssa/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pub mod acir_gen;
pub mod anchor;
pub mod block;
pub mod builtin;
mod anchor;
mod block;
mod builtin;
pub mod code_gen;
pub mod conditional;
pub mod context;
pub mod flatten;
pub mod function;
pub mod inline;
pub mod integer;
pub mod mem;
mod conditional;
mod context;
mod flatten;
mod function;
mod inline;
mod integer;
mod mem;
pub mod node;
pub mod optimizations;
pub mod ssa_form;
mod optimizations;
mod ssa_form;
6 changes: 0 additions & 6 deletions crates/noirc_evaluator/src/ssa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,12 @@ impl Variable {

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum ObjectType {
//Numeric(NumericType),
NativeField,
// custom_field(BigUint), //TODO requires copy trait for BigUint
Boolean,
Unsigned(u32), //bit size
Signed(u32), //bit size
Pointer(ArrayId),

Function,
//TODO big_int
//TODO floats
NotAnObject, //not an object
}

Expand Down Expand Up @@ -497,7 +492,6 @@ pub enum Operation {
root: NodeId,
block_args: Vec<(NodeId, BlockId)>,
},
//Call(function::FunctionCall),
Call {
func: NodeId,
arguments: Vec<NodeId>,
Expand Down
7 changes: 5 additions & 2 deletions crates/noirc_evaluator/src/ssa/optimizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ fn evaluate_intrinsic(
_ => todo!(),
}
}
////////////////////CSE////////////////////////////////////////

//
// The following code will be concerned with Common Subexpression Elimination (CSE)
//

pub fn propagate(ctx: &SsaContext, id: NodeId, modified: &mut bool) -> NodeId {
if let Some(obj) = ctx.try_get_instruction(id) {
Expand Down Expand Up @@ -409,7 +412,7 @@ fn cse_block_with_anchor(
Ok(last)
}

pub fn is_some(ctx: &SsaContext, id: NodeId) -> bool {
fn is_some(ctx: &SsaContext, id: NodeId) -> bool {
if id == NodeId::dummy() {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/noirc_evaluator/src/ssa/ssa_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::ssa::{
use std::collections::HashSet;

// create phi arguments from the predecessors of the block (containing phi)
pub fn write_phi(ctx: &mut SsaContext, predecessors: &[BlockId], var: NodeId, phi: NodeId) {
fn write_phi(ctx: &mut SsaContext, predecessors: &[BlockId], var: NodeId, phi: NodeId) {
let mut result = Vec::new();
for b in predecessors {
let v = get_current_value_in_block(ctx, var, *b);
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn seal_block(ctx: &mut SsaContext, block_id: BlockId, entry_block: BlockId)
}

// write dummy store for join block
pub fn add_dummy_store(ctx: &mut SsaContext, entry: BlockId, join: BlockId) {
fn add_dummy_store(ctx: &mut SsaContext, entry: BlockId, join: BlockId) {
//retrieve modified arrays
let mut modified = HashSet::new();
if entry == join {
Expand All @@ -74,7 +74,7 @@ pub fn add_dummy_store(ctx: &mut SsaContext, entry: BlockId, join: BlockId) {
}

//look-up recursively into predecessors
pub fn get_block_value(ctx: &mut SsaContext, root: NodeId, block_id: BlockId) -> NodeId {
fn get_block_value(ctx: &mut SsaContext, root: NodeId, block_id: BlockId) -> NodeId {
let result = if !ctx.sealed_blocks.contains(&block_id) {
//incomplete CFG
ctx.generate_empty_phi(block_id, root)
Expand Down

0 comments on commit f979918

Please sign in to comment.