Skip to content
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/ci-napi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 != ''
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 26 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`,
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
106 changes: 106 additions & 0 deletions crates/celox-backend-common/src/cranelift_options.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
2 changes: 2 additions & 0 deletions crates/celox-backend-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Target-independent building blocks shared by native machine-code backends.

pub mod regalloc;

pub mod cranelift_options;
1 change: 1 addition & 0 deletions crates/celox-backend-cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
107 changes: 1 addition & 106 deletions crates/celox-backend-cranelift/src/cranelift_options.rs
Original file line number Diff line number Diff line change
@@ -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::*;
5 changes: 5 additions & 0 deletions crates/celox-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -36,3 +37,7 @@ celox-design = { workspace = true }

[lints]
workspace = true

[[bin]]
name = "parallel-report"
required-features = ["cranelift"]
Loading
Loading