Codegen IR (cheetah.internal.codegen_ir
)
The codegen IR models target-level C++/CUDA constructs with explicit precedence rules for pretty-printing.
Types
PrimType(name)
: textual type (e.g.,int32_t
,float
,torch::Tensor
)PtrType(mut, elem)
: emits qualifiers on the right (T const*
,T volatile*
)TensorType(mut, elem)
: emitstorch::Tensor
(const mutability supported)
Expressions
- Literals (
LitExpr
), variables (VarExpr
) - Binary and unary ops with precedence and associativity
- Indexing, address-of/deref, casts (
const/static/reinterpret
) - Raw snippets inserted verbatim when needed
Statements
- Expression statements
- Declarations (scalars, arrays, tensors, shared memory, extern shared)
- Blocks,
if
with optionalelse
,for
with optional pragma unroll,return
- Inline asm statement form
Declarations and programs
FuncDecl
andFuncDef
emit prototypes and definitionsProgram
composes headers, prototypes, and definitions with namespace prologue/epilogue
Pretty printing
- A small precedence/side tracker ensures minimal parentheses and readable formatting
- Namespace handling avoids redundant open/close pairs and inserts padding for readability