Skip to content

Commit f5eeeec

Browse files
authored
[MachinePipeliner] Use Register. NFC (#130165)
1 parent 7425af4 commit f5eeeec

File tree

4 files changed

+89
-88
lines changed

4 files changed

+89
-88
lines changed

llvm/include/llvm/CodeGen/MachinePipeliner.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class SwingSchedulerDAG : public ScheduleDAGInstrs {
269269
using InstrMapTy = DenseMap<MachineInstr *, MachineInstr *>;
270270

271271
/// Instructions to change when emitting the final schedule.
272-
DenseMap<SUnit *, std::pair<unsigned, int64_t>> InstrChanges;
272+
DenseMap<SUnit *, std::pair<Register, int64_t>> InstrChanges;
273273

274274
/// We may create a new instruction, so remember it because it
275275
/// must be deleted when the pass is finished.
@@ -374,12 +374,12 @@ class SwingSchedulerDAG : public ScheduleDAGInstrs {
374374

375375
/// Return the new base register that was stored away for the changed
376376
/// instruction.
377-
unsigned getInstrBaseReg(SUnit *SU) const {
378-
DenseMap<SUnit *, std::pair<unsigned, int64_t>>::const_iterator It =
377+
Register getInstrBaseReg(SUnit *SU) const {
378+
DenseMap<SUnit *, std::pair<Register, int64_t>>::const_iterator It =
379379
InstrChanges.find(SU);
380380
if (It != InstrChanges.end())
381381
return It->second.first;
382-
return 0;
382+
return Register();
383383
}
384384

385385
void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) {
@@ -415,7 +415,7 @@ class SwingSchedulerDAG : public ScheduleDAGInstrs {
415415
bool computeDelta(const MachineInstr &MI, int &Delta) const;
416416
MachineInstr *findDefInLoop(Register Reg);
417417
bool canUseLastOffsetValue(MachineInstr *MI, unsigned &BasePos,
418-
unsigned &OffsetPos, unsigned &NewBase,
418+
unsigned &OffsetPos, Register &NewBase,
419419
int64_t &NewOffset);
420420
void postProcessDAG();
421421
/// Set the Minimum Initiation Interval for this schedule attempt.

llvm/include/llvm/CodeGen/ModuloSchedule.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ class ModuloSchedule {
160160
/// rewriting the old loop and inserting prologs and epilogs as required.
161161
class ModuloScheduleExpander {
162162
public:
163-
using InstrChangesTy = DenseMap<MachineInstr *, std::pair<unsigned, int64_t>>;
163+
using InstrChangesTy = DenseMap<MachineInstr *, std::pair<Register, int64_t>>;
164164

165165
private:
166-
using ValueMapTy = DenseMap<unsigned, unsigned>;
166+
using ValueMapTy = DenseMap<Register, Register>;
167167
using MBBVectorTy = SmallVectorImpl<MachineBasicBlock *>;
168168
using InstrMapTy = DenseMap<MachineInstr *, MachineInstr *>;
169169

@@ -183,7 +183,7 @@ class ModuloScheduleExpander {
183183
/// The first element in the pair is the max difference in stages. The
184184
/// second is true if the register defines a Phi value and loop value is
185185
/// scheduled before the Phi.
186-
std::map<unsigned, std::pair<unsigned, bool>> RegToStageDiff;
186+
std::map<Register, std::pair<unsigned, bool>> RegToStageDiff;
187187

188188
/// Instructions to change when emitting the final schedule.
189189
InstrChangesTy InstrChanges;
@@ -221,21 +221,21 @@ class ModuloScheduleExpander {
221221
void updateInstruction(MachineInstr *NewMI, bool LastDef,
222222
unsigned CurStageNum, unsigned InstrStageNum,
223223
ValueMapTy *VRMap);
224-
MachineInstr *findDefInLoop(unsigned Reg);
225-
unsigned getPrevMapVal(unsigned StageNum, unsigned PhiStage, unsigned LoopVal,
224+
MachineInstr *findDefInLoop(Register Reg);
225+
Register getPrevMapVal(unsigned StageNum, unsigned PhiStage, Register LoopVal,
226226
unsigned LoopStage, ValueMapTy *VRMap,
227227
MachineBasicBlock *BB);
228228
void rewritePhiValues(MachineBasicBlock *NewBB, unsigned StageNum,
229229
ValueMapTy *VRMap, InstrMapTy &InstrMap);
230230
void rewriteScheduledInstr(MachineBasicBlock *BB, InstrMapTy &InstrMap,
231231
unsigned CurStageNum, unsigned PhiNum,
232-
MachineInstr *Phi, unsigned OldReg,
233-
unsigned NewReg, unsigned PrevReg = 0);
232+
MachineInstr *Phi, Register OldReg,
233+
Register NewReg, Register PrevReg = Register());
234234
bool isLoopCarried(MachineInstr &Phi);
235235

236236
/// Return the max. number of stages/iterations that can occur between a
237237
/// register definition and its uses.
238-
unsigned getStagesForReg(int Reg, unsigned CurStage) {
238+
unsigned getStagesForReg(Register Reg, unsigned CurStage) {
239239
std::pair<unsigned, bool> Stages = RegToStageDiff[Reg];
240240
if ((int)CurStage > Schedule.getNumStages() - 1 && Stages.first == 0 &&
241241
Stages.second)
@@ -249,7 +249,7 @@ class ModuloScheduleExpander {
249249
/// This is not the case if the loop value is scheduled prior to the
250250
/// Phi in the same stage. This function returns the number of stages
251251
/// or iterations needed between the Phi definition and any uses.
252-
unsigned getStagesForPhi(int Reg) {
252+
unsigned getStagesForPhi(Register Reg) {
253253
std::pair<unsigned, bool> Stages = RegToStageDiff[Reg];
254254
if (Stages.second)
255255
return Stages.first;
@@ -374,7 +374,7 @@ class PeelingModuloScheduleExpander {
374374
/// It unrolls the kernel enough to avoid overlap of register lifetime.
375375
class ModuloScheduleExpanderMVE {
376376
private:
377-
using ValueMapTy = DenseMap<unsigned, unsigned>;
377+
using ValueMapTy = DenseMap<Register, Register>;
378378
using MBBVectorTy = SmallVectorImpl<MachineBasicBlock *>;
379379
using InstrMapTy = DenseMap<MachineInstr *, MachineInstr *>;
380380

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ void SwingSchedulerDAG::schedule() {
710710
Stages[SU->getInstr()] = Schedule.stageScheduled(SU);
711711
}
712712
}
713-
DenseMap<MachineInstr *, std::pair<unsigned, int64_t>> NewInstrChanges;
713+
DenseMap<MachineInstr *, std::pair<Register, int64_t>> NewInstrChanges;
714714
for (auto &KV : NewMIs) {
715715
Cycles[KV.first] = Cycles[KV.second];
716716
Stages[KV.first] = Stages[KV.second];
@@ -756,27 +756,27 @@ void SwingSchedulerDAG::finishBlock() {
756756
/// Return the register values for the operands of a Phi instruction.
757757
/// This function assume the instruction is a Phi.
758758
static void getPhiRegs(MachineInstr &Phi, MachineBasicBlock *Loop,
759-
unsigned &InitVal, unsigned &LoopVal) {
759+
Register &InitVal, Register &LoopVal) {
760760
assert(Phi.isPHI() && "Expecting a Phi.");
761761

762-
InitVal = 0;
763-
LoopVal = 0;
762+
InitVal = Register();
763+
LoopVal = Register();
764764
for (unsigned i = 1, e = Phi.getNumOperands(); i != e; i += 2)
765765
if (Phi.getOperand(i + 1).getMBB() != Loop)
766766
InitVal = Phi.getOperand(i).getReg();
767767
else
768768
LoopVal = Phi.getOperand(i).getReg();
769769

770-
assert(InitVal != 0 && LoopVal != 0 && "Unexpected Phi structure.");
770+
assert(InitVal && LoopVal && "Unexpected Phi structure.");
771771
}
772772

773773
/// Return the Phi register value that comes the loop block.
774-
static unsigned getLoopPhiReg(const MachineInstr &Phi,
774+
static Register getLoopPhiReg(const MachineInstr &Phi,
775775
const MachineBasicBlock *LoopBB) {
776776
for (unsigned i = 1, e = Phi.getNumOperands(); i != e; i += 2)
777777
if (Phi.getOperand(i + 1).getMBB() == LoopBB)
778778
return Phi.getOperand(i).getReg();
779-
return 0;
779+
return Register();
780780
}
781781

782782
/// Return true if SUb can be reached from SUa following the chain edges.
@@ -937,8 +937,8 @@ void SwingSchedulerDAG::updatePhiDependences() {
937937
for (SUnit &I : SUnits) {
938938
RemoveDeps.clear();
939939
// Set to true if the instruction has an operand defined by a Phi.
940-
unsigned HasPhiUse = 0;
941-
unsigned HasPhiDef = 0;
940+
Register HasPhiUse;
941+
Register HasPhiDef;
942942
MachineInstr *MI = I.getInstr();
943943
// Iterate over each operand, and we process the definitions.
944944
for (const MachineOperand &MO : MI->operands()) {
@@ -1017,7 +1017,8 @@ void SwingSchedulerDAG::changeDependences() {
10171017
// If so, we update the base and offset of the instruction and change
10181018
// the dependences.
10191019
for (SUnit &I : SUnits) {
1020-
unsigned BasePos = 0, OffsetPos = 0, NewBase = 0;
1020+
unsigned BasePos = 0, OffsetPos = 0;
1021+
Register NewBase;
10211022
int64_t NewOffset = 0;
10221023
if (!canUseLastOffsetValue(I.getInstr(), BasePos, OffsetPos, NewBase,
10231024
NewOffset))
@@ -1982,7 +1983,7 @@ static void computeLiveOuts(MachineFunction &MF, RegPressureTracker &RPTracker,
19821983
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
19831984
MachineRegisterInfo &MRI = MF.getRegInfo();
19841985
SmallVector<VRegMaskOrUnit, 8> LiveOutRegs;
1985-
SmallSet<unsigned, 4> Uses;
1986+
SmallSet<Register, 4> Uses;
19861987
for (SUnit *SU : NS) {
19871988
const MachineInstr *MI = SU->getInstr();
19881989
if (MI->isPHI())
@@ -2646,7 +2647,7 @@ bool SwingSchedulerDAG::computeDelta(const MachineInstr &MI, int &Delta) const {
26462647
bool SwingSchedulerDAG::canUseLastOffsetValue(MachineInstr *MI,
26472648
unsigned &BasePos,
26482649
unsigned &OffsetPos,
2649-
unsigned &NewBase,
2650+
Register &NewBase,
26502651
int64_t &Offset) {
26512652
// Get the load instruction.
26522653
if (TII->isPostIncrement(*MI))
@@ -2662,7 +2663,7 @@ bool SwingSchedulerDAG::canUseLastOffsetValue(MachineInstr *MI,
26622663
if (!Phi || !Phi->isPHI())
26632664
return false;
26642665
// Get the register defined in the loop block.
2665-
unsigned PrevReg = getLoopPhiReg(*Phi, MI->getParent());
2666+
Register PrevReg = getLoopPhiReg(*Phi, MI->getParent());
26662667
if (!PrevReg)
26672668
return false;
26682669

@@ -2702,10 +2703,10 @@ bool SwingSchedulerDAG::canUseLastOffsetValue(MachineInstr *MI,
27022703
void SwingSchedulerDAG::applyInstrChange(MachineInstr *MI,
27032704
SMSchedule &Schedule) {
27042705
SUnit *SU = getSUnit(MI);
2705-
DenseMap<SUnit *, std::pair<unsigned, int64_t>>::iterator It =
2706+
DenseMap<SUnit *, std::pair<Register, int64_t>>::iterator It =
27062707
InstrChanges.find(SU);
27072708
if (It != InstrChanges.end()) {
2708-
std::pair<unsigned, int64_t> RegAndOffset = It->second;
2709+
std::pair<Register, int64_t> RegAndOffset = It->second;
27092710
unsigned BasePos, OffsetPos;
27102711
if (!TII->getBaseAndOffsetPosition(*MI, BasePos, OffsetPos))
27112712
return;
@@ -2789,10 +2790,10 @@ bool SwingSchedulerDAG::mayOverlapInLaterIter(
27892790
if (!DefB || !DefO || !DefB->isPHI() || !DefO->isPHI())
27902791
return true;
27912792

2792-
unsigned InitValB = 0;
2793-
unsigned LoopValB = 0;
2794-
unsigned InitValO = 0;
2795-
unsigned LoopValO = 0;
2793+
Register InitValB;
2794+
Register LoopValB;
2795+
Register InitValO;
2796+
Register LoopValO;
27962797
getPhiRegs(*DefB, BB, InitValB, LoopValB);
27972798
getPhiRegs(*DefO, BB, InitValO, LoopValO);
27982799
MachineInstr *InitDefB = MRI.getVRegDef(InitValB);
@@ -3062,7 +3063,7 @@ void SMSchedule::orderDependence(const SwingSchedulerDAG *SSD, SUnit *SU,
30623063
unsigned BasePos, OffsetPos;
30633064
if (ST.getInstrInfo()->getBaseAndOffsetPosition(*MI, BasePos, OffsetPos))
30643065
if (MI->getOperand(BasePos).getReg() == Reg)
3065-
if (unsigned NewReg = SSD->getInstrBaseReg(SU))
3066+
if (Register NewReg = SSD->getInstrBaseReg(SU))
30663067
Reg = NewReg;
30673068
bool Reads, Writes;
30683069
std::tie(Reads, Writes) =
@@ -3180,8 +3181,8 @@ bool SMSchedule::isLoopCarried(const SwingSchedulerDAG *SSD,
31803181
unsigned DefCycle = cycleScheduled(DefSU);
31813182
int DefStage = stageScheduled(DefSU);
31823183

3183-
unsigned InitVal = 0;
3184-
unsigned LoopVal = 0;
3184+
Register InitVal;
3185+
Register LoopVal;
31853186
getPhiRegs(Phi, Phi.getParent(), InitVal, LoopVal);
31863187
SUnit *UseSU = SSD->getSUnit(MRI.getVRegDef(LoopVal));
31873188
if (!UseSU)
@@ -3212,7 +3213,7 @@ bool SMSchedule::isLoopCarriedDefOfUse(const SwingSchedulerDAG *SSD,
32123213
return false;
32133214
if (!isLoopCarried(SSD, *Phi))
32143215
return false;
3215-
unsigned LoopReg = getLoopPhiReg(*Phi, Phi->getParent());
3216+
Register LoopReg = getLoopPhiReg(*Phi, Phi->getParent());
32163217
for (MachineOperand &DMO : Def->all_defs()) {
32173218
if (DMO.getReg() == LoopReg)
32183219
return true;
@@ -3434,8 +3435,8 @@ void SwingSchedulerDAG::checkValidNodeOrder(const NodeSetType &Circuits) const {
34343435
/// In this case p and p' overlap, which means that two registers are needed.
34353436
/// Instead, this function changes the load to use p' and updates the offset.
34363437
void SwingSchedulerDAG::fixupRegisterOverlaps(std::deque<SUnit *> &Instrs) {
3437-
unsigned OverlapReg = 0;
3438-
unsigned NewBaseReg = 0;
3438+
Register OverlapReg;
3439+
Register NewBaseReg;
34393440
for (SUnit *SU : Instrs) {
34403441
MachineInstr *MI = SU->getInstr();
34413442
for (unsigned i = 0, e = MI->getNumOperands(); i < e; ++i) {
@@ -3445,8 +3446,8 @@ void SwingSchedulerDAG::fixupRegisterOverlaps(std::deque<SUnit *> &Instrs) {
34453446
if (MO.isReg() && MO.isUse() && MO.getReg() == OverlapReg) {
34463447
// Check that the instruction appears in the InstrChanges structure,
34473448
// which contains instructions that can have the offset updated.
3448-
DenseMap<SUnit *, std::pair<unsigned, int64_t>>::iterator It =
3449-
InstrChanges.find(SU);
3449+
DenseMap<SUnit *, std::pair<Register, int64_t>>::iterator It =
3450+
InstrChanges.find(SU);
34503451
if (It != InstrChanges.end()) {
34513452
unsigned BasePos, OffsetPos;
34523453
// Update the base register and adjust the offset.
@@ -3461,8 +3462,8 @@ void SwingSchedulerDAG::fixupRegisterOverlaps(std::deque<SUnit *> &Instrs) {
34613462
NewMIs[MI] = NewMI;
34623463
}
34633464
}
3464-
OverlapReg = 0;
3465-
NewBaseReg = 0;
3465+
OverlapReg = Register();
3466+
NewBaseReg = Register();
34663467
break;
34673468
}
34683469
// Look for an instruction of the form p' = op(p), which uses and defines

0 commit comments

Comments
 (0)