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