1 //===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
4 //===----------------------------------------------------------------------===//
6 #ifndef LLVM_MODULO_SCHED_GRAPH_H
7 #define LLVM_MODULO_SCHED_GRAPH_H
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"
18 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
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.
29 ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst,
30 const TargetMachine &target);
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; }
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; }
49 class ModuloSchedGraph : public SchedGraphCommon {
51 const BasicBlock *BB; //The Basic block this graph represents
52 const TargetMachine &Target;
53 hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
55 void buildNodesForBB();
58 typedef hash_map<const Instruction*,
59 ModuloSchedGraphNode*>::iterator iterator;
60 typedef hash_map<const Instruction*,
61 ModuloSchedGraphNode*>::const_iterator const_iterator;
64 ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
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); }
80 class ModuloSchedGraphSet {
82 const Function *function; //Function this set of graphs represent.
83 std::vector<ModuloSchedGraph*> Graphs;
86 typedef std::vector<ModuloSchedGraph*>::iterator iterator;
87 typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
89 iterator begin() { return Graphs.begin(); }
90 iterator end() { return Graphs.end(); }
92 ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
93 ~ModuloSchedGraphSet();
95 void addGraph(ModuloSchedGraph *graph);