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 #define DEBUG_PRINT(x)
20 // for debug information selecton
21 enum ModuloSchedDebugLevel_t {
22 ModuloSchedDebugLevel_NoDebugInfo,
23 ModuloSchedDebugLevel_PrintSchedule,
24 ModuloSchedDebugLevel_PrintScheduleProcess,
27 class ModuloScheduling: NonCopyable {
30 typedef std::vector<ModuloSchedGraphNode*> NodeVec;
31 typedef std::vector<std::vector<unsigned> > Resources;
33 // The graph to feed in
34 ModuloSchedGraph &graph;
35 const TargetMachine ⌖
37 // The BasicBlock to be scheduled
41 // FIXME: II may be a better name for its meaning
44 // The vector containing the nodes which have been scheduled
45 NodeVec nodeScheduled;
47 // The remaining unscheduled nodes
48 const NodeVec &oNodes;
50 // The machine resource table
51 std::vector<std::vector<std::pair<int,int> > > resourceTable;
53 ///the schedule( with many schedule stage)
54 std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
56 ///the kernel(core) schedule(length = II)
57 std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
59 typedef BasicBlock::InstListType InstListType;
60 typedef std::vector<std::vector<ModuloSchedGraphNode*> > vvNodeType;
68 ModuloScheduling(ModuloSchedGraph & _graph):
69 graph(_graph), target(graph.getTarget()), oNodes(graph.getONodes())
72 bb = graph.getBasicBlock();
76 ~ModuloScheduling() {};
83 //return ModuloScheduling::DebugLevel >= DebugLevel_PrintSchedule;
89 printScheduleProcess() {
91 //return DebugLevel >= DebugLevel_PrintScheduleProcess;
97 // The method to compute schedule and instert epilogue and prologue
98 void instrScheduling();
101 // Dump the schedule and core schedule
102 void dumpScheduling();
103 void dumpFinalSchedule();
105 // Dump the input vector of nodes
106 // sch: the input vector of nodes
107 void dumpSchedule(std::vector<std::vector<ModuloSchedGraphNode*> > sch);
109 // Dump the resource usage table
110 void dumpResourceUsageTable();
112 //*******************internal functions*******************************
114 //clear memory from the last round and initialize if necessary
115 void clearInitMem(const TargetSchedInfo&);
117 //compute schedule and coreSchedule with the current II
118 bool computeSchedule();
120 BasicBlock *getSuccBB(BasicBlock *);
121 BasicBlock *getPredBB(BasicBlock *);
122 void constructPrologue(BasicBlock *prologue);
123 void constructKernel(BasicBlock *prologue,
125 BasicBlock *epilogue);
126 void constructEpilogue(BasicBlock *epilogue, BasicBlock *succ_bb);
128 // update the resource table at the startCycle
129 // vec: the resouce usage
130 // startCycle: the start cycle the resouce usage is
131 void updateResourceTable(std::vector<std::vector<unsigned> > vec,
134 // un-do the update in the resource table in the startCycle
135 // vec: the resouce usage
136 // startCycle: the start cycle the resouce usage is
137 void undoUpdateResourceTable(std::vector<std::vector<unsigned> > vec,
140 // return whether the resourcetable has negative element
141 // this function is called after updateResouceTable() to determine whether a
142 // node can be scheduled at certain cycle
143 bool resourceTableNegative();
145 // try to Schedule the node starting from start to end cycle(inclusive)
146 // if it can be scheduled, put it in the schedule and update nodeScheduled
147 // node: the node to be scheduled
148 // start: start cycle
150 // nodeScheduled: a vector storing nodes which has been scheduled
151 bool ScheduleNode(ModuloSchedGraphNode * node, unsigned start,
152 unsigned end, NodeVec &nodeScheduled);
154 //each instruction has a memory of the latest clone instruction
155 //the clone instruction can be get using getClone()
156 //this function clears the memory, i.e. getClone() after calling this function
158 void clearCloneMemory();
160 //this fuction make a clone of this input Instruction and update the clone
162 //inst: the instrution to be cloned
163 Instruction *cloneInstSetMemory(Instruction *inst);
165 //this function update each instrutions which uses ist as its operand
166 //after update, each instruction will use ist's clone as its operand
167 void updateUseWithClone(Instruction * ist);
172 class ModuloSchedulingSet:
176 //the graphSet to feed in
177 ModuloSchedGraphSet & graphSet;
182 //Scheduling graph one by one
183 ModuloSchedulingSet(ModuloSchedGraphSet _graphSet): graphSet(_graphSet) {
184 for (unsigned i = 0; i < graphSet.size(); i++) {
185 ModuloSchedGraph & graph = *(graphSet[i]);
186 if (graph.isLoop(graph.getBasicBlock()))
187 ModuloScheduling ModuloScheduling(graph);
191 ~ModuloSchedulingSet() {};