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

[WIP] try VARSET_TP iterator without arguments. #11945

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,17 @@ void Compiler::optAddCopies()

bool isDominatedByFirstBB = false;

BLOCKSET_ITER_INIT(this, iter, varDsc->lvRefBlks, blkNum);
while (iter.NextElem(&blkNum))
BlockSetOps::Iter iter(this, varDsc->lvRefBlks);
unsigned bbNum = 0;
while (iter.NextElem(&bbNum))
{
/* Find the block 'blkNum' */
/* Find the block 'bbNum' */
BasicBlock* block = fgFirstBB;
while (block && (block->bbNum != blkNum))
while (block && (block->bbNum != bbNum))
{
block = block->bbNext;
}
noway_assert(block && (block->bbNum == blkNum));
noway_assert(block && (block->bbNum == bbNum));

bool importantUseInBlock = (varDsc->lvIsParam) && (block->getBBWeight(this) > paramAvgWtdRefDiv2);
bool isPreHeaderBlock = ((block->bbFlags & BBF_LOOP_PREHEADER) != 0);
Expand Down Expand Up @@ -214,7 +215,7 @@ void Compiler::optAddCopies()
#ifdef DEBUG
if (verbose)
{
printf(" Referenced in BB%02u, bbWeight is %s", blkNum, refCntWtd2str(block->getBBWeight(this)));
printf(" Referenced in BB%02u, bbWeight is %s", bbNum, refCntWtd2str(block->getBBWeight(this)));

if (isDominatedByFirstBB)
{
Expand Down Expand Up @@ -320,17 +321,17 @@ void Compiler::optAddCopies()
#endif

/* We have already calculated paramImportantUseDom above. */

BLOCKSET_ITER_INIT(this, iter, paramImportantUseDom, blkNum);
while (iter.NextElem(&blkNum))
BlockSetOps::Iter iter(this, paramImportantUseDom);
unsigned bbNum = 0;
while (iter.NextElem(&bbNum))
{
/* Advance block to point to 'blkNum' */
/* Advance block to point to 'bbNum' */
/* This assumes that the iterator returns block number is increasing lexical order. */
while (block && (block->bbNum != blkNum))
while (block && (block->bbNum != bbNum))
{
block = block->bbNext;
}
noway_assert(block && (block->bbNum == blkNum));
noway_assert(block && (block->bbNum == bbNum));

#ifdef DEBUG
if (verbose)
Expand Down
16 changes: 0 additions & 16 deletions src/jit/bitvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,4 @@ typedef BitSetShortLongRep BitVec;
typedef BitVecOps::ValArgType BitVec_ValArg_T;
typedef BitVecOps::RetValType BitVec_ValRet_T;

// Initialize "_varName" to "_initVal." Copies contents, not references; if "_varName" is uninitialized, allocates a
// set for it (using "_traits" for any necessary allocation), and copies the contents of "_initVal" into it.
#define BITVEC_INIT(_traits, _varName, _initVal) _varName(BitVecOps::MakeCopy(_traits, _initVal))

// Initializes "_varName" to "_initVal", without copying: if "_initVal" is an indirect representation, copies its
// pointer into "_varName".
#define BITVEC_INIT_NOCOPY(_varName, _initVal) _varName(_initVal)

// The iterator pattern.

// Use this to initialize an iterator "_iterName" to iterate over a BitVec "_bitVec".
// "_bitNum" will be an unsigned variable to which we assign the elements of "_bitVec".
#define BITVEC_ITER_INIT(_traits, _iterName, _bitVec, _bitNum) \
unsigned _bitNum = 0; \
BitVecOps::Iter _iterName(_traits, _bitVec)

#endif // _BITVEC_INCLUDED_
8 changes: 0 additions & 8 deletions src/jit/blockset.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,4 @@ typedef BitSetShortLongRep BlockSet;
typedef BlockSetOps::ValArgType BlockSet_ValArg_T;
typedef BlockSetOps::RetValType BlockSet_ValRet_T;

// The iterator pattern.

// Use this to initialize an iterator "_iterName" to iterate over a BlockSet "_blockSet".
// "_blockNum" will be an unsigned variable to which we assign the elements of "_blockSet".
#define BLOCKSET_ITER_INIT(_comp, _iterName, _blockSet, _blockNum) \
unsigned _blockNum = 0; \
BlockSetOps::Iter _iterName(_comp, _blockSet)

#endif // _BLOCKSET_INCLUDED_
9 changes: 6 additions & 3 deletions src/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,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);
VarSetOps::Iter deadIter(this, deadSet);
unsigned deadVarIndex = 0;
while (deadIter.NextElem(&deadVarIndex))
{
unsigned varNum = lvaTrackedToVarNum[deadVarIndex];
Expand Down Expand Up @@ -1134,7 +1135,8 @@ void Compiler::compChangeLife(VARSET_VALARG_TP newLife DEBUGARG(GenTreePtr tree)
#endif // !LEGACY_BACKEND
}

VARSET_ITER_INIT(this, bornIter, bornSet, bornVarIndex);
VarSetOps::Iter bornIter(this, bornSet);
unsigned bornVarIndex = 0;
while (bornIter.NextElem(&bornVarIndex))
{
unsigned varNum = lvaTrackedToVarNum[bornVarIndex];
Expand Down Expand Up @@ -1304,7 +1306,8 @@ regMaskTP CodeGenInterface::genLiveMask(VARSET_VALARG_TP liveSet)

regMaskTP liveMask = 0;

VARSET_ITER_INIT(compiler, iter, liveSet, varIndex);
VarSetOps::Iter iter(compiler, liveSet);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{

Expand Down
12 changes: 8 additions & 4 deletions src/jit/codegenlegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void CodeGen::genDyingVars(VARSET_VALARG_TP beforeSet, VARSET_VALARG_TP afterSet

/* iterate through the dead variables */

VARSET_ITER_INIT(compiler, iter, deadSet, varIndex);
VarSetOps::Iter iter(compiler, deadSet);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{
varNum = compiler->lvaTrackedToVarNum[varIndex];
Expand Down Expand Up @@ -5631,7 +5632,8 @@ void CodeGen::genCodeForQmark(GenTreePtr tree, regMaskTP destReg, regMaskTP best

VARSET_TP regVarLiveNow(VarSetOps::Intersection(compiler, compiler->raRegVarsMask, rsLiveNow));

VARSET_ITER_INIT(compiler, iter, regVarLiveNow, varIndex);
VarSetOps::Iter iter(compiler, regVarLiveNow);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{
// Find the variable in compiler->lvaTable
Expand Down Expand Up @@ -12579,7 +12581,8 @@ void CodeGen::genCodeForBBlist()
// We should never enregister variables in any of the specialUseMask registers
noway_assert((specialUseMask & regSet.rsMaskVars) == 0);

VARSET_ITER_INIT(compiler, iter, liveSet, varIndex);
VarSetOps::Iter iter(compiler, liveSet);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{
varNum = compiler->lvaTrackedToVarNum[varIndex];
Expand Down Expand Up @@ -15237,7 +15240,8 @@ unsigned CodeGen::genRegCountForLiveIntEnregVars(GenTreePtr tree)
{
unsigned regCount = 0;

VARSET_ITER_INIT(compiler, iter, compiler->compCurLife, varNum);
VarSetOps::Iter iter(compiler, compiler->compCurLife);
unsigned varNum = 0;
while (iter.NextElem(&varNum))
{
unsigned lclNum = compiler->lvaTrackedToVarNum[varNum];
Expand Down
6 changes: 4 additions & 2 deletions src/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ void CodeGen::genCodeForBBlist()
VARSET_TP removedGCVars(VarSetOps::MakeEmpty(compiler));
VARSET_TP addedGCVars(VarSetOps::MakeEmpty(compiler));
#endif
VARSET_ITER_INIT(compiler, iter, block->bbLiveIn, varIndex);
VarSetOps::Iter iter(compiler, block->bbLiveIn);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{
unsigned varNum = compiler->lvaTrackedToVarNum[varIndex];
Expand Down Expand Up @@ -501,7 +502,8 @@ void CodeGen::genCodeForBBlist()

VARSET_TP extraLiveVars(VarSetOps::Diff(compiler, block->bbLiveOut, compiler->compCurLife));
VarSetOps::UnionD(compiler, extraLiveVars, VarSetOps::Diff(compiler, compiler->compCurLife, block->bbLiveOut));
VARSET_ITER_INIT(compiler, extraLiveVarIter, extraLiveVars, extraLiveVarIndex);
VarSetOps::Iter extraLiveVarIter(compiler, extraLiveVars);
unsigned extraLiveVarIndex = 0;
while (extraLiveVarIter.NextElem(&extraLiveVarIndex))
{
unsigned varNum = compiler->lvaTrackedToVarNum[extraLiveVarIndex];
Expand Down
3 changes: 2 additions & 1 deletion src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8297,7 +8297,8 @@ void dumpConvertedVarSet(Compiler* comp, VARSET_VALARG_TP vars)
pVarNumSet = (BYTE*)_alloca(varNumSetBytes);
memset(pVarNumSet, 0, varNumSetBytes); // empty the set

VARSET_ITER_INIT(comp, iter, vars, varIndex);
VarSetOps::Iter iter(comp, vars);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{
unsigned varNum = comp->lvaTrackedToVarNum[varIndex];
Expand Down
2 changes: 1 addition & 1 deletion src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4429,7 +4429,7 @@ class Compiler
void fgTableDispBasicBlock(BasicBlock* block, int ibcColWidth = 0);
void fgDispBasicBlocks(BasicBlock* firstBlock, BasicBlock* lastBlock, bool dumpTrees);
void fgDispBasicBlocks(bool dumpTrees = false);
void fgDumpStmtTree(GenTreePtr stmt, unsigned blkNum);
void fgDumpStmtTree(GenTreePtr stmt, unsigned bbNum);
void fgDumpBlock(BasicBlock* block);
void fgDumpTrees(BasicBlock* firstBlock, BasicBlock* lastBlock);

Expand Down
17 changes: 10 additions & 7 deletions src/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,8 @@ void Compiler::fgComputeEnterBlocksSet()
if (verbose)
{
printf("Enter blocks: ");
BLOCKSET_ITER_INIT(this, iter, fgEnterBlks, bbNum);
BlockSetOps::Iter iter(this, fgEnterBlks);
unsigned bbNum = 0;
while (iter.NextElem(&bbNum))
{
printf("BB%02u ", bbNum);
Expand Down Expand Up @@ -2289,7 +2290,8 @@ BlockSet_ValRet_T Compiler::fgDomFindStartNodes()
if (verbose)
{
printf("\nDominator computation start blocks (those blocks with no incoming edges):\n");
BLOCKSET_ITER_INIT(this, iter, startNodes, bbNum);
BlockSetOps::Iter iter(this, startNodes);
unsigned bbNum = 0;
while (iter.NextElem(&bbNum))
{
printf("BB%02u ", bbNum);
Expand Down Expand Up @@ -3297,7 +3299,7 @@ Compiler::SwitchUniqueSuccSet Compiler::GetDescriptorForSwitch(BasicBlock* switc
// reachability information stored in the blocks. To avoid that, we just use a local BitVec.

BitVecTraits blockVecTraits(fgBBNumMax + 1, this);
BitVec BITVEC_INIT_NOCOPY(uniqueSuccBlocks, BitVecOps::MakeEmpty(&blockVecTraits));
BitVec uniqueSuccBlocks(BitVecOps::MakeEmpty(&blockVecTraits));
BasicBlock** jumpTable = switchBlk->bbJumpSwt->bbsDstTab;
unsigned jumpCount = switchBlk->bbJumpSwt->bbsCount;
for (unsigned i = 0; i < jumpCount; i++)
Expand Down Expand Up @@ -19599,7 +19601,8 @@ void Compiler::fgDispReach()
for (BasicBlock* block = fgFirstBB; block != nullptr; block = block->bbNext)
{
printf("BB%02u : ", block->bbNum);
BLOCKSET_ITER_INIT(this, iter, block->bbReach, bbNum);
BlockSetOps::Iter iter(this, block->bbReach);
unsigned bbNum = 0;
while (iter.NextElem(&bbNum))
{
printf("BB%02u ", bbNum);
Expand Down Expand Up @@ -20095,11 +20098,11 @@ void Compiler::fgDispBasicBlocks(bool dumpTrees)
/*****************************************************************************/
// Increment the stmtNum and dump the tree using gtDispTree
//
void Compiler::fgDumpStmtTree(GenTreePtr stmt, unsigned blkNum)
void Compiler::fgDumpStmtTree(GenTreePtr stmt, unsigned bbNum)
{
compCurStmtNum++; // Increment the current stmtNum

printf("\n***** BB%02u, stmt %d\n", blkNum, compCurStmtNum);
printf("\n***** BB%02u, stmt %d\n", bbNum, compCurStmtNum);

if (fgOrder == FGOrderLinear || opts.compDbgInfo)
{
Expand Down Expand Up @@ -21252,7 +21255,7 @@ void Compiler::fgDebugCheckBlockLinks()
// Create a set with all the successors. Don't use BlockSet, so we don't need to worry
// about the BlockSet epoch.
BitVecTraits bitVecTraits(fgBBNumMax + 1, this);
BitVec BITVEC_INIT_NOCOPY(succBlocks, BitVecOps::MakeEmpty(&bitVecTraits));
BitVec succBlocks(BitVecOps::MakeEmpty(&bitVecTraits));
BasicBlock** jumpTable = block->bbJumpSwt->bbsDstTab;
unsigned jumpCount = block->bbJumpSwt->bbsCount;
for (unsigned i = 0; i < jumpCount; i++)
Expand Down
9 changes: 6 additions & 3 deletions src/jit/liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +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);
VarSetOps::Iter iter(this, initVars);
unsigned varIndex = 0;
while (iter.NextElem(&varIndex))
{
/* Create initialization tree */
Expand Down Expand Up @@ -1358,7 +1359,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);
VarSetOps::Iter iter(this, fgMarkIntfUnionVS);
unsigned refIndex = 0;
while (iter.NextElem(&refIndex))
{
// if varSet1 has this bit set then it interferes with varSet2
Expand Down Expand Up @@ -1411,7 +1413,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);
VarSetOps::Iter iter(this, varSet);
unsigned refIndex = 0;
while (iter.NextElem(&refIndex))
{
// Calculate the set of new interference to add
Expand Down
Loading