Skip to content

Commit

Permalink
remove None target for in_vars_for, add review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 26, 2023
1 parent 980642b commit 024d891
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions vyper/codegen/ir_basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ class IRBasicBlock:
bb.append_instruction(IRInstruction("add", ["%0", "1"], "%1"))
bb.append_instruction(IRInstruction("mul", ["%1", "2"], "%2"))
The label of a basic block is used to refer to it from other basic blocks in order
to branch to it.
The label of a basic block is used to refer to it from other basic blocks
in order to branch to it.
The parent of a basic block is the function it belongs to.
The instructions of a basic block are executed sequentially, and the last instruction
of a basic block is always a terminator instruction, which is used to branch to other
basic blocks.
The instructions of a basic block are executed sequentially, and the last
instruction of a basic block is always a terminator instruction, which is
used to branch to other basic blocks.
"""

label: IRLabel
Expand Down Expand Up @@ -274,21 +274,19 @@ 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" = None) -> OrderedSet[IRVariable]:
assert target is not None
def in_vars_for(self, target: "IRBasicBlock") -> OrderedSet[IRVariable]:
liveness = self.instructions[0].liveness.copy()

if target:
for inst in self.instructions:
if inst.opcode == "select":
if inst.operands[0] == target.label:
liveness.add(inst.operands[1])
if inst.operands[3] in liveness:
liveness.remove(inst.operands[3])
if inst.operands[2] == target.label:
liveness.add(inst.operands[3])
if inst.operands[1] in liveness:
liveness.remove(inst.operands[1])
for inst in self.instructions:
if inst.opcode == "select":
if inst.operands[0] == target.label:
liveness.add(inst.operands[1])
if inst.operands[3] in liveness:
liveness.remove(inst.operands[3])
if inst.operands[2] == target.label:
liveness.add(inst.operands[3])
if inst.operands[1] in liveness:
liveness.remove(inst.operands[1])

return liveness

Expand Down

0 comments on commit 024d891

Please sign in to comment.