From 2987d36e57895be870f1eb7364427f688998c689 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 27 Sep 2024 14:29:44 -0400 Subject: [PATCH 1/2] refactor[venom]: add effects to instructions --- vyper/venom/basicblock.py | 7 ++++++ vyper/venom/effects.py | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 vyper/venom/effects.py diff --git a/vyper/venom/basicblock.py b/vyper/venom/basicblock.py index d6fb9560cd..07367d71fc 100644 --- a/vyper/venom/basicblock.py +++ b/vyper/venom/basicblock.py @@ -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 @@ -242,6 +243,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.reads.get(self.opcode, ()) + def get_label_operands(self) -> Iterator[IRLabel]: """ Get all labels in instruction. diff --git a/vyper/venom/effects.py b/vyper/venom/effects.py new file mode 100644 index 0000000000..7f6aa52ac7 --- /dev/null +++ b/vyper/venom/effects.py @@ -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()} From e9b53036a0c827743f472a3add9f9e74842485ba Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 28 Sep 2024 08:35:03 -0700 Subject: [PATCH 2/2] fix get_write_effects() Co-authored-by: Harry Kalogirou --- vyper/venom/basicblock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/venom/basicblock.py b/vyper/venom/basicblock.py index 07367d71fc..ae1db9b27c 100644 --- a/vyper/venom/basicblock.py +++ b/vyper/venom/basicblock.py @@ -247,7 +247,7 @@ def get_read_effects(self): return effects.reads.get(self.opcode, ()) def get_write_effects(self): - return effects.reads.get(self.opcode, ()) + return effects.writes.get(self.opcode, ()) def get_label_operands(self) -> Iterator[IRLabel]: """