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"
26 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
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.
37 ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst,
38 const TargetMachine &target);
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; }
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; }
57 class ModuloSchedGraph : public SchedGraphCommon {
59 const BasicBlock *BB; //The Basic block this graph represents
60 const TargetMachine &Target;
61 hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
63 void buildNodesForBB();
66 typedef hash_map<const Instruction*,
67 ModuloSchedGraphNode*>::iterator iterator;
68 typedef hash_map<const Instruction*,
69 ModuloSchedGraphNode*>::const_iterator const_iterator;
72 ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
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); }
88 class ModuloSchedGraphSet {
90 const Function *function; //Function this set of graphs represent.
91 std::vector<ModuloSchedGraph*> Graphs;
94 typedef std::vector<ModuloSchedGraph*>::iterator iterator;
95 typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
97 iterator begin() { return Graphs.begin(); }
98 iterator end() { return Graphs.end(); }
100 ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
101 ~ModuloSchedGraphSet();
103 void addGraph(ModuloSchedGraph *graph);