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

[DO NOT MERGE] Implement mov and movptr pseudoinstructions #403

Open
wants to merge 625 commits into
base: main
Choose a base branch
from

Conversation

sayon
Copy link

@sayon sayon commented Feb 25, 2024

Code Review Checklist

Purpose

Ticket Number

Requirements

  • Have the requirements been met?
  • Have stakeholder(s) approved the change?

Implementation

  • Does this code change accomplish what it is supposed to do?
  • Can this solution be simplified?
  • Does this change add unwanted compile-time or run-time dependencies?
  • Could an additional framework, API, library, or service improve the solution?
  • Could we reuse part of LLVM instead of implementing the patch or a part of it?
  • Is the code at the right abstraction level?
  • Is the code modular enough?
  • Can a better solution be found in terms of maintainability, readability, performance, or security?
  • Does similar functionality already exist in the codebase? If yes, why isn’t it reused?
  • Are there any best practices, design patterns or language-specific patterns that could substantially improve this code?

Logic Errors and Bugs

  • Can you think of any use case in which the
    code does not behave as intended?
  • Can you think of any inputs or external events
    that could break the code?

Error Handling and Logging

  • Is error handling done the correct way?
  • Should any logging or debugging information
    be added or removed?
  • Are error messages user-friendly?
  • Are there enough log events and are they
    written in a way that allows for easy
    debugging?

Maintainability

  • Is the code easy to read?
  • Is the code not repeated (DRY Principle)?
  • Is the code method/class not too long?

Dependencies

  • Were updates to documentation, configuration, or readme files made as required by this change?
  • Are there any potential impacts on other parts of the system or backward compatibility?

Security

  • Does the code introduce any security vulnerabilities?

Performance

  • Do you think this code change decreases
    system performance?
  • Do you see any potential to improve the
    performance of the code significantly?

Testing and Testability

  • Is the code testable?
  • Have automated tests been added, or have related ones been updated to cover the change?
    • For changes to mutable state
  • Do tests reasonably cover the code change (unit/integration/system tests)?
    • Line Coverage
    • Region Coverage
    • Branch Coverage
  • Are there some test cases, input or edge cases
    that should be tested in addition?

Readability

  • Is the code easy to understand?
  • Which parts were confusing to you and why?
  • Can the readability of the code be improved by
    smaller methods?
  • Can the readability of the code be improved by
    different function, method or variable names?
  • Is the code located in the right
    file/folder/package?
  • Do you think certain methods should be
    restructured to have a more intuitive control
    flow?
  • Is the data flow understandable?
  • Are there redundant or outdated comments?
  • Could some comments convey the message
    better?
  • Would more comments make the code more
    understandable?
  • Could some comments be removed by making the code itself more readable?
  • Is there any commented-out code?

Documentation

  • Is there sufficient documentation?
  • Is the ReadMe.md file up to date?

Best Practices

  • Follow Single Responsibility principle?
  • Are different errors handled correctly?
  • Are errors and warnings logged?
  • Magic values avoided?
  • No unnecessary comments?
  • Minimal nesting used?

Experts' Opinion

  • Do you think a specific expert, like a security
    expert or a usability expert, should look over
    the code before it can be accepted?
  • Will this code change impact different teams, and should they review the change as well?

akiramenai and others added 30 commits December 1, 2022 13:53
When converting bytes to cell cache the result of the conversion and
reuse it instead of recalculating.
Replace lower switch pass with stich loweing in DAG builder

The patch turns off lowerswitch pass, and change Selection DAG Builder
so that it creates a tree with ult rather than slt branching for a
switch.
Propagate constants to stack address

In case a fuction access to an external frame outside of the entry basic
block, the DAG is constructed so that the address is computed in entry
and copied to a register. SelectAddress therefore can't infer that a
constant could be involved in the computation and use Reg + Imm
addressing mode.
The patch introduces a pass that replicates the logic of propagation
constants to a memory accessing operation. If the inital address is
computed by expression 1, and none of it's patrital results is used more
than once, the pass attempts to find expression 2, so that expression 1
is equal to expression 2 + constant. Then it replaces a memory access by
expression 1 to a memory access by expression 2 + constant.
* Add the MUSL build script

* Install ninja

* Install the Rust target for MUSL

* Install musl-gcc

* Fix the LLVM output path

* Fix the LLVM unit test path and target

* Re-enable unit tests building

* Remove the unit tests CI step

Co-authored-by: Alex Z <a.zarudnyy@matterlabs.dev>
* Test only opt-modes for nightly

* Cleanup the build scripts

