Skip to content

Commit

Permalink
feat[venom]: improve liveness computation time (#4086)
Browse files Browse the repository at this point in the history
reduce time spent in liveness by only recomputing liveness for basic
blocks which need it (any of its `cfg_out` has changed).

reduces time in venom by roughly 25%

there is also a slight codesize improvement. it seems to be sensitive
to the order in which items are added to the worklist.
  • Loading branch information
charles-cooper authored Sep 18, 2024
1 parent 53f7675 commit e1de93a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions vyper/venom/analysis/liveness.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections import deque

from vyper.exceptions import CompilerPanic
from vyper.utils import OrderedSet
from vyper.venom.analysis.analysis import IRAnalysis
Expand All @@ -13,14 +15,19 @@ class LivenessAnalysis(IRAnalysis):
def analyze(self):
self.analyses_cache.request_analysis(CFGAnalysis)
self._reset_liveness()
while True:
changed = False
for bb in self.function.get_basic_blocks():
changed |= self._calculate_out_vars(bb)
changed |= self._calculate_liveness(bb)

if not changed:
break
self._worklist = deque()
self._worklist.extend(self.function.get_basic_blocks())

while len(self._worklist) > 0:
changed = False
bb = self._worklist.popleft()
changed |= self._calculate_out_vars(bb)
changed |= self._calculate_liveness(bb)
# recompute liveness for basic blocks pointing into
# this basic block
if changed:
self._worklist.extend(bb.cfg_in)

def _reset_liveness(self) -> None:
for bb in self.function.get_basic_blocks():
Expand Down

0 comments on commit e1de93a

Please sign in to comment.