Skip to main content

celox_backend_x86/
lib.rs

1//! Self-contained x86-64 code-generation kernel.
2//!
3//! The crate consumes source-independent SIR plus a finalized physical state
4//! layout. It does not know about the Veryl frontend, simulator facade, or
5//! testbench runtime.
6
7pub type HashMap<K, V> = fxhash::FxHashMap<K, V>;
8pub type HashSet<K> = fxhash::FxHashSet<K>;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct NativeDumpOptions {
12    pub block: usize,
13    pub label: Option<String>,
14    pub stage: Option<String>,
15    pub dump_sir: bool,
16    pub mir_limit: usize,
17}
18
19impl Default for NativeDumpOptions {
20    fn default() -> Self {
21        Self {
22            block: 0,
23            label: None,
24            stage: None,
25            dump_sir: true,
26            mir_limit: 64,
27        }
28    }
29}
30
31#[derive(Debug, Clone, Default, PartialEq, Eq)]
32pub struct NativeDiagnostics {
33    pub phase_timing: bool,
34    pub regalloc_timing: bool,
35    pub regalloc_stats: bool,
36    pub mir_stats: bool,
37    pub mir_block_stats: bool,
38    pub verify_sir: bool,
39    pub verify_mir: bool,
40    pub verify_mir_passes: bool,
41    pub verify_regalloc: bool,
42    pub isel_trace_regs: Vec<usize>,
43    pub dump: Option<NativeDumpOptions>,
44    pub perf_map: bool,
45}
46
47#[derive(Debug, Clone)]
48pub struct X86BackendOptions {
49    pub slp: bool,
50    pub native_tick_loop: bool,
51    pub diagnostics: NativeDiagnostics,
52}
53
54impl Default for X86BackendOptions {
55    fn default() -> Self {
56        Self {
57            slp: true,
58            native_tick_loop: true,
59            diagnostics: NativeDiagnostics::default(),
60        }
61    }
62}
63
64pub use celox_design::{
65    AbsoluteAddrBase, BinaryOp, DomainKind, InstanceId, RegionedAbsoluteAddrBase, RuntimeEventKind,
66    SPARSE_WORKING_REGION, STABLE_REGION, StateAddr, TriggerIdWithKind, UnaryOp, WORKING_REGION,
67};
68pub use celox_sir::*;
69
70pub type AbsoluteAddr = celox_design::StateAddr;
71pub type RegionedAbsoluteAddr = celox_design::RegionedStateAddr;
72pub type SirProgram = celox_sir::SirProgram<AbsoluteAddr, RegionedAbsoluteAddr>;
73pub type MemoryLayout = celox_state_layout::MemoryLayout<AbsoluteAddr>;
74
75/// Remaining iterations for an in-function native tick loop.
76pub const STATE_HEADER_NATIVE_LOOP_REMAINING_OFFSET: usize = 8;
77/// Runtime-event sequence observed when a native tick batch starts.
78pub const STATE_HEADER_NATIVE_LOOP_EVENT_SEQ_OFFSET: usize = 24;
79
80const _: () = {
81    assert!(
82        celox_state_layout::STATE_HEADER_RUNTIME_EVENT_ADDR_OFFSET + 8
83            <= STATE_HEADER_NATIVE_LOOP_REMAINING_OFFSET
84    );
85    assert!(
86        STATE_HEADER_NATIVE_LOOP_REMAINING_OFFSET + 8
87            <= celox_state_layout::STATE_HEADER_COMB_CAPTURE_ENABLED_ADDR_OFFSET
88    );
89    assert!(
90        celox_state_layout::STATE_HEADER_COMB_CAPTURE_ENABLED_ADDR_OFFSET + 8
91            <= STATE_HEADER_NATIVE_LOOP_EVENT_SEQ_OFFSET
92    );
93    assert!(STATE_HEADER_NATIVE_LOOP_EVENT_SEQ_OFFSET + 8 <= celox_state_layout::STATE_HEADER_SIZE);
94};
95
96pub mod timing {
97    pub fn now() -> std::time::Instant {
98        std::time::Instant::now()
99    }
100}
101
102#[path = "backend/native/mod.rs"]
103pub mod native;
104
105pub use native::*;