diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 383b0a7de5991cfd6eb55ff68354f2bbfc9cbd8b..8504476d2cdf6db64fff783831e1b1e9a6fb1ca0 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -5900,8 +5900,6 @@ private: // the variable is not enregistered, and is therefore not promoted independently. void fgLclFldAssign(unsigned lclNum); - static fgWalkPreFn gtHasLocalsWithAddrOpCB; - enum TypeProducerKind { TPK_Unknown = 0, // May not be a RuntimeType diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 5549a5166b38644f285d0643c99826f2ff4a7d7e..1e97a840a3263543a5590dbdaaac7526f16b8098 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -2724,48 +2724,49 @@ AGAIN: return result; } -struct AddrTakenDsc -{ - Compiler* comp; - bool hasAddrTakenLcl; -}; - -/* static */ -Compiler::fgWalkResult Compiler::gtHasLocalsWithAddrOpCB(GenTree** pTree, fgWalkData* data) +//------------------------------------------------------------------------------ +// gtHasLocalsWithAddrOp: +// Check if this tree contains locals with lvHasLdAddrOp or +// IsAddressExposed() flags set. Does a full tree walk. +// +// Paramters: +// tree - the tree +// +// Return Value: +// True if any sub tree is such a local. +// +bool Compiler::gtHasLocalsWithAddrOp(GenTree* tree) { - GenTree* tree = *pTree; - Compiler* comp = data->compiler; - - if (tree->gtOper == GT_LCL_VAR) + struct LocalsWithAddrOpVisitor : GenTreeVisitor { - const LclVarDsc* varDsc = comp->lvaGetDesc(tree->AsLclVarCommon()); - - if (varDsc->lvHasLdAddrOp || varDsc->IsAddressExposed()) + enum { - ((AddrTakenDsc*)data->pCallbackData)->hasAddrTakenLcl = true; - return WALK_ABORT; - } - } - - return WALK_CONTINUE; -} + DoPreOrder = true, + DoLclVarsOnly = true, + }; -/***************************************************************************** - * - * Return true if this tree contains locals with lvHasLdAddrOp or IsAddressExposed() - * flag(s) set. - */ + bool HasAddrTakenLocal = false; -bool Compiler::gtHasLocalsWithAddrOp(GenTree* tree) -{ - AddrTakenDsc desc; + LocalsWithAddrOpVisitor(Compiler* comp) : GenTreeVisitor(comp) + { + } - desc.comp = this; - desc.hasAddrTakenLcl = false; + fgWalkResult PreOrderVisit(GenTree** use, GenTree* user) + { + LclVarDsc* varDsc = m_compiler->lvaGetDesc((*use)->AsLclVarCommon()); + if (varDsc->lvHasLdAddrOp || varDsc->IsAddressExposed()) + { + HasAddrTakenLocal = true; + return WALK_ABORT; + } - fgWalkTreePre(&tree, gtHasLocalsWithAddrOpCB, &desc); + return WALK_CONTINUE; + } + }; - return desc.hasAddrTakenLcl; + LocalsWithAddrOpVisitor visitor(this); + visitor.WalkTree(&tree, nullptr); + return visitor.HasAddrTakenLocal; } #ifdef DEBUG