Co-authored-by: Alex Z <a.zarudnyy@matterlabs.dev>
Selection DAG Builder used to build jump tables for minsize attributed
function when switch cases are dense. SyncVM doesn't allow jump tables
yet.
SyncVMCodegenPrepare pass now eliminates such calls.
Despite the command-line option, LLVM unconditioally enables lookup
table building for switch. These tables are global constants and thus
every record there is 4 times as bigger as a single instruction.
Expand memcpy using gep instead of pointer arithrmetic to access
elements, and move the logic to SyncVM target instead of making local
changes in LowerMemIntrinsics.
The patch also corrects the data layout for SyncVM.
Update runtime library to return iN as(3)* when appropriate.
The compiler put all the globals into `.data` section regardless of the
initializer. Linker is to map `.data` to the beggining of the stack.
* adding ptr.add and ptr.pack
* adding corresponding intrinsics
* GEP on AS 3 pointers will be converted to intrinsics before lowering

Co-authored with Dmitry Borisenkov <dmitriy.borisenkov89@gmail.com>
SyncVM threats generic address space pointers as a special data type.
Only VM can produce them, and there are 3 operations that allowed:
* ptr.add pointer, i256
* ptr.sub pointer, i256
* ptr.pack pointer, i256
Any other operation on a pointer would implicitly convert it to i256.
The patch supports fat pointers in backen without introducing a EVT for
them:
* Select load/store iN as(3)** as ptr.add
* Identify via the def-chain that pointer value is to be spilled, and
  generate ptr.add instead of add for the spill
* Identify that pointer is to be reloaded and use ptr.add for that
* Identify that pointer is to be moved and use ptr.add
* Make a copy of each far call runtime function and make each copy to
  take i8 addrspace(3)* as the first argument.
* Handle COPY from a function parameter to a register when the parameter
  is a generic pointer.
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
This is mainly used to test this pass by running it with opt.

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
…s issue

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
…umulativeByteOffset

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Set that offset is signed to fix calculation for large BitWidth.

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Pavel Kopyl <pavelkopyl@gmail.com>
@sayon sayon force-pushed the iz-experiment-mov branch 2 times, most recently from c805ce0 to 1e46ec0 Compare February 26, 2024 09:17
Copy link

Benchmark results:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                               -0.013 ║
║ Best                                8.217 ║
║ Worst                              -8.696 ║
║ Total                              -0.005 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                               -0.012 ║
║ Best                                9.594 ║
║ Worst                              -8.065 ║
║ Total                               0.001 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                               -0.001 ║
║ Best                                4.767 ║
║ Worst                              -4.127 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                               -0.002 ║
║ Best                                8.554 ║
║ Worst                              -8.955 ║
║ Total                               0.062 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                               -0.021 ║
║ Best                                9.664 ║
║ Worst                             -42.517 ║
║ Total                               0.001 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                               -0.004 ║
║ Best                                6.086 ║
║ Worst                             -21.801 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Mean                               -0.000 ║
║ Best                                0.000 ║
║ Worst                              -0.001 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles MzB3 ╞═╗
║ Mean                                0.167 ║
║ Best                                0.509 ║
║ Worst                               0.000 ║
║ Total                               0.249 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.137 ║
║ Best                                2.649 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.118 ║
║ Best                                2.305 ║
║ Worst                              -0.001 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life M3B3 ╞═╗
║ Mean                                0.144 ║
║ Best                                1.942 ║
║ Worst                              -0.478 ║
║ Total                               0.135 ║
╠═╡ Cycles (-%) ╞════════╡ Real life M3B3 ╞═╣
║ Mean                                0.001 ║
║ Best                                0.766 ║
║ Worst                              -0.704 ║
║ Total                               0.016 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Mean                                0.001 ║
║ Best                                0.058 ║
║ Worst                              -0.003 ║
║ Total                               0.001 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life MzB3 ╞═╗
║ Mean                               -0.010 ║
║ Best                                2.156 ║
║ Worst                              -1.592 ║
║ Total                               0.023 ║
╠═╡ Cycles (-%) ╞════════╡ Real life MzB3 ╞═╣
║ Mean                               -0.007 ║
║ Best                                1.724 ║
║ Worst                              -1.314 ║
║ Total                               0.002 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Mean                                0.002 ║
║ Best                                0.868 ║
║ Worst                              -0.200 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

@sayon sayon force-pushed the iz-experiment-mov branch 2 times, most recently from e6a2d16 to 57c35de Compare February 27, 2024 17:02
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
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.

None yet