From bf01b6d9355cab099c4b0182f10ce5310b148c2d Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 25 Oct 2026 20:35:08 +0900 Subject: [PATCH] feat(cli): default celox run to the tiered backend Change-Id: Ibf4c9e23b951e1302840c46d455bbfc4cd6b04de --- crates/celox-vpi/src/bin/celox.rs | 2 +- crates/celox-vpi/src/bin/celox/runner.rs | 33 ++++++++++++++++++++---- crates/celox-vpi/tests/run_cli.rs | 19 ++++++++++++++ docs/guide/cocotb.md | 3 ++- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/crates/celox-vpi/src/bin/celox.rs b/crates/celox-vpi/src/bin/celox.rs index 3ac3ac1a18e..eb1e030dd2d 100644 --- a/crates/celox-vpi/src/bin/celox.rs +++ b/crates/celox-vpi/src/bin/celox.rs @@ -177,7 +177,7 @@ fn run_sv(arguments: RunConfig) -> Result<(), String> { simulate_sv(simulation, max_steps, &mut std::io::stdout().lock()) }}; } - match arguments.execution.backend { + match arguments.execution.backend() { runner::Backend::Native => execute!(build), runner::Backend::Cranelift => execute!(build_cranelift), runner::Backend::Interpreter => execute!(build_interpreter), diff --git a/crates/celox-vpi/src/bin/celox/runner.rs b/crates/celox-vpi/src/bin/celox/runner.rs index 802e60033c9..cb25cfc3b1a 100644 --- a/crates/celox-vpi/src/bin/celox/runner.rs +++ b/crates/celox-vpi/src/bin/celox/runner.rs @@ -30,8 +30,11 @@ macro_rules! report { #[derive(Args, Default)] pub(super) struct ExecutionArgs { - #[arg(long, value_enum, default_value = "native")] - pub backend: Backend, + /// Defaults to `tiered`, or to `native` when an option needs native code + /// (compile-only, native images, the build cache or IR dumps) and in + /// cross-codegen builds. + #[arg(long, value_enum)] + backend: Option, #[arg(long)] compile_only: bool, /// Write a pointer-free native image during compile-only mode. @@ -74,6 +77,26 @@ pub(super) struct ExecutionArgs { } impl ExecutionArgs { + pub(super) fn backend(&self) -> Backend { + self.backend.unwrap_or( + // A cross-codegen build only exports foreign native images. + if cfg!(any( + all(target_arch = "x86_64", feature = "arm64-codegen"), + all(target_arch = "aarch64", feature = "x86_64-codegen") + )) || self.compile_only + || self.native_image_output.is_some() + || self.native_image_input.is_some() + || self.build_cache_dir.is_some() + || self.dump_ir_dir.is_some() + || self.dump_ir_and_run + { + Backend::Native + } else { + Backend::Tiered + }, + ) + } + #[cfg(feature = "systemverilog")] pub(super) fn validate_sv(&self) -> Result<(), String> { if self.compile_only @@ -149,9 +172,8 @@ pub(super) enum RunError { TestFailed { message: String }, } -#[derive(Clone, Copy, Default, PartialEq, ValueEnum)] +#[derive(Clone, Copy, PartialEq, ValueEnum)] pub(super) enum Backend { - #[default] Native, Cranelift, Interpreter, @@ -182,6 +204,7 @@ pub(super) fn run( design: super::project::Design, max_steps: u64, ) -> Result<(), RunError> { + let backend = cli.backend(); let mut opts = Options { report: cli.report, require_compiled: cli.require_compiled, @@ -194,7 +217,7 @@ pub(super) fn run( }), test: design.top.clone(), opt_level: design.opt_level.unwrap_or(OptLevel::O2), - backend: cli.backend, + backend, four_state: design.four_state.unwrap_or(false), compile_only: cli.compile_only, native_image_output: cli.native_image_output, diff --git a/crates/celox-vpi/tests/run_cli.rs b/crates/celox-vpi/tests/run_cli.rs index e68b2bfb196..4c3a66abbf5 100644 --- a/crates/celox-vpi/tests/run_cli.rs +++ b/crates/celox-vpi/tests/run_cli.rs @@ -365,6 +365,25 @@ fn veryl_backends_share_cli_execution_and_opt_in_reports() { assert!(output.stdout.is_empty(), "{output:?}"); } +#[cfg(not(any( + all(target_arch = "x86_64", feature = "arm64-codegen"), + all(target_arch = "aarch64", feature = "x86_64-codegen") +)))] +#[test] +fn backend_defaults_to_tiered_unless_native_code_is_requested() { + let source = + "#[test(Top)] module Top { inst clk: $tb::clock_gen; initial { clk.next(4); $finish(); } }"; + let output = run(&[("top.veryl", source)], &["--report"]); + assert!(output.status.success(), "{output:?}"); + let report = String::from_utf8(output.stdout).unwrap(); + assert!(report.contains("backend=tiered "), "{report}"); + + let output = run(&[("top.veryl", source)], &["--report", "--compile-only"]); + assert!(output.status.success(), "{output:?}"); + let report = String::from_utf8(output.stdout).unwrap(); + assert!(report.contains("backend=native "), "{report}"); +} + #[cfg(feature = "systemverilog")] #[test] fn sv_defaults_to_two_state_and_four_state_is_explicit() { diff --git a/docs/guide/cocotb.md b/docs/guide/cocotb.md index 65123edabbd..ba8bae593a9 100644 --- a/docs/guide/cocotb.md +++ b/docs/guide/cocotb.md @@ -64,7 +64,8 @@ clock limit is needed. `--unlimited` removes the step/tick limit. Source languag `celox run` accepts `--threads N` (1–64, default 1) and `--four-state` for both languages. Both languages support `--backend native|tiered|interpreter|cranelift|wasm` -(default: native). Tiered starts interpreted and adopts compiled code at a scheduler +(default: tiered; native when `--compile-only`, a native image, `--build-cache-dir` or an +IR dump is requested). Tiered starts interpreted and adopts compiled code at a scheduler safe point while preserving pending events. For example: ```sh