Skip to content

Commit 987bf8b

Browse files
committed
Let targets adjust operand latency of bundles
This reverts the AMDGPU DAG mutation implemented in D72487 and gives a more general way of adjusting BUNDLE operand latency. It also replaces FixBundleLatencyMutation with adjustSchedDependency callback in the AMDGPU, fixing not only successor latencies but predecessors' as well. Differential Revision: https://reviews.llvm.org/D72535
1 parent 4c00dbf commit 987bf8b

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

llvm/lib/CodeGen/ScheduleDAGInstrs.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,13 @@ void ScheduleDAGInstrs::addPhysRegDataDeps(SUnit *SU, unsigned OperIdx) {
270270
Dep.setLatency(SchedModel.computeOperandLatency(SU->getInstr(), OperIdx,
271271
RegUse, UseOp));
272272
ST.adjustSchedDependency(SU, UseSU, Dep);
273-
} else
273+
} else {
274274
Dep.setLatency(0);
275+
// FIXME: We could always let target to adjustSchedDependency(), and
276+
// remove this condition, but that currently asserts in Hexagon BE.
277+
if (SU->getInstr()->isBundle() || (RegUse && RegUse->isBundle()))
278+
ST.adjustSchedDependency(SU, UseSU, Dep);
279+
}
275280

276281
UseSU->addPred(Dep);
277282
}

llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp

+25-40
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,31 @@ unsigned GCNSubtarget::getMaxNumVGPRs(const MachineFunction &MF) const {
716716
return MaxNumVGPRs;
717717
}
718718

719+
void GCNSubtarget::adjustSchedDependency(SUnit *Src, SUnit *Dst,
720+
SDep &Dep) const {
721+
if (Dep.getKind() != SDep::Kind::Data || !Dep.getReg() ||
722+
!Src->isInstr() || !Dst->isInstr())
723+
return;
724+
725+
MachineInstr *SrcI = Src->getInstr();
726+
MachineInstr *DstI = Dst->getInstr();
727+
728+
if (SrcI->isBundle()) {
729+
const SIRegisterInfo *TRI = getRegisterInfo();
730+
auto Reg = Dep.getReg();
731+
MachineBasicBlock::const_instr_iterator I(SrcI->getIterator());
732+
MachineBasicBlock::const_instr_iterator E(SrcI->getParent()->instr_end());
733+
for (++I; I != E && I->isBundledWithPred(); ++I) {
734+
if (!I->modifiesRegister(Reg, TRI))
735+
continue;
736+
Dep.setLatency(InstrInfo.getInstrLatency(getInstrItineraryData(), *I));
737+
break;
738+
}
739+
} else if (DstI->isBundle()) {
740+
Dep.setLatency(InstrInfo.getInstrLatency(getInstrItineraryData(), *SrcI));
741+
}
742+
}
743+
719744
namespace {
720745
struct MemOpClusterMutation : ScheduleDAGMutation {
721746
const SIInstrInfo *TII;
@@ -764,45 +789,6 @@ struct MemOpClusterMutation : ScheduleDAGMutation {
764789
}
765790
};
766791

767-
struct FixBundleLatencyMutation : ScheduleDAGMutation {
768-
const SIInstrInfo *TII;
769-
770-
const TargetSchedModel *TSchedModel;
771-
772-
FixBundleLatencyMutation(const SIInstrInfo *tii) : TII(tii) {}
773-
774-
unsigned computeLatency(const MachineInstr &MI, unsigned Reg) const {
775-
const SIRegisterInfo &TRI = TII->getRegisterInfo();
776-
MachineBasicBlock::const_instr_iterator I(MI.getIterator());
777-
MachineBasicBlock::const_instr_iterator E(MI.getParent()->instr_end());
778-
unsigned Lat = 0;
779-
for (++I; I != E && I->isBundledWithPred(); ++I) {
780-
if (!I->modifiesRegister(Reg, &TRI))
781-
continue;
782-
Lat = TSchedModel->computeInstrLatency(&*I);
783-
break;
784-
}
785-
return Lat;
786-
}
787-
788-
void apply(ScheduleDAGInstrs *DAGInstrs) override {
789-
ScheduleDAGMI *DAG = static_cast<ScheduleDAGMI*>(DAGInstrs);
790-
TSchedModel = DAGInstrs->getSchedModel();
791-
if (!TSchedModel || DAG->SUnits.empty())
792-
return;
793-
794-
for (SUnit &SU : DAG->SUnits) {
795-
if (!SU.isInstr() || !SU.getInstr()->isBundle())
796-
continue;
797-
for (SDep &Dep : SU.Succs) {
798-
if (Dep.getKind() == SDep::Kind::Data && Dep.getReg())
799-
if (unsigned Lat = computeLatency(*SU.getInstr(), Dep.getReg()))
800-
Dep.setLatency(Lat);
801-
}
802-
}
803-
}
804-
};
805-
806792
struct FillMFMAShadowMutation : ScheduleDAGMutation {
807793
const SIInstrInfo *TII;
808794

@@ -929,7 +915,6 @@ struct FillMFMAShadowMutation : ScheduleDAGMutation {
929915

930916
void GCNSubtarget::getPostRAMutations(
931917
std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
932-
Mutations.push_back(std::make_unique<FixBundleLatencyMutation>(&InstrInfo));
933918
Mutations.push_back(std::make_unique<MemOpClusterMutation>(&InstrInfo));
934919
Mutations.push_back(std::make_unique<FillMFMAShadowMutation>(&InstrInfo));
935920
}

llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h

+2
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,8 @@ class GCNSubtarget : public AMDGPUGenSubtargetInfo,
12121212
unsigned getMinWavesPerEU() const override {
12131213
return AMDGPU::IsaInfo::getMinWavesPerEU(this);
12141214
}
1215+
1216+
void adjustSchedDependency(SUnit *Src, SUnit *Dst, SDep &Dep) const override;
12151217
};
12161218

12171219
class R600Subtarget final : public R600GenSubtargetInfo,

llvm/lib/Target/AMDGPU/SIInstrInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
10451045

10461046
unsigned getInstrLatency(const InstrItineraryData *ItinData,
10471047
const MachineInstr &MI,
1048-
unsigned *PredCost) const override;
1048+
unsigned *PredCost = nullptr) const override;
10491049
};
10501050

10511051
/// \brief Returns true if a reg:subreg pair P has a TRC class

0 commit comments

Comments
 (0)