Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion tests/unit/compiler/venom/test_calling_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def test_dret_rejects_mixing_ret_and_dret():
main:
%p1 = param
%p2 = param
%retpc = param
%retpc = retpc_param
%x = %p1
%x = %p2
mstore 0, %x
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/compiler/venom/test_dalloca.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def test_dret_full_pipeline_with_and_without_inlining(env):

function callee {
callee:
%retpc = param
%retpc = retpc_param
%p = dalloca 32
mstore %p, 123
dret 1, %p, 32, %retpc
Expand Down Expand Up @@ -928,7 +928,7 @@ def test_unreachable_raw_dret_does_not_block_inlining():

function dret_callee {
dret_callee:
%retpc = param
%retpc = retpc_param
%p = dalloca 32
mstore %p, 7
dret 1, %p, 32, %retpc
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def test_inlined_publishing_callee_host_does_not_publish(env):

function callee {
callee:
%retpc = param
%retpc = retpc_param
%p = dalloca 32
mstore %p, 123
dret 1, %p, 32, %retpc
Expand Down Expand Up @@ -1848,7 +1848,7 @@ def test_escaped_getfmp_capture_pins_reclaim(env):

function callee {
callee:
%retpc = param
%retpc = retpc_param
%s1 = dalloca 32
%s2 = dalloca 32
mstore %s1, 11
Expand Down
49 changes: 44 additions & 5 deletions tests/unit/compiler/venom/test_inliner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from tests.venom_utils import parse_venom
from vyper.compiler.settings import OptimizationLevel, VenomOptimizationFlags
from vyper.evm.assembler.core import assembly_to_evm
from vyper.evm.assembler.instructions import PUSHLABEL, Label
from vyper.venom.analysis.analysis import IRAnalysesCache
from vyper.venom.analysis.fcg import FCGGlobalAnalysis
from vyper.venom.basicblock import IRLabel
from vyper.venom.check_venom import check_venom_ctx
from vyper.venom.passes import FunctionInlinerPass, SimplifyCFGPass
from vyper.venom.venom_to_assembly import VenomCompiler


def test_inliner_phi_invalidation():
Expand Down Expand Up @@ -35,9 +38,10 @@ def test_inliner_phi_invalidation():

function f {
main:
%retpc = retpc_param
%p = source
%1 = add %p, 1
ret %1
ret %retpc, %1
}
"""

Expand Down Expand Up @@ -91,9 +95,10 @@ def test_inliner_phi_invalidation_inner():

function f {
main:
%retpc = retpc_param
%p = source
%1 = add %p, 1
ret %1
ret %retpc, %1
}
"""

Expand Down Expand Up @@ -152,7 +157,7 @@ def test_inliner_preserves_memory_read_max_size():
%dst = param
%src = param
%size = param
%retpc = param
%retpc = retpc_param
mcopy %dst, %src, %size
ret %retpc
}
Expand Down Expand Up @@ -184,9 +189,9 @@ def test_noinline_annotation():

function f [noinline] {
f:
%retpc = param
%retpc = retpc_param
%1 = 42
ret %1, %retpc
ret %retpc, %1
}
"""

Expand All @@ -203,3 +208,37 @@ def run_inliner(source):

# sanity check: without the annotation, the function gets inlined
assert IRLabel("f") not in run_inliner(src.replace(" [noinline]", "")).functions


def test_inliner_retpc_retain():
code = """
function main {
main:
%1 = invoke @f
%ptr = alloca 32
mstore %ptr, %1
return %ptr, 32
}

function f {
f:
%retpc = retpc_param
%1 = 42
ret %retpc, %1
}
"""

flags = VenomOptimizationFlags(level=OptimizationLevel.CODESIZE)

def run_inliner(source):
ctx = parse_venom(source)
analyses = {fn: IRAnalysesCache(fn) for fn in ctx.functions.values()}
FunctionInlinerPass(analyses, ctx, flags).run_pass()
for fn in ctx.functions.values():
SimplifyCFGPass(analyses[fn], fn).run_pass()
return ctx

ctx = run_inliner(code)
asm = VenomCompiler(ctx).generate_evm_assembly()
assert PUSHLABEL(Label("f")) not in asm
_ = assembly_to_evm(asm)
10 changes: 9 additions & 1 deletion vyper/venom/passes/function_inliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from vyper.venom.analysis import CFGAnalysis, DFGAnalysis, DynamicMemoryAnalysis, IRAnalysesCache
from vyper.venom.analysis.fcg import FCGGlobalAnalysis
from vyper.venom.analysis.readonly_memory_args import ReadonlyMemoryArgsGlobalAnalysis
from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRLabel, IROperand, IRVariable
from vyper.venom.basicblock import (
IRBasicBlock,
IRInstruction,
IRLabel,
IRLiteral,
IROperand,
IRVariable,
)
from vyper.venom.call_layout import InvokeLayout, has_dret
from vyper.venom.context import IRContext
from vyper.venom.function import IRFunction
Expand Down Expand Up @@ -131,6 +138,7 @@ def _inline_call_site(self, func: IRFunction, call_site: IRInstruction) -> None:
# pre-lowering) + target-as-return-pc: identical to the old
# operands[1:] + [operands[0]] reorder for raw IR.
binding_ops = InvokeLayout(self.ctx, call_site).bound_params
binding_ops = (*binding_ops[:-1], IRLiteral(0))

for bb in func_copy.get_basic_blocks():
bb.parent = call_site_func
Expand Down
Loading