From 9cf815ce2ef06224d94f5295f375c210e098a7e6 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 28 Oct 2023 11:36:07 -0400 Subject: [PATCH] rename `in_vars_for` to `in_vars_from` --- vyper/codegen/dfg.py | 7 ++++--- vyper/codegen/ir_basicblock.py | 9 +++++---- vyper/ir/bb_optimizer.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vyper/codegen/dfg.py b/vyper/codegen/dfg.py index c604982036..5fb4d77191 100644 --- a/vyper/codegen/dfg.py +++ b/vyper/codegen/dfg.py @@ -219,7 +219,7 @@ def _stack_reorder(assembly: list, stack_map: StackMap, stack_ops: list[IRValueB op = stack_ops[i] final_stack_depth = -(len(stack_ops) - i - 1) depth = stack_map.get_depth_in(op) - assert depth is not StackMap.NOT_IN_STACK, "Operand not in stack" + assert depth is not StackMap.NOT_IN_STACK, f"{op} not in stack: {stack_map.stack_map}" is_in_place = depth == final_stack_depth if not is_in_place: @@ -318,8 +318,9 @@ def _generate_evm_for_instruction_r( # Step 3: Reorder stack if opcode in ["jnz", "jmp"]: - _, b = next(enumerate(inst.parent.cfg_out)) - target_stack = OrderedSet(b.in_vars_for(inst.parent)) + assert isinstance(inst.parent.cfg_out, OrderedSet) + b = next(iter(inst.parent.cfg_out)) + target_stack = OrderedSet(b.in_vars_from(inst.parent)) _stack_reorder(assembly, stack_map, target_stack) _stack_duplications(assembly, inst, stack_map, operands) diff --git a/vyper/codegen/ir_basicblock.py b/vyper/codegen/ir_basicblock.py index 8de5e75b32..48bb6e44b2 100644 --- a/vyper/codegen/ir_basicblock.py +++ b/vyper/codegen/ir_basicblock.py @@ -280,19 +280,20 @@ def union_cfg_out(self, bb_set: OrderedSet["IRBasicBlock"]) -> None: def remove_cfg_out(self, bb: "IRBasicBlock") -> None: self.cfg_out.remove(bb) - # calculate the input variables for the target bb - def in_vars_for(self, target: "IRBasicBlock") -> OrderedSet[IRVariable]: + # calculate the input variables into self from source + def in_vars_from(self, source: "IRBasicBlock") -> OrderedSet[IRVariable]: liveness = self.instructions[0].liveness.copy() + assert isinstance(liveness, OrderedSet) for inst in self.instructions: # REVIEW: might be nice if some of these instructions # were more structured. if inst.opcode == "select": - if inst.operands[0] == target.label: + if inst.operands[0] == source.label: liveness.add(inst.operands[1]) if inst.operands[3] in liveness: liveness.remove(inst.operands[3]) - if inst.operands[2] == target.label: + if inst.operands[2] == source.label: liveness.add(inst.operands[3]) if inst.operands[1] in liveness: liveness.remove(inst.operands[1]) diff --git a/vyper/ir/bb_optimizer.py b/vyper/ir/bb_optimizer.py index 1614c2ca27..4ad6b226e2 100644 --- a/vyper/ir/bb_optimizer.py +++ b/vyper/ir/bb_optimizer.py @@ -124,7 +124,7 @@ def _calculate_liveness(bb: IRBasicBlock, liveness_visited: set) -> None: continue liveness_visited[bb] = out_bb _calculate_liveness(out_bb, liveness_visited) - in_vars = out_bb.in_vars_for(bb) + in_vars = out_bb.in_vars_from(bb) bb.out_vars = bb.out_vars.union(in_vars) bb.calculate_liveness()