OLD | NEW |
---|---|
1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan implementation -----------===// | 1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan implementation -----------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the LinearScan class, which performs the | 10 // This file implements the LinearScan class, which performs the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 // Constraints" by Hanspeter Mössenböck and Michael Pfeiffer, | 57 // Constraints" by Hanspeter Mössenböck and Michael Pfeiffer, |
58 // ftp://ftp.ssw.uni-linz.ac.at/pub/Papers/Moe02.PDF . This | 58 // ftp://ftp.ssw.uni-linz.ac.at/pub/Papers/Moe02.PDF . This |
59 // implementation is modified to take affinity into account and allow | 59 // implementation is modified to take affinity into account and allow |
60 // two interfering variables to share the same register in certain | 60 // two interfering variables to share the same register in certain |
61 // cases. | 61 // cases. |
62 // | 62 // |
63 // Requires running Cfg::liveness(Liveness_Intervals) in | 63 // Requires running Cfg::liveness(Liveness_Intervals) in |
64 // preparation. Results are assigned to Variable::RegNum for each | 64 // preparation. Results are assigned to Variable::RegNum for each |
65 // Variable. | 65 // Variable. |
66 void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { | 66 void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { |
67 TimerMarker T("scan", Func->getContext()); | |
67 assert(RegMaskFull.any()); // Sanity check | 68 assert(RegMaskFull.any()); // Sanity check |
68 Unhandled.clear(); | 69 Unhandled.clear(); |
69 Handled.clear(); | 70 Handled.clear(); |
70 Inactive.clear(); | 71 Inactive.clear(); |
71 Active.clear(); | 72 Active.clear(); |
72 Ostream &Str = Func->getContext()->getStrDump(); | 73 Ostream &Str = Func->getContext()->getStrDump(); |
74 bool Verbose = Func->getContext()->isVerbose(IceV_LinearScan); | |
73 Func->resetCurrentNode(); | 75 Func->resetCurrentNode(); |
74 VariablesMetadata *VMetadata = Func->getVMetadata(); | 76 VariablesMetadata *VMetadata = Func->getVMetadata(); |
75 | 77 |
76 // Gather the live ranges of all variables and add them to the | 78 // Gather the live ranges of all variables and add them to the |
77 // Unhandled set. TODO: Unhandled is a set<> which is based on a | 79 // Unhandled set. TODO: Unhandled is a set<> which is based on a |
78 // balanced binary tree, so inserting live ranges for N variables is | 80 // balanced binary tree, so inserting live ranges for N variables is |
79 // O(N log N) complexity. N may be proportional to the number of | 81 // O(N log N) complexity. N may be proportional to the number of |
80 // instructions, thanks to temporary generation during lowering. As | 82 // instructions, thanks to temporary generation during lowering. As |
81 // a result, it may be useful to design a better data structure for | 83 // a result, it may be useful to design a better data structure for |
82 // storing Func->getVariables(). | 84 // storing Func->getVariables(). |
83 const VarList &Vars = Func->getVariables(); | 85 const VarList &Vars = Func->getVariables(); |
84 for (VarList::const_iterator I = Vars.begin(), E = Vars.end(); I != E; ++I) { | 86 { |
85 Variable *Var = *I; | 87 TimerMarker T("initUnhandled", Func->getContext()); |
86 // Explicitly don't consider zero-weight variables, which are | 88 for (VarList::const_iterator I = Vars.begin(), E = Vars.end(); I != E; |
87 // meant to be spill slots. | 89 ++I) { |
88 if (Var->getWeight() == RegWeight::Zero) | 90 Variable *Var = *I; |
89 continue; | 91 // Explicitly don't consider zero-weight variables, which are |
90 // Don't bother if the variable has a null live range, which means | 92 // meant to be spill slots. |
91 // it was never referenced. | 93 if (Var->getWeight() == RegWeight::Zero) |
92 if (Var->getLiveRange().isEmpty()) | 94 continue; |
93 continue; | 95 // Don't bother if the variable has a null live range, which means |
94 Unhandled.insert(LiveRangeWrapper(Var)); | 96 // it was never referenced. |
95 if (Var->hasReg()) { | 97 if (Var->getLiveRange().isEmpty()) |
96 Var->setRegNumTmp(Var->getRegNum()); | 98 continue; |
97 Var->setLiveRangeInfiniteWeight(); | 99 Unhandled.insert(LiveRangeWrapper(Var)); |
100 if (Var->hasReg()) { | |
101 Var->setRegNumTmp(Var->getRegNum()); | |
102 Var->setLiveRangeInfiniteWeight(); | |
103 } | |
98 } | 104 } |
99 } | 105 } |
100 | 106 |
101 // RegUses[I] is the number of live ranges (variables) that register | 107 // RegUses[I] is the number of live ranges (variables) that register |
102 // I is currently assigned to. It can be greater than 1 as a result | 108 // I is currently assigned to. It can be greater than 1 as a result |
103 // of Variable::AllowRegisterOverlap. | 109 // of Variable::AllowRegisterOverlap. |
104 std::vector<int> RegUses(RegMaskFull.size()); | 110 std::vector<int> RegUses(RegMaskFull.size()); |
105 // Unhandled is already set to all ranges in increasing order of | 111 // Unhandled is already set to all ranges in increasing order of |
106 // start points. | 112 // start points. |
107 assert(Active.empty()); | 113 assert(Active.empty()); |
108 assert(Inactive.empty()); | 114 assert(Inactive.empty()); |
109 assert(Handled.empty()); | 115 assert(Handled.empty()); |
110 UnorderedRanges::iterator Next; | 116 UnorderedRanges::iterator Next; |
111 | 117 |
112 while (!Unhandled.empty()) { | 118 while (!Unhandled.empty()) { |
113 LiveRangeWrapper Cur = *Unhandled.begin(); | 119 LiveRangeWrapper Cur = *Unhandled.begin(); |
114 Unhandled.erase(Unhandled.begin()); | 120 Unhandled.erase(Unhandled.begin()); |
115 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 121 if (Verbose) { |
116 Str << "\nConsidering "; | 122 Str << "\nConsidering "; |
117 Cur.dump(Func); | 123 Cur.dump(Func); |
118 Str << "\n"; | 124 Str << "\n"; |
119 } | 125 } |
120 const llvm::SmallBitVector RegMask = | 126 const llvm::SmallBitVector RegMask = |
121 RegMaskFull & | 127 RegMaskFull & |
122 Func->getTarget()->getRegisterSetForType(Cur.Var->getType()); | 128 Func->getTarget()->getRegisterSetForType(Cur.Var->getType()); |
123 | 129 |
124 // Check for precolored ranges. If Cur is precolored, it | 130 // Check for precolored ranges. If Cur is precolored, it |
125 // definitely gets that register. Previously processed live | 131 // definitely gets that register. Previously processed live |
126 // ranges would have avoided that register due to it being | 132 // ranges would have avoided that register due to it being |
127 // precolored. Future processed live ranges won't evict that | 133 // precolored. Future processed live ranges won't evict that |
128 // register because the live range has infinite weight. | 134 // register because the live range has infinite weight. |
129 if (Cur.Var->hasReg()) { | 135 if (Cur.Var->hasReg()) { |
130 int32_t RegNum = Cur.Var->getRegNum(); | 136 int32_t RegNum = Cur.Var->getRegNum(); |
131 // RegNumTmp should have already been set above. | 137 // RegNumTmp should have already been set above. |
132 assert(Cur.Var->getRegNumTmp() == RegNum); | 138 assert(Cur.Var->getRegNumTmp() == RegNum); |
133 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 139 if (Verbose) { |
134 Str << "Precoloring "; | 140 Str << "Precoloring "; |
135 Cur.dump(Func); | 141 Cur.dump(Func); |
136 Str << "\n"; | 142 Str << "\n"; |
137 } | 143 } |
138 Active.push_back(Cur); | 144 Active.push_back(Cur); |
139 assert(RegUses[RegNum] >= 0); | 145 assert(RegUses[RegNum] >= 0); |
140 ++RegUses[RegNum]; | 146 ++RegUses[RegNum]; |
141 continue; | 147 continue; |
142 } | 148 } |
143 | 149 |
144 // Check for active ranges that have expired or become inactive. | 150 // Check for active ranges that have expired or become inactive. |
145 for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); I != E; | 151 for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); I != E; |
146 I = Next) { | 152 I = Next) { |
147 Next = I; | 153 Next = I; |
148 ++Next; | 154 ++Next; |
149 LiveRangeWrapper Item = *I; | 155 LiveRangeWrapper Item = *I; |
150 bool Moved = false; | 156 bool Moved = false; |
151 if (Item.endsBefore(Cur)) { | 157 if (Item.endsBefore(Cur)) { |
152 // Move Item from Active to Handled list. | 158 // Move Item from Active to Handled list. |
153 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 159 if (Verbose) { |
154 Str << "Expiring "; | 160 Str << "Expiring "; |
155 Item.dump(Func); | 161 Item.dump(Func); |
156 Str << "\n"; | 162 Str << "\n"; |
157 } | 163 } |
158 Active.erase(I); | 164 Active.erase(I); |
159 Handled.push_back(Item); | 165 Handled.push_back(Item); |
160 Moved = true; | 166 Moved = true; |
161 } else if (!Item.overlapsStart(Cur)) { | 167 } else if (!Item.overlapsStart(Cur)) { |
162 // Move Item from Active to Inactive list. | 168 // Move Item from Active to Inactive list. |
163 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 169 if (Verbose) { |
164 Str << "Inactivating "; | 170 Str << "Inactivating "; |
165 Item.dump(Func); | 171 Item.dump(Func); |
166 Str << "\n"; | 172 Str << "\n"; |
167 } | 173 } |
168 Active.erase(I); | 174 Active.erase(I); |
169 Inactive.push_back(Item); | 175 Inactive.push_back(Item); |
170 Moved = true; | 176 Moved = true; |
171 } | 177 } |
172 if (Moved) { | 178 if (Moved) { |
173 // Decrement Item from RegUses[]. | 179 // Decrement Item from RegUses[]. |
174 assert(Item.Var->hasRegTmp()); | 180 assert(Item.Var->hasRegTmp()); |
175 int32_t RegNum = Item.Var->getRegNumTmp(); | 181 int32_t RegNum = Item.Var->getRegNumTmp(); |
176 --RegUses[RegNum]; | 182 --RegUses[RegNum]; |
177 assert(RegUses[RegNum] >= 0); | 183 assert(RegUses[RegNum] >= 0); |
178 } | 184 } |
179 } | 185 } |
180 | 186 |
181 // Check for inactive ranges that have expired or reactivated. | 187 // Check for inactive ranges that have expired or reactivated. |
182 for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end(); | 188 for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end(); |
183 I != E; I = Next) { | 189 I != E; I = Next) { |
184 Next = I; | 190 Next = I; |
185 ++Next; | 191 ++Next; |
186 LiveRangeWrapper Item = *I; | 192 LiveRangeWrapper Item = *I; |
187 if (Item.endsBefore(Cur)) { | 193 if (Item.endsBefore(Cur)) { |
188 // Move Item from Inactive to Handled list. | 194 // Move Item from Inactive to Handled list. |
189 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 195 if (Verbose) { |
190 Str << "Expiring "; | 196 Str << "Expiring "; |
191 Item.dump(Func); | 197 Item.dump(Func); |
192 Str << "\n"; | 198 Str << "\n"; |
193 } | 199 } |
194 Inactive.erase(I); | 200 Inactive.erase(I); |
195 Handled.push_back(Item); | 201 Handled.push_back(Item); |
196 } else if (Item.overlapsStart(Cur)) { | 202 } else if (Item.overlapsStart(Cur)) { |
197 // Move Item from Inactive to Active list. | 203 // Move Item from Inactive to Active list. |
198 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 204 if (Verbose) { |
199 Str << "Reactivating "; | 205 Str << "Reactivating "; |
200 Item.dump(Func); | 206 Item.dump(Func); |
201 Str << "\n"; | 207 Str << "\n"; |
202 } | 208 } |
203 Inactive.erase(I); | 209 Inactive.erase(I); |
204 Active.push_back(Item); | 210 Active.push_back(Item); |
205 // Increment Item in RegUses[]. | 211 // Increment Item in RegUses[]. |
206 assert(Item.Var->hasRegTmp()); | 212 assert(Item.Var->hasRegTmp()); |
207 int32_t RegNum = Item.Var->getRegNumTmp(); | 213 int32_t RegNum = Item.Var->getRegNumTmp(); |
208 assert(RegUses[RegNum] >= 0); | 214 assert(RegUses[RegNum] >= 0); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 IsSingleDef && IsAssign && !overlapsDefs(Func, Cur, SrcVar); | 260 IsSingleDef && IsAssign && !overlapsDefs(Func, Cur, SrcVar); |
255 } | 261 } |
256 if (AllowOverlap || Free[SrcReg]) { | 262 if (AllowOverlap || Free[SrcReg]) { |
257 Prefer = SrcVar; | 263 Prefer = SrcVar; |
258 PreferReg = SrcReg; | 264 PreferReg = SrcReg; |
259 } | 265 } |
260 } | 266 } |
261 } | 267 } |
262 } | 268 } |
263 } | 269 } |
264 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 270 if (Verbose) { |
265 if (Prefer) { | 271 if (Prefer) { |
266 Str << "Initial Prefer=" << *Prefer << " R=" << PreferReg | 272 Str << "Initial Prefer=" << *Prefer << " R=" << PreferReg |
267 << " LIVE=" << Prefer->getLiveRange() << " Overlap=" << AllowOverlap | 273 << " LIVE=" << Prefer->getLiveRange() << " Overlap=" << AllowOverlap |
268 << "\n"; | 274 << "\n"; |
269 } | 275 } |
270 } | 276 } |
271 | 277 |
272 // Remove registers from the Free[] list where an Inactive range | 278 // Remove registers from the Free[] list where an Inactive range |
273 // overlaps with the current range. | 279 // overlaps with the current range. |
274 for (UnorderedRanges::const_iterator I = Inactive.begin(), | 280 for (UnorderedRanges::const_iterator I = Inactive.begin(), |
275 E = Inactive.end(); | 281 E = Inactive.end(); |
276 I != E; ++I) { | 282 I != E; ++I) { |
277 LiveRangeWrapper Item = *I; | 283 LiveRangeWrapper Item = *I; |
278 if (Item.overlaps(Cur)) { | 284 int32_t RegNum = Item.Var->getRegNumTmp(); |
279 int32_t RegNum = Item.Var->getRegNumTmp(); | 285 if (Free[RegNum] && Item.overlaps(Cur)) { |
Jim Stichnoth
2014/09/28 14:26:39
Performance optimization to check Free[] before th
| |
280 // Don't assert(Free[RegNum]) because in theory (though | 286 // Don't assert(Free[RegNum]) because in theory (though |
281 // probably never in practice) there could be two inactive | 287 // probably never in practice) there could be two inactive |
282 // variables that were allowed marked with | 288 // variables that were allowed marked with |
283 // AllowRegisterOverlap. | 289 // AllowRegisterOverlap. |
284 Free[RegNum] = false; | 290 Free[RegNum] = false; |
285 // Disable AllowOverlap if an Inactive variable, which is not | 291 // Disable AllowOverlap if an Inactive variable, which is not |
286 // Prefer, shares Prefer's register, and has a definition | 292 // Prefer, shares Prefer's register, and has a definition |
287 // within Cur's live range. | 293 // within Cur's live range. |
288 if (AllowOverlap && Item.Var != Prefer && RegNum == PreferReg && | 294 if (AllowOverlap && Item.Var != Prefer && RegNum == PreferReg && |
289 overlapsDefs(Func, Cur, Item.Var)) { | 295 overlapsDefs(Func, Cur, Item.Var)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // Disable AllowOverlap if the preferred register is one of | 330 // Disable AllowOverlap if the preferred register is one of |
325 // these precolored unhandled overlapping ranges. | 331 // these precolored unhandled overlapping ranges. |
326 if (AllowOverlap && ItemReg == PreferReg) { | 332 if (AllowOverlap && ItemReg == PreferReg) { |
327 AllowOverlap = false; | 333 AllowOverlap = false; |
328 dumpDisableOverlap(Func, Item.Var, "PrecoloredUnhandled"); | 334 dumpDisableOverlap(Func, Item.Var, "PrecoloredUnhandled"); |
329 } | 335 } |
330 } | 336 } |
331 } | 337 } |
332 | 338 |
333 // Print info about physical register availability. | 339 // Print info about physical register availability. |
334 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 340 if (Verbose) { |
335 for (SizeT i = 0; i < RegMask.size(); ++i) { | 341 for (SizeT i = 0; i < RegMask.size(); ++i) { |
336 if (RegMask[i]) { | 342 if (RegMask[i]) { |
337 Str << Func->getTarget()->getRegName(i, IceType_i32) | 343 Str << Func->getTarget()->getRegName(i, IceType_i32) |
338 << "(U=" << RegUses[i] << ",F=" << Free[i] | 344 << "(U=" << RegUses[i] << ",F=" << Free[i] |
339 << ",P=" << PrecoloredUnhandled[i] << ") "; | 345 << ",P=" << PrecoloredUnhandled[i] << ") "; |
340 } | 346 } |
341 } | 347 } |
342 Str << "\n"; | 348 Str << "\n"; |
343 } | 349 } |
344 | 350 |
345 if (Prefer && (AllowOverlap || Free[PreferReg])) { | 351 if (Prefer && (AllowOverlap || Free[PreferReg])) { |
346 // First choice: a preferred register that is either free or is | 352 // First choice: a preferred register that is either free or is |
347 // allowed to overlap with its linked variable. | 353 // allowed to overlap with its linked variable. |
348 Cur.Var->setRegNumTmp(PreferReg); | 354 Cur.Var->setRegNumTmp(PreferReg); |
349 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 355 if (Verbose) { |
350 Str << "Preferring "; | 356 Str << "Preferring "; |
351 Cur.dump(Func); | 357 Cur.dump(Func); |
352 Str << "\n"; | 358 Str << "\n"; |
353 } | 359 } |
354 assert(RegUses[PreferReg] >= 0); | 360 assert(RegUses[PreferReg] >= 0); |
355 ++RegUses[PreferReg]; | 361 ++RegUses[PreferReg]; |
356 Active.push_back(Cur); | 362 Active.push_back(Cur); |
357 } else if (Free.any()) { | 363 } else if (Free.any()) { |
358 // Second choice: any free register. TODO: After explicit | 364 // Second choice: any free register. TODO: After explicit |
359 // affinity is considered, is there a strategy better than just | 365 // affinity is considered, is there a strategy better than just |
360 // picking the lowest-numbered available register? | 366 // picking the lowest-numbered available register? |
361 int32_t RegNum = Free.find_first(); | 367 int32_t RegNum = Free.find_first(); |
362 Cur.Var->setRegNumTmp(RegNum); | 368 Cur.Var->setRegNumTmp(RegNum); |
363 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 369 if (Verbose) { |
364 Str << "Allocating "; | 370 Str << "Allocating "; |
365 Cur.dump(Func); | 371 Cur.dump(Func); |
366 Str << "\n"; | 372 Str << "\n"; |
367 } | 373 } |
368 assert(RegUses[RegNum] >= 0); | 374 assert(RegUses[RegNum] >= 0); |
369 ++RegUses[RegNum]; | 375 ++RegUses[RegNum]; |
370 Active.push_back(Cur); | 376 Active.push_back(Cur); |
371 } else { | 377 } else { |
372 // Fallback: there are no free registers, so we look for the | 378 // Fallback: there are no free registers, so we look for the |
373 // lowest-weight register and see if Cur has higher weight. | 379 // lowest-weight register and see if Cur has higher weight. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 } | 433 } |
428 } else { | 434 } else { |
429 // Evict all live ranges in Active that register number | 435 // Evict all live ranges in Active that register number |
430 // MinWeightIndex is assigned to. | 436 // MinWeightIndex is assigned to. |
431 for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); | 437 for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); |
432 I != E; I = Next) { | 438 I != E; I = Next) { |
433 Next = I; | 439 Next = I; |
434 ++Next; | 440 ++Next; |
435 LiveRangeWrapper Item = *I; | 441 LiveRangeWrapper Item = *I; |
436 if (Item.Var->getRegNumTmp() == MinWeightIndex) { | 442 if (Item.Var->getRegNumTmp() == MinWeightIndex) { |
437 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 443 if (Verbose) { |
438 Str << "Evicting "; | 444 Str << "Evicting "; |
439 Item.dump(Func); | 445 Item.dump(Func); |
440 Str << "\n"; | 446 Str << "\n"; |
441 } | 447 } |
442 --RegUses[MinWeightIndex]; | 448 --RegUses[MinWeightIndex]; |
443 assert(RegUses[MinWeightIndex] >= 0); | 449 assert(RegUses[MinWeightIndex] >= 0); |
444 Item.Var->setRegNumTmp(Variable::NoRegister); | 450 Item.Var->setRegNumTmp(Variable::NoRegister); |
445 Active.erase(I); | 451 Active.erase(I); |
446 Handled.push_back(Item); | 452 Handled.push_back(Item); |
447 } | 453 } |
448 } | 454 } |
449 // Do the same for Inactive. | 455 // Do the same for Inactive. |
450 for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end(); | 456 for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end(); |
451 I != E; I = Next) { | 457 I != E; I = Next) { |
452 Next = I; | 458 Next = I; |
453 ++Next; | 459 ++Next; |
454 LiveRangeWrapper Item = *I; | 460 LiveRangeWrapper Item = *I; |
455 // Note: The Item.overlaps(Cur) clause is not part of the | 461 // Note: The Item.overlaps(Cur) clause is not part of the |
456 // description of AssignMemLoc() in the original paper. But | 462 // description of AssignMemLoc() in the original paper. But |
457 // there doesn't seem to be any need to evict an inactive | 463 // there doesn't seem to be any need to evict an inactive |
458 // live range that doesn't overlap with the live range | 464 // live range that doesn't overlap with the live range |
459 // currently being considered. It's especially bad if we | 465 // currently being considered. It's especially bad if we |
460 // would end up evicting an infinite-weight but | 466 // would end up evicting an infinite-weight but |
461 // currently-inactive live range. The most common situation | 467 // currently-inactive live range. The most common situation |
462 // for this would be a scratch register kill set for call | 468 // for this would be a scratch register kill set for call |
463 // instructions. | 469 // instructions. |
464 if (Item.Var->getRegNumTmp() == MinWeightIndex && | 470 if (Item.Var->getRegNumTmp() == MinWeightIndex && |
465 Item.overlaps(Cur)) { | 471 Item.overlaps(Cur)) { |
466 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 472 if (Verbose) { |
467 Str << "Evicting "; | 473 Str << "Evicting "; |
468 Item.dump(Func); | 474 Item.dump(Func); |
469 Str << "\n"; | 475 Str << "\n"; |
470 } | 476 } |
471 Item.Var->setRegNumTmp(Variable::NoRegister); | 477 Item.Var->setRegNumTmp(Variable::NoRegister); |
472 Inactive.erase(I); | 478 Inactive.erase(I); |
473 Handled.push_back(Item); | 479 Handled.push_back(Item); |
474 } | 480 } |
475 } | 481 } |
476 // Assign the register to Cur. | 482 // Assign the register to Cur. |
477 Cur.Var->setRegNumTmp(MinWeightIndex); | 483 Cur.Var->setRegNumTmp(MinWeightIndex); |
478 assert(RegUses[MinWeightIndex] >= 0); | 484 assert(RegUses[MinWeightIndex] >= 0); |
479 ++RegUses[MinWeightIndex]; | 485 ++RegUses[MinWeightIndex]; |
480 Active.push_back(Cur); | 486 Active.push_back(Cur); |
481 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 487 if (Verbose) { |
482 Str << "Allocating "; | 488 Str << "Allocating "; |
483 Cur.dump(Func); | 489 Cur.dump(Func); |
484 Str << "\n"; | 490 Str << "\n"; |
485 } | 491 } |
486 } | 492 } |
487 } | 493 } |
488 dump(Func); | 494 dump(Func); |
489 } | 495 } |
490 // Move anything Active or Inactive to Handled for easier handling. | 496 // Move anything Active or Inactive to Handled for easier handling. |
491 for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); I != E; | 497 for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); I != E; |
(...skipping 10 matching lines...) Expand all Loading... | |
502 Handled.push_back(*I); | 508 Handled.push_back(*I); |
503 Inactive.erase(I); | 509 Inactive.erase(I); |
504 } | 510 } |
505 dump(Func); | 511 dump(Func); |
506 | 512 |
507 // Finish up by assigning RegNumTmp->RegNum for each Variable. | 513 // Finish up by assigning RegNumTmp->RegNum for each Variable. |
508 for (UnorderedRanges::const_iterator I = Handled.begin(), E = Handled.end(); | 514 for (UnorderedRanges::const_iterator I = Handled.begin(), E = Handled.end(); |
509 I != E; ++I) { | 515 I != E; ++I) { |
510 LiveRangeWrapper Item = *I; | 516 LiveRangeWrapper Item = *I; |
511 int32_t RegNum = Item.Var->getRegNumTmp(); | 517 int32_t RegNum = Item.Var->getRegNumTmp(); |
512 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 518 if (Verbose) { |
513 if (!Item.Var->hasRegTmp()) { | 519 if (!Item.Var->hasRegTmp()) { |
514 Str << "Not assigning "; | 520 Str << "Not assigning "; |
515 Item.Var->dump(Func); | 521 Item.Var->dump(Func); |
516 Str << "\n"; | 522 Str << "\n"; |
517 } else { | 523 } else { |
518 Str << (RegNum == Item.Var->getRegNum() ? "Reassigning " : "Assigning ") | 524 Str << (RegNum == Item.Var->getRegNum() ? "Reassigning " : "Assigning ") |
519 << Func->getTarget()->getRegName(RegNum, IceType_i32) << "(r" | 525 << Func->getTarget()->getRegName(RegNum, IceType_i32) << "(r" |
520 << RegNum << ") to "; | 526 << RegNum << ") to "; |
521 Item.Var->dump(Func); | 527 Item.Var->dump(Func); |
522 Str << "\n"; | 528 Str << "\n"; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 } | 581 } |
576 Str << "++++++ Inactive:\n"; | 582 Str << "++++++ Inactive:\n"; |
577 for (UnorderedRanges::const_iterator I = Inactive.begin(), E = Inactive.end(); | 583 for (UnorderedRanges::const_iterator I = Inactive.begin(), E = Inactive.end(); |
578 I != E; ++I) { | 584 I != E; ++I) { |
579 I->dump(Func); | 585 I->dump(Func); |
580 Str << "\n"; | 586 Str << "\n"; |
581 } | 587 } |
582 } | 588 } |
583 | 589 |
584 } // end of namespace Ice | 590 } // end of namespace Ice |
OLD | NEW |