Skip to content

Commit a2aed8b

Browse files
committed
[MISched] Add templates for creating custom schedulers
We make `createGenericSchedLive` and `createGenericSchedPostRA` templates that accept a `Strategy`. This can simplify some code for targets that have custom scheduler strategy.
1 parent fdc7812 commit a2aed8b

File tree

5 files changed

+45
-54
lines changed

5 files changed

+45
-54
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,14 +1349,6 @@ class PostGenericScheduler : public GenericSchedulerBase {
13491349
void pickNodeFromQueue(SchedBoundary &Zone, SchedCandidate &Cand);
13501350
};
13511351

1352-
/// Create the standard converging machine scheduler. This will be used as the
1353-
/// default scheduler if the target does not set a default.
1354-
/// Adds default DAG mutations.
1355-
ScheduleDAGMILive *createGenericSchedLive(MachineSchedContext *C);
1356-
1357-
/// Create a generic scheduler with no vreg liveness or DAG mutation passes.
1358-
ScheduleDAGMI *createGenericSchedPostRA(MachineSchedContext *C);
1359-
13601352
/// If ReorderWhileClustering is set to true, no attempt will be made to
13611353
/// reduce reordering due to store clustering.
13621354
std::unique_ptr<ScheduleDAGMutation>
@@ -1375,6 +1367,41 @@ std::unique_ptr<ScheduleDAGMutation>
13751367
createCopyConstrainDAGMutation(const TargetInstrInfo *TII,
13761368
const TargetRegisterInfo *TRI);
13771369

1370+
/// Create the standard converging machine scheduler. This will be used as the
1371+
/// default scheduler if the target does not set a default.
1372+
/// Adds default DAG mutations.
1373+
template <typename Strategy = GenericScheduler>
1374+
ScheduleDAGMILive *createGenericSchedLive(MachineSchedContext *C) {
1375+
ScheduleDAGMILive *DAG =
1376+
new ScheduleDAGMILive(C, std::make_unique<Strategy>(C));
1377+
// Register DAG post-processors.
1378+
//
1379+
// FIXME: extend the mutation API to allow earlier mutations to instantiate
1380+
// data and pass it to later mutations. Have a single mutation that gathers
1381+
// the interesting nodes in one pass.
1382+
DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
1383+
1384+
const TargetSubtargetInfo &STI = C->MF->getSubtarget();
1385+
// Add MacroFusion mutation if fusions are not empty.
1386+
const auto &MacroFusions = STI.getMacroFusions();
1387+
if (!MacroFusions.empty())
1388+
DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
1389+
return DAG;
1390+
}
1391+
1392+
/// Create a generic scheduler with no vreg liveness or DAG mutation passes.
1393+
template <typename Strategy = PostGenericScheduler>
1394+
ScheduleDAGMI *createGenericSchedPostRA(MachineSchedContext *C) {
1395+
ScheduleDAGMI *DAG = new ScheduleDAGMI(C, std::make_unique<Strategy>(C),
1396+
/*RemoveKillFlags=*/true);
1397+
const TargetSubtargetInfo &STI = C->MF->getSubtarget();
1398+
// Add MacroFusion mutation if fusions are not empty.
1399+
const auto &MacroFusions = STI.getMacroFusions();
1400+
if (!MacroFusions.empty())
1401+
DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
1402+
return DAG;
1403+
}
1404+
13781405
} // end namespace llvm
13791406

13801407
#endif // LLVM_CODEGEN_MACHINESCHEDULER_H

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,26 +3848,6 @@ void GenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
38483848
}
38493849
}
38503850

3851-
/// Create the standard converging machine scheduler. This will be used as the
3852-
/// default scheduler if the target does not set a default.
3853-
ScheduleDAGMILive *llvm::createGenericSchedLive(MachineSchedContext *C) {
3854-
ScheduleDAGMILive *DAG =
3855-
new ScheduleDAGMILive(C, std::make_unique<GenericScheduler>(C));
3856-
// Register DAG post-processors.
3857-
//
3858-
// FIXME: extend the mutation API to allow earlier mutations to instantiate
3859-
// data and pass it to later mutations. Have a single mutation that gathers
3860-
// the interesting nodes in one pass.
3861-
DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
3862-
3863-
const TargetSubtargetInfo &STI = C->MF->getSubtarget();
3864-
// Add MacroFusion mutation if fusions are not empty.
3865-
const auto &MacroFusions = STI.getMacroFusions();
3866-
if (!MacroFusions.empty())
3867-
DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
3868-
return DAG;
3869-
}
3870-
38713851
static ScheduleDAGInstrs *createConvergingSched(MachineSchedContext *C) {
38723852
return createGenericSchedLive(C);
38733853
}
@@ -4140,18 +4120,6 @@ void PostGenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
41404120
}
41414121
}
41424122

