-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ssa refactor): Add Context structs and start ssa gen pass (#1196)
* Add Context structs and start ssa gen pass * Fix block arguments * Fix clippy lint * Use the correct dfg * Rename contexts to highlight the inner contexts are shared rather than used directly * Update crates/noirc_evaluator/src/ssa_refactor/ssa_gen/value.rs Co-authored-by: kevaundray <kevtheappdev@gmail.com> --------- Co-authored-by: kevaundray <kevtheappdev@gmail.com>
- Loading branch information
1 parent
7f8d2c2
commit e4c7bb2
Showing
16 changed files
with
442 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,70 @@ | ||
use crate::ssa_refactor::basic_block::{BasicBlock, BasicBlockId}; | ||
|
||
use super::basic_block::{BasicBlock, BasicBlockId}; | ||
use super::dfg::DataFlowGraph; | ||
use super::instruction::Instruction; | ||
use super::map::{DenseMap, Id, SecondaryMap}; | ||
use super::types::Type; | ||
use super::value::Value; | ||
|
||
use iter_extended::vecmap; | ||
use noirc_errors::Location; | ||
use std::collections::HashMap; | ||
|
||
/// A function holds a list of instructions. | ||
/// These instructions are further grouped into | ||
/// Basic blocks | ||
/// These instructions are further grouped into Basic blocks | ||
/// | ||
/// Like Crane-lift all functions outside of the current function is seen as external. | ||
/// To reference external functions, one must first import the function signature | ||
/// into the current function's context. | ||
#[derive(Debug)] | ||
pub(crate) struct Function { | ||
/// Basic blocks associated to this particular function | ||
basic_blocks: HashMap<BasicBlockId, BasicBlock>, | ||
basic_blocks: DenseMap<BasicBlock>, | ||
|
||
/// Maps instructions to source locations | ||
source_locations: HashMap<Instruction, Location>, | ||
source_locations: SecondaryMap<Instruction, Location>, | ||
|
||
/// The first basic block in the function | ||
entry_block: BasicBlockId, | ||
|
||
dfg: DataFlowGraph, | ||
} | ||
|
||
impl Function { | ||
pub(crate) fn new(parameter_count: usize) -> Self { | ||
let mut dfg = DataFlowGraph::default(); | ||
let mut basic_blocks = DenseMap::default(); | ||
|
||
// The parameters for each function are stored as the block parameters | ||
// of the function's entry block | ||
let entry_block = basic_blocks.insert_with_id(|entry_block| { | ||
// TODO: Give each parameter its correct type | ||
let parameters = vecmap(0..parameter_count, |i| { | ||
dfg.make_value(Value::Param { block: entry_block, position: i, typ: Type::Unit }) | ||
}); | ||
|
||
BasicBlock::new(parameters) | ||
}); | ||
|
||
Self { basic_blocks, source_locations: SecondaryMap::new(), entry_block, dfg } | ||
} | ||
|
||
pub(crate) fn entry_block(&self) -> BasicBlockId { | ||
self.entry_block | ||
} | ||
} | ||
|
||
/// FunctionId is a reference for a function | ||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] | ||
pub(crate) struct FunctionId(pub(crate) u32); | ||
pub(crate) type FunctionId = Id<Function>; | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub(crate) struct Signature { | ||
pub(crate) params: Vec<Type>, | ||
pub(crate) returns: Vec<Type>, | ||
} | ||
|
||
#[test] | ||
fn sign_smoke() { | ||
let mut signature = Signature::default(); | ||
|
||
signature.params.push(Type::Numeric(super::types::NumericType::NativeField)); | ||
signature.returns.push(Type::Numeric(super::types::NumericType::Unsigned { bit_size: 32 })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.