Skip to content

Commit 61dfcf4

Browse files
Martien de Jongmartien-de-jong
authored andcommitted
[AIE] Slightly more flexibility in DataDependenceHelper
We pass some flags down which control the asserts that are meant to check completeness of the scheduler model for postscheduler's sake. That allows us to create a more approximate ddg in earlier stages. These would throw, mainly on occurrences of PseudoInstructions
1 parent ef5e33e commit 61dfcf4

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

llvm/lib/Target/AIE/AIEBaseSubtarget.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ bool updateSuccLatency(SDep &SuccEdge, SUnit &PredSU, int Latency) {
195195
// The initial graph will have ordering edges induced by hasSideEffects of the
196196
// locks/DONE.
197197
class LockDelays : public ScheduleDAGMutation {
198+
bool ExactLatencies = true;
198199
void apply(ScheduleDAGInstrs *DAG) override {
199200
const auto *TII = static_cast<const AIEBaseInstrInfo *>(DAG->TII);
200201
const int CoreStallCycle = TII->getCoreStallCycleAfterLock();
@@ -218,22 +219,31 @@ class LockDelays : public ScheduleDAGMutation {
218219
continue;
219220
}
220221
// Ensure memory operation happens before the core stalls
221-
int Delay = *TII->getLastMemoryCycle(LdSt->getDesc().SchedClass) -
222-
CoreStallCycle + 1;
222+
auto OptLastMemCycle =
223+
TII->getLastMemoryCycle(LdSt->getDesc().SchedClass);
224+
assert(!ExactLatencies || OptLastMemCycle);
225+
const int LastMemCycle = OptLastMemCycle.value_or(7);
226+
const int Delay = LastMemCycle - CoreStallCycle + 1;
223227
updatePredLatency(PredEdge, SU, Delay);
224228
}
225229
for (auto &SuccEdge : SU.Succs) {
226230
MachineInstr *LdSt = SuccEdge.getSUnit()->getInstr();
227231
if (SuccEdge.getKind() != SDep::Order || !LdSt->mayLoadOrStore()) {
228232
continue;
229233
}
234+
auto OptFirstMemCycle =
235+
TII->getFirstMemoryCycle(LdSt->getDesc().SchedClass);
236+
assert(!ExactLatencies || OptFirstMemCycle);
237+
const int FirstMemCycle = OptFirstMemCycle.value_or(4);
230238
// Ensure memory operation happens after the core resumes
231-
int Delay = CoreResumeCycle -
232-
*TII->getFirstMemoryCycle(LdSt->getDesc().SchedClass) + 1;
239+
const int Delay = CoreResumeCycle - FirstMemCycle + 1;
233240
updateSuccLatency(SuccEdge, SU, Delay);
234241
}
235242
}
236-
};
243+
}
244+
245+
public:
246+
LockDelays(bool ExactLatencies) : ExactLatencies(ExactLatencies) {};
237247
};
238248

239249
#undef DEBUG_TYPE
@@ -649,6 +659,7 @@ class PropagateIncomingLatencies : public ScheduleDAGMutation {
649659
/// fix the latencies to preserve the ordering.
650660
/// E.g. in AIE2: VST.SRS stores in E7, while VLDA reads in E5.
651661
class MemoryEdges : public ScheduleDAGMutation {
662+
bool ExactLatencies = true;
652663
void apply(ScheduleDAGInstrs *DAG) override {
653664
const auto *TII = static_cast<const AIEBaseInstrInfo *>(DAG->TII);
654665
// Run over all instructions that may load or store, and correct the
@@ -677,16 +688,22 @@ class MemoryEdges : public ScheduleDAGMutation {
677688
// Get the correct latency from the Sched model.
678689
std::optional<int> MemLat = TII->getMemoryLatency(
679690
SrcMI.getDesc().getSchedClass(), MI.getDesc().getSchedClass());
680-
if (!MemLat.has_value()) {
691+
int Latency = 1;
692+
if (MemLat.has_value()) {
693+
Latency = *MemLat;
694+
} else if (ExactLatencies) {
681695
LLVM_DEBUG(llvm::dbgs()
682696
<< "Error: no memory latency info for dependency\n from: "
683697
<< SrcMI << " to: " << MI);
684698
report_fatal_error("Missing memory latency info.");
685699
}
686-
updatePredLatency(PredEdge, SU, *MemLat);
700+
updatePredLatency(PredEdge, SU, Latency);
687701
}
688702
}
689-
};
703+
}
704+
705+
public:
706+
MemoryEdges(bool ExactLatencies) : ExactLatencies(ExactLatencies) {};
690707
};
691708

