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

feat[venom]: add varname freshener #4484

Open
wants to merge 1 commit into
base: venom-develop
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions vyper/venom/function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import textwrap
from collections import defaultdict
from dataclasses import dataclass
from typing import Iterator, Optional

Expand Down Expand Up @@ -106,6 +107,19 @@ def get_next_variable(self) -> IRVariable:
def get_last_variable(self) -> str:
return f"%{self.last_variable}"

def freshen_varnames(self) -> None:
self.last_variable = 0
varmap = defaultdict(self.get_next_variable)
for bb in self.get_basic_blocks():
for inst in bb.instructions:
if inst.output:
inst.output = varmap[inst.output]

for i, op in enumerate(inst.operands):
if not isinstance(op, IRVariable):
continue
inst.operands[i] = varmap[op]

def remove_unreachable_blocks(self) -> int:
# Remove unreachable basic blocks
# pre: requires CFG analysis!
Expand Down
Loading