Skip to content

Commit bf61d05

Browse files
committed
Mark speculative query methods as const
Change-Id: I9ebe0cf7252068dcee90d419945085efae75547d
1 parent 7ee4ffd commit bf61d05

File tree

3 files changed

+33
-49
lines changed

3 files changed

+33
-49
lines changed

llvm/lib/Target/AMDGPU/GCNRegPressure.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,6 @@ void GCNRPTracker::reset(const MachineRegisterInfo &MRI_,
448448
MaxPressure = CurPressure = getRegPressure(MRI_, LiveRegs_);
449449
}
450450

451-
void GCNRPTracker::bumpDeadDefs(ArrayRef<RegisterMaskPair> DeadDefs) {
452-
GCNRegPressure TempPressure = CurPressure;
453-
for (const RegisterMaskPair &P : DeadDefs) {
454-
Register Reg = P.RegUnit;
455-
if (!Reg.isVirtual())
456-
continue;
457-
LaneBitmask LiveMask = LiveRegs[Reg];
458-
LaneBitmask BumpedMask = LiveMask | P.LaneMask;
459-
CurPressure.inc(Reg, LiveMask, BumpedMask, *MRI);
460-
}
461-
MaxPressure = max(MaxPressure, CurPressure);
462-
CurPressure = TempPressure;
463-
}
464451
/// Mostly copy/paste from CodeGen/RegisterPressure.cpp
465452
LaneBitmask GCNRPTracker::getLastUsedLanes(Register RegUnit,
466453
SlotIndex Pos) const {
@@ -535,8 +522,9 @@ void GCNUpwardRPTracker::recede(const MachineInstr &MI) {
535522
assert(CurPressure == getRegPressure(*MRI, LiveRegs));
536523
}
537524

538-
void GCNUpwardRPTracker::bumpUpwardPressure(const MachineInstr *MI,
539-
const SIRegisterInfo *TRI) {
525+
GCNRegPressure
526+
GCNUpwardRPTracker::bumpUpwardPressure(const MachineInstr *MI,
527+
const SIRegisterInfo *TRI) const {
540528
assert(!MI->isDebugOrPseudoInstr() && "Expect a nondebug instruction.");
541529

542530
SlotIndex SlotIdx = LIS.getInstructionIndex(*MI).getRegSlot();
@@ -549,33 +537,32 @@ void GCNUpwardRPTracker::bumpUpwardPressure(const MachineInstr *MI,
549537
adjustDefLaneLiveness(RegOpers.Defs, SlotIdx, LIS, *MRI);
550538
RegOpers.detectDeadDefs(*MI, LIS);
551539

552-
// Boost max pressure for all dead defs together.
553-
// Since CurrSetPressure and MaxSetPressure
554-
bumpDeadDefs(RegOpers.DeadDefs);
540+
GCNRegPressure TempPressure = CurPressure;
555541

556542
// Kill liveness at live defs.
557543
for (const RegisterMaskPair &P : RegOpers.Defs) {
558544
Register Reg = P.RegUnit;
559545
if (!Reg.isVirtual())
560546
continue;
561-
LaneBitmask LiveAfter = LiveRegs[Reg];
547+
LaneBitmask LiveAfter =
548+
LiveRegs.contains(Reg) ? LiveRegs.at(Reg) : LaneBitmask(0);
562549
LaneBitmask UseLanes = getRegLanes(RegOpers.Uses, Reg);
563550
LaneBitmask DefLanes = P.LaneMask;
564551
LaneBitmask LiveBefore = (LiveAfter & ~DefLanes) | UseLanes;
565552

566-
CurPressure.inc(Reg, LiveAfter, LiveAfter & LiveBefore, *MRI);
567-
MaxPressure = max(MaxPressure, CurPressure);
553+
TempPressure.inc(Reg, LiveAfter, LiveAfter & LiveBefore, *MRI);
568554
}
569555
// Generate liveness for uses.
570556
for (const RegisterMaskPair &P : RegOpers.Uses) {
571557
Register Reg = P.RegUnit;
572558
if (!Reg.isVirtual())
573559
continue;
574-
LaneBitmask LiveAfter = LiveRegs[Reg];
560+
LaneBitmask LiveAfter =
561+
LiveRegs.contains(Reg) ? LiveRegs.at(Reg) : LaneBitmask(0);
575562
LaneBitmask LiveBefore = LiveAfter | P.LaneMask;
576-
CurPressure.inc(Reg, LiveAfter, LiveBefore, *MRI);
563+
TempPressure.inc(Reg, LiveAfter, LiveBefore, *MRI);
577564
}
578-
MaxPressure = max(MaxPressure, CurPressure);
565+
return TempPressure;
579566
}
580567

581568
////////////////////////////////////////////////////////////////////////////////
@@ -736,8 +723,9 @@ Printable llvm::reportMismatch(const GCNRPTracker::LiveRegSet &LISLR,
736723
});
737724
}
738725

739-
void GCNDownwardRPTracker::bumpDownwardPressure(const MachineInstr *MI,
740-
const SIRegisterInfo *TRI) {
726+
GCNRegPressure
727+
GCNDownwardRPTracker::bumpDownwardPressure(const MachineInstr *MI,
728+
const SIRegisterInfo *TRI) const {
741729
assert(!MI->isDebugOrPseudoInstr() && "Expect a nondebug instruction.");
742730

743731
SlotIndex SlotIdx;
@@ -747,6 +735,7 @@ void GCNDownwardRPTracker::bumpDownwardPressure(const MachineInstr *MI,
747735
RegisterOperands RegOpers;
748736
RegOpers.collect(*MI, *TRI, *MRI, true, /*IgnoreDead=*/false);
749737
RegOpers.adjustLaneLiveness(LIS, *MRI, SlotIdx);
738+
GCNRegPressure TempPressure = CurPressure;
750739

751740
for (const RegisterMaskPair &Use : RegOpers.Uses) {
752741
Register Reg = Use.RegUnit;
@@ -775,24 +764,24 @@ void GCNDownwardRPTracker::bumpDownwardPressure(const MachineInstr *MI,
775764
if (LastUseMask.none())
776765
continue;
777766

778-
LaneBitmask LiveMask = LiveRegs[Reg];
767+
LaneBitmask LiveMask =
768+
LiveRegs.contains(Reg) ? LiveRegs.at(Reg) : LaneBitmask(0);
779769
LaneBitmask NewMask = LiveMask & ~LastUseMask;
780-
CurPressure.inc(Reg, LiveMask, NewMask, *MRI);
770+
TempPressure.inc(Reg, LiveMask, NewMask, *MRI);
781771
}
782772

783773
// Generate liveness for defs.
784774
for (const RegisterMaskPair &Def : RegOpers.Defs) {
785775
Register Reg = Def.RegUnit;
786776
if (!Reg.isVirtual())
787777
continue;
788-
LaneBitmask LiveMask = LiveRegs[Reg];
778+
LaneBitmask LiveMask =
779+
LiveRegs.contains(Reg) ? LiveRegs.at(Reg) : LaneBitmask(0);
789780
LaneBitmask NewMask = LiveMask | Def.LaneMask;
790-
CurPressure.inc(Reg, LiveMask, NewMask, *MRI);
781+
TempPressure.inc(Reg, LiveMask, NewMask, *MRI);
791782
}
792-
MaxPressure = max(MaxPressure, CurPressure);
793783

794-
// Boost pressure for all dead defs together.
795-
bumpDeadDefs(RegOpers.DeadDefs);
784+
return TempPressure;
796785
}
797786

798787
bool GCNUpwardRPTracker::isValid() const {

llvm/lib/Target/AMDGPU/GCNRegPressure.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class GCNUpwardRPTracker : public GCNRPTracker {
228228
/// does not rely on the implicit program ordering in the LiveIntervals to
229229
/// support RP Speculation. It leaves the state of pressure inconsistent with
230230
/// the current position
231-
void bumpUpwardPressure(const MachineInstr *MI, const SIRegisterInfo *TRI);
231+
GCNRegPressure bumpUpwardPressure(const MachineInstr *MI,
232+
const SIRegisterInfo *TRI) const;
232233

233234
/// \p returns whether the tracker's state after receding MI corresponds
234235
/// to reported by LIS.
@@ -315,7 +316,8 @@ class GCNDownwardRPTracker : public GCNRPTracker {
315316
/// does not rely on the implicit program ordering in the LiveIntervals to
316317
/// support RP Speculation. It leaves the state of pressure inconsistent with
317318
/// the current position
318-
void bumpDownwardPressure(const MachineInstr *MI, const SIRegisterInfo *TRI);
319+
GCNRegPressure bumpDownwardPressure(const MachineInstr *MI,
320+
const SIRegisterInfo *TRI) const;
319321
};
320322

321323
LaneBitmask getLiveLaneMask(unsigned Reg,

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,18 @@ static void getRegisterPressures(
173173
// GCNTrackers
174174
Pressure.resize(4, 0);
175175
MachineInstr *MI = SU->getInstr();
176+
GCNRegPressure NewPressure;
176177
if (AtTop) {
177178
GCNDownwardRPTracker TempDownwardTracker(DownwardTracker);
178-
TempDownwardTracker.bumpDownwardPressure(MI, SRI);
179-
Pressure[AMDGPU::RegisterPressureSets::SReg_32] =
180-
TempDownwardTracker.getPressure().getSGPRNum();
181-
Pressure[AMDGPU::RegisterPressureSets::VGPR_32] =
182-
TempDownwardTracker.getPressure().getArchVGPRNum();
183-
Pressure[AMDGPU::RegisterPressureSets::AGPR_32] =
184-
TempDownwardTracker.getPressure().getAGPRNum();
179+
NewPressure = TempDownwardTracker.bumpDownwardPressure(MI, SRI);
185180
} else {
186181
GCNUpwardRPTracker TempUpwardTracker(UpwardTracker);
187-
TempUpwardTracker.bumpUpwardPressure(MI, SRI);
188-
Pressure[AMDGPU::RegisterPressureSets::SReg_32] =
189-
TempUpwardTracker.getPressure().getSGPRNum();
190-
Pressure[AMDGPU::RegisterPressureSets::VGPR_32] =
191-
TempUpwardTracker.getPressure().getArchVGPRNum();
192-
Pressure[AMDGPU::RegisterPressureSets::AGPR_32] =
193-
TempUpwardTracker.getPressure().getAGPRNum();
182+
NewPressure = TempUpwardTracker.bumpUpwardPressure(MI, SRI);
194183
}
184+
Pressure[AMDGPU::RegisterPressureSets::SReg_32] = NewPressure.getSGPRNum();
185+
Pressure[AMDGPU::RegisterPressureSets::VGPR_32] =
186+
NewPressure.getArchVGPRNum();
187+
Pressure[AMDGPU::RegisterPressureSets::AGPR_32] = NewPressure.getAGPRNum();
195188
}
196189

197190
void GCNSchedStrategy::initCandidate(SchedCandidate &Cand, SUnit *SU,

0 commit comments

Comments
 (0)