-
-
Notifications
You must be signed in to change notification settings - Fork 800
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]: improve liveness computation #4301
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
00165c8
feat[venom]: improve liveness computation
charles-cooper 8619371
fix lint
charles-cooper 87af6df
Merge branch 'master' into perf/liveness2
charles-cooper 66bd73e
Merge branch 'master' into perf/liveness2
charles-cooper 3f8ec64
remove dom tree from sccp pass
charles-cooper 24f90a6
add dfs to cfg analysis. refactor out of dom tree analysis
charles-cooper 9b8d3f3
fix from bad merge
charles-cooper d1951a0
fix dfs search - leaves first
charles-cooper d1e18d6
simplify cfg calculation
charles-cooper 30fa633
fix a regression
charles-cooper 67d1382
refactor: remove IRFunction.compute_reachability
charles-cooper a06d546
change cfg_out order
charles-cooper f198477
add a note
charles-cooper 452c82e
some StackTooDeep are fixed
charles-cooper ee50088
fix sccp tests
charles-cooper 5edb7fe
Merge branch 'master' into refactor/dfg-domtree
charles-cooper d3967f5
fix lint
charles-cooper 240d9d2
use update instead of union
charles-cooper 78da77c
skip unreachable bbs
charles-cooper 2fe1397
refactor fix_phi_nodes
charles-cooper 27518a5
remove useless __eq__ and __hash__ implementations
charles-cooper 1b117c8
remove `IRBasicBlock.reachable`
charles-cooper 6178526
Merge branch 'master' into refactor/dfg-domtree
charles-cooper df01ee8
Merge branch 'refactor/dfg-domtree' into perf/liveness2
charles-cooper 3863ed2
fix from merge
charles-cooper 8135181
Merge branch 'refactor/dfg-domtree' into perf/liveness2
charles-cooper 5ec2cb2
Merge branch 'master' into perf/liveness2
charles-cooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
@@ -1,41 +1,62 @@ | ||
from typing import Iterator | ||
|
||
from vyper.utils import OrderedSet | ||
from vyper.venom.analysis import IRAnalysis | ||
from vyper.venom.basicblock import CFG_ALTERING_INSTRUCTIONS | ||
from vyper.venom.basicblock import CFG_ALTERING_INSTRUCTIONS, IRBasicBlock | ||
|
||
|
||
class CFGAnalysis(IRAnalysis): | ||
""" | ||
Compute control flow graph information for each basic block in the function. | ||
""" | ||
|
||
_dfs: OrderedSet[IRBasicBlock] | ||
|
||
def analyze(self) -> None: | ||
fn = self.function | ||
self._dfs = OrderedSet() | ||
|
||
for bb in fn.get_basic_blocks(): | ||
bb.cfg_in = OrderedSet() | ||
bb.cfg_out = OrderedSet() | ||
bb.out_vars = OrderedSet() | ||
bb.is_reachable = False | ||
|
||
for bb in fn.get_basic_blocks(): | ||
assert len(bb.instructions) > 0, "Basic block should not be empty" | ||
last_inst = bb.instructions[-1] | ||
assert last_inst.is_bb_terminator, f"Last instruction should be a terminator {bb}" | ||
assert bb.is_terminated | ||
|
||
for inst in bb.instructions: | ||
if inst.opcode in CFG_ALTERING_INSTRUCTIONS: | ||
ops = inst.get_label_operands() | ||
for op in ops: | ||
fn.get_basic_block(op.value).add_cfg_in(bb) | ||
term = bb.instructions[-1] | ||
if term.opcode in CFG_ALTERING_INSTRUCTIONS: | ||
ops = term.get_label_operands() | ||
# order of cfg_out matters to performance! | ||
for op in reversed(list(ops)): | ||
next_bb = fn.get_basic_block(op.value) | ||
bb.add_cfg_out(next_bb) | ||
next_bb.add_cfg_in(bb) | ||
|
||
# Fill in the "out" set for each basic block | ||
for bb in fn.get_basic_blocks(): | ||
for in_bb in bb.cfg_in: | ||
in_bb.add_cfg_out(bb) | ||
self._compute_dfs_r(self.function.entry) | ||
|
||
def _compute_dfs_r(self, bb): | ||
if bb.is_reachable: | ||
return | ||
bb.is_reachable = True | ||
|
||
for out_bb in bb.cfg_out: | ||
self._compute_dfs_r(out_bb) | ||
|
||
self._dfs.add(bb) | ||
|
||
@property | ||
def dfs_walk(self) -> Iterator[IRBasicBlock]: | ||
return iter(self._dfs) | ||
|
||
def invalidate(self): | ||
from vyper.venom.analysis import DFGAnalysis, DominatorTreeAnalysis, LivenessAnalysis | ||
|
||
self.analyses_cache.invalidate_analysis(DominatorTreeAnalysis) | ||
self.analyses_cache.invalidate_analysis(LivenessAnalysis) | ||
|
||
self._dfs = None | ||
|
||
# be conservative - assume cfg invalidation invalidates dfg | ||
self.analyses_cache.invalidate_analysis(DFGAnalysis) |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Module-level cyclic import Error