| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 1 | //===-- LiveIntervalUnion.cpp - Live interval union data structure --------===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // LiveIntervalUnion represents a coalesced set of live intervals. This may be | 
|  | 11 | // used during coalescing to represent a congruence class, or during register | 
|  | 12 | // allocation to model liveness of a physical register. | 
|  | 13 | // | 
|  | 14 | //===----------------------------------------------------------------------===// | 
|  | 15 |  | 
|  | 16 | #define DEBUG_TYPE "regalloc" | 
|  | 17 | #include "LiveIntervalUnion.h" | 
| Andrew Trick | 071d1c0 | 2010-11-09 21:04:34 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SparseBitVector.h" | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" | 
|  | 20 | #include "llvm/Support/raw_ostream.h" | 
| Jakob Stoklund Olesen | 4a84cce | 2010-12-14 18:53:47 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetRegisterInfo.h" | 
|  | 22 |  | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 23 | using namespace llvm; | 
|  | 24 |  | 
| Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 25 |  | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 26 | // Merge a LiveInterval's segments. Guarantee no overlaps. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 27 | void LiveIntervalUnion::unify(LiveInterval &VirtReg) { | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 28 | if (VirtReg.empty()) | 
|  | 29 | return; | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 30 |  | 
|  | 31 | // Insert each of the virtual register's live segments into the map. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 32 | LiveInterval::iterator RegPos = VirtReg.begin(); | 
|  | 33 | LiveInterval::iterator RegEnd = VirtReg.end(); | 
|  | 34 | SegmentIter SegPos = Segments.find(RegPos->start); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 35 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 36 | for (;;) { | 
|  | 37 | SegPos.insert(RegPos->start, RegPos->end, &VirtReg); | 
|  | 38 | if (++RegPos == RegEnd) | 
|  | 39 | return; | 
|  | 40 | SegPos.advanceTo(RegPos->start); | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 41 | } | 
|  | 42 | } | 
|  | 43 |  | 
| Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 44 | // Remove a live virtual register's segments from this union. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 45 | void LiveIntervalUnion::extract(LiveInterval &VirtReg) { | 
|  | 46 | if (VirtReg.empty()) | 
|  | 47 | return; | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 48 |  | 
| Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 49 | // Remove each of the virtual register's live segments from the map. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 50 | LiveInterval::iterator RegPos = VirtReg.begin(); | 
|  | 51 | LiveInterval::iterator RegEnd = VirtReg.end(); | 
|  | 52 | SegmentIter SegPos = Segments.find(RegPos->start); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 53 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 54 | for (;;) { | 
|  | 55 | assert(SegPos.value() == &VirtReg && "Inconsistent LiveInterval"); | 
|  | 56 | SegPos.erase(); | 
|  | 57 | if (!SegPos.valid()) | 
|  | 58 | return; | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 59 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 60 | // Skip all segments that may have been coalesced. | 
|  | 61 | RegPos = VirtReg.advanceTo(RegPos, SegPos.start()); | 
|  | 62 | if (RegPos == RegEnd) | 
|  | 63 | return; | 
|  | 64 |  | 
|  | 65 | SegPos.advanceTo(RegPos->start); | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 66 | } | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 67 | } | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 68 |  | 
| Andrew Trick | 071d1c0 | 2010-11-09 21:04:34 +0000 | [diff] [blame] | 69 | void | 
| Jakob Stoklund Olesen | 4a84cce | 2010-12-14 18:53:47 +0000 | [diff] [blame] | 70 | LiveIntervalUnion::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const { | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 71 | OS << "LIU "; | 
| Jakob Stoklund Olesen | 4a84cce | 2010-12-14 18:53:47 +0000 | [diff] [blame] | 72 | TRI->printReg(RepReg, OS); | 
| Jakob Stoklund Olesen | bfce678 | 2010-12-14 19:38:49 +0000 | [diff] [blame] | 73 | if (empty()) { | 
|  | 74 | OS << " empty\n"; | 
|  | 75 | return; | 
|  | 76 | } | 
| Jakob Stoklund Olesen | 4a84cce | 2010-12-14 18:53:47 +0000 | [diff] [blame] | 77 | for (LiveSegments::const_iterator SI = Segments.begin(); SI.valid(); ++SI) { | 
|  | 78 | OS << " [" << SI.start() << ' ' << SI.stop() << "):"; | 
|  | 79 | TRI->printReg(SI.value()->reg, OS); | 
| Andrew Trick | 071d1c0 | 2010-11-09 21:04:34 +0000 | [diff] [blame] | 80 | } | 
| Jakob Stoklund Olesen | bfce678 | 2010-12-14 19:38:49 +0000 | [diff] [blame] | 81 | OS << '\n'; | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | void LiveIntervalUnion::InterferenceResult::print(raw_ostream &OS, | 
|  | 85 | const TargetRegisterInfo *TRI) const { | 
| Jakob Stoklund Olesen | d0bb5e2 | 2010-12-15 23:46:13 +0000 | [diff] [blame] | 86 | OS << '[' << start() << ';' << stop() << "):"; | 
|  | 87 | TRI->printReg(interference()->reg, OS); | 
| Jakob Stoklund Olesen | bfce678 | 2010-12-14 19:38:49 +0000 | [diff] [blame] | 88 | } | 
|  | 89 |  | 
|  | 90 | void LiveIntervalUnion::Query::print(raw_ostream &OS, | 
|  | 91 | const TargetRegisterInfo *TRI) { | 
|  | 92 | OS << "Interferences with "; | 
|  | 93 | LiveUnion->print(OS, TRI); | 
|  | 94 | InterferenceResult IR = firstInterference(); | 
|  | 95 | while (isInterference(IR)) { | 
|  | 96 | OS << "  "; | 
|  | 97 | IR.print(OS, TRI); | 
|  | 98 | OS << '\n'; | 
|  | 99 | nextInterference(IR); | 
|  | 100 | } | 
| Andrew Trick | 071d1c0 | 2010-11-09 21:04:34 +0000 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
| Andrew Trick | 071d1c0 | 2010-11-09 21:04:34 +0000 | [diff] [blame] | 103 | #ifndef NDEBUG | 
|  | 104 | // Verify the live intervals in this union and add them to the visited set. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 105 | void LiveIntervalUnion::verify(LiveVirtRegBitSet& VisitedVRegs) { | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 106 | for (SegmentIter SI = Segments.begin(); SI.valid(); ++SI) | 
|  | 107 | VisitedVRegs.set(SI.value()->reg); | 
| Andrew Trick | 071d1c0 | 2010-11-09 21:04:34 +0000 | [diff] [blame] | 108 | } | 
|  | 109 | #endif //!NDEBUG | 
|  | 110 |  | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 111 | // Private interface accessed by Query. | 
|  | 112 | // | 
|  | 113 | // Find a pair of segments that intersect, one in the live virtual register | 
|  | 114 | // (LiveInterval), and the other in this LiveIntervalUnion. The caller (Query) | 
|  | 115 | // is responsible for advancing the LiveIntervalUnion segments to find a | 
|  | 116 | // "notable" intersection, which requires query-specific logic. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 117 | // | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 118 | // This design assumes only a fast mechanism for intersecting a single live | 
|  | 119 | // virtual register segment with a set of LiveIntervalUnion segments.  This may | 
| Andrew Trick | 34fff59 | 2010-11-30 23:59:50 +0000 | [diff] [blame] | 120 | // be ok since most virtual registers have very few segments.  If we had a data | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 121 | // structure that optimizd MxN intersection of segments, then we would bypass | 
|  | 122 | // the loop that advances within the LiveInterval. | 
|  | 123 | // | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 124 | // If no intersection exists, set VirtRegI = VirtRegEnd, and set SI to the first | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 125 | // segment whose start point is greater than LiveInterval's end point. | 
|  | 126 | // | 
|  | 127 | // Assumes that segments are sorted by start position in both | 
|  | 128 | // LiveInterval and LiveSegments. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 129 | void LiveIntervalUnion::Query::findIntersection(InterferenceResult &IR) const { | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 130 | // Search until reaching the end of the LiveUnion segments. | 
|  | 131 | LiveInterval::iterator VirtRegEnd = VirtReg->end(); | 
| Jakob Stoklund Olesen | 9b0c4f8 | 2010-12-08 23:51:35 +0000 | [diff] [blame] | 132 | if (IR.VirtRegI == VirtRegEnd) | 
|  | 133 | return; | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 134 | while (IR.LiveUnionI.valid()) { | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 135 | // Slowly advance the live virtual reg iterator until we surpass the next | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 136 | // segment in LiveUnion. | 
|  | 137 | // | 
|  | 138 | // Note: If this is ever used for coalescing of fixed registers and we have | 
|  | 139 | // a live vreg with thousands of segments, then change this code to use | 
|  | 140 | // upperBound instead. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 141 | IR.VirtRegI = VirtReg->advanceTo(IR.VirtRegI, IR.LiveUnionI.start()); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 142 | if (IR.VirtRegI == VirtRegEnd) | 
|  | 143 | break; // Retain current (nonoverlapping) LiveUnionI | 
|  | 144 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 145 | // VirtRegI may have advanced far beyond LiveUnionI, catch up. | 
|  | 146 | IR.LiveUnionI.advanceTo(IR.VirtRegI->start); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 147 |  | 
|  | 148 | // Check if no LiveUnionI exists with VirtRegI->Start < LiveUnionI.end | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 149 | if (!IR.LiveUnionI.valid()) | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 150 | break; | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 151 | if (IR.LiveUnionI.start() < IR.VirtRegI->end) { | 
|  | 152 | assert(overlap(*IR.VirtRegI, IR.LiveUnionI) && | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 153 | "upperBound postcondition"); | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 154 | break; | 
|  | 155 | } | 
|  | 156 | } | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 157 | if (!IR.LiveUnionI.valid()) | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 158 | IR.VirtRegI = VirtRegEnd; | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
|  | 161 | // Find the first intersection, and cache interference info | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 162 | // (retain segment iterators into both VirtReg and LiveUnion). | 
| Jakob Stoklund Olesen | a35cce1 | 2010-12-09 01:06:52 +0000 | [diff] [blame] | 163 | const LiveIntervalUnion::InterferenceResult & | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 164 | LiveIntervalUnion::Query::firstInterference() { | 
| Jakob Stoklund Olesen | a35cce1 | 2010-12-09 01:06:52 +0000 | [diff] [blame] | 165 | if (CheckedFirstInterference) | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 166 | return FirstInterference; | 
| Jakob Stoklund Olesen | a35cce1 | 2010-12-09 01:06:52 +0000 | [diff] [blame] | 167 | CheckedFirstInterference = true; | 
|  | 168 | InterferenceResult &IR = FirstInterference; | 
|  | 169 |  | 
|  | 170 | // Quickly skip interference check for empty sets. | 
|  | 171 | if (VirtReg->empty() || LiveUnion->empty()) { | 
|  | 172 | IR.VirtRegI = VirtReg->end(); | 
|  | 173 | } else if (VirtReg->beginIndex() < LiveUnion->startIndex()) { | 
|  | 174 | // VirtReg starts first, perform double binary search. | 
|  | 175 | IR.VirtRegI = VirtReg->find(LiveUnion->startIndex()); | 
|  | 176 | if (IR.VirtRegI != VirtReg->end()) | 
|  | 177 | IR.LiveUnionI = LiveUnion->find(IR.VirtRegI->start); | 
|  | 178 | } else { | 
|  | 179 | // LiveUnion starts first, perform double binary search. | 
|  | 180 | IR.LiveUnionI = LiveUnion->find(VirtReg->beginIndex()); | 
|  | 181 | if (IR.LiveUnionI.valid()) | 
|  | 182 | IR.VirtRegI = VirtReg->find(IR.LiveUnionI.start()); | 
|  | 183 | else | 
|  | 184 | IR.VirtRegI = VirtReg->end(); | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 185 | } | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 186 | findIntersection(FirstInterference); | 
| Jakob Stoklund Olesen | a0382c6 | 2010-12-09 21:20:44 +0000 | [diff] [blame] | 187 | assert((IR.VirtRegI == VirtReg->end() || IR.LiveUnionI.valid()) | 
|  | 188 | && "Uninitialized iterator"); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 189 | return FirstInterference; | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
|  | 192 | // Treat the result as an iterator and advance to the next interfering pair | 
|  | 193 | // of segments. This is a plain iterator with no filter. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 194 | bool LiveIntervalUnion::Query::nextInterference(InterferenceResult &IR) const { | 
|  | 195 | assert(isInterference(IR) && "iteration past end of interferences"); | 
|  | 196 |  | 
|  | 197 | // Advance either the VirtReg or LiveUnion segment to ensure that we visit all | 
|  | 198 | // unique overlapping pairs. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 199 | if (IR.VirtRegI->end < IR.LiveUnionI.stop()) { | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 200 | if (++IR.VirtRegI == VirtReg->end()) | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 201 | return false; | 
|  | 202 | } | 
|  | 203 | else { | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 204 | if (!(++IR.LiveUnionI).valid()) { | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 205 | IR.VirtRegI = VirtReg->end(); | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 206 | return false; | 
|  | 207 | } | 
|  | 208 | } | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 209 | // Short-circuit findIntersection() if possible. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 210 | if (overlap(*IR.VirtRegI, IR.LiveUnionI)) | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 211 | return true; | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 212 |  | 
|  | 213 | // Find the next intersection. | 
|  | 214 | findIntersection(IR); | 
|  | 215 | return isInterference(IR); | 
| Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 216 | } | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 217 |  | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 218 | // Scan the vector of interfering virtual registers in this union. Assume it's | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 219 | // quite small. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 220 | bool LiveIntervalUnion::Query::isSeenInterference(LiveInterval *VirtReg) const { | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 221 | SmallVectorImpl<LiveInterval*>::const_iterator I = | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 222 | std::find(InterferingVRegs.begin(), InterferingVRegs.end(), VirtReg); | 
|  | 223 | return I != InterferingVRegs.end(); | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 224 | } | 
|  | 225 |  | 
|  | 226 | // Count the number of virtual registers in this union that interfere with this | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 227 | // query's live virtual register. | 
|  | 228 | // | 
|  | 229 | // The number of times that we either advance IR.VirtRegI or call | 
|  | 230 | // LiveUnion.upperBound() will be no more than the number of holes in | 
|  | 231 | // VirtReg. So each invocation of collectInterferingVRegs() takes | 
|  | 232 | // time proportional to |VirtReg Holes| * time(LiveUnion.upperBound()). | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 233 | // | 
|  | 234 | // For comments on how to speed it up, see Query::findIntersection(). | 
|  | 235 | unsigned LiveIntervalUnion::Query:: | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 236 | collectInterferingVRegs(unsigned MaxInterferingRegs) { | 
|  | 237 | InterferenceResult IR = firstInterference(); | 
|  | 238 | LiveInterval::iterator VirtRegEnd = VirtReg->end(); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 239 | LiveInterval *RecentInterferingVReg = NULL; | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 240 | while (IR.LiveUnionI.valid()) { | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 241 | // Advance the union's iterator to reach an unseen interfering vreg. | 
|  | 242 | do { | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 243 | if (IR.LiveUnionI.value() == RecentInterferingVReg) | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 244 | continue; | 
|  | 245 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 246 | if (!isSeenInterference(IR.LiveUnionI.value())) | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 247 | break; | 
|  | 248 |  | 
|  | 249 | // Cache the most recent interfering vreg to bypass isSeenInterference. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 250 | RecentInterferingVReg = IR.LiveUnionI.value(); | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 251 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 252 | } while ((++IR.LiveUnionI).valid()); | 
|  | 253 | if (!IR.LiveUnionI.valid()) | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 254 | break; | 
|  | 255 |  | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 256 | // Advance the VirtReg iterator until surpassing the next segment in | 
|  | 257 | // LiveUnion. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 258 | IR.VirtRegI = VirtReg->advanceTo(IR.VirtRegI, IR.LiveUnionI.start()); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 259 | if (IR.VirtRegI == VirtRegEnd) | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 260 | break; | 
|  | 261 |  | 
|  | 262 | // Check for intersection with the union's segment. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 263 | if (overlap(*IR.VirtRegI, IR.LiveUnionI)) { | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 264 |  | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 265 | if (!IR.LiveUnionI.value()->isSpillable()) | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 266 | SeenUnspillableVReg = true; | 
|  | 267 |  | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 268 | if (InterferingVRegs.size() == MaxInterferingRegs) | 
| Andrew Trick | b853e6c | 2010-12-09 18:15:21 +0000 | [diff] [blame] | 269 | // Leave SeenAllInterferences set to false to indicate that at least one | 
|  | 270 | // interference exists beyond those we collected. | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 271 | return MaxInterferingRegs; | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 272 |  | 
| Andrew Trick | b853e6c | 2010-12-09 18:15:21 +0000 | [diff] [blame] | 273 | InterferingVRegs.push_back(IR.LiveUnionI.value()); | 
|  | 274 |  | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 275 | // Cache the most recent interfering vreg to bypass isSeenInterference. | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 276 | RecentInterferingVReg = IR.LiveUnionI.value(); | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 277 | ++IR.LiveUnionI; | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 278 | continue; | 
|  | 279 | } | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 280 | // VirtRegI may have advanced far beyond LiveUnionI, | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 281 | // do a fast intersection test to "catch up" | 
| Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 282 | IR.LiveUnionI.advanceTo(IR.VirtRegI->start); | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 283 | } | 
| Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 284 | SeenAllInterferences = true; | 
|  | 285 | return InterferingVRegs.size(); | 
| Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 286 | } |