Skip to content

Commit

Permalink
handle effects
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 29, 2024
1 parent cd88610 commit 44bbcd4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions vyper/venom/passes/load_elimination.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def _process_bb(self, bb):
memory = ()

for inst in bb.instructions:
if "memory" in inst.get_write_effects():
memory = ()
if "storage" in inst.get_write_effects():
storage = ()
if "transient" in inst.get_write_effects():
transient = ()

if inst.opcode == "mstore":
# mstore [val, ptr]
memory = (inst.operands[1], inst.operands[0])
Expand All @@ -37,15 +44,19 @@ def _process_bb(self, bb):
if inst.opcode == "mload":
prev_memory = memory
memory = (inst.operands[0], inst.output)
if not prev_memory or not self.equivalent(inst.operands[0], prev_memory[0]):
if not prev_memory:
continue
if not self.equivalent(inst.operands[0], prev_memory[0]):
continue
inst.opcode = "store"
inst.operands = [prev_memory[1]]

if inst.opcode == "sload":
prev_storage = storage
storage = (inst.operands[0], inst.output)
if not prev_storage or not self.equivalent(inst.operands[0], prev_storage[0]):
if not prev_storage:
continue
if not self.equivalent(inst.operands[0], prev_storage[0]):
continue
inst.opcode = "store"
inst.operands = [prev_storage[1]]
Expand All @@ -54,7 +65,9 @@ def _process_bb(self, bb):
if inst.opcode == "tload":
prev_transient = transient
transient = (inst.operands[0], inst.output)
if not prev_transient or not self.equivalent(inst.operands[0], prev_transient[0]):
if not prev_transient:
continue
if not self.equivalent(inst.operands[0], prev_transient[0]):
continue
inst.opcode = "store"
inst.operands = [prev_transient[1]]
Expand Down

0 comments on commit 44bbcd4

Please sign in to comment.