blob: 3404a747ee3dba607191e657a1f102a579cd608c [file] [log] [blame]
Misha Brukman8baa01c2003-04-09 21:51:34 +00001//===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
Tanya Lattner4f839cc2003-08-28 17:12:14 +00002//
Guochun Shif1c154f2003-03-27 17:57:44 +00003//
4//===----------------------------------------------------------------------===//
5
Tanya Lattner4f839cc2003-08-28 17:12:14 +00006#ifndef LLVM_MODULO_SCHED_GRAPH_H
7#define LLVM_MODULO_SCHED_GRAPH_H
Misha Brukman8baa01c2003-04-09 21:51:34 +00008
Guochun Shif1c154f2003-03-27 17:57:44 +00009#include "llvm/Instruction.h"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000010#include "llvm/CodeGen/SchedGraphCommon.h"
Guochun Shif1c154f2003-03-27 17:57:44 +000011#include "llvm/Target/TargetMachine.h"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000012#include "llvm/BasicBlock.h"
13#include "llvm/Function.h"
Misha Brukman2c821cc2003-04-10 19:19:23 +000014#include "Support/hash_map"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000015#include <vector>
Guochun Shif1c154f2003-03-27 17:57:44 +000016
Guochun Shif1c154f2003-03-27 17:57:44 +000017
Tanya Lattner4f839cc2003-08-28 17:12:14 +000018class ModuloSchedGraphNode : public SchedGraphNodeCommon {
Guochun Shif1c154f2003-03-27 17:57:44 +000019
Tanya Lattner4f839cc2003-08-28 17:12:14 +000020 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.
Guochun Shif1c154f2003-03-27 17:57:44 +000027
28public:
Tanya Lattner4f839cc2003-08-28 17:12:14 +000029 ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst,
30 const TargetMachine &target);
Misha Brukman8baa01c2003-04-09 21:51:34 +000031
Tanya Lattner4f839cc2003-08-28 17:12:14 +000032 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; }
Guochun Shif3252612003-06-10 19:09:00 +000039
Tanya Lattner4f839cc2003-08-28 17:12:14 +000040 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; }
45
Misha Brukman8baa01c2003-04-09 21:51:34 +000046
Guochun Shif1c154f2003-03-27 17:57:44 +000047};
48
Tanya Lattner4f839cc2003-08-28 17:12:14 +000049class ModuloSchedGraph : public SchedGraphCommon {
Guochun Shi099b0642003-06-02 17:48:56 +000050
Tanya Lattner4f839cc2003-08-28 17:12:14 +000051 const BasicBlock *BB; //The Basic block this graph represents
52 const TargetMachine &Target;
53 hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
Misha Brukman8baa01c2003-04-09 21:51:34 +000054
Tanya Lattner4f839cc2003-08-28 17:12:14 +000055 void buildNodesForBB();
Misha Brukman8baa01c2003-04-09 21:51:34 +000056
57public:
Tanya Lattner4f839cc2003-08-28 17:12:14 +000058 typedef hash_map<const Instruction*,
59 ModuloSchedGraphNode*>::iterator iterator;
60 typedef hash_map<const Instruction*,
61 ModuloSchedGraphNode*>::const_iterator const_iterator;
Guochun Shi099b0642003-06-02 17:48:56 +000062
63
Tanya Lattner4f839cc2003-08-28 17:12:14 +000064 ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
Guochun Shif1c154f2003-03-27 17:57:44 +000065
Tanya Lattner4f839cc2003-08-28 17:12:14 +000066 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); }
Guochun Shif1c154f2003-03-27 17:57:44 +000077};
78
Guochun Shif1c154f2003-03-27 17:57:44 +000079
Tanya Lattner4f839cc2003-08-28 17:12:14 +000080class ModuloSchedGraphSet {
81
82 const Function *function; //Function this set of graphs represent.
83 std::vector<ModuloSchedGraph*> Graphs;
Misha Brukman8baa01c2003-04-09 21:51:34 +000084
Guochun Shif1c154f2003-03-27 17:57:44 +000085public:
Tanya Lattner4f839cc2003-08-28 17:12:14 +000086 typedef std::vector<ModuloSchedGraph*>::iterator iterator;
87 typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
88
89 iterator begin() { return Graphs.begin(); }
90 iterator end() { return Graphs.end(); }
91
92 ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
Misha Brukman8baa01c2003-04-09 21:51:34 +000093 ~ModuloSchedGraphSet();
94
Tanya Lattner4f839cc2003-08-28 17:12:14 +000095 void addGraph(ModuloSchedGraph *graph);
Misha Brukman2c821cc2003-04-10 19:19:23 +000096 void dump() const;
Guochun Shif1c154f2003-03-27 17:57:44 +000097
Guochun Shif1c154f2003-03-27 17:57:44 +000098
Misha Brukman2c821cc2003-04-10 19:19:23 +000099};
Misha Brukman8baa01c2003-04-09 21:51:34 +0000100
101#endif