Skip to content

Commit

Permalink
fix[venom]: remove liveness requests (#4058)
Browse files Browse the repository at this point in the history
This commit sanitizes the requests/invalidations of liveness analysis in
the various passes.

Additionally it renames the property `in_vars` to `liveness_in_vars` to
make it clear that this property is liveness dependent
  • Loading branch information
harkal authored May 29, 2024
1 parent 81b48b7 commit 1b335c5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions vyper/venom/analysis/dfg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

from vyper.venom.analysis.analysis import IRAnalysesCache, IRAnalysis
from vyper.venom.analysis.liveness import LivenessAnalysis
from vyper.venom.basicblock import IRInstruction, IRVariable
from vyper.venom.function import IRFunction

Expand Down Expand Up @@ -67,5 +68,8 @@ def as_graph(self) -> str:
lines.append("}")
return "\n".join(lines)

def invalidate(self):
self.analyses_cache.invalidate_analysis(LivenessAnalysis)

def __repr__(self) -> str:
return self.as_graph()
2 changes: 1 addition & 1 deletion vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def is_terminal(self) -> bool:
return len(self.cfg_out) == 0

@property
def in_vars(self) -> OrderedSet[IRVariable]:
def liveness_in_vars(self) -> OrderedSet[IRVariable]:
for inst in self.instructions:
if inst.opcode != "phi":
return inst.liveness
Expand Down
6 changes: 5 additions & 1 deletion vyper/venom/passes/make_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def run_pass(self):

self.analyses_cache.request_analysis(CFGAnalysis)
self.dom = self.analyses_cache.request_analysis(DominatorTreeAnalysis)

# Request liveness analysis so the `liveness_in_vars` field is valid
self.analyses_cache.request_analysis(LivenessAnalysis)

self._add_phi_nodes()
Expand All @@ -28,6 +30,8 @@ def run_pass(self):
self._rename_vars(fn.entry)
self._remove_degenerate_phis(fn.entry)

self.analyses_cache.invalidate_analysis(LivenessAnalysis)

def _add_phi_nodes(self):
"""
Add phi nodes to the function.
Expand All @@ -54,7 +58,7 @@ def _add_phi_nodes(self):
defs.append(dom)

def _place_phi(self, var: IRVariable, basic_block: IRBasicBlock):
if var not in basic_block.in_vars:
if var not in basic_block.liveness_in_vars:
return

args: list[IROperand] = []
Expand Down
1 change: 0 additions & 1 deletion vyper/venom/passes/mem2var.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Mem2Var(IRPass):
def run_pass(self):
self.analyses_cache.request_analysis(CFGAnalysis)
dfg = self.analyses_cache.request_analysis(DFGAnalysis)
self.analyses_cache.request_analysis(LivenessAnalysis)

self.var_name_count = 0
for var, inst in dfg.outputs.items():
Expand Down
3 changes: 3 additions & 0 deletions vyper/venom/passes/remove_unused_variables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from vyper.utils import OrderedSet
from vyper.venom.analysis.dfg import DFGAnalysis
from vyper.venom.analysis.liveness import LivenessAnalysis
from vyper.venom.basicblock import IRInstruction
from vyper.venom.passes.base_pass import IRPass

Expand All @@ -25,6 +26,8 @@ def run_pass(self):
inst = work_list.pop()
self._process_instruction(inst)

self.analyses_cache.invalidate_analysis(LivenessAnalysis)

def _process_instruction(self, inst):
if inst.output is None:
return
Expand Down

0 comments on commit 1b335c5

Please sign in to comment.