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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceOperand.h ('k') | src/IceSwitchLowering.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceOperand.cpp
diff --git a/src/IceOperand.cpp b/src/IceOperand.cpp
index 32316ba6ffda6d4f1e8bcab3e1a1ddd589960695..c40417e2533a19cb1806ffbc12aab2342e37347f 100644
--- a/src/IceOperand.cpp
+++ b/src/IceOperand.cpp
@@ -147,18 +147,26 @@ Variable *Variable::asType(Type Ty) {
RegWeight Variable::getWeight(const Cfg *Func) const {
VariablesMetadata *VMetadata = Func->getVMetadata();
- return RegWeight(mustHaveReg()
- ? RegWeight::Inf
- : mustNotHaveReg() ? RegWeight::Zero
- : VMetadata->getUseWeight(this));
+ return mustHaveReg() ? RegWeight(RegWeight::Inf)
+ : mustNotHaveReg() ? RegWeight(RegWeight::Zero)
+ : VMetadata->getUseWeight(this);
}
void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr,
CfgNode *Node, bool IsImplicit) {
(void)TrackingKind;
- // TODO(ascull): get the loop nest depth from CfgNode
- UseWeight += 1;
+ // Increment the use weight depending on the loop nest depth. The weight is
+ // exponential in the nest depth as inner loops are expected to be executed
+ // an exponentially greater number of times.
+ constexpr uint32_t LogLoopTripCountEstimate = 2; // 2^2 = 4
+ constexpr SizeT MaxShift = sizeof(uint32_t) * CHAR_BIT - 1;
+ constexpr SizeT MaxLoopNestDepth = MaxShift / LogLoopTripCountEstimate;
+ const uint32_t LoopNestDepth =
+ std::min(Node->getLoopNestDepth(), MaxLoopNestDepth);
+ const uint32_t ThisUseWeight = uint32_t(1)
+ << LoopNestDepth * LogLoopTripCountEstimate;
+ UseWeight.addWeight(ThisUseWeight);
if (MultiBlock == MBS_MultiBlock)
return;
@@ -395,9 +403,9 @@ CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const {
return Metadata[VarNum].getNode();
}
-uint32_t VariablesMetadata::getUseWeight(const Variable *Var) const {
+RegWeight VariablesMetadata::getUseWeight(const Variable *Var) const {
if (!isTracked(Var))
- return 1; // conservative answer
+ return RegWeight(1); // conservative answer
SizeT VarNum = Var->getIndex();
return Metadata[VarNum].getUseWeight();
}
« 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