Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 05bdd2e

Browse files
committed
MachineScheduler: Export function to construct "default" scheduler.
This makes the createGenericSchedLive() function that constructs the default scheduler available for the public API. This should help when you want to get a scheduler and the default list of DAG mutations. This also shrinks the list of default DAG mutations: {Load|Store}ClusterDAGMutation and MacroFusionDAGMutation are no longer added by default. Targets can easily add them if they need them. It also makes it easier for targets to add alternative/custom macrofusion or clustering mutations while staying with the default createGenericSchedLive(). It also saves the callback back and forth in TargetInstrInfo::enableClusterLoads()/enableClusterStores(). Differential Revision: https://reviews.llvm.org/D26986 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288057 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6f1fc60 commit 05bdd2e

12 files changed

+73
-63
lines changed

include/llvm/CodeGen/MachineScheduler.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
//
4343
// ScheduleDAGInstrs *<Target>PassConfig::
4444
// createMachineScheduler(MachineSchedContext *C) {
45-
// ScheduleDAGMI *DAG = new ScheduleDAGMI(C, CustomStrategy(C));
46-
// DAG->addMutation(new CustomDependencies(DAG->TII, DAG->TRI));
45+
// ScheduleDAGMI *DAG = createGenericSchedLive(C);
46+
// DAG->addMutation(new CustomDAGMutation(...));
4747
// return DAG;
4848
// }
4949
//
@@ -295,7 +295,8 @@ class ScheduleDAGMI : public ScheduleDAGInstrs {
295295
///
296296
/// ScheduleDAGMI takes ownership of the Mutation object.
297297
void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) {
298-
Mutations.push_back(std::move(Mutation));
298+
if (Mutation)
299+
Mutations.push_back(std::move(Mutation));
299300
}
300301

301302
/// \brief True if an edge can be added from PredSU to SuccSU without creating
@@ -1015,6 +1016,14 @@ class PostGenericScheduler : public GenericSchedulerBase {
10151016
void pickNodeFromQueue(SchedCandidate &Cand);
10161017
};
10171018

1019+
/// Create the standard converging machine scheduler. This will be used as the
1020+
/// default scheduler if the target does not set a default.
1021+
/// Adds default DAG mutations.
1022+
ScheduleDAGMILive *createGenericSchedLive(MachineSchedContext *C);
1023+
1024+
/// Create a generic scheduler with no vreg liveness or DAG mutation passes.
1025+
ScheduleDAGMI *createGenericSchedPostRA(MachineSchedContext *C);
1026+
10181027
std::unique_ptr<ScheduleDAGMutation>
10191028
createLoadClusterDAGMutation(const TargetInstrInfo *TII,
10201029
const TargetRegisterInfo *TRI);

include/llvm/Target/TargetInstrInfo.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,21 +1058,25 @@ class TargetInstrInfo : public MCInstrInfo {
10581058
return false;
10591059
}
10601060

1061-
virtual bool enableClusterLoads() const { return false; }
1062-
1063-
virtual bool enableClusterStores() const { return false; }
1064-
1061+
/// Returns true if the two given memory operations should be scheduled
1062+
/// adjacent. Note that you have to add:
1063+
/// DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
1064+
/// or
1065+
/// DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
1066+
/// to TargetPassConfig::createMachineScheduler() to have an effect.
10651067
virtual bool shouldClusterMemOps(MachineInstr &FirstLdSt,
10661068
MachineInstr &SecondLdSt,
10671069
unsigned NumLoads) const {
1068-
return false;
1070+
llvm_unreachable("target did not implement shouldClusterMemOps()");
10691071
}
10701072

