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

Commit

Permalink
use static const unsigned Done instead of -1 int.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andreenko committed Jun 15, 2017
1 parent 8a244ad commit 024e8ca
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 69 deletions.
18 changes: 9 additions & 9 deletions src/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void Compiler::optAddCopies()
bool isDominatedByFirstBB = false;

BlockSetOps::Iter iter(this, varDsc->lvRefBlks);
for (int blkNum = iter.NextElem(); blkNum != -1; blkNum = iter.NextElem())
for (int blkNum = iter.NextElem(); blkNum != BlockSetOps::Iter::Done; blkNum = iter.NextElem())
{
/* Find the block 'blkNum' */
BasicBlock* block = fgFirstBB;
Expand Down Expand Up @@ -322,7 +322,7 @@ void Compiler::optAddCopies()
/* We have already calculated paramImportantUseDom above. */

BlockSetOps::Iter iter(this, paramImportantUseDom);
for (int blkNum = iter.NextElem(); blkNum != -1; blkNum = iter.NextElem())
for (int blkNum = iter.NextElem(); blkNum != BlockSetOps::Iter::Done; blkNum = iter.NextElem())
{
/* Advance block to point to 'blkNum' */
/* This assumes that the iterator returns block number is increasing lexical order. */
Expand Down Expand Up @@ -2852,7 +2852,7 @@ GenTreePtr Compiler::optAssertionProp_LclVar(ASSERT_VALARG_TP assertions, const
}

BitVecOps::Iter iter(apTraits, assertions);
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
for (int i = iter.NextElem(); i != BitVecOps::Iter::Done; i = iter.NextElem())
{
AssertionIndex index = GetAssertionIndex(i);
if (index > optAssertionCount)
Expand Down Expand Up @@ -2971,7 +2971,7 @@ AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqual(ASSERT_VALARG_TP as
return NO_ASSERTION_INDEX;
}
BitVecOps::Iter iter(apTraits, assertions);
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
for (int i = iter.NextElem(); i != BitVecOps::Iter::Done; i = iter.NextElem())
{
AssertionIndex index = GetAssertionIndex(i);
if (index > optAssertionCount)
Expand Down Expand Up @@ -3531,7 +3531,7 @@ AssertionIndex Compiler::optAssertionIsNonNullInternal(GenTreePtr op, ASSERT_VAL

// Check each assertion to find if we have a vn == or != null assertion.
BitVecOps::Iter iter(apTraits, assertions);
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
for (int i = iter.NextElem(); i != BitVecOps::Iter::Done; i = iter.NextElem())
{
AssertionIndex index = GetAssertionIndex(i);
if (index > optAssertionCount)
Expand Down Expand Up @@ -3704,7 +3704,7 @@ GenTreePtr Compiler::optAssertionProp_BndsChk(ASSERT_VALARG_TP assertions, const
#endif // FEATURE_ENABLE_NO_RANGE_CHECKS

BitVecOps::Iter iter(apTraits, assertions);
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
for (int i = iter.NextElem(); i != BitVecOps::Iter::Done; i = iter.NextElem())
{
AssertionIndex index = GetAssertionIndex(i);
if (index > optAssertionCount)
Expand Down Expand Up @@ -3956,7 +3956,7 @@ void Compiler::optImpliedAssertions(AssertionIndex assertionIndex, ASSERT_TP& ac

// Check each assertion in chkAssertions to see if it can be applied to curAssertion
BitVecOps::Iter chkIter(apTraits, chkAssertions);
for (int i = chkIter.NextElem(); i != -1; i = chkIter.NextElem())
for (int i = chkIter.NextElem(); i != BitVecOps::Iter::Done; i = chkIter.NextElem())
{
AssertionIndex chkIndex = GetAssertionIndex(i);
if (chkIndex > optAssertionCount)
Expand Down Expand Up @@ -4004,7 +4004,7 @@ void Compiler::optImpliedByTypeOfAssertions(ASSERT_TP& activeAssertions)

// Check each assertion in activeAssertions to see if it can be applied to constAssertion
BitVecOps::Iter chkIter(apTraits, activeAssertions);
for (int i = chkIter.NextElem(); i != -1; i = chkIter.NextElem())
for (int i = chkIter.NextElem(); i != BitVecOps::Iter::Done; i = chkIter.NextElem())
{
AssertionIndex chkIndex = GetAssertionIndex(i);
if (chkIndex > optAssertionCount)
Expand Down Expand Up @@ -4100,7 +4100,7 @@ void Compiler::optImpliedByConstAssertion(AssertionDsc* constAssertion, ASSERT_T

// Check each assertion in chkAssertions to see if it can be applied to constAssertion
BitVecOps::Iter chkIter(apTraits, chkAssertions);
for (int i = chkIter.NextElem(); i != -1; i = chkIter.NextElem())
for (int i = chkIter.NextElem(); i != BitVecOps::Iter::Done; i = chkIter.NextElem())
{
AssertionIndex chkIndex = GetAssertionIndex(i);
if (chkIndex > optAssertionCount)
Expand Down
8 changes: 4 additions & 4 deletions src/jit/bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void BitSetSupport::RunTests(Env env)

typename LclBitSetOps::Iter bsi(env, bs1);
unsigned k = 0;
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
{
assert(bitNum == bs1bits[k]);
k++;
Expand All @@ -62,7 +62,7 @@ void BitSetSupport::RunTests(Env env)
LclBitSetOps::AssignNoCopy(env, bsU12, LclBitSetOps::Union(env, bs1, bs2));
k = 0;
bsi = typename LclBitSetOps::Iter(env, bsU12);
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
{
assert(bitNum == unionBits[k]);
k++;
Expand All @@ -71,7 +71,7 @@ void BitSetSupport::RunTests(Env env)

k = 0;
typename LclBitSetOps::Iter bsiL = typename LclBitSetOps::Iter(env, bsU12);
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
{
assert(bitNum == unionBits[k]);
k++;
Expand All @@ -83,7 +83,7 @@ void BitSetSupport::RunTests(Env env)
LclBitSetOps::AssignNoCopy(env, bsI12, LclBitSetOps::Intersection(env, bs1, bs2));
k = 0;
bsi = typename LclBitSetOps::Iter(env, bsI12);
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
{
assert(bitNum == intersectionBits[k]);
k++;
Expand Down
12 changes: 8 additions & 4 deletions src/jit/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ FORCEINLINE unsigned BitSetSupport::CountBitsInIntegral<unsigned>(unsigned c)
// In addition to implementing the method signatures here, an instantiation of BitSetOps must also export a
// BitSetOps::Iter type, which supports the following operations:
// Iter(BitSetValueArgType): a constructor
// int NextElem(): returns the next yielded member if the iteration is not complete,
// or returns -1 if it is.
// unsigned NextElem(): returns the next yielded member if the iteration is not complete,
// or returns Done if it is.
// static const unsigned Done = (unsigned)-1;
//
// Finally, it should export two further types:
//
Expand Down Expand Up @@ -279,7 +280,8 @@ class BitSetOps
class Iter {
public:
Iter(Env env, BitSetValueArgType bs) {}
int NextElem() { return -1; }
static const unsigned Done = (unsigned)-1;
unsigned NextElem() { return Done; }
};

typename ValArgType;
Expand Down Expand Up @@ -451,7 +453,9 @@ class BitSetOpsWithCounter
{
}

int NextElem()
static const unsigned Done = (unsigned)-1;

unsigned NextElem()
{
BitSetTraits::GetOpCounter(m_env)->RecordOp(BitSetSupport::BSOP_NextBit);
return m_iter.NextElem();
Expand Down
4 changes: 3 additions & 1 deletion src/jit/bitsetasshortlong.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ class BitSetOps</*BitSetType*/ BitSetShortLongRep,
}
}

int NextElem()
static const unsigned Done = (unsigned)-1;

unsigned NextElem()
{
#if BITSET_TRACK_OPCOUNTS
BitSetStaticsImpl::RecordOp(BitSetStaticsImpl::BSOP_NextBit);
Expand Down
6 changes: 4 additions & 2 deletions src/jit/bitsetasuint64.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ class BitSetOps</*BitSetType*/ UINT64,
{
}

int NextElem()
static const unsigned Done = (unsigned)-1;

unsigned NextElem()
{
// TODO-Throughtput: use BitScanForward64() intrinsic (see short/long implementation).
if (m_bits)
Expand All @@ -242,7 +244,7 @@ class BitSetOps</*BitSetType*/ UINT64,
}
else
{
return -1;
return Done;
}
}
};
Expand Down
6 changes: 4 additions & 2 deletions src/jit/bitsetasuint64inclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ class BitSetOps</*BitSetType*/ BitSetUint64<Env, BitSetTraits>,
{
}

int NextElem()
static const unsigned Done = (unsigned)-1;

unsigned NextElem()
{
static const unsigned UINT64_SIZE = 64;

Expand Down Expand Up @@ -500,7 +502,7 @@ class BitSetOps</*BitSetType*/ BitSetUint64<Env, BitSetTraits>,
}
else
{
return -1;
return Done;
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
// This is because, in the RyuJIT backend case, they may occupy registers that
// will be occupied by another var that is newly live.
VarSetOps::Iter deadIter(this, deadSet);
for (int deadVarIndex = deadIter.NextElem(); deadVarIndex != -1; deadVarIndex = deadIter.NextElem())
for (int deadVarIndex = deadIter.NextElem(); deadVarIndex != VarSetOps::Iter::Done;
deadVarIndex = deadIter.NextElem())
{
unsigned varNum = lvaTrackedToVarNum[deadVarIndex];
varDsc = lvaTable + varNum;
Expand Down Expand Up @@ -1135,7 +1136,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
}

VarSetOps::Iter bornIter(this, bornSet);
for (int bornVarIndex = bornIter.NextElem(); bornVarIndex != -1; bornVarIndex = bornIter.NextElem())
for (int bornVarIndex = bornIter.NextElem(); bornVarIndex != VarSetOps::Iter::Done;
bornVarIndex = bornIter.NextElem())
{
unsigned varNum = lvaTrackedToVarNum[bornVarIndex];
varDsc = lvaTable + varNum;
Expand Down Expand Up @@ -1305,7 +1307,7 @@ regMaskTP CodeGenInterface::genLiveMask(VARSET_VALARG_TP liveSet)
regMaskTP liveMask = 0;

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

// If the variable is not enregistered, then it can't contribute to the liveMask
Expand Down
8 changes: 4 additions & 4 deletions src/jit/codegenlegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void CodeGen::genDyingVars(VARSET_VALARG_TP beforeSet, VARSET_VALARG_TP afterSet
/* iterate through the dead variables */

VarSetOps::Iter iter(compiler, deadSet);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
{
varNum = compiler->lvaTrackedToVarNum[varIndex];
varDsc = compiler->lvaTable + varNum;
Expand Down Expand Up @@ -5632,7 +5632,7 @@ void CodeGen::genCodeForQmark(GenTreePtr tree, regMaskTP destReg, regMaskTP best
VARSET_TP regVarLiveNow(VarSetOps::Intersection(compiler, compiler->raRegVarsMask, rsLiveNow));

VarSetOps::Iter iter(compiler, regVarLiveNow);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
{
// Find the variable in compiler->lvaTable
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
Expand Down Expand Up @@ -12580,7 +12580,7 @@ void CodeGen::genCodeForBBlist()
noway_assert((specialUseMask & regSet.rsMaskVars) == 0);

VarSetOps::Iter iter(compiler, liveSet);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
{
varNum = compiler->lvaTrackedToVarNum[varIndex];
varDsc = compiler->lvaTable + varNum;
Expand Down Expand Up @@ -15238,7 +15238,7 @@ unsigned CodeGen::genRegCountForLiveIntEnregVars(GenTreePtr tree)
unsigned regCount = 0;

VarSetOps::Iter iter(compiler, compiler->compCurLife);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
{
unsigned lclNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = &compiler->lvaTable[lclNum];
Expand Down
4 changes: 2 additions & 2 deletions src/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void CodeGen::genCodeForBBlist()
VARSET_TP addedGCVars(VarSetOps::MakeEmpty(compiler));
#endif
VarSetOps::Iter iter(compiler, block->bbLiveIn);
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
LclVarDsc* varDsc = &(compiler->lvaTable[varNum]);
Expand Down Expand Up @@ -502,7 +502,7 @@ void CodeGen::genCodeForBBlist()
VARSET_TP extraLiveVars(VarSetOps::Diff(compiler, block->bbLiveOut, compiler->compCurLife));
VarSetOps::UnionD(compiler, extraLiveVars, VarSetOps::Diff(compiler, compiler->compCurLife, block->bbLiveOut));
VarSetOps::Iter extraLiveVarIter(compiler, extraLiveVars);
for (int i = extraLiveVarIter.NextElem(); i != -1; i = extraLiveVarIter.NextElem())
for (int i = extraLiveVarIter.NextElem(); i != VarSetOps::Iter::Done; i = extraLiveVarIter.NextElem())
{
unsigned varNum = compiler->lvaTrackedToVarNum[i];
LclVarDsc* varDsc = compiler->lvaTable + varNum;
Expand Down
2 changes: 1 addition & 1 deletion src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8298,7 +8298,7 @@ void dumpConvertedVarSet(Compiler* comp, VARSET_VALARG_TP vars)
memset(pVarNumSet, 0, varNumSetBytes); // empty the set

VarSetOps::Iter iter(comp, vars);
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
for (int i = iter.NextElem(); i != VarSetOps::Iter::Done; i = iter.NextElem())
{
unsigned varNum = comp->lvaTrackedToVarNum[i];
assert(varNum < comp->lvaCount);
Expand Down
6 changes: 3 additions & 3 deletions src/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ void Compiler::fgComputeEnterBlocksSet()
{
printf("Enter blocks: ");
BlockSetOps::Iter iter(this, fgEnterBlks);
for (int bbNum = iter.NextElem(); bbNum != -1; bbNum = iter.NextElem())
for (int bbNum = iter.NextElem(); bbNum != BlockSetOps::Iter::Done; bbNum = iter.NextElem())
{
printf("BB%02u ", bbNum);
}
Expand Down Expand Up @@ -2286,7 +2286,7 @@ BlockSet_ValRet_T Compiler::fgDomFindStartNodes()
{
printf("\nDominator computation start blocks (those blocks with no incoming edges):\n");
BlockSetOps::Iter iter(this, startNodes);
for (int bbNum = iter.NextElem(); bbNum != -1; bbNum = iter.NextElem())
for (int bbNum = iter.NextElem(); bbNum != BlockSetOps::Iter::Done; bbNum = iter.NextElem())
{
printf("BB%02u ", bbNum);
}
Expand Down Expand Up @@ -19597,7 +19597,7 @@ void Compiler::fgDispReach()
{
printf("BB%02u : ", block->bbNum);
BlockSetOps::Iter iter(this, block->bbReach);
for (int bbNum = iter.NextElem(); bbNum != -1; bbNum = iter.NextElem())
for (int bbNum = iter.NextElem(); bbNum != BlockSetOps::Iter::Done; bbNum = iter.NextElem())
{
printf("BB%02u ", bbNum);
}
Expand Down
6 changes: 3 additions & 3 deletions src/jit/liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ void Compiler::fgExtendDbgLifetimes()
unsigned blockWeight = block->getBBWeight(this);

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

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

VarSetOps::Iter iter(this, fgMarkIntfUnionVS);
for (int refIndex = iter.NextElem(); refIndex != -1; refIndex = iter.NextElem())
for (int refIndex = iter.NextElem(); refIndex != VarSetOps::Iter::Done; refIndex = iter.NextElem())
{
// if varSet1 has this bit set then it interferes with varSet2
if (VarSetOps::IsMember(this, varSet1, refIndex))
Expand Down Expand Up @@ -1412,7 +1412,7 @@ bool Compiler::fgMarkIntf(VARSET_VALARG_TP varSet)
bool addedIntf = false; // This is set to true if we add any new interferences

VarSetOps::Iter iter(this, varSet);
for (int refIndex = iter.NextElem(); refIndex != -1; refIndex = iter.NextElem())
for (int refIndex = iter.NextElem(); refIndex != VarSetOps::Iter::Done; refIndex = iter.NextElem())
{
// Calculate the set of new interference to add
VARSET_TP newIntf(VarSetOps::Diff(this, varSet, lvaVarIntf[refIndex]));
Expand Down
Loading

0 comments on commit 024e8ca

Please sign in to comment.