fhelium.compile.passes.program
Program-wide analyses and transformations over mixed dialects.
EliminateDeadValuesPass
class View source
EliminateDeadValuesPass(name: str = 'eliminate-dead-values')Erase unused operations according to registered effects.
The pass traverses known structured regions while preserving terminators and result interfaces. Unknown operations or regions, random draws, mutation, and opaque effects remain liveness roots. Removal requires purity registered for the operation's concrete class; an inherited Pure trait alone is insufficient.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'eliminate-dead-values' |
run
method
def run(compilation: 'Compilation') -> PassResult: ...Walk blocks in reverse dependency order and remove dead producers.
ReuseIntermediatesPass
class View source
ReuseIntermediatesPass(name: str = 'reuse-intermediates')Share internal pure computations while preserving observable output storage.
Reuse requires the same concrete operation, ordered SSA operands, result types, attributes and properties. Numerical materials are ordinary operands and must therefore match by SSA identity. A mutation, random draw, unknown operation, region or implementation assignment ends a local reuse run.
Shared results must reach only fresh out-of-place readers, possibly through views. Direct returns, escaping views and unknown or assigned consumers prevent sharing. This preserves independently observable result storage without changing arithmetic order, rounding or value-state transitions.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'reuse-intermediates' |
run
method
def run(compilation: 'Compilation') -> PassResult: ...SvgGraphDirection
type alias View source
SvgGraphDirection = Literal['TB', 'BT', 'LR', 'RL']SvgGraphError
class View source
SvgGraphError()Bases: RuntimeError
Report that Program SVG rendering could not complete.
SvgGraphField
type alias View source
SvgGraphField = Literal['name', 'opcode', 'role', 'operands', 'result_types', 'attributes', 'num_users']SvgGraphOutput
class View source
SvgGraphOutput(path: Path, temporary: bool)Record the SVG file produced by a visualization pass.
Attributes
| Name | Type | Default/value |
|---|---|---|
path | Path | |
temporary | bool |
SvgGraphPresentation
class View source
SvgGraphPresentation(*, fields: Collection[SvgGraphField] | None=None, attribute_names: Collection[str] | None=None, attribute_preview_chars: int | None=180, theme: SvgGraphTheme | None=None)Select and format operation details for an SVG graph.
Subclasses can override select_attributes for filtering, format_attribute_value for one-value display policy, operation_sections for complete operation-row transformation, or operation_tooltip for aggregate hover details. These methods must not mutate their operation or Program.
select_attributes
method
def select_attributes(operation: Operation) -> tuple[tuple[str, Attribute], ...]: ...Return sorted non-internal attributes selected for operation.
format_attribute_value
method
def format_attribute_value(operation: Operation, name: str, attribute: Attribute) -> str: ...Format one selected attribute for its character-limited preview.
operation_sections
method
def operation_sections(context: SvgOperationContext) -> tuple[SvgNodeSection, ...]: ...Return all displayed record rows for one operation.
Override this complete-row hook to reorder, rename, remove, or inject derived sections while reusing super().operation_sections(context).
operation_tooltip
method
def operation_tooltip(context: SvgOperationContext, sections: Collection[SvgNodeSection]) -> str | None: ...Return one aggregate node tooltip from already-rendered sections.
SvgGraphTheme
class View source
SvgGraphTheme(*, operation_palette: Collection[str] | None=None, operation_colors: Mapping[str, str] | None=None, operation_color_key: Callable[[SvgOperationContext], str] | None=None, canvas_color: str='transparent', input_fill_color: str='#DCE4FF', output_fill_color: str='#F3D89D', node_font_color: str='#181B26', node_stroke_color: str='#596178', edge_color: str='#7B8193')Define colors and operation color classification for an SVG graph.
An operation first receives a key from operation_color_key. A matching operation_colors entry wins; otherwise the key is deterministically mapped into operation_palette. Equal keys under one theme receive equal colors. None selects the FHElium default palette or color-key function. operation_colors=None uses the default constant color, while an empty mapping removes it. Theme configuration is read-only and unhashable because a caller-supplied color-key callable does not define a general cache identity.
Attributes
| Name | Type | Default/value |
|---|---|---|
operation_palette | tuple[str, ...] | |
operation_colors | Mapping[str, str] | |
operation_color_key | Callable[[SvgOperationContext], str] | |
canvas_color | str | |
input_fill_color | str | |
output_fill_color | str | |
node_font_color | str | |
node_stroke_color | str | |
edge_color | str |
operation_fill_color
method
def operation_fill_color(context: SvgOperationContext) -> str: ...Return the configured or stable palette color.
SvgGraphVisualizationPass
class View source
SvgGraphVisualizationPass(output_path: str | PathLike[str] | None=None, *, overwrite: bool=False, entry: str='main', presentation: SvgGraphPresentation | None=None, rank_direction: SvgGraphDirection='TB', name: str='visualize-svg')Render one Program function to a local or temporary SVG file.
output_path selects a caller-owned local path. When it is omitted, the pass creates a unique directory under the operating system's temporary location. In both cases, SvgGraphOutput records the produced file in the Compilation workspace.
Attributes
| Name | Type | Default/value |
|---|---|---|
output_path | Path | None | |
overwrite | bool | |
entry | str | |
presentation | SvgGraphPresentation | None | |
rank_direction | SvgGraphDirection | |
name | str |
run
method
def run(compilation: 'Compilation') -> PassResult: ...Render the current Program and publish its output path.
SvgNodeSection
class View source
SvgNodeSection(name: str, value: str, tooltip: str | None = None)Represent one labeled record row inside an SVG operation node.
value participates in Graphviz layout. tooltip optionally adds complete or alternate details for the containing node's aggregate hover text; Graphviz does not attach a separate tooltip to each record cell.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | |
value | str | |
tooltip | str | None | None |
SvgOperationContext
class View source
SvgOperationContext(operation: Operation, result_names: tuple[str, ...], operand_names: tuple[str, ...])Provide stable operation data to an SVG presentation policy.
Attributes
| Name | Type | Default/value |
|---|---|---|
operation | Operation | |
result_names | tuple[str, ...] | |
operand_names | tuple[str, ...] |
opcode
property
opcode: strReturn the registered or dynamic operation name.
default_svg_operation_color_key
function View source
def default_svg_operation_color_key(context: SvgOperationContext) -> str: ...Return the default stable operation color key.
Operation names define ordinary keys. Preserved torch.call operations additionally include call kind and target so custom classifiers can delegate without reproducing that rule.