Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5908,8 +5908,6 @@ class Compiler
// 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
Expand Down
69 changes: 35 additions & 34 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,48 +2724,49 @@ bool GenTree::Compare(GenTree* op1, GenTree* op2, bool swapOK)
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<LocalsWithAddrOpVisitor>
{
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;
Comment thread
jakobbotsch marked this conversation as resolved.
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
Expand Down