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