Skip to content

Commit

Permalink
Add SSA support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andreenko committed Jun 29, 2020
1 parent 3965e9d commit f7a90a3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/coreclr/src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10342,9 +10342,6 @@ GenTree* Compiler::fgMorphCopyBlock(GenTree* tree)
if (varTypeIsStruct(varDsc) && varDsc->CanBeReplacedWithItsField(this))
{
JITDUMP(" not morphing a single reg call return\n");
// Set `lvIsMultiRegRet` to exclude it from SSA, it is a temporary solution,
// inspired by multi-reg call work. We should support SSA for such structs in the future.
varDsc->lvIsMultiRegRet = true;
return tree;
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/coreclr/src/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,12 @@ LclSsaVarDsc* RangeCheck::GetSsaDefAsg(GenTreeLclVarCommon* lclUse)
return nullptr;
}

LclSsaVarDsc* ssaDef = m_pCompiler->lvaGetDesc(lclUse)->GetPerSsaData(ssaNum);
LclVarDsc* varDsc = m_pCompiler->lvaGetDesc(lclUse);
if (varDsc->CanBeReplacedWithItsField(m_pCompiler))
{
varDsc = m_pCompiler->lvaGetDesc(varDsc->lvFieldLclStart);
}
LclSsaVarDsc* ssaDef = varDsc->GetPerSsaData(ssaNum);

// RangeCheck does not care about uninitialized variables.
if (ssaDef->GetAssignment() == nullptr)
Expand Down Expand Up @@ -472,6 +477,11 @@ LclSsaVarDsc* RangeCheck::GetSsaDefAsg(GenTreeLclVarCommon* lclUse)
#ifdef DEBUG
UINT64 RangeCheck::HashCode(unsigned lclNum, unsigned ssaNum)
{
LclVarDsc* varDsc = m_pCompiler->lvaGetDesc(lclNum);
if (varDsc->CanBeReplacedWithItsField(m_pCompiler))
{
lclNum = varDsc->lvFieldLclStart;
}
assert(ssaNum != SsaConfig::RESERVED_SSA_NUM);
return UINT64(lclNum) << 32 | ssaNum;
}
Expand Down Expand Up @@ -499,7 +509,8 @@ RangeCheck::Location* RangeCheck::GetDef(unsigned lclNum, unsigned ssaNum)

RangeCheck::Location* RangeCheck::GetDef(GenTreeLclVarCommon* lcl)
{
return GetDef(lcl->GetLclNum(), lcl->GetSsaNum());
unsigned lclNum = lcl->GetLclNum();
return GetDef(lclNum, lcl->GetSsaNum());
}

// Add the def location to the hash table.
Expand Down Expand Up @@ -546,7 +557,12 @@ void RangeCheck::MergeEdgeAssertions(GenTreeLclVarCommon* lcl, ASSERT_VALARG_TP
Limit limit(Limit::keUndef);
genTreeOps cmpOper = GT_NONE;

LclSsaVarDsc* ssaData = m_pCompiler->lvaTable[lcl->GetLclNum()].GetPerSsaData(lcl->GetSsaNum());
LclVarDsc* varDsc = m_pCompiler->lvaGetDesc(lcl);
if (varDsc->CanBeReplacedWithItsField(m_pCompiler))
{
varDsc = m_pCompiler->lvaGetDesc(varDsc->lvFieldLclStart);
}
LclSsaVarDsc* ssaData = varDsc->GetPerSsaData(lcl->GetSsaNum());
ValueNum normalLclVN = m_pCompiler->vnStore->VNConservativeNormalValue(ssaData->m_vnPair);

// Current assertion is of the form (i < len - cns) != 0
Expand Down
14 changes: 11 additions & 3 deletions src/coreclr/src/jit/ssabuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,15 @@ void SsaBuilder::RenameDef(GenTreeOp* asgNode, BasicBlock* block)

if (isLocal)
{
unsigned lclNum = lclNode->GetLclNum();
unsigned lclNum = lclNode->GetLclNum();
LclVarDsc* varDsc = m_pCompiler->lvaGetDesc(lclNum);

if (!m_pCompiler->lvaInSsa(lclNum) && varDsc->CanBeReplacedWithItsField(m_pCompiler))
{
lclNum = varDsc->lvFieldLclStart;
varDsc = m_pCompiler->lvaGetDesc(lclNum);
assert(isFullDef);
}

if (m_pCompiler->lvaInSsa(lclNum))
{
Expand All @@ -758,7 +766,7 @@ void SsaBuilder::RenameDef(GenTreeOp* asgNode, BasicBlock* block)
// This should have been marked as defintion.
assert((lclNode->gtFlags & GTF_VAR_DEF) != 0);

unsigned ssaNum = m_pCompiler->lvaGetDesc(lclNum)->lvPerSsaData.AllocSsaNum(m_allocator, block, asgNode);
unsigned ssaNum = varDsc->lvPerSsaData.AllocSsaNum(m_allocator, block, asgNode);

if (!isFullDef)
{
Expand Down Expand Up @@ -787,7 +795,7 @@ void SsaBuilder::RenameDef(GenTreeOp* asgNode, BasicBlock* block)
}

// If it's a SSA local then it cannot be address exposed and thus does not define SSA memory.
assert(!m_pCompiler->lvaVarAddrExposed(lclNode->GetLclNum()));
assert(!m_pCompiler->lvaVarAddrExposed(lclNum));
return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/src/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6859,6 +6859,12 @@ void Compiler::fgValueNumberTree(GenTree* tree)
unsigned lclNum = lcl->GetLclNum();
LclVarDsc* varDsc = &lvaTable[lclNum];

if (varDsc->CanBeReplacedWithItsField(this))
{
lclNum = varDsc->lvFieldLclStart;
varDsc = &lvaTable[lclNum];
}

// Do we have a Use (read) of the LclVar?
//
if ((lcl->gtFlags & GTF_VAR_DEF) == 0 ||
Expand Down

0 comments on commit f7a90a3

Please sign in to comment.