Skip to content
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]: memssa #4534

Draft
wants to merge 113 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
24869ec
tmp
harkal Nov 19, 2024
21b75e3
temp
harkal Nov 20, 2024
6125c89
generalize
harkal Dec 16, 2024
ad4f766
work
harkal Dec 16, 2024
ead4e54
lint
harkal Dec 16, 2024
74067a5
print context
harkal Dec 16, 2024
6005571
work
harkal Dec 16, 2024
4a8c792
print changes
harkal Dec 16, 2024
24a7bdd
add operands to phi and printout
harkal Dec 16, 2024
0923660
lint
harkal Dec 16, 2024
0473143
work
harkal Dec 16, 2024
361e583
work
harkal Dec 16, 2024
475ebe2
merge in walker stuff
harkal Dec 17, 2024
619a933
enable passes
harkal Dec 17, 2024
fbd85c0
cleanup
harkal Dec 17, 2024
f00c0fc
use cfg pre walk and prettier output
harkal Dec 17, 2024
a076ecf
post merge
harkal Dec 20, 2024
24738cf
swash alias stuff
harkal Dec 20, 2024
985e271
fix imports
harkal Feb 12, 2025
2f60d50
repr fix
harkal Feb 12, 2025
0dd8a53
post rebase fixes
harkal Feb 12, 2025
b2b6fbd
use zeros to avoid linter nightmare
harkal Feb 12, 2025
8e35a25
lint
harkal Feb 12, 2025
c3f4b23
lint
harkal Mar 17, 2025
dc90054
covert to analysis
harkal Mar 17, 2025
e8e943c
dead store elimination
harkal Mar 17, 2025
5c7252c
lint
harkal Mar 17, 2025
c7e2925
skip invokes for now
harkal Mar 17, 2025
9089613
use effects
harkal Mar 18, 2025
d27030a
constraint to stores
harkal Mar 18, 2025
53794fb
graph construction fixes
harkal Mar 18, 2025
73de7c3
wip
harkal Mar 18, 2025
6b8f91e
preserve old annotation
harkal Mar 18, 2025
11556cc
wip: new alias
harkal Mar 18, 2025
5d8dd20
move location queries to IRInstruction
harkal Mar 19, 2025
cdc1f3d
wip clobbering
harkal Mar 19, 2025
f3d3e3a
version -> id
harkal Mar 19, 2025
b84af30
move memory location close to IRInstruction
harkal Mar 19, 2025
b16cfa6
basic tests
harkal Mar 19, 2025
1895461
cleanup
harkal Mar 19, 2025
303157c
test updates
harkal Mar 19, 2025
b4ee7c2
dead store test
harkal Mar 19, 2025
caf65fa
test def chain
harkal Mar 19, 2025
e9f6c27
test the last too
harkal Mar 19, 2025
47aaefa
get defs and uses
harkal Mar 19, 2025
1b9841f
link the defs
harkal Mar 19, 2025
24a566f
enable pass
harkal Mar 20, 2025
1646399
wip
harkal Mar 20, 2025
9d90c9a
get_clobbering_memory_address()
harkal Mar 20, 2025
3c5b187
still no dice
harkal Mar 20, 2025
4c3c41e
comments
harkal Mar 20, 2025
21053ae
test clobbering case
harkal Mar 20, 2025
b7e07cc
wip
harkal Mar 20, 2025
6adbc3e
lint
harkal Mar 20, 2025
cb03230
fix
harkal Mar 20, 2025
001c02f
squash commit: add `is_volatile` and mark method
harkal Mar 21, 2025
2d635b4
update dead store to ignore volatile memory
harkal Mar 21, 2025
b6524bc
update parser to read hex values
harkal Mar 21, 2025
cc7d27a
test volatile
harkal Mar 21, 2025
d45648d
lint
harkal Mar 21, 2025
0503924
Merge branch 'master' into feat/memssa
harkal Mar 21, 2025
d8868b2
variable size volatile test
harkal Mar 21, 2025
0cc2983
remove `base` in locations for now
harkal Mar 21, 2025
47e92c7
cleanup
harkal Mar 21, 2025
d1ffef2
lint
harkal Mar 21, 2025
c6145e9
Merge branch 'master' into feat/memssa
harkal Mar 21, 2025
6c43b93
add volatile memory locations to function
harkal Mar 21, 2025
1bdb90b
remove `is_alloca`
harkal Mar 21, 2025
32d7f2f
wip
harkal Mar 21, 2025
450fa88
test non dead store
harkal Mar 21, 2025
2c87643
Merge branch 'master' into feat/memssa
harkal Mar 24, 2025
a231c73
wip
harkal Mar 24, 2025
46e7ff3
fix parser whitespace handling
harkal Mar 24, 2025
0ef24d1
Revert "fix parser whitespace handling"
harkal Mar 26, 2025
be3521b
op order
harkal Mar 26, 2025
6b6fcde
overlap testing
harkal Mar 26, 2025
d921c3c
broader
harkal Mar 26, 2025
6edcb81
wip
harkal Mar 26, 2025
1cff1fd
test may_alias
harkal Mar 26, 2025
5ba6516
cleanup
harkal Mar 26, 2025
6189acc
wip
harkal Mar 26, 2025
c83a298
effects
harkal Mar 26, 2025
ec808e0
signatures
harkal Mar 26, 2025
c8c1c43
call tests
harkal Mar 26, 2025
113b954
effects
harkal Mar 26, 2025
4e9aa0a
more basic tests
harkal Mar 26, 2025
0f01a89
wip
harkal Mar 26, 2025
915f63c
pierce through non aliasing defs
harkal Mar 26, 2025
4901b45
test alias piercing
harkal Mar 26, 2025
84909a8
test case
harkal Mar 27, 2025
bfff342
simplify
harkal Mar 27, 2025
4f5d617
wip - move alias checking to "runtime"
harkal Mar 27, 2025
cb5bb0e
wip
harkal Mar 27, 2025
52650a7
check alias when finding reaching def
harkal Mar 27, 2025
33b3f77
test
harkal Mar 27, 2025
eff5b5b
fix dead elimination test
harkal Mar 27, 2025
d3f62a2
fix tests
harkal Mar 27, 2025
f171a13
add codecopy and extcodecopy memory ranges
harkal Mar 27, 2025
3f42c53
call delegatecall staticcall
harkal Mar 27, 2025
e498c89
returndatacopy wip
harkal Mar 27, 2025
4fcbf2b
partial alias and clobber
harkal Mar 27, 2025
287bd38
partial clobber fix
harkal Mar 27, 2025
05bdd69
add create
harkal Mar 27, 2025
46c5c22
wip
harkal Mar 27, 2025
6a2c8d2
log and revert
harkal Mar 27, 2025
b3b8730
proper order
harkal Mar 27, 2025
9036106
no longer scheduler regression
harkal Mar 27, 2025
2b20b05
Merge branch 'master' into feat/memssa
harkal Mar 27, 2025
4f51d8b
lint, cleanup
harkal Mar 27, 2025
f5b832a
simplify test
harkal Mar 27, 2025
5b9f67c
disable hevm for call tests
harkal Mar 27, 2025
4c4de68
disable for test_calldatacopy_example
harkal Mar 27, 2025
120d030
disable hevm for infinte loop
harkal Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
squash commit: add is_volatile and mark method
harkal committed Mar 21, 2025
commit 001c02f2a6519c3dbe1308ca418c8f209adb1b90
24 changes: 24 additions & 0 deletions vyper/venom/analysis/mem_alias.py
Original file line number Diff line number Diff line change
@@ -93,3 +93,27 @@ def may_alias(self, loc1: MemoryLocation, loc2: MemoryLocation) -> bool:
start2, end2 = loc2.offset, loc2.offset + loc2.size

