Class: Kumi::IR::Loop::Passes::ArrayContraction
- Inherits:
-
Passes::Base
- Object
- Passes::Base
- Kumi::IR::Loop::Passes::ArrayContraction
- Defined in:
- lib/kumi/ir/loop/passes/array_contraction.rb
Overview
Replaces single-pass intermediate arrays with the scalar that fills them. After fusion, a vector materialized in one loop and read back at the same index in the same loop is just a named wire:
array_init %a => (removed)
loop_start ... loop_start ...
%v = ... %v = ...
array_push(%a, %v) (removed)
%r = index_read(%a, %i) (uses of %r become uses of %v)
An array contracts only when it has exactly one push, directly in a loop body, and every other use is an index_read at that loop’s index inside the same loop. Anything else — shifts, lengths, escaping into other arrays, the function return — keeps the materialization.
Defined Under Namespace
Classes: Occurrence
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/array_contraction.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 |