Skip to content

Commit

Permalink
rename in_vars_for to in_vars_from
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 28, 2023
1 parent 21f36ea commit 9cf815c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions vyper/codegen/dfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions vyper/codegen/ir_basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion vyper/ir/bb_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9cf815c

Please sign in to comment.