aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/RegAlloc/RegClass.h
blob: 7e1eb6590dfd394211cdad6da3c4d18d0a2c4b9e (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
110
111
112
113
114
115
/* Title:   RegClass.h   -*- C++ -*-
   Author:  Ruchira Sasanka
   Date:    Aug 20, 01
   Purpose: Contains machine independent methods for register coloring.

*/

#ifndef REG_CLASS_H
#define REG_CLASS_H

#include "llvm/Target/TargetRegInfo.h"
#include "InterferenceGraph.h"
#include <stack>
class TargetRegClassInfo;

typedef std::vector<unsigned> ReservedColorListType;


//-----------------------------------------------------------------------------
// Class RegClass
//
//   Implements a machine independant register class. 
//
//   This is the class that contains all data structures and common algos
//   for coloring a particular register class (e.g., int class, fp class).  
//   This class is hardware independent. This class accepts a hardware 
//   dependent description of machine registers (TargetRegInfo class) to 
//   get hardware specific info and to color an individual IG node.
//
//   This class contains the InterferenceGraph (IG).
//   Also it contains an IGNode stack that can be used for coloring. 
//   The class provides some easy access methods to the IG methods, since these
//   methods are called thru a register class.
//
//-----------------------------------------------------------------------------
class RegClass {
  const Function *const Meth;           // Function we are working on
  const TargetRegClassInfo *const MRC; // corresponding MRC
  const unsigned RegClassID;            // my int ID

  InterferenceGraph IG;                 // Interference graph - constructed by
                                        // buildInterferenceGraph
  std::stack<IGNode *> IGNodeStack;     // the stack used for coloring

  // ReservedColorList - for passing registers that are pre-allocated and cannot
  // be used by the register allocator for this function.
  //
  const ReservedColorListType *const ReservedColorList;
  
  // IsColorUsedArr - An array used for coloring each node. This array must be
  // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
  // efficiency.
  //
  std::vector<bool> IsColorUsedArr;



  //--------------------------- private methods ------------------------------

  void pushAllIGNodes();

  bool  pushUnconstrainedIGNodes();

  IGNode * getIGNodeWithMinSpillCost();

  void colorIGNode(IGNode *const Node);


 public:

  RegClass(const Function *M,
	   const TargetRegClassInfo *MRC,
	   const ReservedColorListType *RCL = 0);

  inline void createInterferenceGraph() { IG.createGraph(); }

  inline InterferenceGraph &getIG() { return IG; }

  inline const unsigned getID() const { return RegClassID; }

  // main method called for coloring regs
  //
  void colorAllRegs();                 

  inline unsigned getNumOfAvailRegs() const 
    { return MRC->getNumOfAvailRegs(); }


  // --- following methods are provided to access the IG contained within this
  // ---- RegClass easilly.

  inline void addLRToIG(LiveRange *const LR) 
    { IG.addLRToIG(LR); }

  inline void setInterference(const LiveRange *const LR1,
			      const LiveRange *const LR2)  
    { IG.setInterference(LR1, LR2); }

  inline unsigned getInterference(const LiveRange *const LR1,
			      const LiveRange *const LR2) const 
    { return IG.getInterference(LR1, LR2); }

  inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
				LiveRange *const LR2) 
    { IG.mergeIGNodesOfLRs(LR1, LR2); }


  inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }


  void printIGNodeList() const;
  void printIG();
};

#endif