Skip to content

Commit 28f0ba2

Browse files
update normalization check
1 parent b1ab64f commit 28f0ba2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

vyper/venom/function.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,17 @@ def _compute_reachability_from(self, bb: IRBasicBlock) -> None:
148148
def normalized(self) -> bool:
149149
"""
150150
Check if function is normalized. A function is normalized if in the
151-
CFG, no basic block simultaneously has multiple inputs and outputs.
151+
CFG, no basic block simultaneously has multiple inputs and outputs,
152+
and no basic block has a single input/output.
152153
That is, a basic block can be jumped to *from* multiple blocks, or it
153154
can jump *to* multiple blocks, but it cannot simultaneously do both.
154155
Having a normalized CFG makes calculation of stack layout easier when
155156
emitting assembly.
156157
"""
157158
for bb in self.get_basic_blocks():
159+
if len(bb.cfg_in) == 1 and len(bb.cfg_out) == 1:
160+
return False
161+
158162
# Ignore if there are no multiple predecessors
159163
if len(bb.cfg_in) <= 1:
160164
continue

vyper/venom/venom_to_assembly.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,13 @@ def _generate_evm_for_instruction(
394394

395395
# Step 3: Reorder stack before join points
396396
if opcode == "jmp":
397-
# after cfg normalization, join points are represented by jmp instructions
398397
# prepare stack for jump into another basic block
399-
assert inst.parent and isinstance(inst.parent.cfg_out, OrderedSet)
400-
b = next(iter(inst.parent.cfg_out))
398+
# we only need to reorder stack before join points, which after
399+
# cfg simplification and normalization, join points are represented
400+
# by jmp instructions.
401+
assert isinstance(inst.parent.cfg_out, OrderedSet)
402+
assert len(inst.parent.cfg_out) == 1
403+
b = inst.parent.cfg_out.first()
401404
target_stack = self.liveness_analysis.input_vars_from(inst.parent, b)
402405
# TODO optimize stack reordering at entry and exit from basic blocks
403406
# NOTE: stack in general can contain multiple copies of the same variable,

0 commit comments

Comments
 (0)