* Doxygenified comments
[oota-llvm.git] / lib / CodeGen / ModuloScheduling / ModuloSchedGraph.h
1 //===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
2 // 
3 //
4 //===----------------------------------------------------------------------===//
5
6 #ifndef LLVM_MODULO_SCHED_GRAPH_H
7 #define LLVM_MODULO_SCHED_GRAPH_H
8
9 #include "llvm/Instruction.h"
10 #include "llvm/CodeGen/SchedGraphCommon.h"
11 #include "llvm/Target/TargetMachine.h"
12 #include "llvm/BasicBlock.h"
13 #include "llvm/Function.h"
14 #include "Support/hash_map"
15 #include <vector>
16
17
18 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
19
20   const Instruction *Inst;  //Node's Instruction
21   unsigned Earliest;        //ASAP, or earliest time to be scheduled
22   unsigned Latest;          //ALAP, or latested time to be scheduled
23   unsigned Depth;           //Max Distance from node to the root
24   unsigned Height;          //Max Distance from node to leaf
25   unsigned Mobility;        //MOB, number of time slots it can be scheduled
26   const TargetMachine &Target; //Target information.
27
28 public:
29   ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst, 
30                        const TargetMachine &target);
31   
32   void print(std::ostream &os) const;
33   const Instruction* getInst() { return Inst; }
34   unsigned getEarliest() { return Earliest; }
35   unsigned getLatest() { return Latest; }
36   unsigned getDepth() { return Depth; }
37   unsigned getHeight() { return Height; }
38   unsigned getMobility() { return Mobility; }
39   
40   void setEarliest(unsigned early) { Earliest = early; }
41   void setLatest(unsigned late) { Latest = late; }
42   void setDepth(unsigned depth) { Depth = depth; }
43   void setHeight(unsigned height) { Height = height; }
44   void setMobility(unsigned mob) { Mobility = mob; }
45
46
47 };
48
49 class ModuloSchedGraph : public SchedGraphCommon {
50   
51   const BasicBlock *BB; //The Basic block this graph represents
52   const TargetMachine &Target;
53   hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
54
55   void buildNodesForBB();
56
57 public:
58   typedef hash_map<const Instruction*, 
59                    ModuloSchedGraphNode*>::iterator iterator;
60   typedef hash_map<const Instruction*, 
61                    ModuloSchedGraphNode*>::const_iterator const_iterator;
62
63
64   ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
65
66   const BasicBlock* getBB() { return BB; }
67   void setBB(BasicBlock *bb) { BB = bb; }
68   unsigned size() { return GraphMap.size(); }
69   void addNode(const Instruction *I, ModuloSchedGraphNode *node);
70   void ASAP(); //Calculate earliest schedule time for all nodes in graph.
71   void ALAP(); //Calculate latest schedule time for all nodes in graph.
72   void MOB(); //Calculate mobility for all nodes in the graph.
73   void ComputeDepth(); //Compute depth of each node in graph
74   void ComputeHeight(); //Computer height of each node in graph
75   void addDepEdges(); //Add Dependencies
76   iterator find(const Instruction *I) { return GraphMap.find(I); }
77 };
78
79
80 class ModuloSchedGraphSet {
81   
82   const Function *function; //Function this set of graphs represent.
83   std::vector<ModuloSchedGraph*> Graphs;
84
85 public:
86   typedef std::vector<ModuloSchedGraph*>::iterator iterator;
87   typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
88  
89   iterator begin() { return Graphs.begin(); }
90   iterator end() { return Graphs.end(); }
91  
92   ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
93   ~ModuloSchedGraphSet();
94
95   void addGraph(ModuloSchedGraph *graph);
96   void dump() const;
97
98
99 };
100
101 #endif