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 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: 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/IceSwitchLowering.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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 { 148 RegWeight Variable::getWeight(const Cfg *Func) const {
149 VariablesMetadata *VMetadata = Func->getVMetadata(); 149 VariablesMetadata *VMetadata = Func->getVMetadata();
150 return RegWeight(mustHaveReg() 150 return mustHaveReg() ? RegWeight(RegWeight::Inf)
151 ? RegWeight::Inf 151 : mustNotHaveReg() ? RegWeight(RegWeight::Zero)
152 : mustNotHaveReg() ? RegWeight::Zero 152 : VMetadata->getUseWeight(this);
153 : VMetadata->getUseWeight(this));
154 } 153 }
155 154
156 void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr, 155 void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr,
157 CfgNode *Node, bool IsImplicit) { 156 CfgNode *Node, bool IsImplicit) {
158 (void)TrackingKind; 157 (void)TrackingKind;
159 158
160 // TODO(ascull): get the loop nest depth from CfgNode 159 // Increment the use weight depending on the loop nest depth. The weight is
161 UseWeight += 1; 160 // exponential in the nest depth as inner loops are expected to be executed
161 // an exponentially greater number of times.
162 constexpr uint32_t LogLoopTripCountEstimate = 2; // 2^2 = 4
163 constexpr SizeT MaxShift = sizeof(uint32_t) * CHAR_BIT - 1;
164 constexpr SizeT MaxLoopNestDepth = MaxShift / LogLoopTripCountEstimate;
165 const uint32_t LoopNestDepth =
166 std::min(Node->getLoopNestDepth(), MaxLoopNestDepth);
167 const uint32_t ThisUseWeight = uint32_t(1)
168 << LoopNestDepth * LogLoopTripCountEstimate;
169 UseWeight.addWeight(ThisUseWeight);
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 return Metadata[VarNum].getLatterDefinitions(); 396 return Metadata[VarNum].getLatterDefinitions();
389 } 397 }
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 RegWeight VariablesMetadata::getUseWeight(const Variable *Var) const {
399 if (!isTracked(Var)) 407 if (!isTracked(Var))
400 return 1; // conservative answer 408 return RegWeight(1); // conservative answer
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
« no previous file with comments | « src/IceOperand.h ('k') | src/IceSwitchLowering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698