Skip to content

Commit a47c35a

Browse files
authored
[CodeGen] Move MISched target hooks into TargetMachine (#125700)
The createSIMachineScheduler & createPostMachineScheduler target hooks are currently placed in the PassConfig interface. Moving it out to TargetMachine so that both legacy and the new pass manager can effectively use them.
1 parent b85e71b commit a47c35a

31 files changed

+248
-216
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// scheduled. Targets can override the DAG builder and scheduler without
1818
// replacing the pass as follows:
1919
//
20-
// ScheduleDAGInstrs *<Target>PassConfig::
20+
// ScheduleDAGInstrs *<Target>TargetMachine::
2121
// createMachineScheduler(MachineSchedContext *C) {
2222
// return new CustomMachineScheduler(C);
2323
// }
@@ -29,7 +29,7 @@
2929
// plugin an alternate MachineSchedStrategy. The strategy is responsible for
3030
// selecting the highest priority node from the list:
3131
//
32-
// ScheduleDAGInstrs *<Target>PassConfig::
32+
// ScheduleDAGInstrs *<Target>TargetMachine::
3333
// createMachineScheduler(MachineSchedContext *C) {
3434
// return new ScheduleDAGMILive(C, CustomStrategy(C));
3535
// }
@@ -39,7 +39,7 @@
3939
// can adjust dependencies based on target-specific knowledge or add weak edges
4040
// to aid heuristics:
4141
//
42-
// ScheduleDAGInstrs *<Target>PassConfig::
42+
// ScheduleDAGInstrs *<Target>TargetMachine::
4343
// createMachineScheduler(MachineSchedContext *C) {
4444
// ScheduleDAGMI *DAG = createGenericSchedLive(C);
4545
// DAG->addMutation(new CustomDAGMutation(...));
@@ -137,7 +137,7 @@ struct MachineSchedContext {
137137
MachineFunction *MF = nullptr;
138138
const MachineLoopInfo *MLI = nullptr;
139139
const MachineDominatorTree *MDT = nullptr;
140-
const TargetPassConfig *PassConfig = nullptr;
140+
const TargetMachine *TM = nullptr;
141141
AAResults *AA = nullptr;
142142
LiveIntervals *LIS = nullptr;
143143

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ class TargetInstrInfo : public MCInstrInfo {
15661566
/// DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
15671567
/// or
15681568
/// DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
1569-
/// to TargetPassConfig::createMachineScheduler() to have an effect.
1569+
/// to TargetMachine::createMachineScheduler() to have an effect.
15701570
///
15711571
/// \p BaseOps1 and \p BaseOps2 are memory operands of two memory operations.
15721572
/// \p Offset1 and \p Offset2 are the byte offsets for the memory

llvm/include/llvm/CodeGen/TargetPassConfig.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
namespace llvm {
2323

2424
class TargetMachine;
25-
struct MachineSchedContext;
2625
class PassConfigImpl;
27-
class ScheduleDAGInstrs;
2826
class CSEConfigBase;
2927
class PassInstrumentationCallbacks;
3028

@@ -300,27 +298,6 @@ class TargetPassConfig : public ImmutablePass {
300298
/// Fully developed targets will not generally override this.
301299
virtual void addMachinePasses();
302300

303-
/// Create an instance of ScheduleDAGInstrs to be run within the standard
304-
/// MachineScheduler pass for this function and target at the current
305-
/// optimization level.
306-
///
307-
/// This can also be used to plug a new MachineSchedStrategy into an instance
308-
/// of the standard ScheduleDAGMI:
309-
/// return new ScheduleDAGMI(C, std::make_unique<MyStrategy>(C), /*RemoveKillFlags=*/false)
310-
///
311-
/// Return NULL to select the default (generic) machine scheduler.
312-
virtual ScheduleDAGInstrs *
313-
createMachineScheduler(MachineSchedContext *C) const {
314-
return nullptr;
315-
}
316-
317-
/// Similar to createMachineScheduler but used when postRA machine scheduling
318-
/// is enabled.
319-
virtual ScheduleDAGInstrs *
320-
createPostMachineScheduler(MachineSchedContext *C) const {
321-
return nullptr;
322-
}
323-
324301
/// printAndVerify - Add a pass to dump then verify the machine function, if
325302
/// those steps are enabled.
326303
void printAndVerify(const std::string &Banner);

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ using ModulePassManager = PassManager<Module>;
3939
class Function;
4040
class GlobalValue;
4141
class MachineModuleInfoWrapperPass;
42+
struct MachineSchedContext;
4243
class Mangler;
4344
class MCAsmInfo;
4445
class MCContext;
@@ -50,6 +51,7 @@ class raw_pwrite_stream;
5051
class PassBuilder;
5152
class PassInstrumentationCallbacks;
5253
struct PerFunctionMIParsingState;
54+
class ScheduleDAGInstrs;
5355
class SMDiagnostic;
5456
class SMRange;
5557
class Target;
@@ -147,6 +149,28 @@ class TargetMachine {
147149
return nullptr;
148150
}
149151

152+
/// Create an instance of ScheduleDAGInstrs to be run within the standard
153+
/// MachineScheduler pass for this function and target at the current
154+
/// optimization level.
155+
///
156+
/// This can also be used to plug a new MachineSchedStrategy into an instance
157+
/// of the standard ScheduleDAGMI:
158+
/// return new ScheduleDAGMI(C, std::make_unique<MyStrategy>(C),
159+
/// /*RemoveKillFlags=*/false)
160+
///
161+
/// Return NULL to select the default (generic) machine scheduler.
162+
virtual ScheduleDAGInstrs *
163+
createMachineScheduler(MachineSchedContext *C) const {
164+
return nullptr;
165+
}
166+
167+
/// Similar to createMachineScheduler but used when postRA machine scheduling
168+
/// is enabled.
169+
virtual ScheduleDAGInstrs *
170+
createPostMachineScheduler(MachineSchedContext *C) const {
171+
return nullptr;
172+
}
173+
150174
/// Allocate and return a default initialized instance of the YAML
151175
/// representation for the MachineFunctionInfo.
152176
virtual yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const {

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ bool MachinePipeliner::runWindowScheduler(MachineLoop &L) {
511511
Context.MF = MF;
512512
Context.MLI = MLI;
513513
Context.MDT = MDT;
514-
Context.PassConfig = &getAnalysis<TargetPassConfig>();
514+
Context.TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
515515
Context.AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
516516
Context.LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
517517
Context.RegClassInfo->runOnMachineFunction(*MF);

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/Support/ErrorHandling.h"
5959
#include "llvm/Support/GraphWriter.h"
6060
#include "llvm/Support/raw_ostream.h"
61+
#include "llvm/Target/TargetMachine.h"
6162
#include <algorithm>
6263
#include <cassert>
6364
#include <cstdint>
@@ -392,8 +393,11 @@ ScheduleDAGInstrs *MachineScheduler::createMachineScheduler() {
392393
if (Ctor != useDefaultMachineSched)
393394
return Ctor(this);
394395

396+
const TargetMachine &TM =
397+
getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
398+
395399
// Get the default scheduler set by the target for this function.
396-
ScheduleDAGInstrs *Scheduler = PassConfig->createMachineScheduler(this);
400+
ScheduleDAGInstrs *Scheduler = TM.createMachineScheduler(this);
397401
if (Scheduler)
398402
return Scheduler;
399403

@@ -405,8 +409,10 @@ ScheduleDAGInstrs *MachineScheduler::createMachineScheduler() {
405409
/// the caller. We don't have a command line option to override the postRA
406410
/// scheduler. The Target must configure it.
407411
ScheduleDAGInstrs *PostMachineScheduler::createPostMachineScheduler() {
412+
const TargetMachine &TM =
413+
getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
408414
// Get the postRA scheduler set by the target for this function.
409-
ScheduleDAGInstrs *Scheduler = PassConfig->createPostMachineScheduler(this);
415+
ScheduleDAGInstrs *Scheduler = TM.createPostMachineScheduler(this);
410416
if (Scheduler)
411417
return Scheduler;
412418

@@ -446,7 +452,6 @@ bool MachineScheduler::runOnMachineFunction(MachineFunction &mf) {
446452
MF = &mf;
447453
MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
448454
MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
449-
PassConfig = &getAnalysis<TargetPassConfig>();
450455
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
451456

452457
LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
@@ -484,7 +489,6 @@ bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) {
484489
// Initialize the context of the pass.
485490
MF = &mf;
486491
MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
487-
PassConfig = &getAnalysis<TargetPassConfig>();
488492
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
489493

490494
if (VerifyScheduling)

llvm/lib/CodeGen/WindowScheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/Support/CommandLine.h"
4646
#include "llvm/Support/Debug.h"
4747
#include "llvm/Support/TimeProfiler.h"
48+
#include "llvm/Target/TargetMachine.h"
4849

4950
using namespace llvm;
5051

@@ -167,7 +168,7 @@ WindowScheduler::createMachineScheduler(bool OnlyBuildGraph) {
167168
? new ScheduleDAGMI(
168169
Context, std::make_unique<PostGenericScheduler>(Context),
169170
true)
170-
: Context->PassConfig->createMachineScheduler(Context);
171+
: Context->TM->createMachineScheduler(Context);
171172
}
172173

173174
bool WindowScheduler::initialize() {

llvm/lib/Target/AArch64/AArch64MacroFusion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace llvm {
2020

2121
/// Note that you have to add:
2222
/// DAG.addMutation(createAArch64MacroFusionDAGMutation());
23-
/// to AArch64PassConfig::createMachineScheduler() to have an effect.
23+
/// to AArch64TargetMachine::createMachineScheduler() to have an effect.
2424
std::unique_ptr<ScheduleDAGMutation> createAArch64MacroFusionDAGMutation();
2525

2626
} // llvm

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,33 @@ AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
480480
return I.get();
481481
}
482482

483+
ScheduleDAGInstrs *
484+
AArch64TargetMachine::createMachineScheduler(MachineSchedContext *C) const {
485+
const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
486+
ScheduleDAGMILive *DAG = createGenericSchedLive(C);
487+
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
488+
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
489+
if (ST.hasFusion())
490+
DAG->addMutation(createAArch64MacroFusionDAGMutation());
491+
return DAG;
492+
}
493+
494+
ScheduleDAGInstrs *
495+
AArch64TargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
496+
const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
497+
ScheduleDAGMI *DAG =
498+
new ScheduleDAGMI(C, std::make_unique<AArch64PostRASchedStrategy>(C),
499+
/* RemoveKillFlags=*/true);
500+
if (ST.hasFusion()) {
501+
// Run the Macro Fusion after RA again since literals are expanded from
502+
// pseudos then (v. addPreSched2()).
503+
DAG->addMutation(createAArch64MacroFusionDAGMutation());
504+
return DAG;
505+
}
506+
507+
return DAG;
508+
}
509+
483510
void AArch64leTargetMachine::anchor() { }
484511

485512
AArch64leTargetMachine::AArch64leTargetMachine(
@@ -512,33 +539,6 @@ class AArch64PassConfig : public TargetPassConfig {
512539
return getTM<AArch64TargetMachine>();
513540
}
514541

515-
ScheduleDAGInstrs *
516-
createMachineScheduler(MachineSchedContext *C) const override {
517-
const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
518-
ScheduleDAGMILive *DAG = createGenericSchedLive(C);
519-
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
520-
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
521-
if (ST.hasFusion())
522-
DAG->addMutation(createAArch64MacroFusionDAGMutation());
523-
return DAG;
524-
}
525-
526-
ScheduleDAGInstrs *
527-
createPostMachineScheduler(MachineSchedContext *C) const override {
528-
const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
529-
ScheduleDAGMI *DAG =
530-
new ScheduleDAGMI(C, std::make_unique<AArch64PostRASchedStrategy>(C),
531-
/* RemoveKillFlags=*/true);
532-
if (ST.hasFusion()) {
533-
// Run the Macro Fusion after RA again since literals are expanded from
534-
// pseudos then (v. addPreSched2()).
535-
DAG->addMutation(createAArch64MacroFusionDAGMutation());
536-
return DAG;
537-
}
538-
539-
return DAG;
540-
}
541-
542542
void addIRPasses() override;
543543
bool addPreISel() override;
544544
void addCodeGenPrepare() override;

llvm/lib/Target/AArch64/AArch64TargetMachine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class AArch64TargetMachine : public CodeGenTargetMachineImpl {
7070
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
7171
return getPointerSize(SrcAS) == getPointerSize(DestAS);
7272
}
73+
ScheduleDAGInstrs *
74+
createMachineScheduler(MachineSchedContext *C) const override;
75+
76+
ScheduleDAGInstrs *
77+
createPostMachineScheduler(MachineSchedContext *C) const override;
7378

7479
private:
7580
bool isLittle;

llvm/lib/Target/AMDGPU/AMDGPUMacroFusion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace llvm {
1616

1717
/// Note that you have to add:
1818
/// DAG.addMutation(createAMDGPUMacroFusionDAGMutation());
19-
/// to AMDGPUPassConfig::createMachineScheduler() to have an effect.
19+
/// to AMDGPUTargetMachine::createMachineScheduler() to have an effect.
2020
std::unique_ptr<ScheduleDAGMutation> createAMDGPUMacroFusionDAGMutation();
2121

2222
} // llvm

0 commit comments

Comments
 (0)