Skip to content

Commit

Permalink
feat[venom]: "pickaxe" stack scheduler optimization (#3951)
Browse files Browse the repository at this point in the history
implement "pickaxe" stack scheduler optimization.

sometimes, venom produces some unneeded stack traffic. this can't be
fixed by improved dataflow analysis, because it is an issue in the stack
scheduler rather than instruction reordering. what happens is a stack
item is produced, but it has a longer lifespan than other things on the
stack and the instruction cannot be reordered. this commit introduces a
simple heuristic: at the time of stack item production, check the live
list for something with "shorter" liveness we can swap it with.

i just made up the "pickaxe" term but i think it sounds cool :)
  • Loading branch information
charles-cooper authored May 20, 2024
1 parent f4c9946 commit 0ba1c62
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ def _generate_evm_for_instruction(
if inst.output is not None:
if "call" in inst.opcode and inst.output not in next_liveness:
self.pop(assembly, stack)
elif inst.output in next_liveness:
# peek at next_liveness to find the next scheduled item,
# and optimistically swap with it
next_scheduled = list(next_liveness)[-1]
self.swap_op(assembly, stack, next_scheduled)

return apply_line_numbers(inst, assembly)

Expand Down

0 comments on commit 0ba1c62

Please sign in to comment.