Skip to content

Commit 205ef03

Browse files
authored
JIT: Remove old loop code (#97232)
All dependencies on old loop finding have been removed, so remove all old code associated with it.
1 parent 8accd80 commit 205ef03

19 files changed

+363
-4154
lines changed

src/coreclr/jit/block.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ void BasicBlock::dspFlags() const
491491
{BBF_INTERNAL, "internal"},
492492
{BBF_FAILED_VERIFICATION, "failV"},
493493
{BBF_HAS_SUPPRESSGC_CALL, "sup-gc"},
494-
{BBF_LOOP_HEAD, "Loop"},
494+
{BBF_LOOP_HEAD, "loophead"},
495495
{BBF_HAS_LABEL, "label"},
496496
{BBF_HAS_JMP, "jmp"},
497497
{BBF_HAS_CALL, "hascall"},
@@ -513,7 +513,7 @@ void BasicBlock::dspFlags() const
513513
{BBF_NO_CSE_IN, "no-cse"},
514514
{BBF_CAN_ADD_PRED, "add-pred"},
515515
{BBF_RETLESS_CALL, "retless"},
516-
{BBF_LOOP_PREHEADER, "LoopPH"},
516+
{BBF_LOOP_PREHEADER, "preheader"},
517517
{BBF_COLD, "cold"},
518518
{BBF_KEEP_BBJ_ALWAYS, "KEEP"},
519519
{BBF_CLONED_FINALLY_BEGIN, "cfb"},
@@ -811,7 +811,6 @@ void BasicBlock::CloneBlockState(
811811
to->bbCodeOffs = from->bbCodeOffs;
812812
to->bbCodeOffsEnd = from->bbCodeOffsEnd;
813813
VarSetOps::AssignAllowUninitRhs(compiler, to->bbScope, from->bbScope);
814-
to->bbNatLoopNum = from->bbNatLoopNum;
815814
#ifdef DEBUG
816815
to->bbTgtStkDepth = from->bbTgtStkDepth;
817816
#endif // DEBUG
@@ -1606,11 +1605,6 @@ BasicBlock* BasicBlock::New(Compiler* compiler)
16061605
block->bbMemorySsaNumOut[memoryKind] = 0;
16071606
}
16081607

1609-
// Make sure we reserve a NOT_IN_LOOP value that isn't a legal table index.
1610-
static_assert_no_msg(BasicBlock::MAX_LOOP_NUM < BasicBlock::NOT_IN_LOOP);
1611-
1612-
block->bbNatLoopNum = BasicBlock::NOT_IN_LOOP;
1613-
16141608
block->bbPreorderNum = 0;
16151609
block->bbPostorderNum = 0;
16161610

src/coreclr/jit/block.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef BitVec_ValRet_T ASSERT_VALRET_TP;
4343
// This define is used with string concatenation to put this in printf format strings (Note that %u means unsigned int)
4444
#define FMT_BB "BB%02u"
4545

46-
// Use this format for loop table indices.
46+
// Use this format for loop indices
4747
#define FMT_LP "L%02u"
4848

4949
// And this format for profile weights
@@ -393,7 +393,7 @@ enum BasicBlockFlags : unsigned __int64
393393
BBF_HAS_NULLCHECK = MAKE_BBFLAG(11), // BB contains a null check
394394
BBF_HAS_SUPPRESSGC_CALL = MAKE_BBFLAG(12), // BB contains a call to a method with SuppressGCTransitionAttribute
395395
BBF_RUN_RARELY = MAKE_BBFLAG(13), // BB is rarely run (catch clauses, blocks with throws etc)
396-
BBF_LOOP_HEAD = MAKE_BBFLAG(14), // BB is the head of a loop
396+
BBF_LOOP_HEAD = MAKE_BBFLAG(14), // BB is the head of a loop (can reach a predecessor)
397397
BBF_HAS_LABEL = MAKE_BBFLAG(15), // BB needs a label
398398
BBF_LOOP_ALIGN = MAKE_BBFLAG(16), // Block is lexically the first block in a loop we intend to align.
399399
BBF_HAS_ALIGN = MAKE_BBFLAG(17), // BB ends with 'align' instruction
@@ -1251,14 +1251,6 @@ struct BasicBlock : private LIR::Range
12511251
#define BBCT_FILTER_HANDLER 0xFFFFFFFF
12521252
#define handlerGetsXcptnObj(hndTyp) ((hndTyp) != BBCT_NONE && (hndTyp) != BBCT_FAULT && (hndTyp) != BBCT_FINALLY)
12531253

1254-
// The following fields are used for loop detection
1255-
typedef unsigned char loopNumber;
1256-
static const unsigned NOT_IN_LOOP = UCHAR_MAX;
1257-
static const unsigned MAX_LOOP_NUM = 64;
1258-
1259-
loopNumber bbNatLoopNum; // Index, in optLoopTable, of most-nested loop that contains this block,
1260-
// or else NOT_IN_LOOP if this block is not in a loop.
1261-
12621254
// TODO-Cleanup: Get rid of bbStkDepth and use bbStackDepthOnEntry() instead
12631255
union {
12641256
unsigned short bbStkDepth; // stack depth on entry

src/coreclr/jit/compiler.cpp

Lines changed: 28 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ Histogram computeReachabilitySetsIterationTable(computeReachabilitySetsIteration
305305

306306
unsigned totalLoopMethods; // counts the total number of methods that have natural loops
307307
unsigned maxLoopsPerMethod; // counts the maximum number of loops a method has
308-
unsigned totalLoopOverflows; // # of methods that identified more loops than we can represent
309308
unsigned totalLoopCount; // counts the total number of natural loops
310309
unsigned totalUnnatLoopCount; // counts the total number of (not-necessarily natural) loops
311310
unsigned totalUnnatLoopOverflows; // # of methods that identified more unnatural loops than we can represent
@@ -1576,7 +1575,6 @@ void Compiler::compShutdown()
15761575
jitprintf("Total number of methods with loops is %5u\n", totalLoopMethods);
15771576
jitprintf("Total number of loops is %5u\n", totalLoopCount);
15781577
jitprintf("Maximum number of loops per method is %5u\n", maxLoopsPerMethod);
1579-
jitprintf("# of methods overflowing nat loop table is %5u\n", totalLoopOverflows);
15801578
jitprintf("Total number of 'unnatural' loops is %5u\n", totalUnnatLoopCount);
15811579
jitprintf("# of methods overflowing unnat loop limit is %5u\n", totalUnnatLoopOverflows);
15821580
jitprintf("Total number of loops with an iterator is %5u\n", iterLoopCount);
@@ -5254,10 +5252,9 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
52545252
//
52555253
// Remarks:
52565254
// All innermost loops whose block weight meets a threshold are candidates for alignment.
5257-
// The top block of the loop is marked with the BBF_LOOP_ALIGN flag to indicate this
5258-
// (the loop table itself is not changed).
5255+
// The top block of the loop is marked with the BBF_LOOP_ALIGN flag to indicate this.
52595256
//
5260-
// Depends on the loop table, and on block weights being set.
5257+
// Depends on block weights being set.
52615258
//
52625259
bool Compiler::shouldAlignLoop(FlowGraphNaturalLoop* loop, BasicBlock* top)
52635260
{
@@ -5839,25 +5836,17 @@ void Compiler::RecomputeFlowGraphAnnotations()
58395836

58405837
fgComputeReachability();
58415838
optSetBlockWeights();
5842-
optFindLoops();
58435839

58445840
fgInvalidateDfsTree();
58455841
m_dfsTree = fgComputeDfs();
5846-
optFindNewLoops();
5842+
optFindLoops();
58475843

58485844
if (fgHasLoops)
58495845
{
58505846
optFindAndScaleGeneralLoopBlocks();
58515847
}
58525848

58535849
m_domTree = FlowGraphDominatorTree::Build(m_dfsTree);
5854-
5855-
// Dominators and the loop table are computed above for old<->new loop
5856-
// crossreferencing, but they are not actually used for optimization
5857-
// anymore.
5858-
optLoopTableValid = false;
5859-
optLoopTable = nullptr;
5860-
optLoopCount = 0;
58615850
}
58625851

58635852
/*****************************************************************************/
@@ -9084,7 +9073,7 @@ void JitTimer::PrintCsvMethodStats(Compiler* comp)
90849073
fprintf(s_csvFile, "%u,", comp->info.compILCodeSize);
90859074
fprintf(s_csvFile, "%u,", comp->fgBBcount);
90869075
fprintf(s_csvFile, "%u,", comp->opts.MinOpts());
9087-
fprintf(s_csvFile, "%u,", comp->optLoopCount);
9076+
fprintf(s_csvFile, "%u,", comp->optNumNaturalLoopsFound);
90889077
fprintf(s_csvFile, "%u,", comp->optLoopsCloned);
90899078
#if FEATURE_LOOP_ALIGN
90909079
#ifdef DEBUG
@@ -9337,16 +9326,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
93379326
* cCVarSet, dCVarSet : Display a "converted" VARSET_TP: the varset is assumed to be tracked variable
93389327
* indices. These are converted to variable numbers and sorted. (Calls
93399328
* dumpConvertedVarSet()).
9340-
* cLoop, dLoop : Display the blocks of a loop, including the trees, given a loop number (call
9341-
* optPrintLoopInfo()).
9342-
* cLoopPtr, dLoopPtr : Display the blocks of a loop, including the trees, given a LoopDsc* (call
9343-
* optPrintLoopInfo()).
9344-
* cLoops, dLoops : Display the loop table (call optPrintLoopTable()).
9345-
* cNewLoops, dNewLoops : Display the loop table (call FlowGraphNaturalLoops::Dump()) with
9329+
* cLoops, dLoops : Display the loops (call FlowGraphNaturalLoops::Dump()) with
93469330
* Compiler::m_loops.
9347-
* cNewLoopsA, dNewLoopsA : Display the loop table (call FlowGraphNaturalLoops::Dump()) with a given
9331+
* cLoopsA, dLoopsA : Display the loops (call FlowGraphNaturalLoops::Dump()) with a given
93489332
* loops arg.
9349-
* cNewLoop, dNewLoop : Display a single loop (call FlowGraphNaturalLoop::Dump()) with given
9333+
* cLoop, dLoop : Display a single loop (call FlowGraphNaturalLoop::Dump()) with given
93509334
* loop arg.
93519335
* cTreeFlags, dTreeFlags : Display tree flags for a specified tree.
93529336
* cVN, dVN : Display a ValueNum (call vnPrint()).
@@ -9361,7 +9345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
93619345
* dFindTree : Find a tree in the IR, specifying a tree id. Sets `dbTree` and `dbTreeBlock`.
93629346
* dFindStmt : Find a Statement in the IR, specifying a statement id. Sets `dbStmt`.
93639347
* dFindBlock : Find a block in the IR, specifying a block number. Sets `dbBlock`.
9364-
* dFindLoop : Find a loop in the loop table, specifying a loop number. Sets `dbLoop`.
9348+
* dFindLoop : Find a loop specifying a loop index. Sets `dbLoop`.
93659349
*/
93669350

93679351
// Make the debug helpers available (under #ifdef DEBUG) even though they are unreferenced. When the Microsoft
@@ -9401,12 +9385,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94019385
#pragma comment(linker, "/include:cDoms")
94029386
#pragma comment(linker, "/include:cLiveness")
94039387
#pragma comment(linker, "/include:cCVarSet")
9404-
#pragma comment(linker, "/include:cLoop")
9405-
#pragma comment(linker, "/include:cLoopPtr")
94069388
#pragma comment(linker, "/include:cLoops")
9407-
#pragma comment(linker, "/include:cNewLoops")
9408-
#pragma comment(linker, "/include:cNewLoopsA")
9409-
#pragma comment(linker, "/include:cNewLoop")
9389+
#pragma comment(linker, "/include:cLoopsA")
9390+
#pragma comment(linker, "/include:cLoop")
94109391
#pragma comment(linker, "/include:cTreeFlags")
94119392
#pragma comment(linker, "/include:cVN")
94129393

@@ -9431,11 +9412,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94319412
#pragma comment(linker, "/include:dLiveness")
94329413
#pragma comment(linker, "/include:dCVarSet")
94339414
#pragma comment(linker, "/include:dLoop")
9434-
#pragma comment(linker, "/include:dLoopPtr")
94359415
#pragma comment(linker, "/include:dLoops")
9436-
#pragma comment(linker, "/include:dNewLoops")
9437-
#pragma comment(linker, "/include:dNewLoopsA")
9438-
#pragma comment(linker, "/include:dNewLoop")
94399416
#pragma comment(linker, "/include:dTreeFlags")
94409417
#pragma comment(linker, "/include:dVN")
94419418

@@ -9473,11 +9450,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94739450
#pragma comment(linker, "/include:_cLiveness")
94749451
#pragma comment(linker, "/include:_cCVarSet")
94759452
#pragma comment(linker, "/include:_cLoop")
9476-
#pragma comment(linker, "/include:_cLoopPtr")
94779453
#pragma comment(linker, "/include:_cLoops")
9478-
#pragma comment(linker, "/include:_cNewLoops")
9479-
#pragma comment(linker, "/include:_cNewLoopsA")
9480-
#pragma comment(linker, "/include:_cNewLoop")
9454+
#pragma comment(linker, "/include:_cLoopsA")
94819455
#pragma comment(linker, "/include:_cTreeFlags")
94829456
#pragma comment(linker, "/include:_cVN")
94839457

@@ -9501,12 +9475,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
95019475
#pragma comment(linker, "/include:_dDoms")
95029476
#pragma comment(linker, "/include:_dLiveness")
95039477
#pragma comment(linker, "/include:_dCVarSet")
9504-
#pragma comment(linker, "/include:_dLoop")
9505-
#pragma comment(linker, "/include:_dLoopPtr")
95069478
#pragma comment(linker, "/include:_dLoops")
9507-
#pragma comment(linker, "/include:_dNewLoops")
9508-
#pragma comment(linker, "/include:_dNewLoopsA")
9509-
#pragma comment(linker, "/include:_dNewLoop")
9479+
#pragma comment(linker, "/include:_dLoopsA")
9480+
#pragma comment(linker, "/include:_dLoop")
95109481
#pragma comment(linker, "/include:_dTreeFlags")
95119482
#pragma comment(linker, "/include:_dVN")
95129483

@@ -9682,44 +9653,21 @@ JITDBGAPI void __cdecl cCVarSet(Compiler* comp, VARSET_VALARG_TP vars)
96829653
printf("\n"); // dumpConvertedVarSet() doesn't emit a trailing newline
96839654
}
96849655

9685-
JITDBGAPI void __cdecl cLoop(Compiler* comp, unsigned loopNum)
9686-
{
9687-
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
9688-
printf("===================================================================== *Loop %u\n", sequenceNumber++);
9689-
comp->optPrintLoopInfo(loopNum, /* verbose */ true);
9690-
printf("\n");
9691-
}
9692-
9693-
JITDBGAPI void __cdecl cLoopPtr(Compiler* comp, const Compiler::LoopDsc* loop)
9694-
{
9695-
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
9696-
printf("===================================================================== *LoopPtr %u\n", sequenceNumber++);
9697-
comp->optPrintLoopInfo(loop, /* verbose */ true);
9698-
printf("\n");
9699-
}
9700-
97019656
JITDBGAPI void __cdecl cLoops(Compiler* comp)
9702-
{
9703-
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
9704-
printf("===================================================================== *Loops %u\n", sequenceNumber++);
9705-
comp->optPrintLoopTable();
9706-
}
9707-
9708-
JITDBGAPI void __cdecl cNewLoops(Compiler* comp)
97099657
{
97109658
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
97119659
printf("===================================================================== *NewLoops %u\n", sequenceNumber++);
97129660
FlowGraphNaturalLoops::Dump(comp->m_loops);
97139661
}
97149662

9715-
JITDBGAPI void __cdecl cNewLoopsA(Compiler* comp, FlowGraphNaturalLoops* loops)
9663+
JITDBGAPI void __cdecl cLoopsA(Compiler* comp, FlowGraphNaturalLoops* loops)
97169664
{
97179665
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
97189666
printf("===================================================================== *NewLoopsA %u\n", sequenceNumber++);
97199667
FlowGraphNaturalLoops::Dump(loops);
97209668
}
97219669

9722-
JITDBGAPI void __cdecl cNewLoop(Compiler* comp, FlowGraphNaturalLoop* loop)
9670+
JITDBGAPI void __cdecl cLoop(Compiler* comp, FlowGraphNaturalLoop* loop)
97239671
{
97249672
static unsigned sequenceNumber = 0; // separate calls with a number to indicate this function has been called
97259673
printf("===================================================================== *NewLoop %u\n", sequenceNumber++);
@@ -9778,10 +9726,6 @@ JITDBGAPI void __cdecl cTreeFlags(Compiler* comp, GenTree* tree)
97789726
{
97799727
chars += printf("[VAR_USEASG]");
97809728
}
9781-
if (tree->gtFlags & GTF_VAR_ITERATOR)
9782-
{
9783-
chars += printf("[VAR_ITERATOR]");
9784-
}
97859729
if (tree->gtFlags & GTF_VAR_MOREUSES)
97869730
{
97879731
chars += printf("[VAR_MOREUSES]");
@@ -10318,34 +10262,19 @@ JITDBGAPI void __cdecl dCVarSet(VARSET_VALARG_TP vars)
1031810262
cCVarSet(JitTls::GetCompiler(), vars);
1031910263
}
1032010264

10321-
JITDBGAPI void __cdecl dLoop(unsigned loopNum)
10322-
{
10323-
cLoop(JitTls::GetCompiler(), loopNum);
10324-
}
10325-
10326-
JITDBGAPI void __cdecl dLoopPtr(const Compiler::LoopDsc* loop)
10327-
{
10328-
cLoopPtr(JitTls::GetCompiler(), loop);
10329-
}
10330-
1033110265
JITDBGAPI void __cdecl dLoops()
1033210266
{
1033310267
cLoops(JitTls::GetCompiler());
1033410268
}
1033510269

10336-
JITDBGAPI void __cdecl dNewLoops()
10337-
{
10338-
cNewLoops(JitTls::GetCompiler());
10339-
}
10340-
10341-
JITDBGAPI void __cdecl dNewLoopsA(FlowGraphNaturalLoops* loops)
10270+
JITDBGAPI void __cdecl dLoopsA(FlowGraphNaturalLoops* loops)
1034210271
{
10343-
cNewLoopsA(JitTls::GetCompiler(), loops);
10272+
cLoopsA(JitTls::GetCompiler(), loops);
1034410273
}
1034510274

10346-
JITDBGAPI void __cdecl dNewLoop(FlowGraphNaturalLoop* loop)
10275+
JITDBGAPI void __cdecl dLoop(FlowGraphNaturalLoop* loop)
1034710276
{
10348-
cNewLoop(JitTls::GetCompiler(), loop);
10277+
cLoop(JitTls::GetCompiler(), loop);
1034910278
}
1035010279

1035110280
JITDBGAPI void __cdecl dTreeFlags(GenTree* tree)
@@ -10382,11 +10311,11 @@ JITDBGAPI void __cdecl dBlockList(BasicBlockList* list)
1038210311
// Trees, Stmts, and/or Blocks using id or bbNum.
1038310312
// That can be used in watch window or as a way to get address of fields for data breakpoints.
1038410313

10385-
GenTree* dbTree;
10386-
Statement* dbStmt;
10387-
BasicBlock* dbTreeBlock;
10388-
BasicBlock* dbBlock;
10389-
Compiler::LoopDsc* dbLoop;
10314+
GenTree* dbTree;
10315+
Statement* dbStmt;
10316+
BasicBlock* dbTreeBlock;
10317+
BasicBlock* dbBlock;
10318+
FlowGraphNaturalLoop* dbLoop;
1039010319

1039110320
// Debug APIs for finding Trees, Stmts, and/or Blocks.
1039210321
// As a side effect, they set the debug variables above.
@@ -10478,18 +10407,18 @@ JITDBGAPI BasicBlock* __cdecl dFindBlock(unsigned bbNum)
1047810407
return nullptr;
1047910408
}
1048010409

10481-
JITDBGAPI Compiler::LoopDsc* __cdecl dFindLoop(unsigned loopNum)
10410+
JITDBGAPI FlowGraphNaturalLoop* __cdecl dFindLoop(unsigned index)
1048210411
{
1048310412
Compiler* comp = JitTls::GetCompiler();
1048410413
dbLoop = nullptr;
1048510414

10486-
if (loopNum >= comp->optLoopCount)
10415+
if ((comp->m_loops == nullptr) || (index >= comp->m_loops->NumLoops()))
1048710416
{
10488-
printf("loopNum %u out of range\n", loopNum);
10417+
printf("Index %u out of range\n", index);
1048910418
return nullptr;
1049010419
}
1049110420

10492-
dbLoop = &comp->optLoopTable[loopNum];
10421+
dbLoop = comp->m_loops->GetLoopByIndex(index);
1049310422
return dbLoop;
1049410423
}
1049510424

0 commit comments

Comments
 (0)