Skip to content

Lowering & rendering

cheetah.internal.core_to_codegen performs lowering from core IR to codegen IR and final rendering.

Steps

  1. Collect dependencies: walk all bodies reachable from the selected entry points (calls and addresses)
  2. Generate names: export names reserved first, internal names derived from function internal names or generic prefixes (with deconfliction)
  3. Inlining analysis: mark pure/read expressions used once as inlineable; track control/memory epochs to avoid unsafe movement
  4. Emit codegen IR: walk blocks and convert expressions/statements; hoist decls for values not inlined
  5. Compose program: headers, prototypes, definitions; optional pybind11 stub if bind=True

Naming

  • Variables derive names from user-provided names (via ch.set_name and instrumentation) or type-driven prefixes
  • Functions get stable names with numeric suffixes if needed

Safety and ordering

  • Epoch tracking enforces barriers around control constructs and side-effecting ops (writes, raw code/asm, calls)
  • Logical && / || force operands not to be inlined across short-circuit boundaries