forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from vyper.utils import OrderedSet | ||
from vyper.venom.analysis.analysis import IRAnalysis | ||
from vyper.venom.basicblock import IRVariable | ||
from vyper.venom.analysis.dfg import DFGAnalysis | ||
|
||
|
||
class VarEquivalenceAnalysis(IRAnalysis): | ||
""" | ||
Generate equivalence sets of variables | ||
""" | ||
def analyze(self): | ||
dfg = self.analyses_cache.request_analysis(DFGAnalysis) | ||
|
||
equivalence_set: dict[IRVariable, int] = {} | ||
|
||
for bag, (var, inst) in enumerate(dfg._dfg_outputs.items()): | ||
if inst.opcode != "store": | ||
continue | ||
|
||
source = inst.operands[0] | ||
|
||
if source in equivalence_set: | ||
equivalence_set[var] = equivalence_set[source] | ||
continue | ||
else: | ||
assert var not in equivalence_set | ||
equivalence_set[var] = bag | ||
equivalence_set[source] = bag | ||
|
||
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters