Class: Kumi::Core::Analyzer::Passes::LIR::LoopFusionPass
- Defined in:
- lib/kumi/core/analyzer/passes/lir/loop_fusion_pass.rb
Overview
LoopFusionPass (Simplified Version)
This pass runs AFTER InlineDeclarationsPass AND LocalCSEPass. The CSE pass is crucial as it normalizes the LIR, ensuring that any redundant collection loads are eliminated. This simplifies loop fusion from a data-flow analysis problem to a simple check for adjacent loops iterating over the *exact same register*.
A loop pair is considered “fusable” if:
1. They are "semantically adjacent," meaning they are separated only by
instructions that can be correctly reordered around the fused loop
(e.g., DeclareAccumulator, LoadAccumulator).
2. They iterate over the identical collection register.
Constant Summary collapse
- LIR =
Kumi::Core::LIR
Instance Method Summary collapse
Methods inherited from PassBase
#debug, #debug_enabled?, #initialize
Methods included from ErrorReporting
#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error
Constructor Details
This class inherits a constructor from Kumi::Core::Analyzer::Passes::PassBase
Instance Method Details
#run(_errors) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kumi/core/analyzer/passes/lir/loop_fusion_pass.rb', line 25 def run(_errors) fused_module = get_state(:lir_module).transform_values do |decl| # The decl[:name] might not exist in older states, so provide a fallback. decl_name = decl.is_a?(Hash) ? decl.fetch(:name, "anonymous") : "anonymous" debug "\n--- Fusing loops in: #{decl_name} ---" { operations: fuse_loops_in_block(Array(decl[:operations])) } end state.with(:lir_module, fused_module).with(:lir_04_1_loop_fusion, fused_module) end |