Class: Kumi::Core::Analyzer::Passes::LIR::InstructionSchedulingPass::Scheduler
- Inherits:
-
Object
- Object
- Kumi::Core::Analyzer::Passes::LIR::InstructionSchedulingPass::Scheduler
- Defined in:
- lib/kumi/core/analyzer/passes/lir/instruction_scheduling_pass.rb
Overview
— Main Scheduler Logic —
Defined Under Namespace
Classes: Item
Instance Method Summary collapse
-
#initialize(pass, ops, depth) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #schedule ⇒ Object
Constructor Details
#initialize(pass, ops, depth) ⇒ Scheduler
Returns a new instance of Scheduler.
68 69 70 71 72 73 |
# File 'lib/kumi/core/analyzer/passes/lir/instruction_scheduling_pass.rb', line 68 def initialize(pass, ops, depth) @pass = pass @ops = ops @depth = depth @prefix = " " * @depth end |
Instance Method Details
#schedule ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kumi/core/analyzer/passes/lir/instruction_scheduling_pass.rb', line 75 def schedule debug "#{@prefix}> Starting instruction scheduling for block of #{@ops.size} instructions." items = group_into_atomic_items(@ops) return @ops if items.size <= 1 graph, in_degree = build_dependency_graph(items) debug_graph(items, graph) sorted_item_ids = topological_sort(graph, in_degree, items.map(&:id)) debug "#{@prefix} - Final schedule order: #{sorted_item_ids.join(' -> ')}" items_by_id = items.to_h { |item| [item.id, item] } sorted_item_ids.flat_map { |id| items_by_id[id].ops } end |