return (start1 <= start2 < end1) or (start2 <= start1 < end2)

def mark_volatile(self, loc: MemoryLocation) -> MemoryLocation:
volatile_loc = MemoryLocation(
base=loc.base,
offset=loc.offset,
size=loc.size,
is_alloca=loc.is_alloca,
is_volatile=True
)

if loc in self.alias_sets:
self.alias_sets[volatile_loc] = OrderedSet([volatile_loc])

# new and old locations are aliased
self.alias_sets[volatile_loc].add(loc)
self.alias_sets[loc].add(volatile_loc)

# copy aliasing relationships
for other_loc in self.alias_sets[loc]:
if other_loc != loc and other_loc != volatile_loc:
self.alias_sets[volatile_loc].add(other_loc)
self.alias_sets[other_loc].add(volatile_loc)

return volatile_loc
40 changes: 25 additions & 15 deletions vyper/venom/analysis/mem_ssa.py
Original file line number Diff line number Diff line change
@@ -13,15 +13,16 @@ class MemoryAccess:
def __init__(self, id: int):
self.id = id
self.reaching_def: Optional[MemoryAccess] = None

@property
def loc(self) -> MemoryLocation:
raise NotImplementedError("Subclasses must implement this method")
self.loc: Optional[MemoryLocation] = None

