Added LLVM copyright header.
[oota-llvm.git] / lib / Target / SparcV9 / 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
26 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
27
28   const Instruction *Inst;  //Node's Instruction
29   unsigned Earliest;        //ASAP, or earliest time to be scheduled
30   unsigned Latest;          //ALAP, or latested time to be scheduled
31   unsigned Depth;           //Max Distance from node to the root
32   unsigned Height;          //Max Distance from node to leaf
33   unsigned Mobility;        //MOB, number of time slots it can be scheduled
34   const TargetMachine &Target; //Target information.
35
36 public:
37   ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst, 
38                        const TargetMachine &target);
39   
40   void print(std::ostream &os) const;
41   const Instruction* getInst() { return Inst; }
42   unsigned getEarliest() { return Earliest; }
43   unsigned getLatest() { return Latest; }
44   unsigned getDepth() { return Depth; }
45   unsigned getHeight() { return Height; }
46   unsigned getMobility() { return Mobility; }
47   
48   void setEarliest(unsigned early) { Earliest = early; }
49   void setLatest(unsigned late) { Latest = late; }
50   void setDepth(unsigned depth) { Depth = depth; }
51   void setHeight(unsigned height) { Height = height; }
52   void setMobility(unsigned mob) { Mobility = mob; }
53
54
55 };
56
57 class ModuloSchedGraph : public SchedGraphCommon {
58   
59   const BasicBlock *BB; //The Basic block this graph represents
60   const TargetMachine &Target;
61   hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
62
63   void buildNodesForBB();
64
65 public:
66   typedef hash_map<const Instruction*, 
67                    ModuloSchedGraphNode*>::iterator iterator;
68   typedef hash_map<const Instruction*, 
69                    ModuloSchedGraphNode*>::const_iterator const_iterator;
70
71
72   ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
73
74   const BasicBlock* getBB() { return BB; }
75   void setBB(BasicBlock *bb) { BB = bb; }
76   unsigned size() { return GraphMap.size(); }
77   void addNode(const Instruction *I, ModuloSchedGraphNode *node);
78   void ASAP(); //Calculate earliest schedule time for all nodes in graph.
79   void ALAP(); //Calculate latest schedule time for all nodes in graph.
80   void MOB(); //Calculate mobility for all nodes in the graph.
81   void ComputeDepth(); //Compute depth of each node in graph
82   void ComputeHeight(); //Computer height of each node in graph
83   void addDepEdges(); //Add Dependencies
84   iterator find(const Instruction *I) { return GraphMap.find(I); }
85 };
86
87
88 class ModuloSchedGraphSet {
89   
90   const Function *function; //Function this set of graphs represent.
91   std::vector<ModuloSchedGraph*> Graphs;
92
93 public:
94   typedef std::vector<ModuloSchedGraph*>::iterator iterator;
95   typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
96  
97   iterator begin() { return Graphs.begin(); }
98   iterator end() { return Graphs.end(); }
99  
100   ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
101   ~ModuloSchedGraphSet();
102
103   void addGraph(ModuloSchedGraph *graph);
104   void dump() const;
105
106
107 };
108
109 #endif