Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin-charles/refactor/effects-analysi…
Browse files Browse the repository at this point in the history
…s' into feat/dft_upgrade
  • Loading branch information
harkal committed Oct 1, 2024
2 parents 62616cd + fcb688f commit 805b079
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 43 deletions.
6 changes: 6 additions & 0 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ def is_pseudo(self) -> bool:
"""
return self.is_phi or self.is_param

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

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

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

_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",
}

class Effects(Flag):
STORAGE = auto()
TRANSIENT = auto()
MEMORY = auto()
IMMUTABLES = auto()
BALANCE = auto()
RETURNDATA = auto()


def _mktuple(x):
if not isinstance(x, tuple):
x = (x,)
return x
EMPTY = Effects(0)
ALL = ~EMPTY
STORAGE = Effects.STORAGE
TRANSIENT = Effects.TRANSIENT
MEMORY = Effects.MEMORY
IMMUTABLES = Effects.IMMUTABLES
BALANCE = Effects.BALANCE
RETURNDATA = Effects.RETURNDATA


writes = {k: _mktuple(v) for k, v in _writes.items()}
reads = {k: _mktuple(v) for k, v in _reads.items()}
writes = {
"sstore": STORAGE,
"tstore": TRANSIENT,
"mstore": MEMORY,
"istore": IMMUTABLES,
"call": ALL,
"delegatecall": ALL,
"staticcall": MEMORY | RETURNDATA,
"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,
}

0 comments on commit 805b079

Please sign in to comment.