Skip to content

Commit

Permalink
Merge branch 'master' into fix/offset-operand-order
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 25, 2024
2 parents 71a92dc + 48a5da4 commit d916c44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions tests/functional/codegen/features/test_constructor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import pytest

from tests.evm_backends.base_env import _compile
from vyper.exceptions import StackTooDeep
from vyper.utils import method_id


Expand Down Expand Up @@ -166,6 +169,7 @@ def get_foo() -> uint256:
assert c.get_foo() == 39


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_nested_dynamic_array_constructor_arg_2(env, get_contract):
code = """
foo: int128
Expand Down
29 changes: 17 additions & 12 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,23 @@ def _generate_evm_for_instruction(
# Step 2: Emit instruction's input operands
self._emit_input_operands(assembly, inst, operands, stack)

# Step 3: Reorder stack
if opcode in ["jnz", "djmp", "jmp"]:
# prepare stack for jump into another basic block
assert inst.parent and isinstance(inst.parent.cfg_out, OrderedSet)
b = next(iter(inst.parent.cfg_out))
target_stack = self.liveness_analysis.input_vars_from(inst.parent, b)
# TODO optimize stack reordering at entry and exit from basic blocks
# NOTE: stack in general can contain multiple copies of the same variable,
# however we are safe in the case of jmp/djmp/jnz as it's not going to
# have multiples.
target_stack_list = list(target_stack)
self._stack_reorder(assembly, stack, target_stack_list)
# Step 3: Reorder stack before join points
if opcode == "jmp":
# prepare stack for jump into a join point
# we only need to reorder stack before join points, which after
# cfg normalization, join points can only be led into by
# jmp instructions.
assert isinstance(inst.parent.cfg_out, OrderedSet)
assert len(inst.parent.cfg_out) == 1
next_bb = inst.parent.cfg_out.first()

# guaranteed by cfg normalization+simplification
assert len(next_bb.cfg_in) > 1

target_stack = self.liveness_analysis.input_vars_from(inst.parent, next_bb)
# NOTE: in general the stack can contain multiple copies of
# the same variable, however, before a jump that is not possible
self._stack_reorder(assembly, stack, list(target_stack))

if opcode in COMMUTATIVE_INSTRUCTIONS:
cost_no_swap = self._stack_reorder([], stack, operands, dry_run=True)
Expand Down

0 comments on commit d916c44

Please sign in to comment.