Skip to main content

teeny_compiler/compiler/backend/
mod.rs

1/*
2 * Copyright (c) 2026 Teenygrad.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *   http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use teeny_core::dtype;
18
19use crate::compiler::backend::llvm::{compiler::LlvmCompiler, module::MlirModule};
20
21#[cfg(feature = "ndarray")]
22use crate::compiler::backend::ndarray::{compiler::NdarrayCompiler, module::NdarrayModule};
23
24/// The `ndarray`-backed CPU backend.
25#[cfg(feature = "ndarray")]
26pub mod ndarray;
27
28/// The LLVM/MLIR backend (compiles via the `teenyc` compiler at runtime).
29pub mod llvm;
30
31/// A compiled module, tagged by which backend produced it.
32#[derive(Debug, Clone)]
33pub enum Module<N: dtype::Dtype> {
34    /// A module compiled by the LLVM/MLIR backend.
35    Mlir(MlirModule<N>),
36
37    /// A module compiled by the `ndarray` backend.
38    #[cfg(feature = "ndarray")]
39    Ndarray(NdarrayModule<N>),
40}
41
42/// A backend capable of compiling kernels, tagged by which one it is.
43pub enum Compiler {
44    /// The LLVM/MLIR backend.
45    Llvm(LlvmCompiler),
46
47    /// The `ndarray` backend.
48    #[cfg(feature = "ndarray")]
49    Ndarray(NdarrayCompiler),
50}