Skip to content

Commit

Permalink
roll back var equivalence changes
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jan 12, 2025
1 parent 226b9c9 commit 55cbf90
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions vyper/venom/analysis/equivalent_vars.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from vyper.venom.analysis import IRAnalysis
from vyper.venom.basicblock import IRInstruction, IRLiteral, IROperand
from vyper.venom.analysis import DFGAnalysis, IRAnalysis
from vyper.venom.basicblock import IRVariable


class VarEquivalenceAnalysis(IRAnalysis):
Expand All @@ -12,44 +12,29 @@ class VarEquivalenceAnalysis(IRAnalysis):
"""

def analyze(self):
self._equivalence_set: dict[IROperand, int] = {}
dfg = self.analyses_cache.request_analysis(DFGAnalysis)

# dict from bags to literal values
self._literals: dict[int, IRLiteral] = {}
equivalence_set: dict[IRVariable, int] = {}

bag = 0
for bb in self.function.get_basic_blocks():
for inst in bb.instructions:
if inst.opcode != "store":
continue
self._handle_store(inst, bag)
bag += 1
for bag, (var, inst) in enumerate(dfg._dfg_outputs.items()):
if inst.opcode != "store":
continue

def _handle_store(self, inst: IRInstruction, bag: int):
var = inst.output
source = inst.operands[0]
source = inst.operands[0]

assert var is not None # help mypy
assert var not in self._equivalence_set # invariant
assert var not in equivalence_set # invariant
if source in equivalence_set:
equivalence_set[var] = equivalence_set[source]
continue
else:
equivalence_set[var] = bag
equivalence_set[source] = bag

if source in self._equivalence_set:
bag = self._equivalence_set[source]
self._equivalence_set[var] = bag
else:
self._equivalence_set[source] = bag
self._equivalence_set[var] = bag

if isinstance(source, IRLiteral):
self._literals[bag] = source
self._equivalence_set = equivalence_set

def equivalent(self, var1, var2):
if var1 not in self._equivalence_set:
return False
if var2 not in self._equivalence_set:
return False
return self._equivalence_set[var1] == self._equivalence_set[var2]

def get_literal(self, var):
if (bag := self._equivalence_set.get(var)) is None:
return None
return self._literals.get(bag)

0 comments on commit 55cbf90

Please sign in to comment.