VARSET_VALRET_TP lvaStmtLclMask(GenTreePtr stmt);
- static fgWalkPreFn lvaIncRefCntsCB;
void lvaIncRefCnts(GenTreePtr tree);
-
- static fgWalkPreFn lvaDecRefCntsCB;
void lvaDecRefCnts(GenTreePtr tree);
+
void lvaDecRefCnts(BasicBlock* basicBlock, GenTreePtr tree);
void lvaRecursiveDecRefCounts(GenTreePtr tree);
void lvaRecursiveIncRefCounts(GenTreePtr tree);
}
};
+class IncLclVarRefCountsVisitor final : public GenTreeVisitor<IncLclVarRefCountsVisitor>
+{
+public:
+ enum
+ {
+ DoPreOrder = true,
+ DoLclVarsOnly = true
+ };
+
+ IncLclVarRefCountsVisitor(Compiler* compiler);
+ Compiler::fgWalkResult PreOrderVisit(GenTree** use, GenTree* user);
+
+ static Compiler::fgWalkResult WalkTree(Compiler* compiler, GenTree* tree);
+};
+
+class DecLclVarRefCountsVisitor final : public GenTreeVisitor<DecLclVarRefCountsVisitor>
+{
+public:
+ enum
+ {
+ DoPreOrder = true,
+ DoLclVarsOnly = true
+ };
+
+ DecLclVarRefCountsVisitor(Compiler* compiler);
+ Compiler::fgWalkResult PreOrderVisit(GenTree** use, GenTree* user);
+
+ static Compiler::fgWalkResult WalkTree(Compiler* compiler, GenTree* tree);
+};
+
/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
actualValCopy = gtNewLargeOperNode(GT_ADD, TYP_INT);
}
- fgWalkTreePre(&tree, Compiler::lvaDecRefCntsCB, (void*)this, true);
+ DecLclVarRefCountsVisitor::WalkTree(this, tree);
actualValCopy->CopyFrom(actualVal, this);
actualValCopy->gtType = origType;
actualValCopy->LabelIndex(this);
}
- fgWalkTreePre(&actualValCopy, Compiler::lvaIncRefCntsCB, (void*)this, true);
+ IncLclVarRefCountsVisitor::WalkTree(this, actualValCopy);
if (actualValCopy != tree)
{
if (lvaLocalVarRefCounted)
{
compCurBB = addedToBlock;
- fgWalkTreePre(&clonedTree, Compiler::lvaIncRefCntsCB, (void*)this, true);
+ IncLclVarRefCountsVisitor::WalkTree(this, clonedTree);
}
}
*/
if (keptTree)
{
- fgWalkTreePre(&keptTree, Compiler::lvaIncRefCntsCB, (void*)this, true);
+ IncLclVarRefCountsVisitor::WalkTree(this, keptTree);
}
- fgWalkTreePre(&wholeTree, Compiler::lvaDecRefCntsCB, (void*)this, true);
+ DecLclVarRefCountsVisitor::WalkTree(this, wholeTree);
}
}
{
if (fgStmtListThreaded)
{
- fgWalkTreePre(&stmt->gtStmtExpr, Compiler::lvaDecRefCntsCB, (void*)this, true);
+ DecLclVarRefCountsVisitor::WalkTree(this, stmt->gtStmtExpr);
}
}
}
}
}
-/*****************************************************************************
- *
- * Callback used by the tree walker to call lvaDecRefCnts
- */
-Compiler::fgWalkResult Compiler::lvaDecRefCntsCB(GenTreePtr* pTree, fgWalkData* data)
-{
- data->compiler->lvaDecRefCnts(*pTree);
- return WALK_CONTINUE;
-}
-
// Decrement the ref counts for all locals contained in the tree and its children.
void Compiler::lvaRecursiveDecRefCounts(GenTreePtr tree)
{
}
else
{
- fgWalkTreePre(&tree, Compiler::lvaDecRefCntsCB, (void*)this, true);
+ DecLclVarRefCountsVisitor::WalkTree(this, tree);
}
}
-// Increment the ref counts for all locals contained in the tree and its children.
-void Compiler::lvaRecursiveIncRefCounts(GenTreePtr tree)
+DecLclVarRefCountsVisitor::DecLclVarRefCountsVisitor(Compiler* compiler)
+ : GenTreeVisitor<DecLclVarRefCountsVisitor>(compiler)
{
- assert(lvaLocalVarRefCounted);
+}
- // We could just use the recursive walker for all cases but that is a
- // fairly heavyweight thing to spin up when we're usually just handling a leaf.
- if (tree->OperIsLeaf())
- {
- if (tree->OperIsLocal())
- {
- lvaIncRefCnts(tree);
- }
- }
- else
- {
- fgWalkTreePre(&tree, Compiler::lvaIncRefCntsCB, (void*)this, true);
- }
+Compiler::fgWalkResult DecLclVarRefCountsVisitor::PreOrderVisit(GenTree** use, GenTree* user)
+{
+ m_compiler->lvaDecRefCnts(*use);
+ return fgWalkResult::WALK_CONTINUE;
+}
+
+Compiler::fgWalkResult DecLclVarRefCountsVisitor::WalkTree(Compiler* compiler, GenTree* tree)
+{
+ DecLclVarRefCountsVisitor visitor(compiler);
+ return static_cast<GenTreeVisitor<DecLclVarRefCountsVisitor>*>(&visitor)->WalkTree(&tree, nullptr);
}
/*****************************************************************************
}
}
-/*****************************************************************************
- *
- * Callback used by the tree walker to call lvaIncRefCnts
- */
-Compiler::fgWalkResult Compiler::lvaIncRefCntsCB(GenTreePtr* pTree, fgWalkData* data)
+// Increment the ref counts for all locals contained in the tree and its children.
+void Compiler::lvaRecursiveIncRefCounts(GenTreePtr tree)
{
- data->compiler->lvaIncRefCnts(*pTree);
- return WALK_CONTINUE;
+ assert(lvaLocalVarRefCounted);
+
+ // We could just use the recursive walker for all cases but that is a
+ // fairly heavyweight thing to spin up when we're usually just handling a leaf.
+ if (tree->OperIsLeaf())
+ {
+ if (tree->OperIsLocal())
+ {
+ lvaIncRefCnts(tree);
+ }
+ }
+ else
+ {
+ IncLclVarRefCountsVisitor::WalkTree(this, tree);
+ }
+}
+
+IncLclVarRefCountsVisitor::IncLclVarRefCountsVisitor(Compiler* compiler)
+ : GenTreeVisitor<IncLclVarRefCountsVisitor>(compiler)
+{
+}
+
+Compiler::fgWalkResult IncLclVarRefCountsVisitor::PreOrderVisit(GenTree** use, GenTree* user)
+{
+ m_compiler->lvaIncRefCnts(*use);
+ return fgWalkResult::WALK_CONTINUE;
+}
+
+Compiler::fgWalkResult IncLclVarRefCountsVisitor::WalkTree(Compiler* compiler, GenTree* tree)
+{
+ IncLclVarRefCountsVisitor visitor(compiler);
+ return static_cast<GenTreeVisitor<IncLclVarRefCountsVisitor>*>(&visitor)->WalkTree(&tree, nullptr);
}
/*****************************************************************************