Class: Kumi::Core::Analyzer::Passes::LIR::ConstantPropagationPass
- Inherits:
-
PassBase
- Object
- PassBase
- Kumi::Core::Analyzer::Passes::LIR::ConstantPropagationPass
- Defined in:
- lib/kumi/core/analyzer/passes/lir/constant_propagation_pass.rb
Overview
ConstantPropagationPass
This is an intra-block constant propagation pass. It substitutes the uses of registers that hold a known constant value with the literal constant itself.
This pass must run before DeadCodeEliminationPass to be effective. It doesn’t remove the original constant assignments; rather, it makes them “dead” by removing their uses, allowing a subsequent DCE pass to clean them up.
In : state Out: state.with(:lir_02_const_prop, …)
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
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kumi/core/analyzer/passes/lir/constant_propagation_pass.rb', line 24 def run(_errors) ops_by_decl = get_state(:lir_module) out = {} ops_by_decl.each do |name, payload| operations = Array(payload[:operations]) out[name] = { operations: optimize_decl(operations) } end out.freeze state.with(:lir_module, out).with(:lir_06_const_prop, out) end |