Class: Kumi::IR::Loop::Passes::LoopFusion
- Inherits:
-
Passes::Base
- Object
- Passes::Base
- Kumi::IR::Loop::Passes::LoopFusion
- Defined in:
- lib/kumi/ir/loop/passes/loop_fusion.rb
Overview
Merges sibling loops over the same axis and source into one pass.
The lowerer emits one loop per statement group, so loop-invariant scalar work between two vector statements splits what could be a single traversal. Fusion hoists the independent scalar barrier above the first loop and appends the second loop’s body, renaming its element/index registers.
A pair fuses only when it is provably safe:
-
both loops iterate the same source register on the same axis
-
every instruction between them depends on nothing the first loop defines, no array it pushes to, and no accumulator it steps
-
the second loop touches arrays the first loop pushes to only via index_read at its own loop index (the value produced in the same fused iteration); shifts, lengths, or re-iteration of a partially built array block fusion (stencils legitimately need two passes)
Instance Method Summary collapse
-
#run(graph:, context: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Instance Method Details
#run(graph:, context: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
24 25 26 27 |
# File 'lib/kumi/ir/loop/passes/loop_fusion.rb', line 24 def run(graph:, context: {}) # rubocop:disable Lint/UnusedMethodArgument functions = graph.functions.values.map { |fn| process_function(fn) } Loop::Module.new(name: graph.name, functions: functions) end |