10711073
/// Can this target fuse the given instructions if they are scheduled
1072-
/// adjacent.
1073-
virtual bool shouldScheduleAdjacent(MachineInstr &First,
1074-
MachineInstr &Second) const {
1075-
return false;
1074+
/// adjacent. Note that you have to add:
1075+
/// DAG.addMutation(createMacroFusionDAGMutation());
1076+
/// to TargetPassConfig::createMachineScheduler() to have an effect.
1077+
virtual bool shouldScheduleAdjacent(const MachineInstr &First,
1078+
const MachineInstr &Second) const {
1079+
llvm_unreachable("target did not implement shouldScheduleAdjacent()");
10761080
}
10771081

10781082
/// Reverses the branch condition of the specified condition list,

lib/CodeGen/MachineScheduler.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,6 @@ static cl::opt<bool> EnablePostRAMachineSched(
230230
cl::desc("Enable the post-ra machine instruction scheduling pass."),
231231
cl::init(true), cl::Hidden);
232232

233-
/// Forward declare the standard machine scheduler. This will be used as the
234-
/// default scheduler if the target does not set a default.
235-
static ScheduleDAGInstrs *createGenericSchedLive(MachineSchedContext *C);
236-
static ScheduleDAGInstrs *createGenericSchedPostRA(MachineSchedContext *C);
237-
238233
/// Decrement this iterator until reaching the top or a non-debug instr.
239234
static MachineBasicBlock::const_iterator
240235
priorNonDebug(MachineBasicBlock::const_iterator I,
@@ -1451,13 +1446,15 @@ namespace llvm {
14511446
std::unique_ptr<ScheduleDAGMutation>
14521447
createLoadClusterDAGMutation(const TargetInstrInfo *TII,
14531448
const TargetRegisterInfo *TRI) {
1454-
return make_unique<LoadClusterMutation>(TII, TRI);
1449+
return EnableMemOpCluster ? make_unique<LoadClusterMutation>(TII, TRI)
1450+
: nullptr;
14551451
}
14561452

14571453
std::unique_ptr<ScheduleDAGMutation>
14581454
createStoreClusterDAGMutation(const TargetInstrInfo *TII,
14591455
const TargetRegisterInfo *TRI) {
1460-
return make_unique<StoreClusterMutation>(TII, TRI);
1456+
return EnableMemOpCluster ? make_unique<StoreClusterMutation>(TII, TRI)
1457+
: nullptr;
14611458
}
14621459

14631460
} // namespace llvm
@@ -1566,7 +1563,7 @@ namespace llvm {
15661563

15671564
std::unique_ptr<ScheduleDAGMutation>
15681565
createMacroFusionDAGMutation(const TargetInstrInfo *TII) {
1569-
return make_unique<MacroFusion>(*TII);
1566+
return EnableMacroFusion ? make_unique<MacroFusion>(*TII) : nullptr;
15701567
}
15711568

15721569
} // namespace llvm
@@ -3156,28 +3153,24 @@ void GenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
31563153

31573154
/// Create the standard converging machine scheduler. This will be used as the
31583155
/// default scheduler if the target does not set a default.
3159-
static ScheduleDAGInstrs *createGenericSchedLive(MachineSchedContext *C) {
3156+
ScheduleDAGMILive *llvm::createGenericSchedLive(MachineSchedContext *C) {
31603157
ScheduleDAGMILive *DAG = new ScheduleDAGMILive(C, make_unique<GenericScheduler>(C));
31613158
// Register DAG post-processors.
31623159
//
31633160
// FIXME: extend the mutation API to allow earlier mutations to instantiate
31643161
// data and pass it to later mutations. Have a single mutation that gathers
31653162
// the interesting nodes in one pass.
31663163
DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
3167-
if (EnableMemOpCluster) {
3168-
if (DAG->TII->enableClusterLoads())
3169-
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
3170-
if (DAG->TII->enableClusterStores())
3171-
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
3172-
}
3173-
if (EnableMacroFusion)
3174-
DAG->addMutation(createMacroFusionDAGMutation(DAG->TII));
31753164
return DAG;
31763165
}
31773166

3167+
static ScheduleDAGInstrs *createConveringSched(MachineSchedContext *C) {
3168+
return createGenericSchedLive(C);
3169+
}
3170+
31783171
static MachineSchedRegistry
31793172
GenericSchedRegistry("converge", "Standard converging scheduler.",
3180-
createGenericSchedLive);
3173+
createConveringSched);
31813174

31823175
//===----------------------------------------------------------------------===//
31833176
// PostGenericScheduler - Generic PostRA implementation of MachineSchedStrategy.
@@ -3308,8 +3301,7 @@ void PostGenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
33083301
Top.bumpNode(SU);
33093302
}
33103303

3311-
/// Create a generic scheduler with no vreg liveness or DAG mutation passes.
3312-
static ScheduleDAGInstrs *createGenericSchedPostRA(MachineSchedContext *C) {
3304+
ScheduleDAGMI *llvm::createGenericSchedPostRA(MachineSchedContext *C) {
33133305
return new ScheduleDAGMI(C, make_unique<PostGenericScheduler>(C),
33143306
/*RemoveKillFlags=*/true);
33153307
}

lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,8 +1878,8 @@ bool AArch64InstrInfo::shouldClusterMemOps(MachineInstr &FirstLdSt,
18781878
return Offset1 + 1 == Offset2;
18791879
}
18801880

1881-
bool AArch64InstrInfo::shouldScheduleAdjacent(MachineInstr &First,
1882-
MachineInstr &Second) const {
1881+
bool AArch64InstrInfo::shouldScheduleAdjacent(
1882+
const MachineInstr &First, const MachineInstr &Second) const {
18831883
if (Subtarget.hasArithmeticBccFusion()) {
18841884
// Fuse CMN, CMP, TST followed by Bcc.
18851885
unsigned SecondOpcode = Second.getOpcode();

lib/Target/AArch64/AArch64InstrInfo.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,11 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {
133133
int64_t &Offset, unsigned &Width,
134134
const TargetRegisterInfo *TRI) const;
135135

136-
bool enableClusterLoads() const override { return true; }
137-
138-
bool enableClusterStores() const override { return true; }
139-
140136
bool shouldClusterMemOps(MachineInstr &FirstLdSt, MachineInstr &SecondLdSt,
141137
unsigned NumLoads) const override;
142138

143-
bool shouldScheduleAdjacent(MachineInstr &First,
144-
MachineInstr &Second) const override;
139+
bool shouldScheduleAdjacent(const MachineInstr &First,
140+
const MachineInstr &Second) const override;
145141

146142
MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
147143
uint64_t Offset, const MDNode *Var,

lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
2323
#include "llvm/CodeGen/GlobalISel/Legalizer.h"
2424
#include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
25+
#include "llvm/CodeGen/MachineScheduler.h"
2526
#include "llvm/CodeGen/Passes.h"
2627
#include "llvm/CodeGen/RegAllocRegistry.h"
2728
#include "llvm/CodeGen/TargetPassConfig.h"
@@ -299,6 +300,15 @@ class AArch64PassConfig : public TargetPassConfig {
299300
return getTM<AArch64TargetMachine>();
300301
}
301302

303+
ScheduleDAGInstrs *
304+
createMachineScheduler(MachineSchedContext *C) const override {
305+
ScheduleDAGMILive *DAG = createGenericSchedLive(C);
306+
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
307+
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
308+
DAG->addMutation(createMacroFusionDAGMutation(DAG->TII));
309+
return DAG;
310+
}
311+
302312
void addIRPasses() override;
303313
bool addPreISel() override;
304314
bool addInstSelector() override;

lib/Target/AMDGPU/AMDGPUInstrInfo.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ void AMDGPUInstrInfo::anchor() {}
3232
AMDGPUInstrInfo::AMDGPUInstrInfo(const AMDGPUSubtarget &ST)
3333
: AMDGPUGenInstrInfo(-1, -1), ST(ST) {}
3434

35-
bool AMDGPUInstrInfo::enableClusterLoads() const {
36-
return true;
37-
}
38-
39-
bool AMDGPUInstrInfo::enableClusterStores() const {
40-
return true;
41-
}
42-
4335
// FIXME: This behaves strangely. If, for example, you have 32 load + stores,
4436
// the first 16 loads will be interleaved with the stores, and the next 16 will
4537
// be clustered as expected. It should really split into 2 16 store batches.

lib/Target/AMDGPU/AMDGPUInstrInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class AMDGPUInstrInfo : public AMDGPUGenInstrInfo {
3939
public:
4040
explicit AMDGPUInstrInfo(const AMDGPUSubtarget &st);
4141

42-
bool enableClusterLoads() const override;
43-
bool enableClusterStores() const override;
44-
4542
bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
4643
int64_t Offset1, int64_t Offset2,
4744
unsigned NumLoads) const override;

lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,8 @@ static ScheduleDAGInstrs *
102102
createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C) {
103103
ScheduleDAGMILive *DAG =
104104
new ScheduleDAGMILive(C, make_unique<GCNMaxOccupancySchedStrategy>(C));
105-
106-
const SIInstrInfo *TII = static_cast<const SIInstrInfo *>(DAG->TII);
107-
if (TII->enableClusterLoads())
108-
DAG->addMutation(createLoadClusterDAGMutation(TII, DAG->TRI));
109-
110-
if (TII->enableClusterStores())
111-
DAG->addMutation(createStoreClusterDAGMutation(TII, DAG->TRI));
112-
105+
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
106+
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
113107
return DAG;
114108
}
115109

@@ -291,6 +285,14 @@ class AMDGPUPassConfig : public TargetPassConfig {
291285
return getTM<AMDGPUTargetMachine>();
292286
}
293287

288+
ScheduleDAGInstrs *
289+
createMachineScheduler(MachineSchedContext *C) const override {
290+
ScheduleDAGMILive *DAG = createGenericSchedLive(C);
291+
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
292+
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
293+
return DAG;
294+
}
295+
294296
void addEarlyCSEOrGVNPass();
295297
void addStraightLineScalarOptimizationPasses();
296298
void addIRPasses() override;

lib/Target/X86/X86InstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8023,8 +8023,8 @@ bool X86InstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
80238023
return true;
80248024
}
80258025

8026-
bool X86InstrInfo::shouldScheduleAdjacent(MachineInstr &First,
8027-
MachineInstr &Second) const {
8026+
bool X86InstrInfo::shouldScheduleAdjacent(const MachineInstr &First,
8027+
const MachineInstr &Second) const {
80288028
// Check if this processor supports macro-fusion. Since this is a minor
80298029
// heuristic, we haven't specifically reserved a feature. hasAVX is a decent
80308030
// proxy for SandyBridge+.

lib/Target/X86/X86InstrInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ class X86InstrInfo final : public X86GenInstrInfo {
443443
int64_t Offset1, int64_t Offset2,
444444
unsigned NumLoads) const override;
445445

446-
bool shouldScheduleAdjacent(MachineInstr &First,
447-
MachineInstr &Second) const override;
446+
bool shouldScheduleAdjacent(const MachineInstr &First,
447+
const MachineInstr &Second) const override;
448448

449449
void getNoopForMachoTarget(MCInst &NopInst) const override;
450450

lib/Target/X86/X86TargetMachine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "X86TargetTransformInfo.h"
1919
#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
2020
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
21+
#include "llvm/CodeGen/MachineScheduler.h"
2122
#include "llvm/CodeGen/Passes.h"
2223
#include "llvm/CodeGen/TargetPassConfig.h"
2324
#include "llvm/IR/Function.h"
@@ -284,6 +285,13 @@ class X86PassConfig : public TargetPassConfig {
284285
return getTM<X86TargetMachine>();
285286
}
286287

288+
ScheduleDAGInstrs *
289+
createMachineScheduler(MachineSchedContext *C) const override {
290+
ScheduleDAGMILive *DAG = createGenericSchedLive(C);
291+
DAG->addMutation(createMacroFusionDAGMutation(DAG->TII));
292+
return DAG;
293+
}
294+
287295
void addIRPasses() override;
288296
bool addInstSelector() override;
289297
#ifdef LLVM_BUILD_GLOBAL_ISEL

0 commit comments

Comments
 (0)