@property
def is_live_on_entry(self) -> bool:
return self.id == 0

@property
def is_volatile(self) -> bool:
return self.loc.is_volatile

@property
def id_str(self) -> str:
if self.is_live_on_entry:
@@ -38,23 +39,15 @@ class MemoryDef(MemoryAccess):
def __init__(self, id: int, store_inst: IRInstruction):
super().__init__(id)
self.store_inst = store_inst

@property
def loc(self) -> MemoryLocation:
return self.store_inst.get_write_memory_location()

self.loc = store_inst.get_write_memory_location()

class MemoryUse(MemoryAccess):
"""Represents a use of memory state"""

def __init__(self, id: int, load_inst: IRInstruction):
super().__init__(id)
self.load_inst = load_inst

@property
def loc(self) -> MemoryLocation:
return self.load_inst.get_read_memory_location()

self.loc = load_inst.get_read_memory_location()

class MemoryPhi(MemoryAccess):
"""Represents a phi node for memory states"""
@@ -103,6 +96,23 @@ def analyze(self):
# Clean up unnecessary phi nodes
self._remove_redundant_phis()

def mark_location_volatile(self, loc: MemoryLocation) -> MemoryLocation:
volatile_loc = self.alias.mark_volatile(loc)

for bb in self.memory_defs:
for mem_def in self.memory_defs[bb]:
if self.alias.may_alias(mem_def.loc, loc):
new_loc = MemoryLocation(
base=mem_def.loc.base,
offset=mem_def.loc.offset,
size=mem_def.loc.size,
is_alloca=mem_def.loc.is_alloca,
is_volatile=True
)
mem_def.loc = new_loc

return volatile_loc

def get_memory_def(self, inst: IRInstruction) -> Optional[MemoryDef]:
if inst in self.inst_to_def:
return self.inst_to_def[inst]
@@ -319,7 +329,7 @@ def get_clobbering_memory_access(self, access: MemoryAccess) -> Optional[MemoryA
return next_def
mem_use = self.inst_to_use.get(inst)
if mem_use and mem_use.reaching_def == access:
return None # Use of this def in phi’s block
return None

# Check instructions in successor block
for inst in succ.instructions:
1 change: 1 addition & 0 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
@@ -247,6 +247,7 @@ class MemoryLocation:
offset: int = 0
size: int = 0
is_alloca: bool = False
is_volatile: bool = False


FULL_MEMORY_ACCESS = MemoryLocation(base=IROperand(0), offset=0, size=-1, is_alloca=False)