1 //===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // TODO: Need a description here.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MODULO_SCHED_GRAPH_H
15 #define LLVM_MODULO_SCHED_GRAPH_H
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"
27 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
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.
38 ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst,
39 const TargetMachine &target);
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; }
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; }
58 class ModuloSchedGraph : public SchedGraphCommon {
60 const BasicBlock *BB; //The Basic block this graph represents
61 const TargetMachine &Target;
62 hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
64 void buildNodesForBB();
67 typedef hash_map<const Instruction*,
68 ModuloSchedGraphNode*>::iterator iterator;
69 typedef hash_map<const Instruction*,
70 ModuloSchedGraphNode*>::const_iterator const_iterator;
73 ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
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); }
89 class ModuloSchedGraphSet {
91 const Function *function; //Function this set of graphs represent.
92 std::vector<ModuloSchedGraph*> Graphs;
95 typedef std::vector<ModuloSchedGraph*>::iterator iterator;
96 typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
98 iterator begin() { return Graphs.begin(); }
99 iterator end() { return Graphs.end(); }
101 ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
102 ~ModuloSchedGraphSet();
104 void addGraph(ModuloSchedGraph *graph);
110 } // End llvm namespace