@@ -280,22 +280,30 @@ void GCNHazardRecognizer::processBundle() {
280
280
CurrCycleInstr = nullptr ;
281
281
}
282
282
283
- void GCNHazardRecognizer::reverseProcessBundle () {
283
+ void GCNHazardRecognizer::processBundleBottomUp () {
284
+ // Step through each instruction in the bundle in bottom-up order.
284
285
MachineBasicBlock::instr_iterator MI =
285
286
std::next (CurrCycleInstr->getIterator ());
286
287
MachineBasicBlock::instr_iterator E =
287
288
CurrCycleInstr->getParent ()->instr_end ();
288
289
290
+ // Evict stale entries to maintain a fixed lookahead window.
291
+ // TODO: Hazard detection is not yet implemented. This scheduling
292
+ // is intended for GFX11 and newer.
289
293
for (; MI != E && MI->isInsideBundle (); ++MI) {
290
294
CurrCycleInstr = &*MI;
291
- for (unsigned I = 0 , E = MaxLookAhead - 1 ; I < E; ++I) {
292
- if (!EmittedInstrs.empty ())
293
- EmittedInstrs.pop_back ();
294
- }
295
+
296
+ // Remove up to (MaxLookAhead - 1) oldest entries.
297
+ for (unsigned I = 0 , E = MaxLookAhead - 1 ; I < E && !EmittedInstrs.empty ();
298
+ ++I)
299
+ EmittedInstrs.pop_back ();
295
300
296
301
EmittedInstrs.push_back (CurrCycleInstr);
302
+
303
+ // Keep only the most recent MaxLookAhead entries
297
304
EmittedInstrs.resize (MaxLookAhead);
298
305
}
306
+
299
307
CurrCycleInstr = nullptr ;
300
308
}
301
309
@@ -436,14 +444,16 @@ void GCNHazardRecognizer::AdvanceCycle() {
436
444
}
437
445
438
446
void GCNHazardRecognizer::RecedeCycle () {
447
+ // If no instruction was issued this cycle, pop the oldest placeholder.
439
448
if (!CurrCycleInstr) {
440
449
if (!EmittedInstrs.empty ())
441
450
EmittedInstrs.pop_back ();
442
451
return ;
443
452
}
444
453
454
+ // If this is a bundle header, handle the entire bundle here.
445
455
if (CurrCycleInstr->isBundle ()) {
446
- reverseProcessBundle ();
456
+ processBundleBottomUp ();
447
457
return ;
448
458
}
449
459
@@ -453,14 +463,21 @@ void GCNHazardRecognizer::RecedeCycle() {
453
463
return ;
454
464
}
455
465
466
+ // Add current instruction to the emitted list.
456
467
EmittedInstrs.push_back (CurrCycleInstr);
457
- for (unsigned i = 1 , e = std::min (NumWaitStates, getMaxLookAhead ()); i < e;
458
- ++i) {
468
+
469
+ // Model remaining wait states by removing older placeholders.
470
+ for (unsigned I = 1 , E = std::min (NumWaitStates, getMaxLookAhead ()); I < E;
471
+ ++I) {
459
472
if (!EmittedInstrs.empty ())
460
473
EmittedInstrs.pop_back ();
461
474
}
462
475
476
+ // getMaxLookahead() is the largest number of wait states we will ever need
477
+ // to insert, so there is no point in keeping track of more than that many
478
+ // wait states.
463
479
EmittedInstrs.resize (getMaxLookAhead ());
480
+
464
481
CurrCycleInstr = nullptr ;
465
482
}
466
483
0 commit comments