summaryrefslogtreecommitdiff
path: root/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.h
blob: 214e24cc8b5eca5c122ced03a0790347bb9a2653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
// 
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
// 
//===----------------------------------------------------------------------===//
// 
// TODO: Need a description here.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_MODULO_SCHED_GRAPH_H
#define LLVM_MODULO_SCHED_GRAPH_H

#include "llvm/Instruction.h"
#include "llvm/CodeGen/SchedGraphCommon.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/BasicBlock.h"
#include "llvm/Function.h"
#include "Support/hash_map"
#include <vector>


class ModuloSchedGraphNode : public SchedGraphNodeCommon {

  const Instruction *Inst;  //Node's Instruction
  unsigned Earliest;        //ASAP, or earliest time to be scheduled
  unsigned Latest;          //ALAP, or latested time to be scheduled
  unsigned Depth;           //Max Distance from node to the root
  unsigned Height;          //Max Distance from node to leaf
  unsigned Mobility;        //MOB, number of time slots it can be scheduled
  const TargetMachine &Target; //Target information.

public:
  ModuloSchedGraphNode(unsigned ID, int index, const Instruction *inst, 
		       const TargetMachine &target);
  
  void print(std::ostream &os) const;
  const Instruction* getInst() { return Inst; }
  unsigned getEarliest() { return Earliest; }
  unsigned getLatest() { return Latest; }
  unsigned getDepth() { return Depth; }
  unsigned getHeight() { return Height; }
  unsigned getMobility() { return Mobility; }
  
  void setEarliest(unsigned early) { Earliest = early; }
  void setLatest(unsigned late) { Latest = late; }
  void setDepth(unsigned depth) { Depth = depth; }
  void setHeight(unsigned height) { Height = height; }
  void setMobility(unsigned mob) { Mobility = mob; }


};

class ModuloSchedGraph : public SchedGraphCommon {
  
  const BasicBlock *BB; //The Basic block this graph represents
  const TargetMachine &Target;
  hash_map<const Instruction*, ModuloSchedGraphNode*> GraphMap;

  void buildNodesForBB();

public:
  typedef hash_map<const Instruction*, 
		   ModuloSchedGraphNode*>::iterator iterator;
  typedef hash_map<const Instruction*, 
		   ModuloSchedGraphNode*>::const_iterator const_iterator;


  ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ);

  const BasicBlock* getBB() { return BB; }
  void setBB(BasicBlock *bb) { BB = bb; }
  unsigned size() { return GraphMap.size(); }
  void addNode(const Instruction *I, ModuloSchedGraphNode *node);
  void ASAP(); //Calculate earliest schedule time for all nodes in graph.
  void ALAP(); //Calculate latest schedule time for all nodes in graph.
  void MOB(); //Calculate mobility for all nodes in the graph.
  void ComputeDepth(); //Compute depth of each node in graph
  void ComputeHeight(); //Computer height of each node in graph
  void addDepEdges(); //Add Dependencies
  iterator find(const Instruction *I) { return GraphMap.find(I); }
};


class ModuloSchedGraphSet {
  
  const Function *function; //Function this set of graphs represent.
  std::vector<ModuloSchedGraph*> Graphs;

public:
  typedef std::vector<ModuloSchedGraph*>::iterator iterator;
  typedef std::vector<ModuloSchedGraph*>::const_iterator const_iterator;
 
  iterator begin() { return Graphs.begin(); }
  iterator end() { return Graphs.end(); }
 
  ModuloSchedGraphSet(const Function *func, const TargetMachine &target);
  ~ModuloSchedGraphSet();

  void addGraph(ModuloSchedGraph *graph);
  void dump() const;


};

#endif