-
Notifications
You must be signed in to change notification settings - Fork 389
chore(ssa refactor): Add Context structs and start ssa gen pass #1196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
71efa70
Add Context structs and start ssa gen pass
7dc56ed
Fix block arguments
d63f5f5
Fix clippy lint
5b92199
Fix merge conflict
282fd18
Use the correct dfg
750e1e0
Rename contexts to highlight the inner contexts are shared rather tha…
1578cbf
Update crates/noirc_evaluator/src/ssa_refactor/ssa_gen/value.rs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.