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]: use venom pass instances #3908

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion tests/unit/compiler/venom/test_dominator_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def test_phi_placement():
bb2.insert_instruction(IRInstruction("add", [x, IRLiteral(1)], x), 0)
bb7.insert_instruction(IRInstruction("mstore", [x, IRLiteral(0)]), 0)

MakeSSA.run_pass(ctx, bb1)
MakeSSA().run_pass(ctx, bb1)
2 changes: 1 addition & 1 deletion tests/unit/compiler/venom/test_make_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_phi_case():
bb.append_instruction("jmp", bb_cont.label)

calculate_cfg(ctx)
MakeSSA.run_pass(ctx, ctx.basic_blocks[0])
MakeSSA().run_pass(ctx, ctx.basic_blocks[0])
calculate_liveness(ctx)

condition_block = ctx.get_basic_block("condition")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/compiler/venom/test_multi_entry_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_multi_entry_block_1():
calculate_cfg(ctx)
assert not ctx.normalized, "CFG should not be normalized"

NormalizationPass.run_pass(ctx)
NormalizationPass().run_pass(ctx)

assert ctx.normalized, "CFG should be normalized"

Expand Down Expand Up @@ -86,7 +86,7 @@ def test_multi_entry_block_2():
calculate_cfg(ctx)
assert not ctx.normalized, "CFG should not be normalized"

NormalizationPass.run_pass(ctx)
NormalizationPass().run_pass(ctx)

assert ctx.normalized, "CFG should be normalized"

Expand Down Expand Up @@ -128,7 +128,7 @@ def test_multi_entry_block_with_dynamic_jump():
calculate_cfg(ctx)
assert not ctx.normalized, "CFG should not be normalized"

NormalizationPass.run_pass(ctx)
NormalizationPass().run_pass(ctx)
assert ctx.normalized, "CFG should be normalized"

finish_bb = ctx.get_basic_block(finish_label.value)
Expand Down
11 changes: 6 additions & 5 deletions vyper/venom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def _run_passes(ctx: IRFunction, optimize: OptimizationLevel) -> None:
if bb.label.value.startswith("internal") and len(bb.cfg_in) == 0
]

SimplifyCFGPass.run_pass(ctx, ctx.basic_blocks[0])
SimplifyCFGPass().run_pass(ctx, ctx.basic_blocks[0])
for entry in internals:
SimplifyCFGPass.run_pass(ctx, entry)
SimplifyCFGPass().run_pass(ctx, entry)

MakeSSA.run_pass(ctx, ctx.basic_blocks[0])
make_ssa_pass = MakeSSA()
make_ssa_pass.run_pass(ctx, ctx.basic_blocks[0])
for entry in internals:
MakeSSA.run_pass(ctx, entry)
make_ssa_pass.run_pass(ctx, entry)

while True:
changes = 0
Expand All @@ -73,7 +74,7 @@ def _run_passes(ctx: IRFunction, optimize: OptimizationLevel) -> None:
calculate_cfg(ctx)
calculate_liveness(ctx)

changes += DFTPass.run_pass(ctx)
changes += DFTPass().run_pass(ctx)

calculate_cfg(ctx)
calculate_liveness(ctx)
Expand Down
8 changes: 3 additions & 5 deletions vyper/venom/passes/base_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ class IRPass:
until no more changes are made.
"""

@classmethod
def run_pass(cls, *args, **kwargs):
t = cls()
def run_pass(self, *args, **kwargs):
count = 0

for _ in range(1000):
changes_count = t._run_pass(*args, **kwargs) or 0
changes_count = self._run_pass(*args, **kwargs) or 0
count += changes_count
if changes_count == 0:
break
else:
raise Exception("Too many iterations in IR pass!", t.__class__)
raise Exception("Too many iterations in IR pass!", self.__class__)

return count

Expand Down
4 changes: 2 additions & 2 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ def generate_evm(self, no_optimize: bool = False) -> list[str]:

# Before emitting the assembly, we need to make sure that the
# CFG is normalized. Calling calculate_cfg() will denormalize IR (reset)
# so it should not be called after calling NormalizationPass.run_pass().
# so it should not be called after calling NormalizationPass().run_pass().
# Liveness is then computed for the normalized IR, and we can proceed to
# assembly generation.
# This is a side-effect of how dynamic jumps are temporarily being used
# to support the O(1) dispatcher. -> look into calculate_cfg()
for ctx in self.ctxs:
NormalizationPass.run_pass(ctx)
NormalizationPass().run_pass(ctx)
calculate_cfg(ctx)
calculate_liveness(ctx)
calculate_dup_requirements(ctx)
Expand Down
Loading