delete useless functions
[oota-llvm.git] / lib / Target / SparcV9 / ModuloScheduling / ModuloScheduling.h
1 // ModuloScheduling.h -------------------------------------------*- C++ -*-===//
2 //
3 // This header defines the the classes ModuloScheduling and 
4 // ModuloSchedulingSet's structure
5 //
6 //===----------------------------------------------------------------------===//
7
8
9 #ifndef LLVM_CODEGEN_MODULOSCHEDULING_H
10 #define LLVM_CODEGEN_MODULOSCHEDULING_H
11
12 #include "ModuloSchedGraph.h"
13 #include <iostream>
14 #include <vector>
15
16 #define DEBUG_PRINT(x) x
17
18 // for debug information selecton
19 enum ModuloSchedDebugLevel_t { 
20   ModuloSchedDebugLevel_NoDebugInfo,
21   ModuloSchedDebugLevel_PrintSchedule,
22   ModuloSchedDebugLevel_PrintScheduleProcess,
23 };
24
25 class ModuloScheduling: NonCopyable {
26 private:
27
28   typedef std::vector<ModuloSchedGraphNode*> NodeVec;
29   typedef std::vector<std::vector<unsigned> > Resources;
30
31   // The graph to feed in
32   ModuloSchedGraph &graph;
33   const TargetMachine &target;
34
35   // The BasicBlock to be scheduled
36   BasicBlock *bb;
37
38   // Iteration Interval
39   // FIXME: II may be a better name for its meaning
40   unsigned II;
41
42   // The vector containing the nodes which have been scheduled
43   NodeVec nodeScheduled;
44
45   // The remaining unscheduled nodes 
46   const NodeVec &oNodes;
47
48   // The machine resource table
49   std::vector<std::vector<std::pair<int,int> > > resourceTable;
50
51   ///the schedule( with many schedule stage)
52   std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
53
54   ///the kernel(core) schedule(length = II)
55   std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
56
57   typedef BasicBlock::InstListType InstListType;
58   typedef std::vector<std::vector<ModuloSchedGraphNode*> > vvNodeType;
59
60
61
62
63
64 public:
65
66   ModuloScheduling(ModuloSchedGraph & _graph):
67     graph(_graph), target(graph.getTarget()), oNodes(graph.getONodes())
68   {
69     II = graph.getMII();
70     bb = graph.getBasicBlock();
71     instrScheduling();
72   };
73
74   ~ModuloScheduling() {};
75
76
77
78   static bool 
79   printSchedule() { 
80
81     //return ModuloScheduling::DebugLevel >= DebugLevel_PrintSchedule; 
82     return true;
83
84     
85   }
86   static bool 
87   printScheduleProcess() {
88   
89     //return DebugLevel >= DebugLevel_PrintScheduleProcess;
90     return true;
91
92
93   }
94
95   // The method to compute schedule and instert epilogue and prologue
96   void instrScheduling();
97
98   // Debug functions:
99   // Dump the schedule and core schedule
100   void dumpScheduling();
101
102   // Dump the input vector of nodes
103   // sch: the input vector of nodes
104   void dumpSchedule(std::vector<std::vector<ModuloSchedGraphNode*> > sch);
105
106   // Dump the resource usage table
107   void dumpResourceUsageTable();
108
109   //*******************internal functions*******************************
110 private:
111   //clear memory from the last round and initialize if necessary
112   void clearInitMem(const TargetSchedInfo&);
113
114   //compute schedule and coreSchedule with the current II
115   bool computeSchedule();
116
117   BasicBlock *getSuccBB(BasicBlock *);
118   BasicBlock *getPredBB(BasicBlock *);
119   void constructPrologue(BasicBlock *prologue);
120   void constructKernel(BasicBlock *prologue,
121                        BasicBlock *kernel,
122                        BasicBlock *epilogue);
123   void constructEpilogue(BasicBlock *epilogue, BasicBlock *succ_bb);
124
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,
129                            int startCycle);
130
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,
135                                int startCycle);
136
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();
141
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
146   // end : end cycle
147   // nodeScheduled: a vector storing nodes which has been scheduled
148   bool ScheduleNode(ModuloSchedGraphNode * node, unsigned start,
149                     unsigned end, NodeVec &nodeScheduled);
150
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
154   //returns null
155   void clearCloneMemory();
156
157   //this fuction make a clone of this input Instruction and update the clone
158   //memory
159   //inst: the instrution to be cloned
160   Instruction *cloneInstSetMemory(Instruction *inst);
161
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);
165
166 };
167
168
169 class ModuloSchedulingSet:
170 NonCopyable {
171 private:
172
173   //the graphSet to feed in
174   ModuloSchedGraphSet & graphSet;
175
176 public:
177
178   //constructor
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);
185     }
186   };
187
188   ~ModuloSchedulingSet() {};
189 };
190
191 #endif