Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
try iter without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andreenko committed May 27, 2017
1 parent 6b83771 commit ce7d18c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 71 deletions.
40 changes: 40 additions & 0 deletions src/jit/bitsetasshortlong.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,46 @@ class BitSetOps</*BitSetType*/ BitSetShortLongRep,
}
}
}

int NextElem()
{
#if BITSET_TRACK_OPCOUNTS
BitSetStaticsImpl::RecordOp(BitSetStaticsImpl::BSOP_NextBit);
#endif
DWORD nextBit;
BOOL hasBit;
for (;;)
{
#ifdef _HOST_64BIT_
static_assert_no_msg(sizeof(size_t) == 8);
hasBit = BitScanForward64(&nextBit, m_bits);
#else
static_assert_no_msg(sizeof(size_t) == 4);
hasBit = BitScanForward(&nextBit, m_bits);
#endif

// If there's a bit, doesn't matter if we're short or long.
if (m_bits != 0)
{
m_bits &= ~(((size_t)1) << nextBit); // clear bit we just found so we don't find it again
return m_bitNum + nextBit;
}
else
{
// Go to the next size_t bit element. For short bitsets, this will hit the end condition
// and exit.
++m_bs;
if (m_bs == m_bsEnd)
{
return -1;
}

// If we get here, it's not a short type, so get the next size_t element.
m_bitNum += sizeof(size_t) * BitSetSupport::BitsInByte;
m_bits = *m_bs;
}
}
}
};

friend class Iter;
Expand Down
12 changes: 6 additions & 6 deletions src/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
// Handle the dying vars first, then the newly live vars.
// This is because, in the RyuJIT backend case, they may occupy registers that
// will be occupied by another var that is newly live.
VARSET_ITER_INIT(this, deadIter, deadSet, deadVarIndex);
while (deadIter.NextElem(&deadVarIndex))
VarSetOps::Iter deadIter(this, deadSet);
for (int deadVarIndex = deadIter.NextElem(); deadVarIndex != -1; deadVarIndex = deadIter.NextElem())
{
unsigned varNum = lvaTrackedToVarNum[deadVarIndex];
varDsc = lvaTable + varNum;
Expand Down Expand Up @@ -1130,8 +1130,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
#endif // !LEGACY_BACKEND
}

