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

Side by Side Diff: src/IceOperand.cpp

Issue 1318553003: Compute the loop nest depth of each CfgNode and weight Variables by it. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: calculate -> compute (consistency) 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
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return RegWeight(mustHaveReg() 150 return RegWeight(mustHaveReg()
151 ? RegWeight::Inf 151 ? RegWeight::Inf
152 : mustNotHaveReg() ? RegWeight::Zero 152 : mustNotHaveReg() ? RegWeight::Zero
153 : VMetadata->getUseWeight(this)); 153 : VMetadata->getUseWeight(this));
154 } 154 }
155 155
156 void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr, 156 void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr,
157 CfgNode *Node, bool IsImplicit) { 157 CfgNode *Node, bool IsImplicit) {
158 (void)TrackingKind; 158 (void)TrackingKind;
159 159
160 // TODO(ascull): get the loop nest depth from CfgNode 160 // Increment the use weight depending on the loop nest depth. The weight is
161 UseWeight += 1; 161 // exponential in the nest depth as inner loops are expected to be executed
162 // an exponentially greater number of times.
163 constexpr uint32_t LogTypicalLoopTripCount = 3; // 2^3 = 8
Jim Stichnoth 2015/09/01 22:17:37 nit: "Typical" implies knowledge we don't have. I
ascull 2015/09/03 19:52:38 Done.
164 uint32_t ThisUseWeight =
Jim Stichnoth 2015/09/01 22:17:37 Maybe SizeT instead of uint32_t?
ascull 2015/09/03 19:52:38 Done.
165 1 << std::min(Node->getLoopNestDepth() * LogTypicalLoopTripCount, 31u);
Jim Stichnoth 2015/09/01 22:17:37 No magic constants please. :) CHAR_BIT * sizeof(T
ascull 2015/09/03 19:52:38 Done.
166 uint32_t NewWeight = UseWeight + ThisUseWeight;
167 // Make sure the weight doesn't overflow or become infinite.
168 UseWeight = NewWeight < UseWeight ? RegWeight::Inf - 1
Jim Stichnoth 2015/09/01 22:17:38 How about something defining something like RegWei
169 : std::min(NewWeight, RegWeight::Inf - 1);
162 170
163 if (MultiBlock == MBS_MultiBlock) 171 if (MultiBlock == MBS_MultiBlock)
164 return; 172 return;
165 // TODO(stichnot): If the use occurs as a source operand in the 173 // TODO(stichnot): If the use occurs as a source operand in the
166 // first instruction of the block, and its definition is in this 174 // first instruction of the block, and its definition is in this
167 // block's only predecessor, we might consider not marking this as a 175 // block's only predecessor, we might consider not marking this as a
168 // separate use. This may also apply if it's the first instruction 176 // separate use. This may also apply if it's the first instruction
169 // of the block that actually uses a Variable. 177 // of the block that actually uses a Variable.
170 assert(Node); 178 assert(Node);
171 bool MakeMulti = false; 179 bool MakeMulti = false;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 398
391 CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const { 399 CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const {
392 if (!isTracked(Var)) 400 if (!isTracked(Var))
393 return nullptr; // conservative answer 401 return nullptr; // conservative answer
394 SizeT VarNum = Var->getIndex(); 402 SizeT VarNum = Var->getIndex();
395 return Metadata[VarNum].getNode(); 403 return Metadata[VarNum].getNode();
396 } 404 }
397 405
398 uint32_t VariablesMetadata::getUseWeight(const Variable *Var) const { 406 uint32_t VariablesMetadata::getUseWeight(const Variable *Var) const {
399 if (!isTracked(Var)) 407 if (!isTracked(Var))
400 return 1; // conservative answer 408 return 1; // conservative answer
ascull 2015/09/03 19:52:38 Is 1 the right number here? Why would a variable n
Jim Stichnoth 2015/09/03 21:35:08 If the variable is not tracked, it usually means t
401 SizeT VarNum = Var->getIndex(); 409 SizeT VarNum = Var->getIndex();
402 return Metadata[VarNum].getUseWeight(); 410 return Metadata[VarNum].getUseWeight();
403 } 411 }
404 412
405 const InstDefList VariablesMetadata::NoDefinitions; 413 const InstDefList VariablesMetadata::NoDefinitions;
406 414
407 // ======================== dump routines ======================== // 415 // ======================== dump routines ======================== //
408 416
409 void Variable::emit(const Cfg *Func) const { 417 void Variable::emit(const Cfg *Func) const {
410 if (BuildDefs::dump()) 418 if (BuildDefs::dump())
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 if (getType() != IceType_i32 && getType() != IceType_i16 && 531 if (getType() != IceType_i32 && getType() != IceType_i16 &&
524 getType() != IceType_i8) 532 getType() != IceType_i8)
525 return false; 533 return false;
526 // The Following checks if the signed representation of Value is between 534 // The Following checks if the signed representation of Value is between
527 // -Threshold/2 and +Threshold/2 535 // -Threshold/2 and +Threshold/2
528 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; 536 bool largerThanThreshold = Threshold / 2 + Value >= Threshold;
529 return largerThanThreshold; 537 return largerThanThreshold;
530 } 538 }
531 539
532 } // end of namespace Ice 540 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698