Skip to content

Commit

Permalink
Merge branch 'refactor/effects-analysis' into feat/load-elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 29, 2024
2 parents d83d79e + e9b5303 commit cd88610
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING, Any, Iterator, Optional, Union

import vyper.venom.effects as effects
from vyper.codegen.ir_node import IRnode
from vyper.utils import OrderedSet

Expand Down Expand Up @@ -240,6 +241,12 @@ def is_volatile(self) -> bool:
def is_bb_terminator(self) -> bool:
return self.opcode in BB_TERMINATORS

def get_read_effects(self):
return effects.reads.get(self.opcode, ())

def get_write_effects(self):
return effects.writes.get(self.opcode, ())

def get_label_operands(self) -> Iterator[IRLabel]:
"""
Get all labels in instruction.
Expand Down
48 changes: 48 additions & 0 deletions vyper/venom/effects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
_ALL = ("storage", "transient", "memory", "immutables", "balance", "returndata")

_writes = {
"sstore": "storage",
"tstore": "transient",
"mstore": "memory",
"istore": "immutables",
"call": _ALL,
"delegatecall": _ALL,
"staticcall": "memory",
"create": _ALL,
"create2": _ALL,
"invoke": _ALL, # could be smarter, look up the effects of the invoked function
"dloadbytes": "memory",
"returndatacopy": "memory",
"calldatacopy": "memory",
"codecopy": "memory",
"extcodecopy": "memory",
"mcopy": "memory",
}
_reads = {
"sload": "storage",
"tload": "transient",
"iload": "immutables",
"mload": "memory",
"mcopy": "memory",
"call": _ALL,
"delegatecall": _ALL,
"staticcall": _ALL,
"returndatasize": "returndata",
"returndatacopy": "returndata",
"balance": "balance",
"selfbalance": "balance",
"log": "memory",
"revert": "memory",
"return": "memory",
"sha3": "memory",
}


def _mktuple(x):
if not isinstance(x, tuple):
x = (x,)
return x


writes = {k: _mktuple(v) for k, v in _writes.items()}
reads = {k: _mktuple(v) for k, v in _reads.items()}

0 comments on commit cd88610

Please sign in to comment.