Skip to content
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5ccffc0
VenomOptimizationFlags
harkal Sep 28, 2025
f61443c
more
harkal Sep 28, 2025
a3167ba
json
harkal Sep 28, 2025
7a54581
lint
harkal Sep 28, 2025
6c69d4d
parsing
harkal Sep 28, 2025
591856e
lint
harkal Sep 28, 2025
62c6a01
inliner
harkal Sep 28, 2025
7ec2bc1
wip
harkal Sep 28, 2025
550d954
convert to "data" driven pass running
harkal Sep 29, 2025
0bfdc81
lint
harkal Sep 29, 2025
03d2b3f
reverse the settings flags and refactor
harkal Sep 29, 2025
c0c9f6a
wip
harkal Sep 29, 2025
b02b43c
refactor
harkal Sep 29, 2025
83350a0
only venom flags
harkal Sep 29, 2025
3d6c5f8
tests updates
harkal Sep 29, 2025
6471f56
skip venom flags
harkal Sep 29, 2025
616d92c
use just flags
harkal Sep 29, 2025
b749b86
pragma
harkal Sep 29, 2025
ceb1693
merge param to original
harkal Sep 29, 2025
3d16940
lint
harkal Sep 29, 2025
e1179ab
type validation
harkal Sep 29, 2025
93cac44
refactor
harkal Sep 29, 2025
568a8ce
proper object to run passes
harkal Oct 1, 2025
c888762
add simplify cfg
harkal Oct 1, 2025
c853107
remove dups
harkal Oct 1, 2025
297bc14
use the non-legacy enum
harkal Oct 1, 2025
f3ff76d
fix typo
harkal Oct 1, 2025
79f3123
Merge branch 'master' into feat/fine_params
harkal Oct 1, 2025
ffc5b67
remove Oz
harkal Oct 5, 2025
4dd02ef
split out optimization levels to separate files
harkal Oct 7, 2025
e2a9a50
squash and lint
harkal Oct 21, 2025
4ae171a
import to fix hevm
harkal Oct 21, 2025
62e3e0d
Merge remote-tracking branch 'origin/master' into feat/fine_params
harkal Oct 21, 2025
792ee69
lint
harkal Oct 21, 2025
a541703
Merge remote-tracking branch 'origin/master' into feat/fine_params
harkal Oct 21, 2025
ba14181
cleanup O0
harkal Oct 21, 2025
3855a26
drop O0
harkal Oct 29, 2025
2a11939
Merge branch 'master' into feat/fine_params
harkal Nov 25, 2025
a38e638
review
harkal Nov 27, 2025
22ab0ca
unify naming of params and members
harkal Nov 27, 2025
2704015
lint
harkal Nov 27, 2025
b05ee88
remove O1 for now
harkal Nov 27, 2025
19c1447
lint
harkal Nov 27, 2025
da2200a
cleanup
harkal Nov 27, 2025
08e90cc
increase iterations hevm
harkal Nov 27, 2025
01bfe35
Merge branch 'master' into feat/fine_params
harkal Nov 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
8 changes: 5 additions & 3 deletions tests/functional/venom/test_empty_liveness_guard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tests.venom_utils import parse_venom
from vyper.compiler.settings import OptimizationLevel
from vyper.compiler.settings import OptimizationLevel, VenomOptimizationFlags
from vyper.venom import generate_assembly_experimental, run_passes_on


Expand All @@ -13,7 +13,8 @@ def test_empty_liveness_at_function_entry_param_then_stop():
}
"""
ctx = parse_venom(venom)
run_passes_on(ctx, OptimizationLevel.GAS)
flags = VenomOptimizationFlags(level=OptimizationLevel.GAS)
run_passes_on(ctx, flags)
generate_assembly_experimental(ctx)


Expand All @@ -38,5 +39,6 @@ def test_empty_liveness_param_then_revert_immediates2():
}
"""
ctx = parse_venom(venom)
run_passes_on(ctx, OptimizationLevel.GAS)
flags = VenomOptimizationFlags(level=OptimizationLevel.GAS)
run_passes_on(ctx, flags)
generate_assembly_experimental(ctx)
6 changes: 4 additions & 2 deletions tests/functional/venom/test_venom_label_variables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from vyper.compiler.phases import generate_bytecode
from vyper.compiler.settings import OptimizationLevel
from vyper.compiler.settings import OptimizationLevel, VenomOptimizationFlags
from vyper.venom import generate_assembly_experimental, run_passes_on
from vyper.venom.check_venom import check_venom_ctx
from vyper.venom.parser import parse_venom
Expand Down Expand Up @@ -80,6 +80,8 @@ def test_labels_as_variables():

check_venom_ctx(ctx)

run_passes_on(ctx, OptimizationLevel.default())
opt_level = OptimizationLevel.default()
flags = VenomOptimizationFlags(level=opt_level)
run_passes_on(ctx, flags)
asm = generate_assembly_experimental(ctx)
generate_bytecode(asm)
5 changes: 3 additions & 2 deletions tests/functional/venom/test_venom_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tests.venom_utils import assert_ctx_eq, parse_venom
from vyper.compiler import compile_code
from vyper.compiler.phases import generate_bytecode
from vyper.compiler.settings import OptimizationLevel
from vyper.compiler.settings import OptimizationLevel, VenomOptimizationFlags
from vyper.venom import generate_assembly_experimental, run_passes_on
from vyper.venom.context import IRContext

