1 // ModuloScheduling.h -------------------------------------------*- C++ -*-===//
3 // This header defines the the classes ModuloScheduling and
4 // ModuloSchedulingSet's structure
6 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_MODULOSCHEDULING_H
10 #define LLVM_CODEGEN_MODULOSCHEDULING_H
12 #include "ModuloSchedGraph.h"
16 #define DEBUG_PRINT(x) x
18 // for debug information selecton
19 enum ModuloSchedDebugLevel_t {
20 ModuloSchedDebugLevel_NoDebugInfo,
21 ModuloSchedDebugLevel_PrintSchedule,
22 ModuloSchedDebugLevel_PrintScheduleProcess,
25 class ModuloScheduling: NonCopyable {
28 typedef std::vector<ModuloSchedGraphNode*> NodeVec;
29 typedef std::vector<std::vector<unsigned> > Resources;
31 // The graph to feed in
32 ModuloSchedGraph &graph;
33 const TargetMachine ⌖
35 // The BasicBlock to be scheduled
39 // FIXME: II may be a better name for its meaning
42 // The vector containing the nodes which have been scheduled
43 NodeVec nodeScheduled;
45 // The remaining unscheduled nodes
46 const NodeVec &oNodes;
48 // The machine resource table
49 std::vector<std::vector<std::pair<int,int> > > resourceTable;
51 ///the schedule( with many schedule stage)
52 std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
54 ///the kernel(core) schedule(length = II)
55 std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
57 typedef BasicBlock::InstListType InstListType;
58 typedef std::vector<std::vector<ModuloSchedGraphNode*> > vvNodeType;
66 ModuloScheduling(ModuloSchedGraph & _graph):
67 graph(_graph), target(graph.getTarget()), oNodes(graph.getONodes())
70 bb = graph.getBasicBlock();
74 ~ModuloScheduling() {};
81 //return ModuloScheduling::DebugLevel >= DebugLevel_PrintSchedule;
87 printScheduleProcess() {
89 //return DebugLevel >= DebugLevel_PrintScheduleProcess;
95 // The method to compute schedule and instert epilogue and prologue
96 void instrScheduling();
99 // Dump the schedule and core schedule
100 void dumpScheduling();
102 // Dump the input vector of nodes
103 // sch: the input vector of nodes
104 void dumpSchedule(std::vector<std::vector<ModuloSchedGraphNode*> > sch);
106 // Dump the resource usage table
107 void dumpResourceUsageTable();
109 //*******************internal functions*******************************
111 //clear memory from the last round and initialize if necessary
112 void clearInitMem(const TargetSchedInfo&);
114 //compute schedule and coreSchedule with the current II
115 bool computeSchedule();
117 BasicBlock *getSuccBB(BasicBlock *);
118 BasicBlock *getPredBB(BasicBlock *);
119 void constructPrologue(BasicBlock *prologue);
120 void constructKernel(BasicBlock *prologue,
122 BasicBlock *epilogue);
123 void constructEpilogue(BasicBlock *epilogue, BasicBlock *succ_bb);
125 // update the resource table at the startCycle
126 // vec: the resouce usage
127 // startCycle: the start cycle the resouce usage is
128 void updateResourceTable(std::vector<std::vector<unsigned> > vec,
131 // un-do the update in the resource table in the startCycle
132 // vec: the resouce usage
133 // startCycle: the start cycle the resouce usage is
134 void undoUpdateResourceTable(std::vector<std::vector<unsigned> > vec,
137 // return whether the resourcetable has negative element
138 // this function is called after updateResouceTable() to determine whether a
139 // node can be scheduled at certain cycle
140 bool resourceTableNegative();
142 // try to Schedule the node starting from start to end cycle(inclusive)
143 // if it can be scheduled, put it in the schedule and update nodeScheduled
144 // node: the node to be scheduled
145 // start: start cycle
147 // nodeScheduled: a vector storing nodes which has been scheduled
148 bool ScheduleNode(ModuloSchedGraphNode * node, unsigned start,
149 unsigned end, NodeVec &nodeScheduled);
151 //each instruction has a memory of the latest clone instruction
152 //the clone instruction can be get using getClone()
153 //this function clears the memory, i.e. getClone() after calling this function
155 void clearCloneMemory();
157 //this fuction make a clone of this input Instruction and update the clone
159 //inst: the instrution to be cloned
160 Instruction *cloneInstSetMemory(Instruction *inst);
162 //this function update each instrutions which uses ist as its operand
163 //after update, each instruction will use ist's clone as its operand
164 void updateUseWithClone(Instruction * ist);
169 class ModuloSchedulingSet:
173 //the graphSet to feed in
174 ModuloSchedGraphSet & graphSet;
179 //Scheduling graph one by one
180 ModuloSchedulingSet(ModuloSchedGraphSet _graphSet): graphSet(_graphSet) {
181 for (unsigned i = 0; i < graphSet.size(); i++) {
182 ModuloSchedGraph & graph = *(graphSet[i]);
183 if (graph.isLoop(graph.getBasicBlock()))
184 ModuloScheduling ModuloScheduling(graph);
188 ~ModuloSchedulingSet() {};