Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 uint32_t ThisUseWeight = | |
| 166 1 | |
| 167 << std::min(Node->getLoopNestDepth(), MaxLoopNestDepth) * LogLoopTripCount Estimate; | |
|
ascull
2015/09/03 19:52:38
Why does clang-format fail here? Should I just use
Jim Stichnoth
2015/09/03 21:35:09
Maybe do the std::min() in a separate statement?
ascull
2015/09/03 22:47:13
Done.
| |
| 168 UseWeight.addWeight(ThisUseWeight); | |
| 162 | 169 |
| 163 if (MultiBlock == MBS_MultiBlock) | 170 if (MultiBlock == MBS_MultiBlock) |
| 164 return; | 171 return; |
| 165 // TODO(stichnot): If the use occurs as a source operand in the | 172 // TODO(stichnot): If the use occurs as a source operand in the |
| 166 // first instruction of the block, and its definition is in this | 173 // first instruction of the block, and its definition is in this |
| 167 // block's only predecessor, we might consider not marking this as a | 174 // 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 | 175 // separate use. This may also apply if it's the first instruction |
| 169 // of the block that actually uses a Variable. | 176 // of the block that actually uses a Variable. |
| 170 assert(Node); | 177 assert(Node); |
| 171 bool MakeMulti = false; | 178 bool MakeMulti = false; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 return Metadata[VarNum].getLatterDefinitions(); | 395 return Metadata[VarNum].getLatterDefinitions(); |
| 389 } | 396 } |
| 390 | 397 |
| 391 CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const { | 398 CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const { |
| 392 if (!isTracked(Var)) | 399 if (!isTracked(Var)) |
| 393 return nullptr; // conservative answer | 400 return nullptr; // conservative answer |
| 394 SizeT VarNum = Var->getIndex(); | 401 SizeT VarNum = Var->getIndex(); |
| 395 return Metadata[VarNum].getNode(); | 402 return Metadata[VarNum].getNode(); |
| 396 } | 403 } |
| 397 | 404 |
| 398 uint32_t VariablesMetadata::getUseWeight(const Variable *Var) const { | 405 RegWeight VariablesMetadata::getUseWeight(const Variable *Var) const { |
| 399 if (!isTracked(Var)) | 406 if (!isTracked(Var)) |
| 400 return 1; // conservative answer | 407 return RegWeight(1); // conservative answer |
| 401 SizeT VarNum = Var->getIndex(); | 408 SizeT VarNum = Var->getIndex(); |
| 402 return Metadata[VarNum].getUseWeight(); | 409 return Metadata[VarNum].getUseWeight(); |
| 403 } | 410 } |
| 404 | 411 |
| 405 const InstDefList VariablesMetadata::NoDefinitions; | 412 const InstDefList VariablesMetadata::NoDefinitions; |
| 406 | 413 |
| 407 // ======================== dump routines ======================== // | 414 // ======================== dump routines ======================== // |
| 408 | 415 |
| 409 void Variable::emit(const Cfg *Func) const { | 416 void Variable::emit(const Cfg *Func) const { |
| 410 if (BuildDefs::dump()) | 417 if (BuildDefs::dump()) |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 if (getType() != IceType_i32 && getType() != IceType_i16 && | 530 if (getType() != IceType_i32 && getType() != IceType_i16 && |
| 524 getType() != IceType_i8) | 531 getType() != IceType_i8) |
| 525 return false; | 532 return false; |
| 526 // The Following checks if the signed representation of Value is between | 533 // The Following checks if the signed representation of Value is between |
| 527 // -Threshold/2 and +Threshold/2 | 534 // -Threshold/2 and +Threshold/2 |
| 528 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; | 535 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; |
| 529 return largerThanThreshold; | 536 return largerThanThreshold; |
| 530 } | 537 } |
| 531 | 538 |
| 532 } // end of namespace Ice | 539 } // end of namespace Ice |
| OLD | NEW |