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