Skip to content
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

Gd/ssa arrays #190

Merged
merged 74 commits into from
Mar 21, 2022
Merged

Gd/ssa arrays #190

merged 74 commits into from
Mar 21, 2022

Conversation

guipublic
Copy link
Contributor

Support for Arrays in the SSA form.

  • Only static arrays (i.e fixed length and constant indexing) are supported for now.
  • Arrays are treated as a chunk of memory, access to the array is translated into accessing the memory.
  • Array objects are represented with the Pointer type, for equality check or constraints and function parameters or return type.

Static access to the memory is optimized via the use, when reading the memory, of a mapping of addresses to their stored values. Overflow strategy uses this mapping when possible and also maintains a maximum value of the array (for the case when the mapping does not exist).
CSE put all read/write operations in the same anchor but uses a different one for each array. It is checked in reverse order so that most recent write operation kills the rest of the anchor.

In summary, the changes are mainly around these files:

  1. mem.rs: define a virtual memory containing arrays
  2. node.rs: new Pointer type which references an array. New Constrain operator to implement distinct and equal constraints
  3. code_gen.rs (parse AST): generate read and write instructions (there is no ssa value for the arrays as any write would invalidate the whole array)
  4. optim.rs (CSE): remove redundant memory access (e.g 2 consecutive reads or two consecutive writes)
  5. integer.rs (overflow): map static writes to their values to retrieve the maximum values of a read.
  6. acir_gen.rs (ACIR): map static writes to their values to retrieve relevant witnesses for read operations. Implement equality checks and constraints using predicates.

- generate the cfg
- generate phi instructions
- unroll
Handle 'for' expression by generating CFG and Phi instructions
Unroll the CFG into one block
constant folding
arithmetic simplification
standard form
- successive blocks use proper values computed during unrolling
- In ACIR gate genrations, use existing witness corresponding to input variables
Fix unrolling:
- proper generation of phi instructions
- remove the update of phi instruction which was done
at the end of a block as they
need to be updated before a variable is used
- activate the simplification for phi instructions
splitted the code in several files
unrolling is working
enable integer arithmetic for ssa form
integration tests pass
Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, some style/naming suggestions mainly.

crates/acir/src/optimiser/csat_optimiser.rs Show resolved Hide resolved
crates/nargo/tests/test_data/6_array/src/main.nr Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/lib.rs Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/acir_gen.rs Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/acir_gen.rs Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/optim.rs Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/optim.rs Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/optim.rs Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/ssa_form.rs Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/ssa_form.rs Outdated Show resolved Hide resolved
(until it is feature complete with the previous evaluator)
jfecher
jfecher previously approved these changes Mar 7, 2022
Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

and use type given by the frontend instead.
@jfecher jfecher merged commit 81576d3 into master Mar 21, 2022
@jfecher jfecher deleted the gd/ssa_arrays branch March 21, 2022 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants