MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / count_uses

Function count_uses

crates/ir-to-asm/src/compiler/register_allocator.rs:112–130  ·  view source on GitHub ↗

Static use+def occurrence count per register; the allocation priority.

(func: &IrFunction)

Source from the content-addressed store, hash-verified

110// Static use+def occurrence count per register; the allocation priority.
111fn 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)]
132mod tests {
133 use super::*;

Callers 1

allocate_registersFunction · 0.85

Calls 3

inst_usesFunction · 0.85
inst_defsFunction · 0.85
term_usesFunction · 0.85

Tested by

no test coverage detected