Class: Kumi::Core::Analyzer::Passes::LIR::LocalCSEPass
- Defined in:
- lib/kumi/core/analyzer/passes/lir/local_cse_pass.rb
Overview
LIRLocalCSEPass
Tiny, safe, per-declaration CSE:
-
Deduplicates pure ops only (see PURE)
-
Renames later uses to the first result (within a declaration)
-
Ignores control/side-effect ops (loops, accums, yield)
In : state Out: state.with(:lir_03_cse, …)
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
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kumi/core/analyzer/passes/lir/local_cse_pass.rb', line 20 def run(_errors) ops_by_decl = get_state(:lir_module, required: true) out = {} ops_by_decl.each do |name, payload| out[name] = { operations: optimize_decl(Array(payload[:operations])) } end out.freeze state.with(:lir_module, out).with(:lir_03_cse, out) end |