692709
void dumpDependencies(ScheduleDAGInstrs *DAG, SDep::Kind depType,
@@ -865,12 +882,12 @@ class WAWStickyRegistersEdges : public ScheduleDAGMutation {
865882
std::vector<std::unique_ptr<ScheduleDAGMutation>>
866883
AIEBaseSubtarget::getPostRAMutationsImpl(const Triple &TT) {
867884
std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
868-
Mutations.emplace_back(std::make_unique<LockDelays>());
885+
Mutations.emplace_back(std::make_unique<LockDelays>(true));
869886
if (!TT.isAIE1()) {
870887
if (EnableWAWStickyRegisters)
871888
Mutations.emplace_back(std::make_unique<WAWStickyRegistersEdges>());
872889
Mutations.emplace_back(std::make_unique<RegionEndEdges>());
873-
Mutations.emplace_back(std::make_unique<MemoryEdges>());
890+
Mutations.emplace_back(std::make_unique<MemoryEdges>(true));
874891
Mutations.emplace_back(std::make_unique<MachineSchedWAWEdges>());
875892
Mutations.emplace_back(std::make_unique<BiasDepth>());
876893
Mutations.emplace_back(std::make_unique<EmitFixedSUnits>());
@@ -880,12 +897,12 @@ AIEBaseSubtarget::getPostRAMutationsImpl(const Triple &TT) {
880897

881898
// List the Mutations that apply to the interblock DAG construction.
882899
std::vector<std::unique_ptr<ScheduleDAGMutation>>
883-
AIEBaseSubtarget::getInterBlockMutationsImpl(const Triple &TT) {
900+
AIEBaseSubtarget::getDDGMutationsImpl(const Triple &TT, bool ExactLatencies) {
884901
std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
885-
Mutations.emplace_back(std::make_unique<LockDelays>());
902+
Mutations.emplace_back(std::make_unique<LockDelays>(ExactLatencies));
886903
if (!TT.isAIE1()) {
887904
Mutations.emplace_back(std::make_unique<RegionEndEdges>());
888-
Mutations.emplace_back(std::make_unique<MemoryEdges>());
905+
Mutations.emplace_back(std::make_unique<MemoryEdges>(ExactLatencies));
889906
Mutations.emplace_back(std::make_unique<MachineSchedWAWEdges>());
890907
}
891908
return Mutations;

llvm/lib/Target/AIE/AIEBaseSubtarget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
// (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
7+
// (c) Copyright 2023-2025 Advanced Micro Devices, Inc. or its affiliates
88
//
99
//===----------------------------------------------------------------------===//
1010
//
@@ -77,7 +77,7 @@ class AIEBaseSubtarget {
7777

7878
/// Required DAG mutations for InterBlock dependence analysis
7979
static std::vector<std::unique_ptr<ScheduleDAGMutation>>
80-
getInterBlockMutationsImpl(const Triple &TT);
80+
getDDGMutationsImpl(const Triple &TT, bool ExactLatencies);
8181

8282
/// Required DAG mutations during Pre-RA scheduling.
8383
static std::vector<std::unique_ptr<ScheduleDAGMutation>>

llvm/lib/Target/AIE/AIEDataDependenceHelper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ static cl::opt<bool>
2121
cl::desc("Allow memory dependences in DataDependenceHelper "));
2222

2323
DataDependenceHelper::DataDependenceHelper(const MachineSchedContext &Context,
24-
bool AddMutators)
24+
bool AddMutators,
25+
bool ExactLatencies)
2526
: ScheduleDAGInstrs(*Context.MF, Context.MLI), Context(Context) {
2627
if (!AddMutators)
2728
return;
2829

2930
auto &Subtarget = Context.MF->getSubtarget();
3031
auto TT = Subtarget.getTargetTriple();
31-
for (auto &M : AIEBaseSubtarget::getInterBlockMutationsImpl(TT)) {
32+
for (auto &M : AIEBaseSubtarget::getDDGMutationsImpl(TT, ExactLatencies)) {
3233
Mutations.emplace_back(std::move(M));
3334
}
3435
}

llvm/lib/Target/AIE/AIEDataDependenceHelper.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ class DataDependenceHelper : public ScheduleDAGInstrs {
3939
bool mayAlias(SUnit *SUa, SUnit *SUb, bool TBAA) override;
4040

4141
public:
42-
DataDependenceHelper(const MachineSchedContext &Context,
43-
bool AddMutators = true);
44-
45-
// After adding the nodes, create the edges, using the order in which the
46-
// nodes were added.
42+
DataDependenceHelper(const MachineSchedContext &Context, bool AddMutators,
43+
bool ExactLatencies);
4744
void buildEdges();
4845

4946
// Compute the maximum depth of all nodes. The depth is the earliest cycle

llvm/lib/Target/AIE/AIEInterBlockScheduling.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class InterBlockEdges {
4646
IndexMap SuccMap;
4747

4848
public:
49-
InterBlockEdges(const MachineSchedContext &Context) : DDG(Context) {}
49+
InterBlockEdges(const MachineSchedContext &Context)
50+
: DDG(Context, true, true) {}
5051

5152
/// Add a Node to the DAG.
5253
void addNode(MachineInstr *);

llvm/lib/Target/AIE/AIEPtrModOptimizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ bool AIEPtrModOptimizer::runOnMachineFunction(MachineFunction &MF) {
6060

6161
// To build the edges in the DAG, the reserved Registers have to be freezed
6262
MRI.freezeReservedRegs();
63-
AIE::DataDependenceHelper DAG(Context, /*AddMutators=*/false);
63+
const bool AddMutators = false;
64+
const bool ExactLatencies = false;
65+
AIE::DataDependenceHelper DAG(Context, AddMutators, ExactLatencies);
6466

6567
// Fixme: these combiners should be provided by tablegen
6668
std::vector<const AIE::GenericCombiner *> Combiners;

0 commit comments

Comments
 (0)