Initializes the allocation queue from the set of existing virtual register and virtual register groups.
(&mut self, virt_regs: &VirtRegs)
| 130 | /// Initializes the allocation queue from the set of existing virtual |
| 131 | /// register and virtual register groups. |
| 132 | pub fn init(&mut self, virt_regs: &VirtRegs) { |
| 133 | let mut vec = mem::take(&mut self.queue).into_vec(); |
| 134 | vec.clear(); |
| 135 | |
| 136 | // Add virtual registers that are not part of a group. |
| 137 | vec.extend( |
| 138 | virt_regs |
| 139 | .virt_regs() |
| 140 | .filter(|&vreg| virt_regs[vreg].group.is_none()) |
| 141 | .map(|vreg| Entry::encode(vreg, Stage::Evict, virt_regs)), |
| 142 | ); |
| 143 | |
| 144 | // Add virtual register groups. |
| 145 | vec.extend( |
| 146 | virt_regs |
| 147 | .groups() |
| 148 | .map(|group| Entry::encode_group(group, Stage::Evict, virt_regs)), |
| 149 | ); |
| 150 | |
| 151 | // O(n) heap construction, which is much faster than inserting entries |
| 152 | // one by one. |
| 153 | self.queue = vec.into(); |
| 154 | } |
| 155 | |
| 156 | /// Dequeues the entry with the highest priority from the queue. |
| 157 | pub fn dequeue(&mut self) -> Option<(VirtRegOrGroup, Stage)> { |