Expand Down Expand Up @@ -100,7 +100,8 @@ def _helper1(vyper_source, optimize):
# check it's valid to run venom passes+analyses
# (note this breaks bytecode equality, in the future we should
# test that separately)
run_passes_on(ctx, optimize)
flags = VenomOptimizationFlags(level=optimize)
run_passes_on(ctx, flags)

# test we can generate assembly+bytecode
asm = generate_assembly_experimental(ctx)
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/compiler/venom/test_inliner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tests.venom_utils import parse_venom
from vyper.compiler.settings import OptimizationLevel
from vyper.compiler.settings import OptimizationLevel, VenomOptimizationFlags
from vyper.venom.analysis.analysis import IRAnalysesCache
from vyper.venom.check_venom import check_venom_ctx
from vyper.venom.passes import FunctionInlinerPass, SimplifyCFGPass
Expand Down Expand Up @@ -45,7 +45,8 @@ def test_inliner_phi_invalidation():
for fn in ctx.functions.values():
ir_analyses[fn] = IRAnalysesCache(fn)

FunctionInlinerPass(ir_analyses, ctx, OptimizationLevel.CODESIZE).run_pass()
flags = VenomOptimizationFlags(level=OptimizationLevel.CODESIZE)
FunctionInlinerPass(ir_analyses, ctx, flags).run_pass()

for fn in ctx.get_functions():
ac = IRAnalysesCache(fn)
Expand Down Expand Up @@ -100,7 +101,8 @@ def test_inliner_phi_invalidation_inner():
for fn in ctx.functions.values():
ir_analyses[fn] = IRAnalysesCache(fn)

FunctionInlinerPass(ir_analyses, ctx, OptimizationLevel.CODESIZE).run_pass()
flags = VenomOptimizationFlags(level=OptimizationLevel.CODESIZE)
FunctionInlinerPass(ir_analyses, ctx, flags).run_pass()

for fn in ctx.get_functions():
ac = IRAnalysesCache(fn)
Expand Down
2 changes: 1 addition & 1 deletion vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def to_dict(self) -> dict:
if isinstance(value, list):
ast_dict[key] = [_to_dict(i) for i in value]
elif isinstance(value, Settings):
ast_dict[key] = value.as_dict()
ast_dict[key] = value.as_dict(include_venom_flags=False)
else:
ast_dict[key] = _to_dict(value)

Expand Down
1 change: 1 addition & 0 deletions vyper/ast/pre_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _parse_pragma(comment_contents, settings, is_interface, code, start):
try:
mode = pragma.removeprefix("optimize").strip()
settings.optimize = OptimizationLevel.from_string(mode)
settings.venom_flags.set_level(settings.optimize)
except ValueError:
raise PragmaException(f"Invalid optimization mode `{mode}`", *location)
return
Expand Down
10 changes: 8 additions & 2 deletions vyper/cli/venom_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import vyper
import vyper.evm.opcodes as evm
from vyper.compiler.phases import generate_bytecode
from vyper.compiler.settings import OptimizationLevel, Settings, set_global_settings
from vyper.compiler.settings import (
OptimizationLevel,
Settings,
VenomOptimizationFlags,
set_global_settings,
)
from vyper.venom import generate_assembly_experimental, run_passes_on
from vyper.venom.check_venom import check_venom_ctx
from vyper.venom.parser import parse_venom
Expand Down Expand Up @@ -59,7 +64,8 @@ def _parse_args(argv: list[str]):

check_venom_ctx(ctx)

