---
title: "IR, a category in the TypeShade API reference"
description: "IR in the TypeShade API reference. The intermediate representation every backend reads: nodes, statements and declarations."
url: https://typeshade.dev/api/ir/
language: en
---

# IR

43 members

The intermediate representation every backend reads: nodes, statements and declarations.

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

**[`AddressSpace`](https://typeshade.dev/api/addressspace/) Type**

The BindingDecl.space a resource binding lives in: WGSL's var<uniform> or var<storage, ...>.

**[`ALL_CAPABILITIES`](https://typeshade.dev/api/allcapabilities/) Constant**

Every Capability, as a runtime value: the list a capability matrix, a doc generator or a coverage check iterates.

**[`ASSEMBLED_AS`](https://typeshade.dev/api/assembledas/) Constant**

Non-enumerable marker key on a FuncDecl: the name the declaration was last assembled under by module.

**[`BindingDecl`](https://typeshade.dev/api/bindingdecl/) Interface**

A ModuleDecl.bindings entry: a resource bound at a slot.

**[`BinOp`](https://typeshade.dev/api/binop/) Type**

The operator tag on Expr.binop: arithmetic (+ - \* /), remainder (%) and bitwise.

**[`Capability`](https://typeshade.dev/api/capability/) Type**

A GPU or language feature a target backend may or may not support.

**[`CmpOp`](https://typeshade.dev/api/cmpop/) Type**

The operator tag on Expr.compare: the six relational operators.

**[`ConstDecl`](https://typeshade.dev/api/constdecl-interface/) Interface**

A ModuleDecl.consts entry: a module-scope constant.

**[`DeclarableCapability`](https://typeshade.dev/api/declarablecapability/) Type**

The capabilities a module may name in ModuleDecl.enables: Capability minus the nine capabilities derived from the module's shape.

**[`DiagnosticDirective`](https://typeshade.dev/api/diagnosticdirective/) Interface**

A WGSL \`diagnostic(severity, rule);\` directive.

**[`EntryParam`](https://typeshade.dev/api/entryparam/) Interface**

An entry-point parameter: it carries a `@builtin(...)` or a `@location(n)`.

**[`Expr`](https://typeshade.dev/api/expr/) Type**

Every expression shape the IR can hold: the closed set that Node and ReadonlyNode build and that the WGSL, GLSL and CPU backends walk to emit or evaluate.

**[`ExternVarDecl`](https://typeshade.dev/api/externvardecl/) Interface**

A host-provided global, the declaration behind externVar.

**[`FuncDecl`](https://typeshade.dev/api/funcdecl/) Interface**

A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (stage set).

**[`grad`](https://typeshade.dev/api/grad/) Function**

Differentiate a function of a module and add the derivative as a new function.

**[`gradCheck`](https://typeshade.dev/api/gradcheck/) Function**

Compare the derivative grad builds for fn with a central difference on the CPU oracle at `f64`, at each point of opts.at, for every component of every parameter of opts.wrt and every component of the result.

**[`GradCheckOptions`](https://typeshade.dev/api/gradcheckoptions/) Interface**

Options for gradCheck.

**[`GradCheckResult`](https://typeshade.dev/api/gradcheckresult/) Interface**

What gradCheck returns.

**[`GradOptions`](https://typeshade.dev/api/gradoptions/) Interface**

Options for grad.

**[`GradResult`](https://typeshade.dev/api/gradresult/) Interface**

What grad returns: the module with the derivative function added, and its name.

**[`installStmtSink`](https://typeshade.dev/api/installstmtsink/) Function**

Installs the statement sink that Node.assign() writes through.

**[`isNodeValue`](https://typeshade.dev/api/isnodevalue/) Function**

Runtime type guard for "is this value a node".

**[`lift`](https://typeshade.dev/api/lift/) Function**

Normalizes a NodeLike operand to a ReadonlyNode: a JS number becomes an `f32` literal, and an existing node passes through unchanged.

**[`LogOp`](https://typeshade.dev/api/logop/) Type**

The operator tag on Expr.logical: the short-circuiting boolean operators && and ||.

**[`ModuleDecl`](https://typeshade.dev/api/moduledecl/) Interface**

The whole-shader unit: everything a backend needs to emit a complete WGSL or GLSL ES 3.00 module, or to evaluate one on the CPU oracle.

**[`ModuleVarDecl`](https://typeshade.dev/api/modulevardecl/) Interface**

One entry of ModuleDecl.vars: a module-scope variable that is not a resource.

**[`Node`](https://typeshade.dev/api/node/) Class**

The write-capable node.

**[`NODE_BRAND`](https://typeshade.dev/api/nodebrand/) Constant**

The symbol every node carries as a brand, installed once on the ReadonlyNode prototype.

**[`OverrideDecl`](https://typeshade.dev/api/overridedecl/) Interface**

A pipeline specialization constant, the declaration behind overrideConst.

**[`RawPayload`](https://typeshade.dev/api/rawpayload/) Type**

The argument to rawStmt: the wgsl and glsl source text of a raw statement.

**[`RawStmt`](https://typeshade.dev/api/rawstmt-type/) Type**

The raw statement node: a fragment of target source spliced verbatim into a function body, spelled per target.

**[`ReadonlyNode`](https://typeshade.dev/api/readonlynode/) Class**

The read-only base of every value node: every literal, parameter, constRef and Let() binding is a ReadonlyNode.

**[`renameVarrefsInFunc`](https://typeshade.dev/api/renamevarrefsinfunc/) Function**

Renames variable references in the body of f.

**[`rewriteExprsInFunc`](https://typeshade.dev/api/rewriteexprsinfunc/) Function**

Applies rewrite to every expression in the body of f and returns the rewritten function.

**[`SourceSpan`](https://typeshade.dev/api/sourcespan/) Interface**

Where an IR node came from in its authored source: the file, the exact UTF-16 offsets, and the line and character of each end for display.

**[`sourceSpanOf`](https://typeshade.dev/api/sourcespanof/) Function**

The authored source span of an IR node, or undefined when it has none.

**[`stageOf`](https://typeshade.dev/api/stageof/) Function**

The stage of a function declaration: 'vertex', 'fragment' or 'compute' for an entry point, undefined for a helper.

**[`Stmt`](https://typeshade.dev/api/stmt/) Type**

Every statement shape the IR can hold: the ordered readonly Stmt\[\] that makes up a FuncDecl.body.

**[`StructDecl`](https://typeshade.dev/api/structdecl-interface/) Interface**

A ModuleDecl.structs entry: a WGSL struct declaration.

**[`StructField`](https://typeshade.dev/api/structfield/) Interface**

One field of a StructDecl: a plain data member of a uniform or storage struct, or, in a vertex/fragment I/O struct, a member carrying a `@builtin` or `@location` attribute.

**[`WorkgroupShape`](https://typeshade.dev/api/workgroupshape/) Type**

The x, y and z extents of a compute entry's workgroup, WGSL's `@workgroup_size(x, y, z)`.

**[`workgroupShapeOf`](https://typeshade.dev/api/workgroupshapeof/) Function**

The workgroup shape of a compute entry: the structured workgroupShape field first, then \[workgroupSize, 1, 1\], then the extents of the `@workgroup_size(x, y, z)` attribute string; undefined when none is present.

**[`workgroupSizeOf`](https://typeshade.dev/api/workgroupsizeof/) Function**

The x workgroup size of a compute entry: the structured workgroupSize field first, then the `@workgroup_size(n)` attribute string; undefined when neither is present.
