Skip to content

Commit

Permalink
simplify some code
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 22, 2024
1 parent 59f64f0 commit 1128c60
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions vyper/venom/passes/simplify_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ class SimplifyCFGPass(IRPass):
visited: OrderedSet

def _merge_blocks(self, a: IRBasicBlock, b: IRBasicBlock):
a.instructions.pop()
a.instructions.pop() # pop terminating instructoin
for inst in b.instructions:
assert inst.opcode != "phi", f"Instruction should never be phi {inst}"
assert inst.opcode != "phi", f"Instruction should never be phi {b}"
inst.parent = a
a.instructions.append(inst)

# Update CFG
a.cfg_out = b.cfg_out
if len(b.cfg_out) > 0:
for next_bb in b.cfg_out:
next_bb.remove_cfg_in(b)
next_bb.add_cfg_in(a)

for inst in next_bb.instructions:
if inst.opcode != "phi":
break
inst.operands[inst.operands.index(b.label)] = a.label

for next_bb in a.cfg_out:
next_bb.remove_cfg_in(b)
next_bb.add_cfg_in(a)

for inst in next_bb.instructions:
# assume phi instructions are at beginning of bb
if inst.opcode != "phi":
break
inst.operands[inst.operands.index(b.label)] = a.label

self.function.remove_basic_block(b)

Expand Down

0 comments on commit 1128c60

Please sign in to comment.