1 //==- MachineScheduler.h - MachineInstr Scheduling Pass ----------*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides a MachineSchedRegistry for registering alternative machine
11 // schedulers. A Target may provide an alternative scheduler implementation by
12 // implementing the following boilerplate:
14 // static ScheduleDAGInstrs *createCustomMachineSched(MachineSchedContext *C) {
15 // return new CustomMachineScheduler(C);
17 // static MachineSchedRegistry
18 // SchedCustomRegistry("custom", "Run my target's custom scheduler",
19 // createCustomMachineSched);
21 // Inside <Target>PassConfig:
22 // enablePass(MachineSchedulerID);
23 // MachineSchedRegistry::setDefault(createCustomMachineSched);
25 //===----------------------------------------------------------------------===//
27 #ifndef MACHINESCHEDULER_H
28 #define MACHINESCHEDULER_H
30 #include "RegisterClassInfo.h"
31 #include "llvm/CodeGen/MachinePassRegistry.h"
37 class MachineDominatorTree;
38 class MachineLoopInfo;
39 class ScheduleDAGInstrs;
41 /// MachineSchedContext provides enough context from the MachineScheduler pass
42 /// for the target to instantiate a scheduler.
43 struct MachineSchedContext {
45 const MachineLoopInfo *MLI;
46 const MachineDominatorTree *MDT;
47 const TargetPassConfig *PassConfig;
51 RegisterClassInfo RegClassInfo;
53 MachineSchedContext():
54 MF(0), MLI(0), MDT(0), PassConfig(0), AA(0), LIS(0) {}
57 /// MachineSchedRegistry provides a selection of available machine instruction
59 class MachineSchedRegistry : public MachinePassRegistryNode {
61 typedef ScheduleDAGInstrs *(*ScheduleDAGCtor)(MachineSchedContext *);
63 // RegisterPassParser requires a (misnamed) FunctionPassCtor type.
64 typedef ScheduleDAGCtor FunctionPassCtor;
66 static MachinePassRegistry Registry;
68 MachineSchedRegistry(const char *N, const char *D, ScheduleDAGCtor C)
69 : MachinePassRegistryNode(N, D, (MachinePassCtor)C) {
72 ~MachineSchedRegistry() { Registry.Remove(this); }
76 MachineSchedRegistry *getNext() const {
77 return (MachineSchedRegistry *)MachinePassRegistryNode::getNext();
79 static MachineSchedRegistry *getList() {
80 return (MachineSchedRegistry *)Registry.getList();
82 static ScheduleDAGCtor getDefault() {
83 return (ScheduleDAGCtor)Registry.getDefault();
85 static void setDefault(ScheduleDAGCtor C) {
86 Registry.setDefault((MachinePassCtor)C);
88 static void setDefault(StringRef Name) {
89 Registry.setDefault(Name);
91 static void setListener(MachinePassRegistryListener *L) {
92 Registry.setListener(L);