Returns an iterator over the units in an allocation.
(self, reginfo: &impl RegInfo)
| 106 | impl Allocation { |
| 107 | /// Returns an iterator over the units in an allocation. |
| 108 | pub(crate) fn units(self, reginfo: &impl RegInfo) -> impl Iterator<Item = AllocationUnit> + '_ { |
| 109 | enum EitherIter<A, B> { |
| 110 | A(A), |
| 111 | B(B), |
| 112 | } |
| 113 | impl<A, B> Iterator for EitherIter<A, B> |
| 114 | where |
| 115 | A: Iterator, |
| 116 | B: Iterator<Item = A::Item>, |
| 117 | { |
| 118 | type Item = A::Item; |
| 119 | |
| 120 | fn next(&mut self) -> Option<Self::Item> { |
| 121 | match self { |
| 122 | EitherIter::A(a) => a.next(), |
| 123 | EitherIter::B(b) => b.next(), |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | match self.kind() { |
| 129 | AllocationKind::PhysReg(reg) => { |
| 130 | EitherIter::A(reginfo.reg_units(reg).map(AllocationUnit::reg)) |
| 131 | } |
| 132 | AllocationKind::SpillSlot(slot) => { |
| 133 | EitherIter::B(iter::once(AllocationUnit::spillslot(slot))) |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
no test coverage detected