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

Side by Side Diff: src/IceOperand.cpp

Issue 619893002: Subzero: Auto-awesome iterators. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Use AsmCodeByte instead of uint8_t Created 6 years, 2 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/IceIntrinsics.cpp ('k') | src/IceRegAlloc.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/IceOperand.cpp - High-level operand implementation -----===// 1 //===- subzero/src/IceOperand.cpp - High-level operand 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 Operand class and its target-independent 10 // This file implements the Operand class and its target-independent
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ++I2; 116 ++I2;
117 continue; 117 continue;
118 } 118 }
119 return true; 119 return true;
120 } 120 }
121 return false; 121 return false;
122 } 122 }
123 123
124 bool LiveRange::overlaps(InstNumberT OtherBegin) const { 124 bool LiveRange::overlaps(InstNumberT OtherBegin) const {
125 bool Result = false; 125 bool Result = false;
126 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; 126 for (const RangeElementType &I : Range) {
127 ++I) { 127 if (OtherBegin < I.first) {
128 if (OtherBegin < I->first) {
129 Result = false; 128 Result = false;
130 break; 129 break;
131 } 130 }
132 if (OtherBegin < I->second) { 131 if (OtherBegin < I.second) {
133 Result = true; 132 Result = true;
134 break; 133 break;
135 } 134 }
136 } 135 }
137 #if 0 136 #if 0
138 // An equivalent but less inefficient implementation: 137 // An equivalent but less inefficient implementation:
139 LiveRange Temp; 138 LiveRange Temp;
140 Temp.addSegment(OtherBegin, OtherBegin + 1); 139 Temp.addSegment(OtherBegin, OtherBegin + 1);
141 bool Validation = overlaps(Temp); 140 bool Validation = overlaps(Temp);
142 assert(Result == Validation); 141 assert(Result == Validation);
143 #endif 142 #endif
144 return Result; 143 return Result;
145 } 144 }
146 145
147 // Returns true if the live range contains the given instruction 146 // Returns true if the live range contains the given instruction
148 // number. This is only used for validating the live range 147 // number. This is only used for validating the live range
149 // calculation. 148 // calculation.
150 bool LiveRange::containsValue(InstNumberT Value) const { 149 bool LiveRange::containsValue(InstNumberT Value) const {
151 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; 150 for (const RangeElementType &I : Range) {
152 ++I) { 151 if (I.first <= Value && Value <= I.second)
153 if (I->first <= Value && Value <= I->second)
154 return true; 152 return true;
155 } 153 }
156 return false; 154 return false;
157 } 155 }
158 156
159 IceString Variable::getName() const { 157 IceString Variable::getName() const {
160 if (!Name.empty()) 158 if (!Name.empty())
161 return Name; 159 return Name;
162 char buf[30]; 160 char buf[30];
163 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); 161 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 273 }
276 } 274 }
277 275
278 void VariablesMetadata::init() { 276 void VariablesMetadata::init() {
279 static TimerIdT IDvmetadata = GlobalContext::getTimerID("vmetadata"); 277 static TimerIdT IDvmetadata = GlobalContext::getTimerID("vmetadata");
280 TimerMarker T(IDvmetadata, Func->getContext()); 278 TimerMarker T(IDvmetadata, Func->getContext());
281 Metadata.clear(); 279 Metadata.clear();
282 Metadata.resize(Func->getNumVariables()); 280 Metadata.resize(Func->getNumVariables());
283 281
284 // Mark implicit args as being used in the entry node. 282 // Mark implicit args as being used in the entry node.
285 const VarList &ImplicitArgList = Func->getImplicitArgs(); 283 for (Variable *Var : Func->getImplicitArgs()) {
286 for (VarList::const_iterator I = ImplicitArgList.begin(),
287 E = ImplicitArgList.end();
288 I != E; ++I) {
289 const Variable *Var = *I;
290 const Inst *NoInst = NULL; 284 const Inst *NoInst = NULL;
291 const CfgNode *EntryNode = Func->getEntryNode(); 285 const CfgNode *EntryNode = Func->getEntryNode();
292 const bool IsFromDef = false; 286 const bool IsFromDef = false;
293 const bool IsImplicit = true; 287 const bool IsImplicit = true;
294 Metadata[Var->getIndex()].markUse(NoInst, EntryNode, IsFromDef, IsImplicit); 288 Metadata[Var->getIndex()].markUse(NoInst, EntryNode, IsFromDef, IsImplicit);
295 } 289 }
296 290
297 SizeT NumNodes = Func->getNumNodes(); 291 SizeT NumNodes = Func->getNumNodes();
298 for (SizeT N = 0; N < NumNodes; ++N) { 292 for (SizeT N = 0; N < NumNodes; ++N) {
299 CfgNode *Node = Func->getNodes()[N]; 293 CfgNode *Node = Func->getNodes()[N];
300 const InstList &Insts = Node->getInsts(); 294 for (Inst *I : Node->getInsts()) {
301 for (InstList::const_iterator I = Insts.begin(), E = Insts.end(); I != E; 295 if (I->isDeleted())
302 ++I) {
303 if ((*I)->isDeleted())
304 continue; 296 continue;
305 if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(*I)) { 297 if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) {
306 // A FakeKill instruction indicates certain Variables (usually 298 // A FakeKill instruction indicates certain Variables (usually
307 // physical scratch registers) are redefined, so we register 299 // physical scratch registers) are redefined, so we register
308 // them as defs. 300 // them as defs.
309 for (SizeT SrcNum = 0; SrcNum < (*I)->getSrcSize(); ++SrcNum) { 301 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) {
310 Variable *Var = llvm::cast<Variable>((*I)->getSrc(SrcNum)); 302 Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum));
311 SizeT VarNum = Var->getIndex(); 303 SizeT VarNum = Var->getIndex();
312 assert(VarNum < Metadata.size()); 304 assert(VarNum < Metadata.size());
313 Metadata[VarNum].markDef(Kill, Node); 305 Metadata[VarNum].markDef(Kill, Node);
314 } 306 }
315 continue; // no point in executing the rest 307 continue; // no point in executing the rest
316 } 308 }
317 if (Variable *Dest = (*I)->getDest()) { 309 if (Variable *Dest = I->getDest()) {
318 SizeT DestNum = Dest->getIndex(); 310 SizeT DestNum = Dest->getIndex();
319 assert(DestNum < Metadata.size()); 311 assert(DestNum < Metadata.size());
320 Metadata[DestNum].markDef(*I, Node); 312 Metadata[DestNum].markDef(I, Node);
321 } 313 }
322 for (SizeT SrcNum = 0; SrcNum < (*I)->getSrcSize(); ++SrcNum) { 314 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) {
323 Operand *Src = (*I)->getSrc(SrcNum); 315 Operand *Src = I->getSrc(SrcNum);
324 SizeT NumVars = Src->getNumVars(); 316 SizeT NumVars = Src->getNumVars();
325 for (SizeT J = 0; J < NumVars; ++J) { 317 for (SizeT J = 0; J < NumVars; ++J) {
326 const Variable *Var = Src->getVar(J); 318 const Variable *Var = Src->getVar(J);
327 SizeT VarNum = Var->getIndex(); 319 SizeT VarNum = Var->getIndex();
328 assert(VarNum < Metadata.size()); 320 assert(VarNum < Metadata.size());
329 const bool IsFromDef = false; 321 const bool IsFromDef = false;
330 const bool IsImplicit = false; 322 const bool IsImplicit = false;
331 Metadata[VarNum].markUse(*I, Node, IsFromDef, IsImplicit); 323 Metadata[VarNum].markUse(I, Node, IsFromDef, IsImplicit);
332 } 324 }
333 } 325 }
334 } 326 }
335 } 327 }
336 } 328 }
337 329
338 bool VariablesMetadata::isMultiDef(const Variable *Var) const { 330 bool VariablesMetadata::isMultiDef(const Variable *Var) const {
339 if (Var->getIsArg()) 331 if (Var->getIsArg())
340 return false; 332 return false;
341 if (!isTracked(Var)) 333 if (!isTracked(Var))
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 425 }
434 426
435 void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const { 427 void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const {
436 Str << "@" << Name; 428 Str << "@" << Name;
437 if (Offset) 429 if (Offset)
438 Str << "+" << Offset; 430 Str << "+" << Offset;
439 } 431 }
440 432
441 void LiveRange::dump(Ostream &Str) const { 433 void LiveRange::dump(Ostream &Str) const {
442 Str << "(weight=" << Weight << ") "; 434 Str << "(weight=" << Weight << ") ";
443 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; 435 bool First = true;
444 ++I) { 436 for (const RangeElementType &I : Range) {
445 if (I != Range.begin()) 437 if (First)
446 Str << ", "; 438 Str << ", ";
447 Str << "[" << (*I).first << ":" << (*I).second << ")"; 439 First = false;
440 Str << "[" << I.first << ":" << I.second << ")";
448 } 441 }
449 } 442 }
450 443
451 Ostream &operator<<(Ostream &Str, const LiveRange &L) { 444 Ostream &operator<<(Ostream &Str, const LiveRange &L) {
452 L.dump(Str); 445 L.dump(Str);
453 return Str; 446 return Str;
454 } 447 }
455 448
456 Ostream &operator<<(Ostream &Str, const RegWeight &W) { 449 Ostream &operator<<(Ostream &Str, const RegWeight &W) {
457 if (W.getWeight() == RegWeight::Inf) 450 if (W.getWeight() == RegWeight::Inf)
458 Str << "Inf"; 451 Str << "Inf";
459 else 452 else
460 Str << W.getWeight(); 453 Str << W.getWeight();
461 return Str; 454 return Str;
462 } 455 }
463 456
464 } // end of namespace Ice 457 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceIntrinsics.cpp ('k') | src/IceRegAlloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698