Inline dup
InlineDup: canonicalise stack_move.Dup out of the IR.
A Dup is an identity: both of its results, top and below, are its
operand. In SSA form that copy says nothing a second use of the operand does
not, so this rule gives each copy's consumers the operand itself and deletes
the Dup — as kirin's InlineAlias does for py.Alias. It is the
one thing that does: a Dup is not Pure, so DCE and ConstantFold
leave it. load_program(..., inline_dup=True) runs it on a decoded kernel.
RewriteStackMoveToMove lowers each Dup with it: move keeps no
stack, so a copy means nothing there. stackify uses it for one case only,
and only in a block that is not already a stack program: a Dup of a
constant, since a copy of a constant is that constant, which it re-creates in
front of each consumer. It keeps every other Dup. Inlining those too
would still be correct, since the operand then has a consumer per copy and is
moved to a local and reloaded for each, but it would spend a local where the
dup needed none.
InlineDup
dataclass
InlineDup()
Bases: RewriteRule
flowchart TD
bloqade.lanes.rewrite.inline_dup.InlineDup[InlineDup]
click bloqade.lanes.rewrite.inline_dup.InlineDup href "" "bloqade.lanes.rewrite.inline_dup.InlineDup"
Replace every use of a Dup's copies by its operand, and delete it.