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