Static use+def occurrence count per register; the allocation priority.
(func: &IrFunction)
| 110 | // Static use+def occurrence count per register; the allocation priority. |
| 111 | fn count_uses(func: &IrFunction) -> HashMap<IrRegister, usize> { |
| 112 | let mut counts: HashMap<IrRegister, usize> = HashMap::new(); |
| 113 | for block in &func.blocks { |
| 114 | for inst in &block.instructions { |
| 115 | for r in slot_coloring::inst_uses(inst) { |
| 116 | *counts.entry(r).or_insert(0) += 1; |
| 117 | } |
| 118 | for r in slot_coloring::inst_defs(inst) { |
| 119 | *counts.entry(r).or_insert(0) += 1; |
| 120 | } |
| 121 | } |
| 122 | if let Some(term) = &block.terminator { |
| 123 | for r in slot_coloring::term_uses(term) { |
| 124 | *counts.entry(r).or_insert(0) += 1; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | counts |
| 129 | } |
| 130 | |
| 131 | #[cfg(test)] |
| 132 | mod tests { |
| 133 | use super::*; |
no test coverage detected