1 //// - head file for the classes ModuloScheduling and ModuloScheduling ----*- C++ -*-===//
3 // This header defines the the classes ModuloScheduling and ModuloSchedulingSet 's structure
6 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_MODULOSCHEDULING_H
10 #define LLVM_CODEGEN_MODULOSCHEDULING_H
12 #include "ModuloSchedGraph.h"
18 class ModuloScheduling:NonCopyable {
20 typedef std::vector<ModuloSchedGraphNode*> NodeVec;
22 /// the graph to feed in
23 ModuloSchedGraph& graph;
24 const TargetMachine& target;
26 //the BasicBlock to be scheduled
30 ///FIXME: II may be a better name for its meaning
33 //the vector containing the nodes which have been scheduled
34 NodeVec nodeScheduled;
36 ///the remaining unscheduled nodes
37 const NodeVec& oNodes;
39 ///the machine resource table
40 std::vector< std::vector<pair<int,int> > > resourceTable ;
42 ///the schedule( with many schedule stage)
43 std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
45 ///the kernel(core) schedule(length = II)
46 std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
48 typedef BasicBlock::InstListType InstListType;
49 typedef std::vector <std::vector<ModuloSchedGraphNode*> > vvNodeType;
56 ModuloScheduling(ModuloSchedGraph& _graph):
58 target(graph.getTarget()),
59 oNodes(graph.getONodes())
62 bb=(BasicBlock*)graph.getBasicBlocks()[0];
68 ~ModuloScheduling(){};
70 ///the method to compute schedule and instert epilogue and prologue
71 void instrScheduling();
74 ///dump the schedule and core schedule
75 void dumpScheduling();
77 ///dump the input vector of nodes
78 //sch: the input vector of nodes
79 void dumpSchedule( std::vector<std::vector<ModuloSchedGraphNode*> > sch);
81 ///dump the resource usage table
82 void dumpResourceUsageTable();
85 //*******************internel functions*******************************
87 //clear memory from the last round and initialize if necessary
88 void clearInitMem(const TargetSchedInfo& );
90 //compute schedule and coreSchedule with the current II
91 bool computeSchedule();
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);
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);
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);
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();
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
120 //nodeScheduled: a vector storing nodes which has been scheduled
121 bool ScheduleNode(ModuloSchedGraphNode* node,unsigned start, unsigned end, NodeVec& nodeScheduled);
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();
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);
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);
139 class ModuloSchedulingSet:NonCopyable{
142 //the graphSet to feed in
143 ModuloSchedGraphSet& graphSet;
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);
156 ~ModuloSchedulingSet(){};