@@ -343,24 +343,25 @@ void GCNRPTracker::reset(const MachineInstr &MI,
343343 MaxPressure = CurPressure = getRegPressure (*MRI, LiveRegs);
344344}
345345
346- // //////////////////////////////////////////////////////////////////////////////
347- // GCNUpwardRPTracker
348-
349- void GCNUpwardRPTracker::reset (const MachineRegisterInfo &MRI_,
350- const LiveRegSet &LiveRegs_) {
346+ void GCNRPTracker::reset (const MachineRegisterInfo &MRI_,
347+ const LiveRegSet &LiveRegs_) {
351348 MRI = &MRI_;
352349 LiveRegs = LiveRegs_;
353350 LastTrackedMI = nullptr ;
354351 MaxPressure = CurPressure = getRegPressure (MRI_, LiveRegs_);
355352}
356353
357- void GCNUpwardRPTracker::recede (const MachineInstr &MI) {
354+ // //////////////////////////////////////////////////////////////////////////////
355+ // GCNUpwardRPTracker
356+
357+ bool GCNUpwardRPTracker::recede (const MachineInstr &MI, bool ShouldTrackIt) {
358358 assert (MRI && " call reset first" );
359359
360- LastTrackedMI = &MI;
360+ if (ShouldTrackIt)
361+ LastTrackedMI = &MI;
361362
362363 if (MI.isDebugInstr ())
363- return ;
364+ return false ;
364365
365366 // Kill all defs.
366367 GCNRegPressure DefPressure, ECDefPressure;
@@ -412,6 +413,7 @@ void GCNUpwardRPTracker::recede(const MachineInstr &MI) {
412413 : max (CurPressure, MaxPressure);
413414
414415 assert (CurPressure == getRegPressure (*MRI, LiveRegs));
416+ return false ;
415417}
416418
417419// //////////////////////////////////////////////////////////////////////////////
@@ -430,28 +432,44 @@ bool GCNDownwardRPTracker::reset(const MachineInstr &MI,
430432 return true ;
431433}
432434
433- bool GCNDownwardRPTracker::advanceBeforeNext () {
435+ bool GCNDownwardRPTracker::advanceBeforeNext (MachineInstr *MI,
436+ bool ShouldTrackIt,
437+ LiveIntervals *TheLIS) {
434438 assert (MRI && " call reset first" );
435- if (!LastTrackedMI)
436- return NextMI == MBBEnd;
439+ SlotIndex SI;
440+ LiveIntervals *CurrLIS;
441+ MachineInstr *CurrMI;
442+ if (ShouldTrackIt) {
443+ if (!LastTrackedMI)
444+ return NextMI == MBBEnd;
445+
446+ assert (NextMI == MBBEnd || !NextMI->isDebugInstr ());
447+ CurrLIS = const_cast <LiveIntervals *>(&LIS);
448+ CurrMI = const_cast <MachineInstr *>(LastTrackedMI);
449+
450+ SI = NextMI == MBBEnd
451+ ? CurrLIS->getInstructionIndex (*LastTrackedMI).getDeadSlot ()
452+ : CurrLIS->getInstructionIndex (*NextMI).getBaseIndex ();
453+ }
437454
438- assert (NextMI == MBBEnd || !NextMI->isDebugInstr ());
455+ else { // ! ShouldTrackIt
456+ CurrLIS = TheLIS;
457+ SI = CurrLIS->getInstructionIndex (*MI).getBaseIndex ();
458+ CurrMI = MI;
459+ }
439460
440- SlotIndex SI = NextMI == MBBEnd
441- ? LIS.getInstructionIndex (*LastTrackedMI).getDeadSlot ()
442- : LIS.getInstructionIndex (*NextMI).getBaseIndex ();
443461 assert (SI.isValid ());
444462
445463 // Remove dead registers or mask bits.
446464 SmallSet<Register, 8 > SeenRegs;
447- for (auto &MO : LastTrackedMI ->operands ()) {
465+ for (auto &MO : CurrMI ->operands ()) {
448466 if (!MO.isReg () || !MO.getReg ().isVirtual ())
449467 continue ;
450468 if (MO.isUse () && !MO.readsReg ())
451469 continue ;
452470 if (!SeenRegs.insert (MO.getReg ()).second )
453471 continue ;
454- const LiveInterval &LI = LIS. getInterval (MO.getReg ());
472+ const LiveInterval &LI = CurrLIS-> getInterval (MO.getReg ());
455473 if (LI.hasSubRanges ()) {
456474 auto It = LiveRegs.end ();
457475 for (const auto &S : LI.subranges ()) {
@@ -481,15 +499,18 @@ bool GCNDownwardRPTracker::advanceBeforeNext() {
481499
482500 LastTrackedMI = nullptr ;
483501
484- return NextMI == MBBEnd;
502+ return ShouldTrackIt && ( NextMI == MBBEnd) ;
485503}
486504
487- void GCNDownwardRPTracker::advanceToNext () {
505+ void GCNDownwardRPTracker::advanceToNext (MachineInstr *MI, bool ShouldTrackIt ) {
488506 LastTrackedMI = &*NextMI++;
489507 NextMI = skipDebugInstructionsForward (NextMI, MBBEnd);
490508
509+ MachineInstr *CurrMI =
510+ ShouldTrackIt ? const_cast <MachineInstr *>(LastTrackedMI) : MI;
511+
491512 // Add new registers or mask bits.
492- for (const auto &MO : LastTrackedMI ->all_defs ()) {
513+ for (const auto &MO : CurrMI ->all_defs ()) {
493514 Register Reg = MO.getReg ();
494515 if (!Reg.isVirtual ())
495516 continue ;
@@ -502,11 +523,12 @@ void GCNDownwardRPTracker::advanceToNext() {
502523 MaxPressure = max (MaxPressure, CurPressure);
503524}
504525
505- bool GCNDownwardRPTracker::advance () {
506- if (NextMI == MBBEnd)
526+ bool GCNDownwardRPTracker::advance (MachineInstr *MI, bool ShouldTrackIt,
527+ LiveIntervals *TheLIS) {
528+ if (ShouldTrackIt && NextMI == MBBEnd)
507529 return false ;
508- advanceBeforeNext ();
509- advanceToNext ();
530+ advanceBeforeNext (MI, ShouldTrackIt, TheLIS );
531+ advanceToNext (MI, ShouldTrackIt );
510532 return true ;
511533}
512534
0 commit comments