run_passes_on(ctx, OptimizationLevel.default())
flags = VenomOptimizationFlags(level=OptimizationLevel.default())
run_passes_on(ctx, flags)
asm = generate_assembly_experimental(ctx)
bytecode, _ = generate_bytecode(asm)
print(f"0x{bytecode.hex()}")
Expand Down
55 changes: 47 additions & 8 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,28 @@ def _parse_args(argv):
parser.add_argument(
"-O",
"--optimize",
help="Optimization flag (defaults to 'gas')",
choices=["gas", "codesize", "none"],
help="Optimization level (defaults to 'gas'). Valid options: "
"0 (none), 1 (basic), 2 (gas/default), 3 (aggressive - experimental), "
"s (size), or legacy names: none, gas, codesize",
metavar="LEVEL",
dest="optimize",
)
parser.add_argument(
"--no-inlining", help="Disable function inlining optimization", action="store_true"
)
parser.add_argument(
"--no-cse", help="Disable common subexpression elimination", action="store_true"
)
parser.add_argument(
"--no-sccp", help="Disable sparse conditional constant propagation", action="store_true"
)
parser.add_argument(
"--no-load-elimination", help="Disable load elimination optimization", action="store_true"
)
parser.add_argument(
"--no-dead-store-elimination", help="Disable dead store elimination", action="store_true"
)
parser.add_argument("--inline-threshold", help="Function inlining cost threshold", type=int)
parser.add_argument("--debug", help="Compile in debug mode", action="store_true")
parser.add_argument(
"--no-bytecode-metadata", help="Do not add metadata to bytecode", action="store_true"
Expand Down Expand Up @@ -220,15 +239,35 @@ def _parse_args(argv):
output_formats = ("archive_b64",)

if args.no_optimize and args.optimize:
raise ValueError("Cannot use `--no-optimize` and `--optimize` at the same time!")

settings = Settings()
raise ValueError("Cannot use `--no-optimize` and `-O/--optimize` at the same time!")

# TODO: refactor to something like Settings.from_args()
optimize = None
if args.no_optimize:
settings.optimize = OptimizationLevel.NONE
optimize = OptimizationLevel.NONE
elif args.optimize is not None:
settings.optimize = OptimizationLevel.from_string(args.optimize)
# Handle both old-style (none, gas, codesize) and new-style (0, 1, 2, 3, s) arguments
opt_level = args.optimize.lower()
if opt_level in ["0", "1", "2", "3"]:
opt_level = "O" + opt_level
elif opt_level == "s":
opt_level = "Os"
optimize = OptimizationLevel.from_string(opt_level)

settings = Settings(optimize=optimize)

# Apply individual flag overrides
if args.no_inlining:
settings.venom_flags.disable_inlining = True
if args.no_cse:
settings.venom_flags.disable_cse = True
if args.no_sccp:
settings.venom_flags.disable_sccp = True
if args.no_load_elimination:
settings.venom_flags.disable_load_elimination = True
if args.no_dead_store_elimination:
settings.venom_flags.disable_dead_store_elimination = True
if args.inline_threshold is not None:
settings.venom_flags.inline_threshold = args.inline_threshold

if args.evm_version:
settings.evm_version = args.evm_version
Expand Down
45 changes: 43 additions & 2 deletions vyper/cli/vyper_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import vyper
from vyper.compiler.input_bundle import FileInput, JSONInput, JSONInputBundle, _normpath
from vyper.compiler.settings import OptimizationLevel, Settings
from vyper.compiler.settings import OptimizationLevel, Settings, VenomOptimizationFlags
from vyper.evm.opcodes import EVM_VERSIONS
from vyper.exceptions import JSONError
from vyper.utils import OrderedSet, keccak256
Expand Down Expand Up @@ -304,14 +304,20 @@ def get_settings(input_dict: dict) -> Settings:
evm_version = get_evm_version(input_dict)

optimize = input_dict["settings"].get("optimize")
opt_level = input_dict["settings"].get("optLevel")

if optimize is not None and opt_level is not None:
raise JSONError("both 'optimize' and 'optLevel' cannot be set")

experimental_codegen = input_dict["settings"].get("experimentalCodegen")
if experimental_codegen is None:
experimental_codegen = input_dict["settings"].get("venomExperimental")
elif input_dict["settings"].get("venomExperimental") is not None:
raise JSONError("both experimentalCodegen and venomExperimental cannot be set")

if isinstance(optimize, bool):
if opt_level is not None:
optimize = OptimizationLevel.from_string(opt_level)
elif isinstance(optimize, bool):
# bool optimization level for backwards compatibility
vyper_warn(
Deprecation(
Expand All @@ -329,12 +335,47 @@ def get_settings(input_dict: dict) -> Settings:
# TODO: maybe change these to camelCase for consistency
enable_decimals = input_dict["settings"].get("enable_decimals", None)

# Create Venom optimization flags with the optimization level
venom_flags = VenomOptimizationFlags(level=optimize)

# Check for Venom-specific settings
venom_settings = input_dict["settings"].get("venom", {})
if venom_settings:
if venom_flags is None:
venom_flags = VenomOptimizationFlags()

flag_mapping = {
"disableInlining": ("disable_inlining", bool),
"disableCSE": ("disable_cse", bool),
"disableSCCP": ("disable_sccp", bool),
"disableLoadElimination": ("disable_load_elimination", bool),
"disableDeadStoreElimination": ("disable_dead_store_elimination", bool),
"disableAlgebraicOptimization": ("disable_algebraic_optimization", bool),
"disableBranchOptimization": ("disable_branch_optimization", bool),
"disableMem2Var": ("disable_mem2var", bool),
"disableSimplifyCFG": ("disable_simplify_cfg", bool),
"disableRemoveUnusedVariables": ("disable_remove_unused_variables", bool),
"inlineThreshold": ("inline_threshold", int),
}

# Apply settings from venom_settings
for json_field, (attr_name, expected_type) in flag_mapping.items():
if json_field in venom_settings:
value = venom_settings[json_field]
if not isinstance(value, expected_type):
raise JSONError(
f"venom.{json_field} must be {expected_type.__name__}, "
f"got {type(value).__name__}"
)
setattr(venom_flags, attr_name, value)

return Settings(
evm_version=evm_version,
optimize=optimize,
experimental_codegen=experimental_codegen,
debug=debug,
enable_decimals=enable_decimals,
venom_flags=venom_flags,
)


Expand Down
Loading
Loading