VARSET_ITER_INIT(this, bornIter, bornSet, bornVarIndex);
while (bornIter.NextElem(&bornVarIndex))
VarSetOps::Iter bornIter(this, bornSet);
for (int bornVarIndex = bornIter.NextElem(); bornVarIndex != -1; bornVarIndex = bornIter.NextElem())
{
unsigned varNum = lvaTrackedToVarNum[bornVarIndex];
varDsc = lvaTable + varNum;
Expand Down Expand Up @@ -1300,8 +1300,8 @@ regMaskTP CodeGenInterface::genLiveMask(VARSET_VALARG_TP liveSet)

regMaskTP liveMask = 0;

VARSET_ITER_INIT(compiler, iter, liveSet, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, liveSet);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{

// If the variable is not enregistered, then it can't contribute to the liveMask
Expand Down
12 changes: 6 additions & 6 deletions src/jit/liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,8 @@ void Compiler::fgExtendDbgLifetimes()
/* Add statements initializing the vars, if there are any to initialize */
unsigned blockWeight = block->getBBWeight(this);

VARSET_ITER_INIT(this, iter, initVars, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(this, initVars);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
/* Create initialization tree */

Expand Down Expand Up @@ -1358,8 +1358,8 @@ bool Compiler::fgMarkIntf(VARSET_VALARG_TP varSet1, VARSET_VALARG_TP varSet2)
VarSetOps::Assign(this, fgMarkIntfUnionVS, varSet1);
VarSetOps::UnionD(this, fgMarkIntfUnionVS, varSet2);

VARSET_ITER_INIT(this, iter, fgMarkIntfUnionVS, refIndex);
while (iter.NextElem(&refIndex))
VarSetOps::Iter iter(this, fgMarkIntfUnionVS);
for (int refIndex = iter.NextElem(); refIndex != -1; refIndex = iter.NextElem())
{
// if varSet1 has this bit set then it interferes with varSet2
if (VarSetOps::IsMember(this, varSet1, refIndex))
Expand Down Expand Up @@ -1411,8 +1411,8 @@ bool Compiler::fgMarkIntf(VARSET_VALARG_TP varSet)

bool addedIntf = false; // This is set to true if we add any new interferences

VARSET_ITER_INIT(this, iter, varSet, refIndex);
while (iter.NextElem(&refIndex))
VarSetOps::Iter iter(this, varSet);
for (int refIndex = iter.NextElem(); refIndex != -1; refIndex = iter.NextElem())
{
// Calculate the set of new interference to add
VARSET_TP newIntf(VarSetOps::Diff(this, varSet, lvaVarIntf[refIndex]));
Expand Down
116 changes: 57 additions & 59 deletions src/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1813,8 +1813,8 @@ void LinearScan::recordVarLocationsAtStartOfBB(BasicBlock* bb)
VarToRegMap map = getInVarToRegMap(bb->bbNum);
unsigned count = 0;

VARSET_ITER_INIT(compiler, iter, bb->bbLiveIn, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, bb->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = &(compiler->lvaTable[varNum]);
Expand Down Expand Up @@ -1910,8 +1910,8 @@ void LinearScan::identifyCandidatesExceptionDataflow()
block as either volatile for non-GC ref types or as
'explicitly initialized' (volatile and must-init) for GC-ref types */

VARSET_ITER_INIT(compiler, iter, exceptVars, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, exceptVars);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = compiler->lvaTable + varNum;
Expand Down Expand Up @@ -2620,8 +2620,8 @@ void LinearScan::checkLastUses(BasicBlock* block)
VarSetOps::DiffD(compiler, temp, block->bbLiveIn);

{
VARSET_ITER_INIT(compiler, iter, temp, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, temp);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
if (compiler->lvaTable[varNum].lvLRACandidate)
Expand All @@ -2633,8 +2633,8 @@ void LinearScan::checkLastUses(BasicBlock* block)
}

{
VARSET_ITER_INIT(compiler, iter, temp2, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, temp2);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
if (compiler->lvaTable[varNum].lvLRACandidate)
Expand Down Expand Up @@ -2891,9 +2891,8 @@ bool LinearScan::buildKillPositionsForNode(GenTree* tree, LsraLocation currentLo
// to be done before making this change.
// if (!blockSequence[curBBSeqNum]->isRunRarely())
{

VARSET_ITER_INIT(compiler, iter, currentLiveVars, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, currentLiveVars);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = compiler->lvaTable + varNum;
Expand Down Expand Up @@ -3335,8 +3334,8 @@ LinearScan::buildUpperVectorSaveRefPositions(GenTree* tree, LsraLocation current
{
VarSetOps::AssignNoCopy(compiler, liveLargeVectors,
VarSetOps::Intersection(compiler, currentLiveVars, largeVectorVars));
VARSET_ITER_INIT(compiler, iter, liveLargeVectors, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, liveLargeVectors);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
Interval* varInterval = getIntervalForLocalVar(varIndex);
Interval* tempInterval = newInterval(LargeVectorType);
Expand All @@ -3361,8 +3360,8 @@ void LinearScan::buildUpperVectorRestoreRefPositions(GenTree* tree,
{
if (!VarSetOps::IsEmpty(compiler, liveLargeVectors))
{
VARSET_ITER_INIT(compiler, iter, liveLargeVectors, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, liveLargeVectors);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
Interval* varInterval = getIntervalForLocalVar(varIndex);
Interval* tempInterval = varInterval->relatedInterval;
Expand Down Expand Up @@ -4184,9 +4183,8 @@ BasicBlock* getNonEmptyBlock(BasicBlock* block)
void LinearScan::insertZeroInitRefPositions()
{
// insert defs for this, then a block boundary

VARSET_ITER_INIT(compiler, iter, compiler->fgFirstBB->bbLiveIn, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, compiler->fgFirstBB->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = compiler->lvaTable + varNum;
Expand Down Expand Up @@ -4644,8 +4642,9 @@ void LinearScan::buildIntervals()
assert(!predBlockIsAllocated);

JITDUMP("Creating dummy definitions\n");
VARSET_ITER_INIT(compiler, iter, newLiveIn, varIndex);
while (iter.NextElem(&varIndex))

VarSetOps::Iter iter(compiler, newLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = compiler->lvaTable + varNum;
Expand Down Expand Up @@ -4736,8 +4735,8 @@ void LinearScan::buildIntervals()
if (!VarSetOps::IsEmpty(compiler, expUseSet))
{
JITDUMP("Exposed uses:");
VARSET_ITER_INIT(compiler, iter, expUseSet, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, expUseSet);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = compiler->lvaTable + varNum;
Expand All @@ -4754,8 +4753,8 @@ void LinearScan::buildIntervals()

// Clear the "last use" flag on any vars that are live-out from this block.
{
VARSET_ITER_INIT(compiler, iter, block->bbLiveOut, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, block->bbLiveOut);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* const varDsc = &compiler->lvaTable[varNum];
Expand Down Expand Up @@ -6678,9 +6677,9 @@ void LinearScan::processBlockStartLocations(BasicBlock* currentBlock, bool alloc
// inactive registers available for the rotation.
regMaskTP inactiveRegs = RBM_NONE;
#endif // DEBUG
regMaskTP liveRegs = RBM_NONE;
VARSET_ITER_INIT(compiler, iter, *liveIn, varIndex);
while (iter.NextElem(&varIndex))
regMaskTP liveRegs = RBM_NONE;
VarSetOps::Iter iter(compiler, *liveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
if (!compiler->lvaTable[varNum].lvLRACandidate)
Expand Down Expand Up @@ -6900,9 +6899,9 @@ void LinearScan::processBlockEndLocations(BasicBlock* currentBlock)
liveOut = &compiler->lvaTrackedVars;
}
#endif // DEBUG
regMaskTP liveRegs = RBM_NONE;
VARSET_ITER_INIT(compiler, iter, *liveOut, varIndex);
while (iter.NextElem(&varIndex))
regMaskTP liveRegs = RBM_NONE;
VarSetOps::Iter iter(compiler, *liveOut);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
Interval* interval = getIntervalForLocalVar(varIndex);
if (interval->isActive)
Expand Down Expand Up @@ -9230,8 +9229,8 @@ regNumber LinearScan::getTempRegForResolution(BasicBlock* fromBlock, BasicBlock*
INDEBUG(freeRegs = stressLimitRegs(nullptr, freeRegs));

// We are only interested in the variables that are live-in to the "to" block.
VARSET_ITER_INIT(compiler, iter, toBlock->bbLiveIn, varIndex);
while (iter.NextElem(&varIndex) && freeRegs != RBM_NONE)
VarSetOps::Iter iter(compiler, toBlock->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber fromReg = fromVarToRegMap[varIndex];
regNumber toReg = toVarToRegMap[varIndex];
Expand Down Expand Up @@ -9346,11 +9345,11 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block)
// available to copy into.
// Note that for this purpose we use the full live-out set, because we must ensure that
// even the registers that remain the same across the edge are preserved correctly.
regMaskTP liveOutRegs = RBM_NONE;
VARSET_ITER_INIT(compiler, iter1, block->bbLiveOut, varIndex1);
while (iter1.NextElem(&varIndex1))
regMaskTP liveOutRegs = RBM_NONE;
VarSetOps::Iter iter(compiler, block->bbLiveOut);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber fromReg = getVarReg(outVarToRegMap, varIndex1);
regNumber fromReg = getVarReg(outVarToRegMap, varIndex);
if (fromReg != REG_STK)
{
liveOutRegs |= genRegMask(fromReg);
Expand Down Expand Up @@ -9389,8 +9388,8 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block)
// write to any registers that are read by those in the diffResolutionSet:
// sameResolutionSet

VARSET_ITER_INIT(compiler, iter, outResolutionSet, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter2(compiler, outResolutionSet);
for (int varIndex = iter2.NextElem(); varIndex != -1; varIndex = iter2.NextElem())
{
regNumber fromReg = getVarReg(outVarToRegMap, varIndex);
bool isMatch = true;
Expand Down Expand Up @@ -9515,8 +9514,8 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block)
bool needsResolution = false;
VarToRegMap succInVarToRegMap = getInVarToRegMap(succBlock->bbNum);
VARSET_TP edgeResolutionSet(VarSetOps::Intersection(compiler, diffResolutionSet, succBlock->bbLiveIn));
VARSET_ITER_INIT(compiler, iter, edgeResolutionSet, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, edgeResolutionSet);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber fromReg = getVarReg(outVarToRegMap, varIndex);
regNumber toReg = getVarReg(succInVarToRegMap, varIndex);
Expand Down Expand Up @@ -9715,10 +9714,10 @@ void LinearScan::resolveEdges()
VarToRegMap toVarToRegMap = getInVarToRegMap(block->bbNum);
for (flowList* pred = block->bbPreds; pred != nullptr; pred = pred->flNext)
{
BasicBlock* predBlock = pred->flBlock;
VarToRegMap fromVarToRegMap = getOutVarToRegMap(predBlock->bbNum);
VARSET_ITER_INIT(compiler, iter, block->bbLiveIn, varIndex);
while (iter.NextElem(&varIndex))
BasicBlock* predBlock = pred->flBlock;
VarToRegMap fromVarToRegMap = getOutVarToRegMap(predBlock->bbNum);
VarSetOps::Iter iter(compiler, block->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber fromReg = getVarReg(fromVarToRegMap, varIndex);
regNumber toReg = getVarReg(toVarToRegMap, varIndex);
Expand Down Expand Up @@ -9871,9 +9870,8 @@ void LinearScan::resolveEdge(BasicBlock* fromBlock,
// record the interval associated with the target reg
// TODO-Throughput: We should be looping over the liveIn and liveOut registers, since
// that will scale better than the live variables

VARSET_ITER_INIT(compiler, iter, liveSet, varIndex);
while (iter.NextElem(&varIndex))
VarSetOps::Iter iter(compiler, liveSet);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber fromReg = getVarReg(fromVarToRegMap, varIndex);
regNumber toReg = getVarReg(toVarToRegMap, varIndex);
Expand Down Expand Up @@ -11935,9 +11933,9 @@ void LinearScan::verifyFinalAllocation()
}

// Validate the locations at the end of the previous block.
VarToRegMap outVarToRegMap = outVarToRegMaps[currentBlock->bbNum];
VARSET_ITER_INIT(compiler, iter, currentBlock->bbLiveOut, varIndex);
while (iter.NextElem(&varIndex))
VarToRegMap outVarToRegMap = outVarToRegMaps[currentBlock->bbNum];
VarSetOps::Iter iter(compiler, currentBlock->bbLiveOut);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber regNum = getVarReg(outVarToRegMap, varIndex);
interval = getIntervalForLocalVar(varIndex);
Expand All @@ -11960,9 +11958,9 @@ void LinearScan::verifyFinalAllocation()

if (currentBlock != nullptr)
{
VarToRegMap inVarToRegMap = inVarToRegMaps[currentBlock->bbNum];
VARSET_ITER_INIT(compiler, iter, currentBlock->bbLiveIn, varIndex);
while (iter.NextElem(&varIndex))
VarToRegMap inVarToRegMap = inVarToRegMaps[currentBlock->bbNum];
VarSetOps::Iter iter(compiler, currentBlock->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber regNum = getVarReg(inVarToRegMap, varIndex);
interval = getIntervalForLocalVar(varIndex);
Expand Down Expand Up @@ -12201,9 +12199,9 @@ void LinearScan::verifyFinalAllocation()
}

// Set the incoming register assignments
VarToRegMap inVarToRegMap = getInVarToRegMap(currentBlock->bbNum);
VARSET_ITER_INIT(compiler, iter, currentBlock->bbLiveIn, varIndex);
while (iter.NextElem(&varIndex))
VarToRegMap inVarToRegMap = getInVarToRegMap(currentBlock->bbNum);
VarSetOps::Iter iter(compiler, currentBlock->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber regNum = getVarReg(inVarToRegMap, varIndex);
Interval* interval = getIntervalForLocalVar(varIndex);
Expand All @@ -12228,9 +12226,9 @@ void LinearScan::verifyFinalAllocation()

// Verify the outgoing register assignments
{
VarToRegMap outVarToRegMap = getOutVarToRegMap(currentBlock->bbNum);
VARSET_ITER_INIT(compiler, iter, currentBlock->bbLiveOut, varIndex);
while (iter.NextElem(&varIndex))
VarToRegMap outVarToRegMap = getOutVarToRegMap(currentBlock->bbNum);
VarSetOps::Iter iter(compiler, currentBlock->bbLiveOut);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
{
regNumber regNum = getVarReg(outVarToRegMap, varIndex);
Interval* interval = getIntervalForLocalVar(varIndex);
Expand Down

0 comments on commit ce7d18c

Please sign in to comment.