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