Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 1 | //===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===// |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 2 | // |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 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. |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 14 | #ifndef LLVM_MODULO_SCHED_GRAPH_H |
| 15 | #define LLVM_MODULO_SCHED_GRAPH_H |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 16 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 17 | #include "llvm/Instruction.h" |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/SchedGraphCommon.h" |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachine.h" |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 20 | #include "llvm/BasicBlock.h" |
| 21 | #include "llvm/Function.h" |
Misha Brukman | 2c821cc | 2003-04-10 19:19:23 +0000 | [diff] [blame] | 22 | #include "Support/hash_map" |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 23 | #include <vector> |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 24 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 25 | namespace llvm { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 26 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 27 | class ModuloSchedGraphNode : public SchedGraphNodeCommon { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 28 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 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. |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 36 | |
| 37 | public: |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 38 | ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst, |
| 39 | const TargetMachine &target); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 40 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 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; } |
Guochun Shi | f325261 | 2003-06-10 19:09:00 +0000 | [diff] [blame] | 48 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 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 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 55 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 58 | class ModuloSchedGraph : public SchedGraphCommon { |
Guochun Shi | 099b064 | 2003-06-02 17:48:56 +0000 | [diff] [blame] | 59 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 60 | const BasicBlock *BB; //The Basic block this graph represents |
| 61 | const TargetMachine &Target; |
| 62 | hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 63 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 64 | void buildNodesForBB(); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 65 | |
| 66 | public: |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 67 | typedef hash_map<const Instruction*, |
| 68 | ModuloSchedGraphNode*>::iterator iterator; |
| 69 | typedef hash_map<const Instruction*, |
| 70 | ModuloSchedGraphNode*>::const_iterator const_iterator; |
Guochun Shi | 099b064 | 2003-06-02 17:48:56 +0000 | [diff] [blame] | 71 | |
| 72 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 73 | ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 74 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 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); } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 88 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 89 | class ModuloSchedGraphSet { |
| 90 | |
| 91 | const Function *function; //Function this set of graphs represent. |
| 92 | std::vector<ModuloSchedGraph*> Graphs; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 93 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 94 | public: |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 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); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 102 | ~ModuloSchedGraphSet(); |
| 103 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 104 | void addGraph(ModuloSchedGraph *graph); |
Misha Brukman | 2c821cc | 2003-04-10 19:19:23 +0000 | [diff] [blame] | 105 | void dump() const; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 106 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 107 | |
Misha Brukman | 2c821cc | 2003-04-10 19:19:23 +0000 | [diff] [blame] | 108 | }; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 109 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 110 | } // End llvm namespace |
| 111 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 112 | #endif |