ConversionContext

class ConversionContext @JvmOverloads constructor(typeMapper: TypeMapper, graph: ComputeGraph? = null, val materializationPolicy: ConstantMaterializationPolicy = ConstantMaterializationPolicy.InlineAlways)(source)

Context object for maintaining state during StableHLO conversion.

This class manages SSA value names, type mapping, and MLIR code generation during the conversion process from ComputeGraph to StableHLO.

Constructors

Link copied to clipboard
constructor(typeMapper: TypeMapper, graph: ComputeGraph? = null, materializationPolicy: ConstantMaterializationPolicy = ConstantMaterializationPolicy.InlineAlways)

Properties

Link copied to clipboard

Governs whether constant tensors are inlined as dense<...> or lifted into util.global module declarations. Default ConstantMaterializationPolicy.InlineAlways preserves historical behavior for every caller that constructs a context without naming a policy — the external path is strictly opt-in. See issue #523 for the architecture context.

Functions

Link copied to clipboard
fun clear()

Clear all state (useful for testing)

Link copied to clipboard
fun emitComment(comment: String)

Emit a comment with proper indentation

Link copied to clipboard
fun emitEncodingAnnotation(role: String, index: Int, spec: TensorSpec)

Emit a tensor_encoding diagnostic comment when spec carries a non-null tensorEncoding (set via sk.ainet.lang.tensor.ops.withTensorEncoding).

Link copied to clipboard
fun emitLine(line: String)

Emit a line of MLIR code with proper indentation

Link copied to clipboard

Emit a module-scope declaration (e.g. util.global private @w : ...).

Link copied to clipboard
fun emitOperation(operation: String)

Emit an operation with proper indentation

Link copied to clipboard

Get the complete generated MLIR content

Link copied to clipboard

Snapshot of every externalized constant registered during this conversion. Surfaced on StableHloModule.externalParameters.

Link copied to clipboard

Get input nodes for a given node from the graph

Link copied to clipboard

Return every module-scope declaration emitted so far. Used by StableHloConverter when assembling the final content.

Link copied to clipboard

Get the type mapper instance

Link copied to clipboard
fun getValueName(nodeId: String): String?

Get the SSA value name for a node ID

Link copied to clipboard
fun getValueType(valueName: String): String?

Get the MLIR tensor type for an SSA value name, or null if the value was produced by a converter that did not record its type.

Link copied to clipboard

Generate the next temporary SSA value name

Link copied to clipboard

Register an externalized constant tensor. The converter records these alongside MLIR emission so a downstream packager (see PR C in issue #523) can write them into an IREE .irpa archive.

Link copied to clipboard

Set the graph reference for node lookups

Link copied to clipboard
fun setValueName(nodeId: String, valueName: String)

Set the SSA value name for a node ID

Link copied to clipboard
fun setValueType(valueName: String, mlirType: String)

Record the MLIR tensor type associated with an SSA value name.