diff --git a/.github/workflows/ci-napi.yml b/.github/workflows/ci-napi.yml
index f900d6aba48..76645afad97 100644
--- a/.github/workflows/ci-napi.yml
+++ b/.github/workflows/ci-napi.yml
@@ -211,17 +211,17 @@ jobs:
working-directory: crates/celox-napi
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
- run: npx napi build --platform --release --manifest-path ../../Cargo.toml -p celox-napi --target ${{ matrix.target }} --use-napi-cross
+ run: npx napi build --platform --release --manifest-path ../../Cargo.toml -p celox-napi --features wasm-component --target ${{ matrix.target }} --use-napi-cross
- name: Build (zigbuild)
if: matrix.zigbuild
working-directory: crates/celox-napi
- run: npx napi build --platform --release --manifest-path ../../Cargo.toml -p celox-napi --target ${{ matrix.target }} -x
+ run: npx napi build --platform --release --manifest-path ../../Cargo.toml -p celox-napi --features wasm-component --target ${{ matrix.target }} -x
- name: Build (native)
if: ${{ !matrix.napi-cross && !matrix.zigbuild }}
working-directory: crates/celox-napi
- run: npx napi build --platform --release --manifest-path ../../Cargo.toml -p celox-napi --target ${{ matrix.target }}
+ run: npx napi build --platform --release --manifest-path ../../Cargo.toml -p celox-napi --features wasm-component --target ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v7
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 86607a1b55e..c55dba1bb18 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -149,7 +149,7 @@ jobs:
- name: cargo clippy
if: (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false'
- run: cargo clippy --locked --workspace --exclude lydite-celox --all-targets --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim --no-deps
+ run: cargo clippy --locked --workspace --exclude lydite-celox --all-targets --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim --no-deps
- name: Lint the crates this pull request can affect
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_lint_packages != ''
@@ -259,7 +259,7 @@ jobs:
if: needs.changes.outputs.rust_full != 'false'
run: >-
cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci
- --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
+ --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
- name: Run the tests this pull request can affect
id: scoped-tests
@@ -305,7 +305,7 @@ jobs:
if: needs.changes.outputs.rust_full != 'false'
run: >-
cargo test --locked --workspace --exclude 'lydite*' --doc
- --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
+ --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
- name: Run the documentation tests of the changed libraries
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_libraries != ''
@@ -722,7 +722,7 @@ jobs:
- name: Test partial-word reduction AND on AArch64
run: >-
- cargo test --locked -p celox --features systemverilog
+ cargo test --locked -p celox --features systemverilog,cranelift,wasm-runtime,wasm-component,veryl-reference
--test systemverilog wide_reduction_and_respects_partial_storage_words::native
- name: Check x86-64 cross-codegen from AArch64
diff --git a/.github/workflows/rust-cache.yml b/.github/workflows/rust-cache.yml
index 5bd5f9becc4..b60213d58e9 100644
--- a/.github/workflows/rust-cache.yml
+++ b/.github/workflows/rust-cache.yml
@@ -54,7 +54,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: >-
cargo nextest list --locked --workspace --exclude 'lydite*' --message-format json
- --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
+ --features celox/systemverilog,celox/cranelift,celox/wasm-runtime,celox/wasm-component,celox/veryl-reference,celox-vpi/cranelift,celox-vpi/wasm-runtime,celox-bench/cranelift,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
> /dev/null
rust-default-tests:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4a0f4e9c930..32e53fcd12e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -4,6 +4,31 @@ Use the locked environment described in [docs/development.md](docs/development.m
Cargo builds use the workspace's default `target/`, managed by mbx. Do not set an
ad-hoc `CARGO_TARGET_DIR` or `--target-dir`.
+## Optional execution backends
+
+Ordinary workspace commands select Celox, NAPI and the CLI. Their default native
+and tiered runtimes do not compile Cranelift or Wasmtime. Use `--workspace`
+explicitly to include backend development and comparison crates.
+
+Enable only the backend needed for the task:
+
+- `--features celox/veryl-reference`: upstream Veryl simulator comparisons (its WASM host also depends on Wasmtime).
+- `--features celox/cranelift`: Cranelift JIT and its comparison tests.
+- `--features celox/wasm-runtime`: execute generated WASM with Wasmtime.
+- `--features celox/wasm-component`: load Veryl `.wasm` component libraries.
+
+The CLI forwards all three features; NAPI forwards `cranelift` and
+`wasm-component`. Native component libraries and browser WASM generation do
+not require Wasmtime. Published native NAPI bindings explicitly enable
+`wasm-component`; local debug builds leave it disabled. A disabled WASM component host reports the required
+feature when a `.wasm` library is requested.
+
+Common test matrices use the enabled backends. Binaries that directly compare
+optional backends declare required features. To run the complete Celox suite,
+use `cargo test -p celox --features systemverilog,cranelift,wasm-runtime,wasm-component,veryl-reference`.
+CI explicitly enables these features to retain backend coverage.
+Host cross-codegen features also enable Cranelift for their fallback runtime.
+
## Select checks from the change
Before running checks, identify the behavior that changed and the code that
@@ -44,7 +69,7 @@ For repeated local vtest runs, use the optimized shared executor:
```sh
node scripts/run-vtest.mjs --test counter
-node scripts/run-vtest.mjs --test systemverilog -E 'test(operators::)'
+CELOX_TEST_FEATURES=cranelift,wasm-runtime node scripts/run-vtest.mjs --test systemverilog -E 'test(operators::)'
```
This builds `vtest-exec` with the `vtest` Cargo profile (`opt-level = 1`,
diff --git a/Cargo.lock b/Cargo.lock
index ad69b908def..ae3aff84d83 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -396,6 +396,7 @@ dependencies = [
"bit-set",
"celox-analysis",
"celox-backend-arm64",
+ "celox-backend-common",
"celox-backend-cranelift",
"celox-backend-wasm",
"celox-backend-x86",
@@ -483,6 +484,7 @@ dependencies = [
name = "celox-backend-cranelift"
version = "0.11.0"
dependencies = [
+ "celox-backend-common",
"celox-design",
"celox-sir",
"celox-state-layout",
diff --git a/Cargo.toml b/Cargo.toml
index 2b9681999dd..03951a942f3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,4 +1,6 @@
[workspace]
+# Keep optional backend and comparison crates out of ordinary local builds.
+default-members = ["crates/celox", "crates/celox-napi", "crates/celox-vpi"]
members = [
"crates/celox",
"crates/celox-analysis",
diff --git a/crates/celox-backend-common/src/cranelift_options.rs b/crates/celox-backend-common/src/cranelift_options.rs
new file mode 100644
index 00000000000..3cedc7cbe67
--- /dev/null
+++ b/crates/celox-backend-common/src/cranelift_options.rs
@@ -0,0 +1,106 @@
+//! Cranelift-owned compilation policy.
+
+/// Cranelift backend optimization level.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+pub enum CraneliftOptLevel {
+ /// No Cranelift-level optimizations.
+ None,
+ /// Optimize for execution speed (default).
+ #[default]
+ Speed,
+ /// Optimize for both speed and code size.
+ SpeedAndSize,
+}
+
+impl CraneliftOptLevel {
+ /// Returns the Cranelift settings string for this level.
+ pub fn as_cranelift_str(self) -> &'static str {
+ match self {
+ CraneliftOptLevel::None => "none",
+ CraneliftOptLevel::Speed => "speed",
+ CraneliftOptLevel::SpeedAndSize => "speed_and_size",
+ }
+ }
+}
+
+/// Register allocator algorithm for the Cranelift backend.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+pub enum RegallocAlgorithm {
+ /// Backtracking allocator with range splitting.
+ /// Slower compilation but generates better code with fewer spills.
+ #[default]
+ Backtracking,
+ /// Single-pass allocator.
+ /// Much faster compilation but generates code with more register spills and moves.
+ SinglePass,
+}
+
+impl RegallocAlgorithm {
+ /// Returns the Cranelift settings string for this algorithm.
+ pub fn as_cranelift_str(self) -> &'static str {
+ match self {
+ RegallocAlgorithm::Backtracking => "backtracking",
+ RegallocAlgorithm::SinglePass => "single_pass",
+ }
+ }
+}
+
+/// Fine-grained Cranelift backend options beyond the optimization level.
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+pub struct CraneliftDiagnostics {
+ pub pass_timing: bool,
+}
+
+/// Fine-grained Cranelift backend options beyond the optimization level.
+#[derive(Debug, Clone, Copy)]
+pub struct CraneliftOptions {
+ /// Optimization level (default: Speed).
+ pub opt_level: CraneliftOptLevel,
+ /// Register allocator algorithm (default: Backtracking).
+ pub regalloc_algorithm: RegallocAlgorithm,
+ /// Enable alias analysis during egraph optimization (default: true).
+ /// Only effective when `opt_level` is not `None`.
+ pub enable_alias_analysis: bool,
+ /// Enable the Cranelift IR verifier (default: true).
+ /// Disabling saves compile time at the cost of less validation.
+ pub enable_verifier: bool,
+ /// Enable backend-owned splitting for oversized functions.
+ pub tail_call_split: bool,
+ pub diagnostics: CraneliftDiagnostics,
+}
+
+impl Default for CraneliftOptions {
+ fn default() -> Self {
+ Self {
+ opt_level: CraneliftOptLevel::default(),
+ regalloc_algorithm: RegallocAlgorithm::default(),
+ enable_alias_analysis: true,
+ enable_verifier: true,
+ tail_call_split: true,
+ diagnostics: CraneliftDiagnostics::default(),
+ }
+ }
+}
+
+impl CraneliftOptions {
+ /// Fast compilation preset: no optimizations, single-pass regalloc, no verifier.
+ pub fn fast_compile() -> Self {
+ Self {
+ opt_level: CraneliftOptLevel::None,
+ regalloc_algorithm: RegallocAlgorithm::SinglePass,
+ enable_alias_analysis: false,
+ enable_verifier: false,
+ tail_call_split: true,
+ diagnostics: CraneliftDiagnostics::default(),
+ }
+ }
+
+ /// Select backend defaults without importing the facade's optimization policy.
+ pub fn for_speed_optimization(enabled: bool) -> Self {
+ if enabled {
+ Self::default()
+ } else {
+ Self::fast_compile()
+ }
+ }
+}
diff --git a/crates/celox-backend-common/src/lib.rs b/crates/celox-backend-common/src/lib.rs
index 80ff5b4be29..b5434f8969b 100644
--- a/crates/celox-backend-common/src/lib.rs
+++ b/crates/celox-backend-common/src/lib.rs
@@ -1,3 +1,5 @@
//! Target-independent building blocks shared by native machine-code backends.
pub mod regalloc;
+
+pub mod cranelift_options;
diff --git a/crates/celox-backend-cranelift/Cargo.toml b/crates/celox-backend-cranelift/Cargo.toml
index 171b7166c46..957eafbf01d 100644
--- a/crates/celox-backend-cranelift/Cargo.toml
+++ b/crates/celox-backend-cranelift/Cargo.toml
@@ -10,6 +10,7 @@ edition.workspace = true
rust-version.workspace = true
[dependencies]
+celox-backend-common = { workspace = true }
tracing = { workspace = true }
celox-design = { workspace = true }
celox-sir = { workspace = true }
diff --git a/crates/celox-backend-cranelift/src/cranelift_options.rs b/crates/celox-backend-cranelift/src/cranelift_options.rs
index 3cedc7cbe67..7febb891e0a 100644
--- a/crates/celox-backend-cranelift/src/cranelift_options.rs
+++ b/crates/celox-backend-cranelift/src/cranelift_options.rs
@@ -1,106 +1 @@
-//! Cranelift-owned compilation policy.
-
-/// Cranelift backend optimization level.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
-pub enum CraneliftOptLevel {
- /// No Cranelift-level optimizations.
- None,
- /// Optimize for execution speed (default).
- #[default]
- Speed,
- /// Optimize for both speed and code size.
- SpeedAndSize,
-}
-
-impl CraneliftOptLevel {
- /// Returns the Cranelift settings string for this level.
- pub fn as_cranelift_str(self) -> &'static str {
- match self {
- CraneliftOptLevel::None => "none",
- CraneliftOptLevel::Speed => "speed",
- CraneliftOptLevel::SpeedAndSize => "speed_and_size",
- }
- }
-}
-
-/// Register allocator algorithm for the Cranelift backend.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
-pub enum RegallocAlgorithm {
- /// Backtracking allocator with range splitting.
- /// Slower compilation but generates better code with fewer spills.
- #[default]
- Backtracking,
- /// Single-pass allocator.
- /// Much faster compilation but generates code with more register spills and moves.
- SinglePass,
-}
-
-impl RegallocAlgorithm {
- /// Returns the Cranelift settings string for this algorithm.
- pub fn as_cranelift_str(self) -> &'static str {
- match self {
- RegallocAlgorithm::Backtracking => "backtracking",
- RegallocAlgorithm::SinglePass => "single_pass",
- }
- }
-}
-
-/// Fine-grained Cranelift backend options beyond the optimization level.
-#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
-pub struct CraneliftDiagnostics {
- pub pass_timing: bool,
-}
-
-/// Fine-grained Cranelift backend options beyond the optimization level.
-#[derive(Debug, Clone, Copy)]
-pub struct CraneliftOptions {
- /// Optimization level (default: Speed).
- pub opt_level: CraneliftOptLevel,
- /// Register allocator algorithm (default: Backtracking).
- pub regalloc_algorithm: RegallocAlgorithm,
- /// Enable alias analysis during egraph optimization (default: true).
- /// Only effective when `opt_level` is not `None`.
- pub enable_alias_analysis: bool,
- /// Enable the Cranelift IR verifier (default: true).
- /// Disabling saves compile time at the cost of less validation.
- pub enable_verifier: bool,
- /// Enable backend-owned splitting for oversized functions.
- pub tail_call_split: bool,
- pub diagnostics: CraneliftDiagnostics,
-}
-
-impl Default for CraneliftOptions {
- fn default() -> Self {
- Self {
- opt_level: CraneliftOptLevel::default(),
- regalloc_algorithm: RegallocAlgorithm::default(),
- enable_alias_analysis: true,
- enable_verifier: true,
- tail_call_split: true,
- diagnostics: CraneliftDiagnostics::default(),
- }
- }
-}
-
-impl CraneliftOptions {
- /// Fast compilation preset: no optimizations, single-pass regalloc, no verifier.
- pub fn fast_compile() -> Self {
- Self {
- opt_level: CraneliftOptLevel::None,
- regalloc_algorithm: RegallocAlgorithm::SinglePass,
- enable_alias_analysis: false,
- enable_verifier: false,
- tail_call_split: true,
- diagnostics: CraneliftDiagnostics::default(),
- }
- }
-
- /// Select backend defaults without importing the facade's optimization policy.
- pub fn for_speed_optimization(enabled: bool) -> Self {
- if enabled {
- Self::default()
- } else {
- Self::fast_compile()
- }
- }
-}
+pub use celox_backend_common::cranelift_options::*;
diff --git a/crates/celox-bench/Cargo.toml b/crates/celox-bench/Cargo.toml
index f60dc650a26..ffa140da835 100644
--- a/crates/celox-bench/Cargo.toml
+++ b/crates/celox-bench/Cargo.toml
@@ -9,6 +9,7 @@ description = "Macro-benchmark runners for Celox"
edition.workspace = true
[features]
+cranelift = ["celox/cranelift"]
default = []
arm64-codegen = ["celox/arm64-codegen"]
x86_64-codegen = ["celox/x86_64-codegen"]
@@ -36,3 +37,7 @@ celox-design = { workspace = true }
[lints]
workspace = true
+
+[[bin]]
+name = "parallel-report"
+required-features = ["cranelift"]
diff --git a/crates/celox-frontend-core/src/watch.rs b/crates/celox-frontend-core/src/watch.rs
index 6043ddcbc9a..40a2bdbbc5c 100644
--- a/crates/celox-frontend-core/src/watch.rs
+++ b/crates/celox-frontend-core/src/watch.rs
@@ -388,52 +388,201 @@ pub fn multi_store_only_candidates(
/// [`multi_store_candidates`] with the written key of each instruction
/// given by `key`, for callers that count only some kinds of writes.
+///
+/// The blocks are condensed into strongly connected components once; each
+/// component then knows the keys written in it or downstream of it, so a
+/// write is a candidate if its key is written again later in its block, or
+/// in a block reachable from it. Candidates come in the order of their
+/// first such write, by block id and then position.
pub fn multi_write_candidates(
unit: &ExecutionUnit,
key: impl Fn(&SIRInstruction) -> Option,
) -> Vec {
- let writes = |block: &celox_sir::BasicBlock| -> Vec