svod_codegen/lib.rs
1//! Code generation for svod tensor operations.
2//!
3//! This crate provides backend-agnostic code generation infrastructure
4//! for converting optimized UOp graphs into executable code.
5//!
6//! # Architecture
7//!
8//! - **Traits**: Backend-agnostic interfaces (`Renderer`)
9//! - **LLVM**: LLVM IR code generation for CPU execution
10//! - **Future**: CUDA, Metal, OpenCL renderers
11//!
12//! # Usage
13//!
14//! ```ignore
15//! use svod_codegen::{llvm, program_pipeline};
16//!
17//! let linear = svod_ir::UOp::linear(svod_schedule::linearize_with_cfg(optimized_uop_graph).into());
18//! let kernel = llvm::text::render(&linear, Some("kernel"))?;
19//! // Canonical staged flow: PROGRAM -> LINEAR -> SOURCE -> BINARY.
20//! // See `program_pipeline` for the strict staged entrypoints.
21//! ```
22//!
23//! # Pre-render invariants
24//!
25//! Direct callers of [`Renderer::render`] (and the per-backend `render` free
26//! functions) must pass a LINEAR-stage UOp produced by
27//! [`svod_schedule::linearize::line_rewrite_cleanups`]. The cleanup pass
28//! lowers gated LOADs into IF/STORE/ENDIF and provides the `alt` value that
29//! per-backend op handlers rely on; backends report `Error::InvalidGraph` if
30//! these invariants are violated. The staged entrypoints in
31//! [`program_pipeline`] run the cleanup pass automatically.
32
33pub mod c;
34pub mod common;
35pub mod error;
36pub mod llvm;
37#[cfg(feature = "mlir")]
38pub mod mlir;
39pub mod program_pipeline;
40pub mod traits;
41pub mod types;
42
43#[cfg(test)]
44pub mod test;
45
46pub use common::collect_buffers_and_vars;
47pub use error::*;
48pub use traits::*;
49pub use types::*;