Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor[venom]: simplify SimplifyCFG pass #4528

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 3 additions & 41 deletions vyper/venom/passes/simplify_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,6 @@ def _collapse_chained_blocks(self, entry: IRBasicBlock):
self.visited = OrderedSet()
self._collapse_chained_blocks_r(entry)

def _optimize_empty_basicblocks(self) -> int:
"""
Remove empty basic blocks.
"""
# NOTE CMC 2025-03-12 this function is a no-op!

fn = self.function
worklist = list(fn.get_basic_blocks())
i = count = 0
while i < len(worklist):
bb = worklist[i]
i += 1

if len(bb.instructions) > 0:
continue

next_bb = worklist[i]

replaced_label = bb.label
replacement_label = next_bb.label

# Try to preserve symbol labels
if replaced_label.is_symbol:
replaced_label, replacement_label = replacement_label, replaced_label
next_bb.label = replacement_label

self._replace_label(replaced_label, replacement_label)

fn.remove_basic_block(bb)
i -= 1
count += 1

return count

def _replace_label(self, original_label: IRLabel, replacement_label: IRLabel):
for bb in self.function.get_basic_blocks():
for inst in bb.instructions:
Expand All @@ -125,14 +91,10 @@ def run_pass(self):
fn = self.function
entry = fn.entry

for _ in range(fn.num_basic_blocks):
changes = self._optimize_empty_basicblocks()
self.analyses_cache.request_analysis(CFGAnalysis)
changes = fn.remove_unreachable_blocks()
if changes:
self.analyses_cache.force_analysis(CFGAnalysis)
changes += fn.remove_unreachable_blocks()
if changes == 0:
break
else:
raise CompilerPanic("Too many iterations removing empty basic blocks")

for _ in range(fn.num_basic_blocks): # essentially `while True`
self._collapse_chained_blocks(entry)
Expand Down