4143-
ScheduleDAGMI *llvm::createGenericSchedPostRA(MachineSchedContext *C) {
4144-
ScheduleDAGMI *DAG =
4145-
new ScheduleDAGMI(C, std::make_unique<PostGenericScheduler>(C),
4146-
/*RemoveKillFlags=*/true);
4147-
const TargetSubtargetInfo &STI = C->MF->getSubtarget();
4148-
// Add MacroFusion mutation if fusions are not empty.
4149-
const auto &MacroFusions = STI.getMacroFusions();
4150-
if (!MacroFusions.empty())
4151-
DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
4152-
return DAG;
4153-
}
4154-
41554123
//===----------------------------------------------------------------------===//
41564124
// ILP Scheduler. Currently for experimental analysis of heuristics.
41574125
//===----------------------------------------------------------------------===//

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ class AArch64PassConfig : public TargetPassConfig {
527527
createPostMachineScheduler(MachineSchedContext *C) const override {
528528
const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
529529
ScheduleDAGMI *DAG =
530-
new ScheduleDAGMI(C, std::make_unique<AArch64PostRASchedStrategy>(C),
531-
/* RemoveKillFlags=*/true);
530+
createGenericSchedPostRA<AArch64PostRASchedStrategy>(C);
532531
if (ST.hasFusion()) {
533532
// Run the Macro Fusion after RA again since literals are expanded from
534533
// pseudos then (v. addPreSched2()).

llvm/lib/Target/PowerPC/PPCTargetMachine.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ getEffectivePPCCodeModel(const Triple &TT, std::optional<CodeModel::Model> CM,
317317
static ScheduleDAGInstrs *createPPCMachineScheduler(MachineSchedContext *C) {
318318
const PPCSubtarget &ST = C->MF->getSubtarget<PPCSubtarget>();
319319
ScheduleDAGMILive *DAG =
320-
new ScheduleDAGMILive(C, ST.usePPCPreRASchedStrategy() ?
321-
std::make_unique<PPCPreRASchedStrategy>(C) :
322-
std::make_unique<GenericScheduler>(C));
320+
ST.usePPCPreRASchedStrategy()
321+
? createGenericSchedLive<PPCPreRASchedStrategy>(C)
322+
: createGenericSchedLive<GenericScheduler>(C);
323323
// add DAG Mutations here.
324324
DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
325325
if (ST.hasStoreFusion())
@@ -330,13 +330,12 @@ static ScheduleDAGInstrs *createPPCMachineScheduler(MachineSchedContext *C) {
330330
return DAG;
331331
}
332332

333-
static ScheduleDAGInstrs *createPPCPostMachineScheduler(
334-
MachineSchedContext *C) {
333+
static ScheduleDAGInstrs *
334+
createPPCPostMachineScheduler(MachineSchedContext *C) {
335335
const PPCSubtarget &ST = C->MF->getSubtarget<PPCSubtarget>();
336-
ScheduleDAGMI *DAG =
337-
new ScheduleDAGMI(C, ST.usePPCPostRASchedStrategy() ?
338-
std::make_unique<PPCPostRASchedStrategy>(C) :
339-
std::make_unique<PostGenericScheduler>(C), true);
336+
ScheduleDAGMI *DAG = ST.usePPCPostRASchedStrategy()
337+
? createGenericSchedPostRA<PPCPostRASchedStrategy>(C)
338+
: createGenericSchedPostRA<PostGenericScheduler>(C);
340339
// add DAG Mutations here.
341340
if (ST.hasStoreFusion())
342341
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));

llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ class SystemZPassConfig : public TargetPassConfig {
219219

220220
ScheduleDAGInstrs *
221221
createPostMachineScheduler(MachineSchedContext *C) const override {
222-
return new ScheduleDAGMI(C,
223-
std::make_unique<SystemZPostRASchedStrategy>(C),
224-
/*RemoveKillFlags=*/true);
222+
return createGenericSchedPostRA<SystemZPostRASchedStrategy>(C);
225223
}
226224

227225
void addIRPasses() override;

0 commit comments

Comments
 (0)