Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1 | //// - head file for the classes ModuloScheduling and ModuloScheduling ----*- C++ -*-===// |
| 2 | // |
| 3 | // This header defines the the classes ModuloScheduling and ModuloSchedulingSet 's structure |
| 4 | // |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
| 8 | |
| 9 | #ifndef LLVM_CODEGEN_MODULOSCHEDULING_H |
| 10 | #define LLVM_CODEGEN_MODULOSCHEDULING_H |
| 11 | |
| 12 | #include "ModuloSchedGraph.h" |
| 13 | #include <iostream> |
Guochun Shi | 6fbe5fb | 2003-04-06 23:56:19 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
| 16 | using std::vector; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 17 | |
| 18 | class ModuloScheduling:NonCopyable { |
| 19 | private: |
| 20 | typedef std::vector<ModuloSchedGraphNode*> NodeVec; |
| 21 | |
| 22 | /// the graph to feed in |
| 23 | ModuloSchedGraph& graph; |
| 24 | const TargetMachine& target; |
| 25 | |
| 26 | //the BasicBlock to be scheduled |
| 27 | BasicBlock* bb; |
| 28 | |
| 29 | ///Iteration Intervel |
| 30 | ///FIXME: II may be a better name for its meaning |
| 31 | unsigned II; |
| 32 | |
| 33 | //the vector containing the nodes which have been scheduled |
| 34 | NodeVec nodeScheduled; |
| 35 | |
| 36 | ///the remaining unscheduled nodes |
| 37 | const NodeVec& oNodes; |
| 38 | |
| 39 | ///the machine resource table |
| 40 | std::vector< std::vector<pair<int,int> > > resourceTable ; |
| 41 | |
| 42 | ///the schedule( with many schedule stage) |
| 43 | std::vector<std::vector<ModuloSchedGraphNode*> > schedule; |
| 44 | |
| 45 | ///the kernel(core) schedule(length = II) |
| 46 | std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule; |
| 47 | |
| 48 | typedef BasicBlock::InstListType InstListType; |
| 49 | typedef std::vector <std::vector<ModuloSchedGraphNode*> > vvNodeType; |
| 50 | |
| 51 | |
| 52 | |
| 53 | public: |
| 54 | |
| 55 | ///constructor |
| 56 | ModuloScheduling(ModuloSchedGraph& _graph): |
| 57 | graph(_graph), |
| 58 | target(graph.getTarget()), |
| 59 | oNodes(graph.getONodes()) |
| 60 | { |
| 61 | II = graph.getMII(); |
| 62 | bb=(BasicBlock*)graph.getBasicBlocks()[0]; |
| 63 | |
| 64 | instrScheduling(); |
| 65 | }; |
| 66 | |
| 67 | ///destructor |
| 68 | ~ModuloScheduling(){}; |
| 69 | |
| 70 | ///the method to compute schedule and instert epilogue and prologue |
| 71 | void instrScheduling(); |
| 72 | |
| 73 | ///debug functions: |
| 74 | ///dump the schedule and core schedule |
| 75 | void dumpScheduling(); |
| 76 | |
| 77 | ///dump the input vector of nodes |
| 78 | //sch: the input vector of nodes |
| 79 | void dumpSchedule( std::vector<std::vector<ModuloSchedGraphNode*> > sch); |
| 80 | |
| 81 | ///dump the resource usage table |
| 82 | void dumpResourceUsageTable(); |
| 83 | |
| 84 | |
| 85 | //*******************internel functions******************************* |
| 86 | private: |
| 87 | //clear memory from the last round and initialize if necessary |
Guochun Shi | 6fbe5fb | 2003-04-06 23:56:19 +0000 | [diff] [blame] | 88 | void clearInitMem(const TargetSchedInfo& ); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 89 | |
| 90 | //compute schedule and coreSchedule with the current II |
| 91 | bool computeSchedule(); |
| 92 | |
| 93 | BasicBlock* getSuccBB(BasicBlock*); |
| 94 | BasicBlock* getPredBB(BasicBlock*); |
| 95 | void constructPrologue(BasicBlock* prologue); |
| 96 | void constructKernel(BasicBlock* prologue,BasicBlock* kernel,BasicBlock* epilogue); |
| 97 | void constructEpilogue(BasicBlock* epilogue,BasicBlock* succ_bb); |
| 98 | |
| 99 | ///update the resource table at the startCycle |
| 100 | //vec: the resouce usage |
| 101 | //startCycle: the start cycle the resouce usage is |
| 102 | void updateResourceTable(std::vector<vector<unsigned int> > vec,int startCycle); |
| 103 | |
| 104 | ///un-do the update in the resource table in the startCycle |
| 105 | //vec: the resouce usage |
| 106 | //startCycle: the start cycle the resouce usage is |
| 107 | void undoUpdateResourceTable(std::vector<vector<unsigned int> > vec,int startCycle); |
| 108 | |
| 109 | ///return whether the resourcetable has negative element |
| 110 | ///this function is called after updateResouceTable() to determine whether a node can |
| 111 | /// be scheduled at certain cycle |
| 112 | bool resourceTableNegative(); |
| 113 | |
| 114 | |
| 115 | ///try to Schedule the node starting from start to end cycle(inclusive) |
| 116 | //if it can be scheduled, put it in the schedule and update nodeScheduled |
| 117 | //node: the node to be scheduled |
| 118 | //start: start cycle |
| 119 | //end : end cycle |
| 120 | //nodeScheduled: a vector storing nodes which has been scheduled |
| 121 | bool ScheduleNode(ModuloSchedGraphNode* node,unsigned start, unsigned end, NodeVec& nodeScheduled); |
| 122 | |
| 123 | //each instruction has a memory of the latest clone instruction |
| 124 | //the clone instruction can be get using getClone() |
| 125 | //this function clears the memory, i.e. getClone() after calling this function returns null |
| 126 | void clearCloneMemory(); |
| 127 | |
| 128 | //this fuction make a clone of this input Instruction and update the clone memory |
| 129 | //inst: the instrution to be cloned |
| 130 | Instruction* cloneInstSetMemory(Instruction* inst); |
| 131 | |
| 132 | //this function update each instrutions which uses ist as its operand |
| 133 | //after update, each instruction will use ist's clone as its operand |
| 134 | void updateUseWithClone(Instruction* ist); |
| 135 | |
| 136 | }; |
| 137 | |
| 138 | |
| 139 | class ModuloSchedulingSet:NonCopyable{ |
| 140 | private: |
| 141 | |
| 142 | //the graphSet to feed in |
| 143 | ModuloSchedGraphSet& graphSet; |
| 144 | public: |
| 145 | |
| 146 | //constructor |
| 147 | //Scheduling graph one by one |
| 148 | ModuloSchedulingSet(ModuloSchedGraphSet _graphSet):graphSet(_graphSet){ |
| 149 | for(unsigned i=0;i<graphSet.size();i++){ |
| 150 | ModuloSchedGraph& graph=*(graphSet[i]); |
| 151 | if(graph.isLoop())ModuloScheduling ModuloScheduling(graph); |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | //destructor |
| 156 | ~ModuloSchedulingSet(){}; |
| 157 | }; |
| 158 | |
| 159 | |
| 160 | |
| 161 | #endif |
| 162 | |
| 163 | |