-
-
Notifications
You must be signed in to change notification settings - Fork 803
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
feat: implement new IR for vyper (venom IR) #3659
Merged
Merged
Conversation
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
not sure if needed will check again
Not required after the refactor
charles-cooper
changed the title
feat: new IR for vyper (venom IR)
feat: implement new IR for vyper (venom IR)
Nov 30, 2023
buckets and fallback
IRBasicBlock
I reverted to my original code for normalized that works on instructions This is important as because of how deploy works (in order to be compatible with the old system) some CFG connections are created that are not visible in IR
TODOS regarding the CFG<->deploy<->dynamic jump interactions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What I did
--experimental-codegen
to activate the new pathHow I did it
This branch contains the ongoing work to update the current IR implementation of Vyper to a new one. The Venom IR is departing from the original s-expression format to a more basic block oriented with strict enforcement of SSA to enable easier optimisations at a later stage.
The implementation is taking as input the original IR and does not stem from the AST.
At it's current state of implementation the code below:
Compiles down to the new SSA based IR below:
Expand Venom IR
Resulting in the opcodes:
Expand
PUSH0 CALLDATALOAD PUSH1 0xE0 SHR PUSH4 0x5E2499D5 SWAP1 XOR ISZERO PUSH2 0x015 JUMPI PUSH0 PUSH0 SWAP1 REVERT JUMPDEST PUSH1 0xA4 CALLDATASIZE LT CALLVALUE OR PUSH2 0x1B9 JUMPI PUSH1 0x10 PUSH1 0x4 CALLDATALOAD PUSH1 0x4 ADD DUP1 CALLDATALOAD SWAP2 SWAP1 SWAP2 GT PUSH2 0x1B9 JUMPI PUSH1 0x20 DUP2 CALLDATALOAD ADD PUSH1 0xC0 DUP1 SWAP3 SWAP1 CALLDATACOPY PUSH1 0x10 PUSH1 0x24 CALLDATALOAD PUSH1 0x4 ADD DUP1 CALLDATALOAD SWAP2 SWAP1 SWAP2 GT PUSH2 0x1B9 JUMPI PUSH1 0x20 DUP2 CALLDATALOAD ADD PUSH2 0x10 DUP1 SWAP3 SWAP1 CALLDATACOPY PUSH1 0xA PUSH1 0x44 CALLDATALOAD PUSH2 0x160 PUSH2 0x06A PUSH2 0x110 JUMP JUMPDEST PUSH1 0x1E PUSH2 0x180 PUSH2 0x077 PUSH2 0x19C JUMP JUMPDEST PUSH1 0xB SWAP1 LT ISZERO PUSH2 0x0C8 JUMPI PUSH1 0x20 PUSH2 0x160 DUP2 SWAP1 MSTORE PUSH2 0x160 DUP2 SWAP1 ADD SWAP2 MLOAD DUP3 MSTORE PUSH1 0x20 DUP3 ADD PUSH2 0x10 PUSH1 0x20 ADD MLOAD SWAP1 MSTORE DUP2 MLOAD PUSH1 0x1F PUSH0 DUP3 SWAP1 SUB AND CALLDATASIZE PUSH1 0x20 DUP6 ADD SWAP3 SWAP1 SWAP3 ADD SWAP1 SWAP2 SWAP1 CALLDATACOPY SWAP1 MLOAD PUSH1 0x20 ADD PUSH1 0x1F ADD PUSH1 0x1F NOT AND SWAP1 ADD PUSH2 0x160 RETURN JUMPDEST PUSH1 0x20 PUSH2 0x160 DUP2 SWAP1 MSTORE PUSH2 0x160 DUP2 SWAP1 ADD SWAP3 MLOAD DUP4 MSTORE PUSH1 0x20 DUP4 ADD PUSH1 0xC0 PUSH1 0x20 ADD MLOAD SWAP1 MSTORE DUP3 MLOAD PUSH1 0x1F PUSH0 DUP3 SWAP1 SUB AND CALLDATASIZE PUSH1 0x20 DUP7 ADD SWAP3 SWAP1 SWAP3 ADD SWAP1 SWAP2 SWAP1 CALLDATACOPY SWAP2 MLOAD PUSH1 0x20 ADD PUSH1 0x1F ADD PUSH1 0x1F NOT AND SWAP1 SWAP2 ADD PUSH2 0x160 RETURN JUMPDEST DUP3 DUP5 ADD DUP5 DUP2 LT PUSH2 0x1B9 JUMPI DUP4 ISZERO SWAP1 DUP5 DUP2 MUL DUP6 DUP2 DIV SWAP2 SWAP1 SWAP2 EQ SWAP2 SWAP1 SWAP2 OR ISZERO PUSH2 0x1B9 JUMPI DUP4 DUP6 ADD DUP1 SWAP6 SWAP1 LT PUSH2 0x1B9 JUMPI DUP1 SWAP5 SWAP1 ADD DUP1 SWAP5 SWAP1 LT PUSH2 0x1B9 JUMPI SWAP3 DUP3 DUP2 SUB DUP2 DUP2 GT PUSH2 0x1B9 JUMPI PUSH1 0x4 DUP2 SWAP1 SHL PUSH1 0x4 DUP2 SWAP1 SHR SWAP2 SWAP1 SWAP2 XOR PUSH2 0x1B9 JUMPI PUSH1 0xB SWAP1 LT ISZERO SWAP4 SWAP2 SWAP1 SWAP4 PUSH2 0x17B JUMPI SWAP1 SWAP2 SWAP3 JUMPDEST DUP2 MSTORE MLOAD SWAP1 JUMP JUMPDEST PUSH1 0xA PUSH1 0xA SWAP4 SWAP1 ADD SWAP3 SWAP1 SWAP3 LT PUSH2 0x1B9 JUMPI PUSH1 0xA DUP4 SUB DUP1 SWAP4 SWAP1 GT PUSH2 0x1B9 JUMPI SWAP2 PUSH2 0x175 JUMP JUMPDEST DUP3 ISZERO DUP4 DUP6 MUL DUP1 SWAP5 SWAP1 DIV SWAP5 SWAP1 SWAP5 EQ SWAP4 SWAP1 SWAP4 OR ISZERO PUSH2 0x1B9 JUMPI SWAP1 DUP2 MSTORE MLOAD SWAP1 JUMP JUMPDEST PUSH0 DUP1 REVERT
The size above is 446 bytes. Compiling with the original codegen the size was 530 bytes.
The above basic block based IR is then passed to the next step that outputs the EVM assembly, that is then again passed to the original compiler's assembler to produce the final opcodes.
The compiler now does a full liveness analysis on the IR to gain the information for optimising it's assembly output. The stack scheduling is performed with the traversal of the DFG transform of the IR, resulting it minimal operant stack manipulation requirements. Further scheduling optimisations are in order.
Currently, we are seeing improvements in the order of 20%-30% reduction in the size of the code emitted, relative to the original SIR path, which should result in equivalent reduction in gas usage.
More optimization passes will be applied to IR, like deadcode elimination, constant propagation, scallar evolution, etc. Additionally the stack scheduler of the code generator can also be optimized further to minimize gas usage and size.
NOTES:
Commit Message
Cute Animal Picture