Skip to content

Commit

Permalink
Convert JitHashTable iteration to range-based for (#80265)
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceForstall committed Jan 6, 2023
1 parent 1808d1c commit 42a82dd
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 241 deletions.
6 changes: 2 additions & 4 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,11 +1926,9 @@ void Compiler::optPrintVnAssertionMapping()
{
printf("\nVN Assertion Mapping\n");
printf("---------------------\n");
for (ValueNumToAssertsMap::KeyIterator ki = optValueNumToAsserts->Begin(); !ki.Equal(optValueNumToAsserts->End());
++ki)
for (ValueNumToAssertsMap::Node* const iter : ValueNumToAssertsMap::KeyValueIteration(optValueNumToAsserts))
{
printf("(%d => ", ki.Get());
printf("%s)\n", BitVecOps::ToString(apTraits, ki.GetValue()));
printf("(%d => %s)\n", iter->GetKey(), BitVecOps::ToString(apTraits, iter->GetValue()));
}
}
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,11 +1226,10 @@ void DisplayNowayAssertMap()
NowayAssertCountMap* nacp = new NowayAssertCountMap[count];
unsigned i = 0;

for (FileLineToCountMap::KeyIterator iter = NowayAssertMap->Begin(), end = NowayAssertMap->End();
!iter.Equal(end); ++iter)
for (FileLineToCountMap::Node* const iter : FileLineToCountMap::KeyValueIteration(NowayAssertMap))
{
nacp[i].count = iter.GetValue();
nacp[i].fl = iter.Get();
nacp[i].count = iter->GetValue();
nacp[i].fl = iter->GetKey();
++i;
}

Expand Down
20 changes: 10 additions & 10 deletions src/coreclr/jit/copyprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ void Compiler::optBlockCopyPropPopStacks(BasicBlock* block, LclNumToLiveDefsMap*
void Compiler::optDumpCopyPropStack(LclNumToLiveDefsMap* curSsaName)
{
JITDUMP("{ ");
for (LclNumToLiveDefsMap::KeyIterator iter = curSsaName->Begin(); !iter.Equal(curSsaName->End()); ++iter)
for (LclNumToLiveDefsMap::Node* const iter : LclNumToLiveDefsMap::KeyValueIteration(curSsaName))
{
unsigned defLclNum = iter.Get();
GenTreeLclVarCommon* lclDefNode = iter.GetValue()->Top().GetDefNode()->AsLclVarCommon();
LclSsaVarDsc* ssaDef = iter.GetValue()->Top().GetSsaDef();
unsigned defLclNum = iter->GetKey();
GenTreeLclVarCommon* lclDefNode = iter->GetValue()->Top().GetDefNode()->AsLclVarCommon();
LclSsaVarDsc* ssaDef = iter->GetValue()->Top().GetSsaDef();

if (ssaDef != nullptr)
{
Expand Down Expand Up @@ -165,17 +165,17 @@ bool Compiler::optCopyProp(
ValueNum lclDefVN = varDsc->GetPerSsaData(tree->GetSsaNum())->m_vnPair.GetConservative();
assert(lclDefVN != ValueNumStore::NoVN);

for (LclNumToLiveDefsMap::KeyIterator iter = curSsaName->Begin(); !iter.Equal(curSsaName->End()); ++iter)
for (LclNumToLiveDefsMap::Node* const iter : LclNumToLiveDefsMap::KeyValueIteration(curSsaName))
{
unsigned newLclNum = iter.Get();
unsigned newLclNum = iter->GetKey();

// Nothing to do if same.
if (lclNum == newLclNum)
{
continue;
}

CopyPropSsaDef newLclDef = iter.GetValue()->Top();
CopyPropSsaDef newLclDef = iter->GetValue()->Top();
LclSsaVarDsc* const newLclSsaDef = newLclDef.GetSsaDef();

// Likewise, nothing to do if the most recent def is not available.
Expand Down Expand Up @@ -494,12 +494,12 @@ PhaseStatus Compiler::optVnCopyProp()

#ifdef DEBUG
// Verify the definitions remaining are only those we pushed for parameters.
for (LclNumToLiveDefsMap::KeyIterator iter = m_curSsaName.Begin(); !iter.Equal(m_curSsaName.End()); ++iter)
for (LclNumToLiveDefsMap::Node* const iter : LclNumToLiveDefsMap::KeyValueIteration(&m_curSsaName))
{
unsigned lclNum = iter.Get();
unsigned lclNum = iter->GetKey();
assert(m_compiler->lvaGetDesc(lclNum)->lvIsParam || (lclNum == m_compiler->info.compThisArg));

CopyPropSsaDefStack* defStack = iter.GetValue();
CopyPropSsaDefStack* defStack = iter->GetValue();
assert(defStack->Height() == 1);
}
#endif // DEBUG
Expand Down
10 changes: 4 additions & 6 deletions src/coreclr/jit/fgehopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,14 +2121,12 @@ PhaseStatus Compiler::fgTailMergeThrows()
// Second pass.
//
// We walk the map rather than the block list, to save a bit of time.
BlockToBlockMap::KeyIterator iter(blockMap.Begin());
BlockToBlockMap::KeyIterator end(blockMap.End());
unsigned updateCount = 0;
unsigned updateCount = 0;

for (; !iter.Equal(end); iter++)
for (BlockToBlockMap::Node* const iter : BlockToBlockMap::KeyValueIteration(&blockMap))
{
BasicBlock* const nonCanonicalBlock = iter.Get();
BasicBlock* const canonicalBlock = iter.GetValue();
BasicBlock* const nonCanonicalBlock = iter->GetKey();
BasicBlock* const canonicalBlock = iter->GetValue();
flowList* nextPredEdge = nullptr;
bool updated = false;

Expand Down
Loading

0 comments on commit 42a82dd

Please sign in to comment.