Skip to main content

Crate ruxla_codegen

Crate ruxla_codegen 

Source
Expand description

Ahead-of-time compilation of the IR to Rust: a traced function is optimized (opt) and turned into a Rust function of fixed-size arrays and scalars (emit) that rustc compiles with the rest of the program. Generated code calls rt.

§Examples

use ruxla_ir::{AVal, DType, Eqn, Function, Params, Var};

let x = Var::new(AVal::new([3], DType::F32));
let y = Var::new(AVal::new([3], DType::F32));
let f = Function {
    invars: vec![x.clone()],
    eqns: vec![Eqn {
        prim: ruxla_prims::MUL,
        inputs: vec![x.clone().into(), x.into()],
        params: Params::None,
        outputs: vec![y.clone()],
        loc: None,
    }],
    outvars: vec![y.into()],
    ..Function::default()
};
let code = ruxla_codegen::compile("square", &f, &Default::default()).unwrap();
assert!(code.contains("pub fn square(a0: &[f32; 3]) -> ([f32; 3],)"));

Re-exports§

pub use emit::ConstPool;
pub use emit::Error;
pub use emit::Input;
pub use emit::Output;
pub use emit::Signature;
pub use emit::emit_function;
pub use emit::emit_function_pooled;
pub use emit::emit_function_with;
pub use opt::Options;
pub use opt::Skip;
pub use opt::optimize;

Modules§

emit
Rust code from the IR: a function of fixed-size arrays and scalars.
opt
Optimizations of the IR before code generation: inlining of calls, constant folding and algebraic simplification, common subexpression elimination, dead code elimination, and the conversion of selects on a scalar predicate into conditionals (so that only the chosen side is computed).
rt
Helpers that generated code calls (not meant to be used directly).

Functions§

compile
Optimizes f and generates the Rust function name that computes it (see emit_function).
compile_pooled
compile_with whose constant arrays go to pool, shared by the functions of a module (see ConstPool).
compile_with
compile with the arguments and results of sig.