Hint const in loops
Set const hints on statements inside preserved scf.For bodies.
The standard kirin pipeline runs const.Propagate once at the top-level
method scope, so SSA values inside preserved scf.For bodies don't pick up
const hints. This module fills that gap with a generic rule that mimics
const.Propagate's pure-fallback logic (run each Pure statement's
concrete impl on its const-hinted args, stamp the result back as a const
hint), plus a few specialized rules for cases that need static-type info
or scf.For-aware traversal.
HintConstInLoops
dataclass
HintConstInLoops()
Bases: Pass
flowchart TD
bloqade.stim.passes.hint_const_in_loops.HintConstInLoops[HintConstInLoops]
click bloqade.stim.passes.hint_const_in_loops.HintConstInLoops href "" "bloqade.stim.passes.hint_const_in_loops.HintConstInLoops"
Pass that sets const hints inside preserved scf.For loop bodies.
Composes PropagateInitializerHints (for For-level hint/type propagation) with per-statement hinting rules (HintConstant, HintTupleNew, etc.). Also installs the early-terminating constprop override for scf.For.
HintLen
Bases: RewriteRule
flowchart TD
bloqade.stim.passes.hint_const_in_loops.HintLen[HintLen]
click bloqade.stim.passes.hint_const_in_loops.HintLen href "" "bloqade.stim.passes.hint_const_in_loops.HintLen"
Hint py.Len results as const from static IList type info.
Kept distinct from HintPureFromConcrete because the length comes
from the operand's type (IList[X, Literal(N)]), not from a
const-hinted operand value — useful when the IList itself isn't const
but its length is statically known.
HintPureFromConcrete
dataclass
HintPureFromConcrete(dialects: DialectGroup)
Bases: RewriteRule
flowchart TD
bloqade.stim.passes.hint_const_in_loops.HintPureFromConcrete[HintPureFromConcrete]
click bloqade.stim.passes.hint_const_in_loops.HintPureFromConcrete href "" "bloqade.stim.passes.hint_const_in_loops.HintPureFromConcrete"
Generic const-folder mimicking const.Propagate's pure fallback.
For any Pure statement whose args all carry const.Value hints,
run the concrete impl on the const data and stamp each result with a
const.Value hint. Subsumes per-stmt hand-rolled folders for
Constant, TupleNew, IListNew, Range, Slice, USub, and similar.
PropagateBodyArgTypes
Bases: RewriteRule
flowchart TD
bloqade.stim.passes.hint_const_in_loops.PropagateBodyArgTypes[PropagateBodyArgTypes]
click bloqade.stim.passes.hint_const_in_loops.PropagateBodyArgTypes href "" "bloqade.stim.passes.hint_const_in_loops.PropagateBodyArgTypes"
For preserved scf.For loops where an iter_arg follows the concat
accumulator pattern (acc = acc + ms or acc = ms + acc), refine
the body block arg's type to IList[ms_elem_type, Any] and propagate
through in-body uses. Enables partial rewrites to recognize fixed-size
list literals and REPEAT-faithful slices derived from the accumulator
(e.g., [acc[-1]], acc[-2:]).
PropagateInitializerHints
Bases: RewriteRule
flowchart TD
bloqade.stim.passes.hint_const_in_loops.PropagateInitializerHints[PropagateInitializerHints]
click bloqade.stim.passes.hint_const_in_loops.PropagateInitializerHints href "" "bloqade.stim.passes.hint_const_in_loops.PropagateInitializerHints"
Propagate hints and types from For loop initializers to body block args and results.
Only applies to REPEAT-eligible For loops. Also propagates types through downstream GetItem and ilist.New use chains.