blob: 552d699e768f8d8ef5debadacb7ffdf994bf78a9 [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//
John Criswell856ba762003-10-21 15:17:13 +00003// 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 Shif1c154f2003-03-27 17:57:44 +000011//
12//===----------------------------------------------------------------------===//
13
Tanya Lattner4f839cc2003-08-28 17:12:14 +000014#ifndef LLVM_MODULO_SCHED_GRAPH_H
15#define LLVM_MODULO_SCHED_GRAPH_H
Misha Brukman8baa01c2003-04-09 21:51:34 +000016
Guochun Shif1c154f2003-03-27 17:57:44 +000017#include "llvm/Instruction.h"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000018#include "llvm/CodeGen/SchedGraphCommon.h"
Guochun Shif1c154f2003-03-27 17:57:44 +000019#include "llvm/Target/TargetMachine.h"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000020#include "llvm/BasicBlock.h"
21#include "llvm/Function.h"
Misha Brukman2c821cc2003-04-10 19:19:23 +000022#include "Support/hash_map"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000023#include <vector>
Guochun Shif1c154f2003-03-27 17:57:44 +000024
Brian Gaeked0fde302003-11-11 22:41:34 +000025namespace llvm {
Guochun Shif1c154f2003-03-27 17:57:44 +000026
Tanya Lattner4f839cc2003-08-28 17:12:14 +000027class ModuloSchedGraphNode : public SchedGraphNodeCommon {
Guochun Shif1c154f2003-03-27 17:57:44 +000028
Tanya Lattner4f839cc2003-08-28 17:12:14 +000029 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 Shif1c154f2003-03-27 17:57:44 +000036
37public:
Tanya Lattner4f839cc2003-08-28 17:12:14 +000038 ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst,
39 const TargetMachine &target);
Misha Brukman8baa01c2003-04-09 21:51:34 +000040
Tanya Lattner4f839cc2003-08-28 17:12:14 +000041 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 Shif3252612003-06-10 19:09:00 +000048
Tanya Lattner4f839cc2003-08-28 17:12:14 +000049 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 Brukman8baa01c2003-04-09 21:51:34 +000055
Guochun Shif1c154f2003-03-27 17:57:44 +000056};
57
Tanya Lattner4f839cc2003-08-28 17:12:14 +000058class ModuloSchedGraph : public SchedGraphCommon {
Guochun Shi099b0642003-06-02 17:48:56 +000059
Tanya Lattner4f839cc2003-08-28 17:12:14 +000060 const BasicBlock *BB; //The Basic block this graph represents
61 const TargetMachine &Target;
62 hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;
Misha Brukman8baa01c2003-04-09 21:51:34 +000063
Tanya Lattner4f839cc2003-08-28 17:12:14 +000064 void buildNodesForBB();
Misha Brukman8baa01c2003-04-09 21:51:34 +000065
66public:
Tanya Lattner4f839cc2003-08-28 17:12:14 +000067 typedef hash_map<const Instruction*,
68 ModuloSchedGraphNode*>::iterator iterator;
69 typedef hash_map<const Instruction*,
70 ModuloSchedGraphNode*>::const_iterator const_iterator;
Guochun Shi099b0642003-06-02 17:48:56 +000071
72
Tanya Lattner4f839cc2003-08-28 17:12:14 +000073 ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);
Guochun Shif1c154f2003-03-27 17:57:44 +000074
Tanya Lattner4f839cc2003-08-28 17:12:14 +000075 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 Shif1c154f2003-03-27 17:57:44 +000086};
87
Guochun Shif1c154f2003-03-27 17:57:44 +000088
Tanya Lattner4f839cc2003-08-28 17:12:14 +000089class ModuloSchedGraphSet {
90
91 const Function *function; //Function this set of graphs represent.
92 std::vector<ModuloSchedGraph*> Graphs;
Misha Brukman8baa01c2003-04-09 21:51:34 +000093
Guochun Shif1c154f2003-03-27 17:57:44 +000094public:
Tanya Lattner4f839cc2003-08-28 17:12:14 +000095 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 Brukman8baa01c2003-04-09 21:51:34 +0000102 ~ModuloSchedGraphSet();
103
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000104 void addGraph(ModuloSchedGraph *graph);
Misha Brukman2c821cc2003-04-10 19:19:23 +0000105 void dump() const;
Guochun Shif1c154f2003-03-27 17:57:44 +0000106
Guochun Shif1c154f2003-03-27 17:57:44 +0000107
Misha Brukman2c821cc2003-04-10 19:19:23 +0000108};
Misha Brukman8baa01c2003-04-09 21:51:34 +0000109
Brian Gaeked0fde302003-11-11 22:41:34 +0000110} // End llvm namespace
111
Misha Brukman8baa01c2003-04-09 21:51:34 +0000112#endif