Skip to content

Commit

Permalink
add a heuristic to swap out top of stack
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Nov 1, 2023
1 parent 88dcd5d commit 829580d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vyper/venom/dfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ def _emit_input_operands(

# print("EMIT INPUTS FOR", inst)

# dumb heuristic: if the top of stack is not wanted here, swap
# it with something that is wanted
if ops and stack.stack and stack.stack[-1] not in ops:
for op in ops:
if isinstance(op, IRVariable) and op not in inst.dup_requirements:
depth = stack.get_depth(op)
assert depth is not StackModel.NOT_IN_STACK
stack.swap(assembly, depth)
break

for op in ops:
if isinstance(op, IRLabel):
# invoke emits the actual instruction itself so we don't need to emit it here
Expand Down

0 comments on commit 829580d

Please sign in to comment.