Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/IceRegAlloc.cpp

Issue 1323693002: Subzero: Provide a macro for iterating over instruction variables. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: "Addresses comments" Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceOperand.cpp ('k') | src/IceTargetLowering.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// \file 10 /// \file
11 /// This file implements the LinearScan class, which performs the linear-scan 11 /// This file implements the LinearScan class, which performs the linear-scan
12 /// register allocation after liveness analysis has been performed. 12 /// register allocation after liveness analysis has been performed.
13 /// 13 ///
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include "IceRegAlloc.h" 16 #include "IceRegAlloc.h"
17 17
18 #include "IceCfg.h" 18 #include "IceCfg.h"
19 #include "IceCfgNode.h" 19 #include "IceCfgNode.h"
20 #include "IceInst.h" 20 #include "IceInst.h"
21 #include "IceInstVarIter.h"
21 #include "IceOperand.h" 22 #include "IceOperand.h"
22 #include "IceTargetLowering.h" 23 #include "IceTargetLowering.h"
23 24
24 namespace Ice { 25 namespace Ice {
25 26
26 namespace { 27 namespace {
27 28
28 // Returns true if Var has any definitions within Item's live range. 29 // Returns true if Var has any definitions within Item's live range.
29 // TODO(stichnot): Consider trimming the Definitions list similar to how the 30 // TODO(stichnot): Consider trimming the Definitions list similar to how the
30 // live ranges are trimmed, since all the overlapsDefs() tests are whether some 31 // live ranges are trimmed, since all the overlapsDefs() tests are whether some
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 continue; 174 continue;
174 if (const Variable *Var = Inst.getDest()) { 175 if (const Variable *Var = Inst.getDest()) {
175 if (!Var->getIgnoreLiveness() && 176 if (!Var->getIgnoreLiveness() &&
176 (Var->hasReg() || Var->mustHaveReg())) { 177 (Var->hasReg() || Var->mustHaveReg())) {
177 if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) { 178 if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) {
178 LRBegin[Var->getIndex()] = Inst.getNumber(); 179 LRBegin[Var->getIndex()] = Inst.getNumber();
179 ++NumVars; 180 ++NumVars;
180 } 181 }
181 } 182 }
182 } 183 }
183 for (SizeT I = 0; I < Inst.getSrcSize(); ++I) { 184 FOREACH_VAR_IN_INST(Var, Inst) {
184 Operand *Src = Inst.getSrc(I); 185 if (Var->getIgnoreLiveness())
185 SizeT NumVars = Src->getNumVars(); 186 continue;
186 for (SizeT J = 0; J < NumVars; ++J) { 187 if (Var->hasReg() || Var->mustHaveReg())
187 const Variable *Var = Src->getVar(J); 188 LREnd[Var->getIndex()] = Inst.getNumber();
188 if (Var->getIgnoreLiveness())
189 continue;
190 if (Var->hasReg() || Var->mustHaveReg())
191 LREnd[Var->getIndex()] = Inst.getNumber();
192 }
193 } 189 }
194 } 190 }
195 } 191 }
196 192
197 Unhandled.reserve(NumVars); 193 Unhandled.reserve(NumVars);
198 UnhandledPrecolored.reserve(NumVars); 194 UnhandledPrecolored.reserve(NumVars);
199 for (SizeT i = 0; i < Vars.size(); ++i) { 195 for (SizeT i = 0; i < Vars.size(); ++i) {
200 Variable *Var = Vars[i]; 196 Variable *Var = Vars[i];
201 if (LRBegin[i] != Inst::NumberSentinel) { 197 if (LRBegin[i] != Inst::NumberSentinel) {
202 assert(LREnd[i] != Inst::NumberSentinel); 198 assert(LREnd[i] != Inst::NumberSentinel);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 for (auto I = Insts.begin(), E = Insts.end(); 287 for (auto I = Insts.begin(), E = Insts.end();
292 I != E && (SpillPoint == E || FillPoint == E); ++I) { 288 I != E && (SpillPoint == E || FillPoint == E); ++I) {
293 if (I->getNumber() == Start) 289 if (I->getNumber() == Start)
294 SpillPoint = I; 290 SpillPoint = I;
295 if (I->getNumber() == End) 291 if (I->getNumber() == End)
296 FillPoint = I; 292 FillPoint = I;
297 if (SpillPoint != E) { 293 if (SpillPoint != E) {
298 // Remove from RegMask any physical registers referenced during Cur's live 294 // Remove from RegMask any physical registers referenced during Cur's live
299 // range. Start looking after SpillPoint gets set, i.e. once Cur's live 295 // range. Start looking after SpillPoint gets set, i.e. once Cur's live
300 // range begins. 296 // range begins.
301 for (SizeT i = 0; i < I->getSrcSize(); ++i) { 297 FOREACH_VAR_IN_INST(Var, *I) {
302 Operand *Src = I->getSrc(i); 298 if (Var->hasRegTmp())
303 SizeT NumVars = Src->getNumVars(); 299 Iter.RegMask[Var->getRegNumTmp()] = false;
304 for (SizeT j = 0; j < NumVars; ++j) {
305 const Variable *Var = Src->getVar(j);
306 if (Var->hasRegTmp())
307 Iter.RegMask[Var->getRegNumTmp()] = false;
308 }
309 } 300 }
310 } 301 }
311 } 302 }
312 assert(SpillPoint != Insts.end()); 303 assert(SpillPoint != Insts.end());
313 assert(FillPoint != Insts.end()); 304 assert(FillPoint != Insts.end());
314 ++FillPoint; 305 ++FillPoint;
315 // TODO(stichnot): Randomize instead of find_first(). 306 // TODO(stichnot): Randomize instead of find_first().
316 int32_t RegNum = Iter.RegMask.find_first(); 307 int32_t RegNum = Iter.RegMask.find_first();
317 assert(RegNum != -1); 308 assert(RegNum != -1);
318 Iter.Cur->setRegNumTmp(RegNum); 309 Iter.Cur->setRegNumTmp(RegNum);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 Str << "\n"; 828 Str << "\n";
838 } 829 }
839 Str << "++++++ Inactive:\n"; 830 Str << "++++++ Inactive:\n";
840 for (const Variable *Item : Inactive) { 831 for (const Variable *Item : Inactive) {
841 dumpLiveRange(Item, Func); 832 dumpLiveRange(Item, Func);
842 Str << "\n"; 833 Str << "\n";
843 } 834 }
844 } 835 }
845 836
846 } // end of namespace Ice 837 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceOperand.cpp ('k') | src/IceTargetLowering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698