Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
aeda862
start of the memalloc
HodanPlodky Sep 8, 2025
9c23759
why does is pass
HodanPlodky Sep 8, 2025
b9c8a77
fix up for palloca
HodanPlodky Sep 8, 2025
00ce650
start of concretization
HodanPlodky Sep 9, 2025
95397d1
fixes and testing
HodanPlodky Sep 11, 2025
73d1272
new inst for copy runtime code
HodanPlodky Sep 12, 2025
62d5e28
debug and fixes
HodanPlodky Sep 16, 2025
ac0f5aa
not deleting codecopyruntime
HodanPlodky Sep 16, 2025
12b81a3
more debug and fixes in sccp
HodanPlodky Sep 17, 2025
c3cb95d
more debug
HodanPlodky Sep 18, 2025
89c4511
eliminating the unused geps
HodanPlodky Sep 19, 2025
f7a7ae1
fixes for mem2var and changes for loadelim
HodanPlodky Sep 19, 2025
36b0adb
more "fixes"
HodanPlodky Sep 19, 2025
2103f76
temp mem correct start
HodanPlodky Sep 19, 2025
5e4272f
palloca
HodanPlodky Sep 20, 2025
d261ca4
removed stray print
HodanPlodky Sep 22, 2025
c0f014c
allocated args
HodanPlodky Sep 23, 2025
9345f5e
allocated args fixing
HodanPlodky Sep 24, 2025
53b4adc
fix calloca
HodanPlodky Sep 28, 2025
28c8b88
fix for palloca creation
HodanPlodky Sep 28, 2025
bbeaf66
removed unused args from allocas
HodanPlodky Sep 29, 2025
57bd9cf
more fixes
HodanPlodky Sep 29, 2025
d0b18a9
allocate tmp vars
HodanPlodky Sep 29, 2025
b51c387
alloca fix
HodanPlodky Sep 29, 2025
9fd0e20
pass tests
HodanPlodky Sep 29, 2025
66192b6
clean up
HodanPlodky Sep 30, 2025
a2fab56
lint
HodanPlodky Sep 30, 2025
d5f5930
better allocation (can reuse mem)
HodanPlodky Oct 1, 2025
ff0428b
Merge branch 'master' into feat/venom/mem-alloc
HodanPlodky Oct 1, 2025
baac637
fix get literal
HodanPlodky Oct 1, 2025
c4396f2
fixes for merge
HodanPlodky Oct 1, 2025
dbdb9db
removed calloca that do not have palloca
HodanPlodky Oct 2, 2025
65ffc5c
removed wrong comment
HodanPlodky Oct 2, 2025
0b63bdd
more single uses
HodanPlodky Oct 2, 2025
236d3e4
test and parser
HodanPlodky Oct 3, 2025
a7fab0d
Merge branch 'master' into feat/venom/mem-alloc
HodanPlodky Oct 6, 2025
ac58045
order of allocation
HodanPlodky Oct 7, 2025
2c69a8d
better memalloc
HodanPlodky Oct 7, 2025
ec88eb7
gep handle
HodanPlodky Oct 8, 2025
f3e69d9
fix for calloca remove
HodanPlodky Oct 8, 2025
b7ef1ff
gep for calloca
HodanPlodky Oct 8, 2025
fcaa785
incorrect name fix
HodanPlodky Oct 8, 2025
110cfcd
xfail the test that is dependant on mem allocator
HodanPlodky Oct 8, 2025
fbf9ec5
eq and follow adds
HodanPlodky Oct 8, 2025
81fb8be
mem location split
HodanPlodky Oct 10, 2025
9770693
mem_ssa test
HodanPlodky Oct 10, 2025
397c33b
mem abstract
HodanPlodky Oct 10, 2025
d3ab301
better pass order
HodanPlodky Oct 13, 2025
94aa73a
tests and more calls to dead load elim
HodanPlodky Oct 13, 2025
9598d18
load elim at concrete
HodanPlodky Oct 14, 2025
5444796
remove stray print
HodanPlodky Oct 14, 2025
96a3773
dead store with concrete
HodanPlodky Oct 14, 2025
a11e0ff
sccp
HodanPlodky Oct 21, 2025
1738a27
invoke problem
HodanPlodky Oct 21, 2025
0541dea
removed stray print
HodanPlodky Oct 21, 2025
27f8fb2
fix for mem livemenss
HodanPlodky Oct 23, 2025
b969f23
another sccp
HodanPlodky Oct 23, 2025
c20e8a2
different order
HodanPlodky Oct 23, 2025
45f330f
Merge pull request #4 from HodanPlodky/deadstore_abstract
HodanPlodky Oct 24, 2025
7516612
cleanup and lint
HodanPlodky Oct 24, 2025
2af9abd
different import
HodanPlodky Oct 24, 2025
f4b769b
Merge branch 'master' into feat/venom/mem-alloc
HodanPlodky Oct 24, 2025
d0f6781
different import
HodanPlodky Oct 24, 2025
e080cab
lint
HodanPlodky Oct 24, 2025
a1d821a
fix
HodanPlodky Oct 27, 2025
2144b3e
value
HodanPlodky Oct 27, 2025
fcf6990
removed unreachable code
HodanPlodky Oct 27, 2025
2450b96
another unreachable
HodanPlodky Oct 27, 2025
04bb7c4
hevm needs to use concretaze
HodanPlodky Oct 27, 2025
9de728d
lint
HodanPlodky Oct 27, 2025
111055f
better imports
HodanPlodky Oct 27, 2025
735cac5
imports
HodanPlodky Oct 27, 2025
f093f66
imports
HodanPlodky Oct 27, 2025
311c425
tried to remove cycle
HodanPlodky Oct 27, 2025
1440eb9
imports
HodanPlodky Oct 28, 2025
5fe0fb0
fix for overlap
HodanPlodky Oct 28, 2025
e94fe51
better may overlap for abstract
HodanPlodky Oct 28, 2025
d275430
better contains
HodanPlodky Oct 28, 2025
d3c192f
seems like fix but for some reason this is never triggered
HodanPlodky Oct 28, 2025
3d1f1b5
more changes to mem loc
HodanPlodky Oct 28, 2025
0224c76
invalidate dfg
HodanPlodky Oct 28, 2025
04a062c
correct size
HodanPlodky Oct 28, 2025
4c0de27
load elim better
HodanPlodky Oct 28, 2025
15bf144
allowed to analyze through `gep`
HodanPlodky Oct 31, 2025
5d0d907
better livesets
HodanPlodky Nov 4, 2025
b0b078f
better internal function handle
HodanPlodky Nov 4, 2025
720319f
lint
HodanPlodky Nov 5, 2025
adc8211
removed unused code
HodanPlodky Nov 5, 2025
2d4d3c2
removed unnecessary condition
HodanPlodky Nov 5, 2025
2288329
removed allocas emit (they should be there at that point)
HodanPlodky Nov 5, 2025
635eb9d
small cleanup
HodanPlodky Nov 5, 2025
7b203e0
pragma nocover on interface methods
HodanPlodky Nov 5, 2025
cde156f
lint
HodanPlodky Nov 5, 2025
3b97b3e
better api for mem allocator
HodanPlodky Nov 5, 2025
067fcd0
better api for mem allocator
HodanPlodky Nov 5, 2025
c5ac264
fix for hevm tests
HodanPlodky Nov 5, 2025
42112f6
lint
HodanPlodky Nov 5, 2025
73590ba
fix for instaces where you write and read at the same time
HodanPlodky Nov 6, 2025
6313917
test for allocation
HodanPlodky Nov 10, 2025
583a698
rename `_follow_get` -> `_follow_gep`
HodanPlodky Nov 10, 2025
f2fd516
renamed traslates to var_base_pointers
HodanPlodky Nov 11, 2025
f46f960
renamed `MemoryLocatationConcrete` -> `MemoryLocationSegment`
HodanPlodky Nov 11, 2025
8c915ec
moved unused handle into FixCallocas pass
HodanPlodky Nov 11, 2025
6eeb4a3
removed unused
HodanPlodky Nov 11, 2025
a25621e
removed unused code
HodanPlodky Nov 11, 2025
7204708
lint and used property offset in abs memloc
HodanPlodky Nov 11, 2025
ef644e9
fix for fix_mem_loc in read_op case
HodanPlodky Nov 11, 2025
4c733c5
renamed _update_write_op to _update_write_location (and read version)
HodanPlodky Nov 12, 2025
08d522b
moving code around
HodanPlodky Nov 12, 2025
1f5928f
lint
HodanPlodky Nov 12, 2025
2bee027
added upper bound
HodanPlodky Nov 13, 2025
534e8fd
lint
HodanPlodky Nov 13, 2025
ff30bc4
Merge branch 'master' into feat/venom/mem-alloc
HodanPlodky Nov 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def huge_bytestring():
def test_contract_size_exceeded(huge_bytestring):
code = f"""
@external
def a() -> bool:
def a() -> Bytes[24577]:
q: Bytes[24577] = {huge_bytestring}
return True
return q
"""
with pytest.warns(vyper.warnings.ContractSizeLimit):
vyper.compile_code(code, output_formats=["bytecode_runtime"])
2 changes: 2 additions & 0 deletions tests/hevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from vyper.ir.compile_ir import assembly_to_evm
from vyper.venom import (
CFGNormalization,
ConcretizeMemLocPass,
LowerDloadPass,
SimplifyCFGPass,
SingleUseExpansion,
Expand Down Expand Up @@ -70,6 +71,7 @@ def _prep_hevm_venom_ctx(ctx, verbose=False):

# requirements for venom_to_assembly
LowerDloadPass(ac, fn).run_pass()
ConcretizeMemLocPass(ac, fn).run_pass()
SingleUseExpansion(ac, fn).run_pass()
CFGNormalization(ac, fn).run_pass()

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/compiler/venom/test_abstract_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from vyper.venom.basicblock import IRAbstractMemLoc
from vyper.venom.memory_location import (
MemoryLocation,
MemoryLocationAbstract,
MemoryLocationSegment,
)


def test_abstract_may_overlap():
op1 = IRAbstractMemLoc(256, offset=0, force_id=0)
op2 = IRAbstractMemLoc(256, offset=128, force_id=0)
loc1 = MemoryLocationAbstract(
op=op1, segment=MemoryLocationSegment(_offset=op1.offset, _size=32)
)
loc2 = MemoryLocationAbstract(
op=op2, segment=MemoryLocationSegment(_offset=op2.offset, _size=32)
)

assert not MemoryLocation.may_overlap(loc1, loc2)
34 changes: 30 additions & 4 deletions tests/unit/compiler/venom/test_common_subexpression_elimination.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ def call(callname: str, i: int, var_name: str):
%{var_name}1 = add 1, %{callname}1
"""

def call2(callname: str, i: int, var_name: str):
return f"""
%g{2*i} = gas
%{callname}0 = {callname} %g0, 0, 0, 0, 0, 0, 0
%{var_name}0 = add 1, %{callname}0
%g{2*i + 1} = gas
%{callname}1 = {callname} %g0, 0, 0, 0, 0, 0, 0
%{var_name}1 = add 1, %{callname}1
"""

pre = f"""
main:
; staticcall
Expand All @@ -366,7 +376,7 @@ def call(callname: str, i: int, var_name: str):
{call("delegatecall", 1, "d")}

; call
{call("call", 2, "c")}
{call2("call", 2, "c")}
sink %s0, %s1, %d0, %d1, %c0, %c1
"""

Expand Down Expand Up @@ -470,9 +480,7 @@ def test_cse_immutable_queries(opcode):
_check_pre_post(pre, post, hevm=opcode != "codesize")


@pytest.mark.parametrize(
"opcode", ("dloadbytes", "extcodecopy", "codecopy", "returndatacopy", "calldatacopy")
)
@pytest.mark.parametrize("opcode", ("dloadbytes", "codecopy", "returndatacopy", "calldatacopy"))
def test_cse_other_mem_ops_elimination(opcode):
pre = f"""
main:
Expand All @@ -491,6 +499,24 @@ def test_cse_other_mem_ops_elimination(opcode):
_check_pre_post(pre, post)


def test_cse_other_mem_ops_elimination_extcodecopy():
pre = """
main:
extcodecopy 10, 20, 30, 40
extcodecopy 10, 20, 30, 40
stop
"""

post = """
main:
extcodecopy 10, 20, 30, 40
nop
stop
"""

_check_pre_post(pre, post, hevm=False)


def test_cse_self_conflicting_effects():
"""
Test that expression that have conflict in their own effects
Expand Down
106 changes: 106 additions & 0 deletions tests/unit/compiler/venom/test_concretize_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from tests.venom_utils import PrePostChecker
from vyper.venom.passes import AssignElimination, ConcretizeMemLocPass, Mem2Var

_check_pre_post = PrePostChecker([ConcretizeMemLocPass], default_hevm=False)
_check_pre_post_mem2var = PrePostChecker([Mem2Var, AssignElimination], default_hevm=False)


def test_valid_overlap():
pre = """
main:
calldatacopy [3,256], 100, 256
%1 = mload [3,256]
calldatacopy [4,32], 200, 32
%2 = mload [4,32]
calldatacopy [3,256], 1000, 256
%3 = mload [3,256]
sink %1, %2, %3
"""
post = """
main:
calldatacopy 64, 100, 256
%1 = mload 64
calldatacopy 64, 200, 32
%2 = mload 64
calldatacopy 64, 1000, 256
%3 = mload 64
sink %1, %2, %3
"""

_check_pre_post(pre, post)


def test_venom_allocation():
pre = """
main:
%ptr = alloca 0, [3,256]
calldatacopy %ptr, 100, 256
%1 = mload %ptr
sink %1
"""

post1 = """
main:
calldatacopy [3,256], 100, 256
%1 = mload [3,256]
sink %1
"""

post2 = """
main:
calldatacopy 64, 100, 256
%1 = mload 64
sink %1
"""

_check_pre_post_mem2var(pre, post1)
_check_pre_post(post1, post2)


def test_venom_allocation_branches():
pre = """
main:
%ptr1 = alloca 0, [3,256]
%ptr2 = alloca 1, [4,128]
%cond = source
jnz %cond, @then, @else
then:
calldatacopy %ptr1, 100, 256
%1 = mload %ptr1
sink %1
else:
calldatacopy %ptr2, 1000, 64
%2 = mload %ptr2
sink %2
"""

post1 = """
main:
%cond = source
jnz %cond, @then, @else
then:
calldatacopy [3,256], 100, 256
%1 = mload [3,256]
sink %1
else:
calldatacopy [4,128], 1000, 64
%2 = mload [4,128]
sink %2
"""

post2 = """
main:
%cond = source
jnz %cond, @then, @else
then:
calldatacopy 64, 100, 256
%1 = mload 64
sink %1
else:
calldatacopy 64, 1000, 64
%2 = mload 64
sink %2
"""

_check_pre_post_mem2var(pre, post1)
_check_pre_post(post1, post2)
93 changes: 51 additions & 42 deletions tests/unit/compiler/venom/test_dead_store_elimination.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
self.volatile_locations = volatile_locations

def __call__(self, pre: str, post: str, hevm: bool | None = None) -> list[IRPass]:
from vyper.venom.memory_location import MemoryLocation
from vyper.venom.memory_location import MemoryLocationSegment

self.pass_objects.clear()

Expand All @@ -41,7 +41,7 @@ def __call__(self, pre: str, post: str, hevm: bool | None = None) -> list[IRPass
mem_ssa = ac.request_analysis(mem_ssa_type_factory(self.addr_space))

for address, size in self.volatile_locations:
volatile_loc = MemoryLocation(offset=address, size=size, is_volatile=True)
volatile_loc = MemoryLocationSegment(_offset=address, _size=size, _is_volatile=True)
mem_ssa.mark_location_volatile(volatile_loc)

for p in self.passes:
Expand Down Expand Up @@ -74,25 +74,26 @@ def _check_no_change(code, hevm=False):
return _check_pre_post(code, code, hevm=hevm)


def test_basic_dead_store():
pre = """
@pytest.mark.parametrize("position", [0, "[0,32]"])
def test_basic_dead_store(position):
pre = f"""
_global:
%val1 = 42
%val2 = 24
mstore 0, %val1 ; Dead store - overwritten before read
mstore 0, 10 ; Dead store - overwritten before read
mstore 0, %val2
%loaded = mload 0 ; Only reads val2
mstore {position}, %val1 ; Dead store - overwritten before read
mstore {position}, 10 ; Dead store - overwritten before read
mstore {position}, %val2
%loaded = mload {position} ; Only reads val2
stop
"""
post = """
post = f"""
_global:
%val1 = 42
%val2 = 24
nop
nop
mstore 0, %val2
%loaded = mload 0
mstore {position}, %val2
%loaded = mload {position}
stop
"""
_check_pre_post(pre, post)
Expand All @@ -117,49 +118,54 @@ def test_basic_not_dead_store():
_check_pre_post(pre, post)


def test_basic_not_dead_store_with_mload():
pre = """
@pytest.mark.parametrize("positions", [(0, 32), ("[0,32]", "[1,32]")])
def test_basic_not_dead_store_with_mload(positions):
a, b = positions
pre = f"""
_global:
%1 = source
mstore 0, 1
mstore 32, 2
%2 = mload 0
mstore {a}, 1
mstore {b}, 2
%2 = mload {a}
stop
"""
post = """
post = f"""
_global:
%1 = source
mstore 0, 1
mstore {a}, 1
nop
%2 = mload 0
%2 = mload {a}
stop
"""
_check_pre_post(pre, post)


def test_basic_not_dead_store_with_return():
pre = """
@pytest.mark.parametrize("positions", [(0, 32), ("[0,32]", "[1,32]"), ("[2,32]", "[3,32]")])
def test_basic_not_dead_store_with_return(positions):
a, b = positions
pre = f"""
_global:
%1 = source
mstore 0, 1
mstore 32, 2
return 0, 32
mstore {a}, 1
mstore {b}, 2
return {a}, 32
"""
post = """
post = f"""
_global:
%1 = source
mstore 0, 1
mstore {a}, 1
nop
return 0, 32
return {a}, 32
"""
_check_pre_post(pre, post)


def test_never_read_store():
pre = """
@pytest.mark.parametrize("position", [0, 32, "[0,32]", "[1,32]"])
def test_never_read_store(position):
pre = f"""
_global:
%val = 42
mstore 0, %val ; Dead store - never read
mstore {position}, %val ; Dead store - never read
stop
"""
post = """
Expand All @@ -171,34 +177,37 @@ def test_never_read_store():
_check_pre_post(pre, post)


def test_live_store():
pre = """
@pytest.mark.parametrize("position", [0, 32, "[0,32]", "[1,32]"])
def test_live_store(position):
pre = f"""
_global:
%val = 42
mstore 0, %val
%loaded = mload 0 ; Makes the store live
mstore {position}, %val
%loaded = mload {position} ; Makes the store live
stop
"""
_check_pre_post(pre, pre) # Should not change


def test_dead_store_different_locations():
pre = """
@pytest.mark.parametrize("positions", [(0, 32), ("[0,32]", "[1,32]"), ("[2,32]", "[3,32]")])
def test_dead_store_different_locations(positions):
a, b = positions
pre = f"""
_global:
%val1 = 42
%val2 = 24
mstore 0, %val1 ; Dead store - never read
mstore 32, %val2 ; Live store
%loaded = mload 32
mstore {a}, %val1 ; Dead store - never read
mstore {b}, %val2 ; Live store
%loaded = mload {b}
stop
"""
post = """
post = f"""
_global:
%val1 = 42
%val2 = 24
nop
mstore 32, %val2
%loaded = mload 32
mstore {b}, %val2
%loaded = mload {b}
stop
"""
_check_pre_post(pre, post)
Expand Down
Loading