Skip to content

Commit

Permalink
Provide operand indices to adjustSchedDependency
Browse files Browse the repository at this point in the history
This allows targets to know exactly which operands are contributing to
the dependency, which is required for targets with per-operand
scheduling models.

Differential Revision: https://reviews.llvm.org/D77135
  • Loading branch information
frasercrmck committed Apr 17, 2020
1 parent fa7f328 commit c819ef9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 22 deletions.
8 changes: 6 additions & 2 deletions llvm/include/llvm/CodeGen/TargetSubtargetInfo.h
Expand Up @@ -224,9 +224,13 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
unsigned NumRegionInstrs) const {}

// Perform target specific adjustments to the latency of a schedule
// Perform target-specific adjustments to the latency of a schedule
// dependency.
virtual void adjustSchedDependency(SUnit *def, SUnit *use, SDep &dep) const {}
// If a pair of operands is associated with the schedule dependency, DefOpIdx
// and UseOpIdx are the indices of the operands in Def and Use, respectively.
// Otherwise, either may be -1.
virtual void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use,
int UseOpIdx, SDep &Dep) const {}

// For use with PostRAScheduling: get the anti-dependence breaking that should
// be performed before post-RA scheduling.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachinePipeliner.cpp
Expand Up @@ -809,7 +809,7 @@ void SwingSchedulerDAG::updatePhiDependences() {
if (!MI->isPHI()) {
SDep Dep(SU, SDep::Data, Reg);
Dep.setLatency(0);
ST.adjustSchedDependency(SU, &I, Dep);
ST.adjustSchedDependency(SU, 0, &I, MI->getOperandNo(MOI), Dep);
I.addPred(Dep);
} else {
HasPhiUse = Reg;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
Expand Up @@ -269,13 +269,13 @@ void ScheduleDAGInstrs::addPhysRegDataDeps(SUnit *SU, unsigned OperIdx) {
if (!ImplicitPseudoDef && !ImplicitPseudoUse) {
Dep.setLatency(SchedModel.computeOperandLatency(SU->getInstr(), OperIdx,
RegUse, UseOp));
ST.adjustSchedDependency(SU, UseSU, Dep);
ST.adjustSchedDependency(SU, OperIdx, UseSU, UseOp, Dep);
} else {
Dep.setLatency(0);
// FIXME: We could always let target to adjustSchedDependency(), and
// remove this condition, but that currently asserts in Hexagon BE.
if (SU->getInstr()->isBundle() || (RegUse && RegUse->isBundle()))
ST.adjustSchedDependency(SU, UseSU, Dep);
ST.adjustSchedDependency(SU, OperIdx, UseSU, UseOp, Dep);
}

UseSU->addPred(Dep);
Expand Down Expand Up @@ -444,7 +444,7 @@ void ScheduleDAGInstrs::addVRegDefDeps(SUnit *SU, unsigned OperIdx) {
SDep Dep(SU, SDep::Data, Reg);
Dep.setLatency(SchedModel.computeOperandLatency(MI, OperIdx, Use,
I->OperandIndex));
ST.adjustSchedDependency(SU, UseSU, Dep);
ST.adjustSchedDependency(SU, OperIdx, UseSU, I->OperandIndex, Dep);
UseSU->addPred(Dep);
}

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
Expand Up @@ -474,6 +474,7 @@ void ScheduleDAGSDNodes::AddSchedEdges() {

for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
SDNode *OpN = N->getOperand(i).getNode();
unsigned DefIdx = N->getOperand(i).getResNo();
if (isPassiveNode(OpN)) continue; // Not scheduled.
SUnit *OpSU = &SUnits[OpN->getNodeId()];
assert(OpSU && "Node has no SUnit!");
Expand Down Expand Up @@ -508,7 +509,7 @@ void ScheduleDAGSDNodes::AddSchedEdges() {
Dep.setLatency(OpLatency);
if (!isChain && !UnitLatencies) {
computeOperandLatency(OpN, N, i, Dep);
ST.adjustSchedDependency(OpSU, SU, Dep);
ST.adjustSchedDependency(OpSU, DefIdx, SU, i, Dep);
}

if (!SU->addPred(Dep) && !Dep.isCtrl() && OpSU->NumRegDefsLeft > 1) {
Expand Down
24 changes: 12 additions & 12 deletions llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp
Expand Up @@ -722,20 +722,20 @@ unsigned GCNSubtarget::getMaxNumVGPRs(const MachineFunction &MF) const {
return MaxNumVGPRs;
}

void GCNSubtarget::adjustSchedDependency(SUnit *Src, SUnit *Dst,
SDep &Dep) const {
void GCNSubtarget::adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use,
int UseOpIdx, SDep &Dep) const {
if (Dep.getKind() != SDep::Kind::Data || !Dep.getReg() ||
!Src->isInstr() || !Dst->isInstr())
!Def->isInstr() || !Use->isInstr())
return;

MachineInstr *SrcI = Src->getInstr();
MachineInstr *DstI = Dst->getInstr();
MachineInstr *DefI = Def->getInstr();
MachineInstr *UseI = Use->getInstr();

if (SrcI->isBundle()) {
if (DefI->isBundle()) {
const SIRegisterInfo *TRI = getRegisterInfo();
auto Reg = Dep.getReg();
MachineBasicBlock::const_instr_iterator I(SrcI->getIterator());
MachineBasicBlock::const_instr_iterator E(SrcI->getParent()->instr_end());
MachineBasicBlock::const_instr_iterator I(DefI->getIterator());
MachineBasicBlock::const_instr_iterator E(DefI->getParent()->instr_end());
unsigned Lat = 0;
for (++I; I != E && I->isBundledWithPred(); ++I) {
if (I->modifiesRegister(Reg, TRI))
Expand All @@ -744,12 +744,12 @@ void GCNSubtarget::adjustSchedDependency(SUnit *Src, SUnit *Dst,
--Lat;
}
Dep.setLatency(Lat);
} else if (DstI->isBundle()) {
} else if (UseI->isBundle()) {
const SIRegisterInfo *TRI = getRegisterInfo();
auto Reg = Dep.getReg();
MachineBasicBlock::const_instr_iterator I(DstI->getIterator());
MachineBasicBlock::const_instr_iterator E(DstI->getParent()->instr_end());
unsigned Lat = InstrInfo.getInstrLatency(getInstrItineraryData(), *SrcI);
MachineBasicBlock::const_instr_iterator I(UseI->getIterator());
MachineBasicBlock::const_instr_iterator E(UseI->getParent()->instr_end());
unsigned Lat = InstrInfo.getInstrLatency(getInstrItineraryData(), *DefI);
for (++I; I != E && I->isBundledWithPred() && Lat; ++I) {
if (I->readsRegister(Reg, TRI))
break;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
Expand Up @@ -1193,7 +1193,8 @@ class GCNSubtarget : public AMDGPUGenSubtargetInfo,
return AMDGPU::IsaInfo::getMinWavesPerEU(this);
}

void adjustSchedDependency(SUnit *Src, SUnit *Dst, SDep &Dep) const override;
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
SDep &Dep) const override;
};

class R600Subtarget final : public R600GenSubtargetInfo,
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
Expand Up @@ -315,7 +315,8 @@ bool HexagonSubtarget::useAA() const {

/// Perform target specific adjustments to the latency of a schedule
/// dependency.
void HexagonSubtarget::adjustSchedDependency(SUnit *Src, SUnit *Dst,
void HexagonSubtarget::adjustSchedDependency(SUnit *Src, int SrcOpIdx,
SUnit *Dst, int DstOpIdx,
SDep &Dep) const {
MachineInstr *SrcInst = Src->getInstr();
MachineInstr *DstInst = Dst->getInstr();
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/Hexagon/HexagonSubtarget.h
Expand Up @@ -258,7 +258,8 @@ class HexagonSubtarget : public HexagonGenSubtargetInfo {

/// Perform target specific adjustments to the latency of a schedule
/// dependency.
void adjustSchedDependency(SUnit *def, SUnit *use, SDep& dep) const override;
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
SDep &Dep) const override;

unsigned getVectorLength() const {
assert(useHVXOps());
Expand Down

0 comments on commit c819ef9

Please sign in to comment.