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

Side by Side Diff: src/IceOperand.cpp

Issue 1312433004: Weight variables by their number of uses for register allocation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: 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.h ('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 /// \file 10 /// \file
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (!BuildDefs::dump() || getType() == Ty) 138 if (!BuildDefs::dump() || getType() == Ty)
139 return this; 139 return this;
140 Variable *V = new (getCurrentCfgAllocator()->Allocate<Variable>()) 140 Variable *V = new (getCurrentCfgAllocator()->Allocate<Variable>())
141 Variable(kVariable, Ty, Number); 141 Variable(kVariable, Ty, Number);
142 V->NameIndex = NameIndex; 142 V->NameIndex = NameIndex;
143 V->RegNum = RegNum; 143 V->RegNum = RegNum;
144 V->StackOffset = StackOffset; 144 V->StackOffset = StackOffset;
145 return V; 145 return V;
146 } 146 }
147 147
148 RegWeight Variable::getWeight(const Cfg *Func) const {
149 VariablesMetadata *VMetadata = Func->getVMetadata();
150 return RegWeight(mustHaveReg()
151 ? RegWeight::Inf
152 : mustNotHaveReg() ? RegWeight::Zero
153 : VMetadata->getUseWeight(this));
154 }
155
148 void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr, 156 void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr,
149 CfgNode *Node, bool IsImplicit) { 157 CfgNode *Node, bool IsImplicit) {
150 (void)TrackingKind; 158 (void)TrackingKind;
159
160 // TODO(ascull): get the loop nest depth from CfgNode
161 UseWeight += 1;
162
151 if (MultiBlock == MBS_MultiBlock) 163 if (MultiBlock == MBS_MultiBlock)
152 return; 164 return;
153 // TODO(stichnot): If the use occurs as a source operand in the 165 // TODO(stichnot): If the use occurs as a source operand in the
154 // first instruction of the block, and its definition is in this 166 // first instruction of the block, and its definition is in this
155 // block's only predecessor, we might consider not marking this as a 167 // block's only predecessor, we might consider not marking this as a
156 // separate use. This may also apply if it's the first instruction 168 // separate use. This may also apply if it's the first instruction
157 // of the block that actually uses a Variable. 169 // of the block that actually uses a Variable.
158 assert(Node); 170 assert(Node);
159 bool MakeMulti = false; 171 bool MakeMulti = false;
160 if (IsImplicit) 172 if (IsImplicit)
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 return Metadata[VarNum].getLatterDefinitions(); 388 return Metadata[VarNum].getLatterDefinitions();
377 } 389 }
378 390
379 CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const { 391 CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const {
380 if (!isTracked(Var)) 392 if (!isTracked(Var))
381 return nullptr; // conservative answer 393 return nullptr; // conservative answer
382 SizeT VarNum = Var->getIndex(); 394 SizeT VarNum = Var->getIndex();
383 return Metadata[VarNum].getNode(); 395 return Metadata[VarNum].getNode();
384 } 396 }
385 397
398 uint32_t VariablesMetadata::getUseWeight(const Variable *Var) const {
399 if (!isTracked(Var))
400 return 1; // conservative answer
401 SizeT VarNum = Var->getIndex();
402 return Metadata[VarNum].getUseWeight();
403 }
404
386 const InstDefList VariablesMetadata::NoDefinitions; 405 const InstDefList VariablesMetadata::NoDefinitions;
387 406
388 // ======================== dump routines ======================== // 407 // ======================== dump routines ======================== //
389 408
390 void Variable::emit(const Cfg *Func) const { 409 void Variable::emit(const Cfg *Func) const {
391 if (BuildDefs::dump()) 410 if (BuildDefs::dump())
392 Func->getTarget()->emitVariable(this); 411 Func->getTarget()->emitVariable(this);
393 } 412 }
394 413
395 void Variable::dump(const Cfg *Func, Ostream &Str) const { 414 void Variable::dump(const Cfg *Func, Ostream &Str) const {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 478 }
460 if (Offset) 479 if (Offset)
461 Str << "+" << Offset; 480 Str << "+" << Offset;
462 } 481 }
463 482
464 void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); } 483 void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); }
465 484
466 void LiveRange::dump(Ostream &Str) const { 485 void LiveRange::dump(Ostream &Str) const {
467 if (!BuildDefs::dump()) 486 if (!BuildDefs::dump())
468 return; 487 return;
469 Str << "(weight=" << Weight << ") ";
470 bool First = true; 488 bool First = true;
471 for (const RangeElementType &I : Range) { 489 for (const RangeElementType &I : Range) {
472 if (!First) 490 if (!First)
473 Str << ", "; 491 Str << ", ";
474 First = false; 492 First = false;
475 Str << "[" << I.first << ":" << I.second << ")"; 493 Str << "[" << I.first << ":" << I.second << ")";
476 } 494 }
477 } 495 }
478 496
479 Ostream &operator<<(Ostream &Str, const LiveRange &L) { 497 Ostream &operator<<(Ostream &Str, const LiveRange &L) {
(...skipping 25 matching lines...) Expand all
505 if (getType() != IceType_i32 && getType() != IceType_i16 && 523 if (getType() != IceType_i32 && getType() != IceType_i16 &&
506 getType() != IceType_i8) 524 getType() != IceType_i8)
507 return false; 525 return false;
508 // The Following checks if the signed representation of Value is between 526 // The Following checks if the signed representation of Value is between
509 // -Threshold/2 and +Threshold/2 527 // -Threshold/2 and +Threshold/2
510 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; 528 bool largerThanThreshold = Threshold / 2 + Value >= Threshold;
511 return largerThanThreshold; 529 return largerThanThreshold;
512 } 530 }
513 531
514 } // end of namespace Ice 532 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceOperand.h ('k') | src/IceRegAlloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698