Intermediate Representation
The MIND IR is a typed, SSA-based intermediate representation designed for tensor operations and automatic differentiation.
📐 IR canon (mindc 0.10.x, RFC 0021 steps 1–3):
- • Canonical data shape:
IRModule(the SSA structure described below). - • Canonical text serialisation:
mic@1. RFC 0001 fixed-point form; the evidence-chaintrace_hashis computed overmic@3binary (RFC 0016 GAP-1, re-anchored 2026-05-31). - • Canonical binary serialisation:
mic@3(magicMIC3). Round-trip equivalent tomic@1; carries the evidence MAP epilogue via a0x4Dsentinel. - • Compact alternative (back-compat):
mic@2/[email protected](with MAP) — slated for demotion tomind-model@2per RFC 0021 step 5. - • Stability surface: /docs/stability + mind-spec ir-stability.md.
IR Structure
MIND IR uses Static Single Assignment (SSA) form with explicit types:
// Example IR for: y = relu(x @ w) %0 = mind.const : tensor<2x2xf32> = [[1.0, 2.0], [3.0, 4.0]] %1 = mind.randn : tensor<2x2xf32> %2 = mind.matmul(%0, %1) : tensor<2x2xf32> %3 = mind.relu(%2) : tensor<2x2xf32> mind.return %3
Core Operations
| Category | Operations |
|---|---|
| Arithmetic | add, sub, mul, div, neg, pow |
| Linear Algebra | matmul, transpose, dot |
| Activations | relu, sigmoid, tanh, softmax, gelu |
| Reductions | sum, mean, max, min, prod |
| Shape | reshape, broadcast, squeeze, unsqueeze |
| Convolution | conv2d, maxpool2d, avgpool2d |
Type Representation
IR types encode both dtype and shape information:
tensor<f32> // Scalar tensor<10xf32> // 1D, static shape tensor<2x3xf32> // 2D, static shape tensor<?x?xf32> // 2D, dynamic shape tensor<2x?xf32> // Mixed static/dynamic
Canonicalization
The IR undergoes canonicalization passes to normalize operations:
- Constant folding for compile-time-known values
- Identity elimination (x + 0 → x, x * 1 → x)
- Strength reduction (x * 2 → x + x for integers)
- Dead code elimination
Lowering Pipeline
The normative self-host backend emits native x86-64/ELF directly from the canonical IR. The MLIR → LLVM path shown below is the downstream-interchange route for specialty targets (see MLIR Lowering):
Source (.mind)
↓ Parse
AST
↓ Type check
Typed AST
↓ Lower
MIND IR (High-level)
↓ Canonicalize
MIND IR (Canonical)
↓ Autodiff (if needed)
MIND IR + Gradients
↓ Lower to MLIR
MLIR Dialects
↓ Lower to LLVM
LLVM IR
↓ Codegen
Machine CodeLearn More
See the full IR specification at mind-spec/ir.md.