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

Commit 024e8ca

Browse files
author
Sergey Andreenko
committed
use static const unsigned Done instead of -1 int.
1 parent 8a244ad commit 024e8ca

17 files changed

+87
-69
lines changed

src/jit/assertionprop.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void Compiler::optAddCopies()
169169
bool isDominatedByFirstBB = false;
170170

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

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

28542854
BitVecOps::Iter iter(apTraits, assertions);
2855-
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
2855+
for (int i = iter.NextElem(); i != BitVecOps::Iter::Done; i = iter.NextElem())
28562856
{
28572857
AssertionIndex index = GetAssertionIndex(i);
28582858
if (index > optAssertionCount)
@@ -2971,7 +2971,7 @@ AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqual(ASSERT_VALARG_TP as
29712971
return NO_ASSERTION_INDEX;
29722972
}
29732973
BitVecOps::Iter iter(apTraits, assertions);
2974-
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
2974+
for (int i = iter.NextElem(); i != BitVecOps::Iter::Done; i = iter.NextElem())
29752975
{
29762976
AssertionIndex index = GetAssertionIndex(i);
29772977
if (index > optAssertionCount)
@@ -3531,7 +3531,7 @@ AssertionIndex Compiler::optAssertionIsNonNullInternal(GenTreePtr op, ASSERT_VAL
35313531

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

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

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

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

41014101
// Check each assertion in chkAssertions to see if it can be applied to constAssertion
41024102
BitVecOps::Iter chkIter(apTraits, chkAssertions);
4103-
for (int i = chkIter.NextElem(); i != -1; i = chkIter.NextElem())
4103+
for (int i = chkIter.NextElem(); i != BitVecOps::Iter::Done; i = chkIter.NextElem())
41044104
{
41054105
AssertionIndex chkIndex = GetAssertionIndex(i);
41064106
if (chkIndex > optAssertionCount)

src/jit/bitset.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void BitSetSupport::RunTests(Env env)
3838

3939
typename LclBitSetOps::Iter bsi(env, bs1);
4040
unsigned k = 0;
41-
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
41+
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
4242
{
4343
assert(bitNum == bs1bits[k]);
4444
k++;
@@ -62,7 +62,7 @@ void BitSetSupport::RunTests(Env env)
6262
LclBitSetOps::AssignNoCopy(env, bsU12, LclBitSetOps::Union(env, bs1, bs2));
6363
k = 0;
6464
bsi = typename LclBitSetOps::Iter(env, bsU12);
65-
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
65+
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
6666
{
6767
assert(bitNum == unionBits[k]);
6868
k++;
@@ -71,7 +71,7 @@ void BitSetSupport::RunTests(Env env)
7171

7272
k = 0;
7373
typename LclBitSetOps::Iter bsiL = typename LclBitSetOps::Iter(env, bsU12);
74-
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
74+
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
7575
{
7676
assert(bitNum == unionBits[k]);
7777
k++;
@@ -83,7 +83,7 @@ void BitSetSupport::RunTests(Env env)
8383
LclBitSetOps::AssignNoCopy(env, bsI12, LclBitSetOps::Intersection(env, bs1, bs2));
8484
k = 0;
8585
bsi = typename LclBitSetOps::Iter(env, bsI12);
86-
for (int bitNum = bsi.NextElem(); bitNum != -1; bitNum = bsi.NextElem())
86+
for (int bitNum = bsi.NextElem(); bitNum != LclBitSetOps::Iter::Done; bitNum = bsi.NextElem())
8787
{
8888
assert(bitNum == intersectionBits[k]);
8989
k++;

src/jit/bitset.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ FORCEINLINE unsigned BitSetSupport::CountBitsInIntegral<unsigned>(unsigned c)
147147
// In addition to implementing the method signatures here, an instantiation of BitSetOps must also export a
148148
// BitSetOps::Iter type, which supports the following operations:
149149
// Iter(BitSetValueArgType): a constructor
150-
// int NextElem(): returns the next yielded member if the iteration is not complete,
151-
// or returns -1 if it is.
150+
// unsigned NextElem(): returns the next yielded member if the iteration is not complete,
151+
// or returns Done if it is.
152+
// static const unsigned Done = (unsigned)-1;
152153
//
153154
// Finally, it should export two further types:
154155
//
@@ -279,7 +280,8 @@ class BitSetOps
279280
class Iter {
280281
public:
281282
Iter(Env env, BitSetValueArgType bs) {}
282-
int NextElem() { return -1; }
283+
static const unsigned Done = (unsigned)-1;
284+
unsigned NextElem() { return Done; }
283285
};
284286

285287
typename ValArgType;
@@ -451,7 +453,9 @@ class BitSetOpsWithCounter
451453
{
452454
}
453455

454-
int NextElem()
456+
static const unsigned Done = (unsigned)-1;
457+
458+
unsigned NextElem()
455459
{
456460
BitSetTraits::GetOpCounter(m_env)->RecordOp(BitSetSupport::BSOP_NextBit);
457461
return m_iter.NextElem();

src/jit/bitsetasshortlong.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ class BitSetOps</*BitSetType*/ BitSetShortLongRep,
495495
}
496496
}
497497

498-
int NextElem()
498+
static const unsigned Done = (unsigned)-1;
499+
500+
unsigned NextElem()
499501
{
500502
#if BITSET_TRACK_OPCOUNTS
501503
BitSetStaticsImpl::RecordOp(BitSetStaticsImpl::BSOP_NextBit);

src/jit/bitsetasuint64.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ class BitSetOps</*BitSetType*/ UINT64,
225225
{
226226
}
227227

228-
int NextElem()
228+
static const unsigned Done = (unsigned)-1;
229+
230+
unsigned NextElem()
229231
{
230232
// TODO-Throughtput: use BitScanForward64() intrinsic (see short/long implementation).
231233
if (m_bits)
@@ -242,7 +244,7 @@ class BitSetOps</*BitSetType*/ UINT64,
242244
}
243245
else
244246
{
245-
return -1;
247+
return Done;
246248
}
247249
}
248250
};

src/jit/bitsetasuint64inclass.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ class BitSetOps</*BitSetType*/ BitSetUint64<Env, BitSetTraits>,
471471
{
472472
}
473473

474-
int NextElem()
474+
static const unsigned Done = (unsigned)-1;
475+
476+
unsigned NextElem()
475477
{
476478
static const unsigned UINT64_SIZE = 64;
477479

@@ -500,7 +502,7 @@ class BitSetOps</*BitSetType*/ BitSetUint64<Env, BitSetTraits>,
500502
}
501503
else
502504
{
503-
return -1;
505+
return Done;
504506
}
505507
}
506508
}

src/jit/codegencommon.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
11001100
// This is because, in the RyuJIT backend case, they may occupy registers that
11011101
// will be occupied by another var that is newly live.
11021102
VarSetOps::Iter deadIter(this, deadSet);
1103-
for (int deadVarIndex = deadIter.NextElem(); deadVarIndex != -1; deadVarIndex = deadIter.NextElem())
1103+
for (int deadVarIndex = deadIter.NextElem(); deadVarIndex != VarSetOps::Iter::Done;
1104+
deadVarIndex = deadIter.NextElem())
11041105
{
11051106
unsigned varNum = lvaTrackedToVarNum[deadVarIndex];
11061107
varDsc = lvaTable + varNum;
@@ -1135,7 +1136,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
11351136
}
11361137

11371138
VarSetOps::Iter bornIter(this, bornSet);
1138-
for (int bornVarIndex = bornIter.NextElem(); bornVarIndex != -1; bornVarIndex = bornIter.NextElem())
1139+
for (int bornVarIndex = bornIter.NextElem(); bornVarIndex != VarSetOps::Iter::Done;
1140+
bornVarIndex = bornIter.NextElem())
11391141
{
11401142
unsigned varNum = lvaTrackedToVarNum[bornVarIndex];
11411143
varDsc = lvaTable + varNum;
@@ -1305,7 +1307,7 @@ regMaskTP CodeGenInterface::genLiveMask(VARSET_VALARG_TP liveSet)
13051307
regMaskTP liveMask = 0;
13061308

13071309
VarSetOps::Iter iter(compiler, liveSet);
1308-
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
1310+
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
13091311
{
13101312

13111313
// If the variable is not enregistered, then it can't contribute to the liveMask

src/jit/codegenlegacy.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void CodeGen::genDyingVars(VARSET_VALARG_TP beforeSet, VARSET_VALARG_TP afterSet
5353
/* iterate through the dead variables */
5454

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

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

1258212582
VarSetOps::Iter iter(compiler, liveSet);
12583-
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
12583+
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
1258412584
{
1258512585
varNum = compiler->lvaTrackedToVarNum[varIndex];
1258612586
varDsc = compiler->lvaTable + varNum;
@@ -15238,7 +15238,7 @@ unsigned CodeGen::genRegCountForLiveIntEnregVars(GenTreePtr tree)
1523815238
unsigned regCount = 0;
1523915239

1524015240
VarSetOps::Iter iter(compiler, compiler->compCurLife);
15241-
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
15241+
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
1524215242
{
1524315243
unsigned lclNum = compiler->lvaTrackedToVarNum[varIndex];
1524415244
LclVarDsc* varDsc = &compiler->lvaTable[lclNum];

src/jit/codegenlinear.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void CodeGen::genCodeForBBlist()
170170
VARSET_TP addedGCVars(VarSetOps::MakeEmpty(compiler));
171171
#endif
172172
VarSetOps::Iter iter(compiler, block->bbLiveIn);
173-
for (int varIndex = iter.NextElem(); varIndex != -1; varIndex = iter.NextElem())
173+
for (int varIndex = iter.NextElem(); varIndex != VarSetOps::Iter::Done; varIndex = iter.NextElem())
174174
{
175175
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
176176
LclVarDsc* varDsc = &(compiler->lvaTable[varNum]);
@@ -502,7 +502,7 @@ void CodeGen::genCodeForBBlist()
502502
VARSET_TP extraLiveVars(VarSetOps::Diff(compiler, block->bbLiveOut, compiler->compCurLife));
503503
VarSetOps::UnionD(compiler, extraLiveVars, VarSetOps::Diff(compiler, compiler->compCurLife, block->bbLiveOut));
504504
VarSetOps::Iter extraLiveVarIter(compiler, extraLiveVars);
505-
for (int i = extraLiveVarIter.NextElem(); i != -1; i = extraLiveVarIter.NextElem())
505+
for (int i = extraLiveVarIter.NextElem(); i != VarSetOps::Iter::Done; i = extraLiveVarIter.NextElem())
506506
{
507507
unsigned varNum = compiler->lvaTrackedToVarNum[i];
508508
LclVarDsc* varDsc = compiler->lvaTable + varNum;

src/jit/compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8298,7 +8298,7 @@ void dumpConvertedVarSet(Compiler* comp, VARSET_VALARG_TP vars)
82988298
memset(pVarNumSet, 0, varNumSetBytes); // empty the set
82998299

83008300
VarSetOps::Iter iter(comp, vars);
8301-
for (int i = iter.NextElem(); i != -1; i = iter.NextElem())
8301+
for (int i = iter.NextElem(); i != VarSetOps::Iter::Done; i = iter.NextElem())
83028302
{
83038303
unsigned varNum = comp->lvaTrackedToVarNum[i];
83048304
assert(varNum < comp->lvaCount);

0 commit comments

Comments
 (0)