Fix problems linking against the reoptimizer; _llvm_regAllocState must have
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / RegClass.h
1 //===-- RegClass.h - Machine Independent register coloring ------*- C++ -*-===//
2 // 
3 //                     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 /* Title:   RegClass.h   -*- C++ -*-
11    Author:  Ruchira Sasanka
12    Date:    Aug 20, 01
13    Purpose: Contains machine independent methods for register coloring.
14
15 */
16
17 #ifndef REGCLASS_H
18 #define REGCLASS_H
19
20 #include "llvm/Target/TargetRegInfo.h"
21 #include "InterferenceGraph.h"
22 #include <stack>
23 class TargetRegClassInfo;
24
25
26 //-----------------------------------------------------------------------------
27 // Class RegClass
28 //
29 //   Implements a machine independent register class. 
30 //
31 //   This is the class that contains all data structures and common algos
32 //   for coloring a particular register class (e.g., int class, fp class).  
33 //   This class is hardware independent. This class accepts a hardware 
34 //   dependent description of machine registers (TargetRegInfo class) to 
35 //   get hardware specific info and to color an individual IG node.
36 //
37 //   This class contains the InterferenceGraph (IG).
38 //   Also it contains an IGNode stack that can be used for coloring. 
39 //   The class provides some easy access methods to the IG methods, since these
40 //   methods are called thru a register class.
41 //
42 //-----------------------------------------------------------------------------
43 class RegClass {
44   const Function *const Meth;           // Function we are working on
45   const TargetRegInfo *MRI;             // Machine register information 
46   const TargetRegClassInfo *const MRC;  // Machine reg. class for this RegClass
47   const unsigned RegClassID;            // my int ID
48
49   InterferenceGraph IG;                 // Interference graph - constructed by
50                                         // buildInterferenceGraph
51   std::stack<IGNode *> IGNodeStack;     // the stack used for coloring
52
53   // IsColorUsedArr - An array used for coloring each node. This array must be
54   // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
55   // efficiency.
56   //
57   std::vector<bool> IsColorUsedArr;
58
59
60
61   //--------------------------- private methods ------------------------------
62
63   void pushAllIGNodes();
64
65   bool  pushUnconstrainedIGNodes();
66
67   IGNode * getIGNodeWithMinSpillCost();
68
69   void colorIGNode(IGNode *const Node);
70
71   // This directly marks the colors used by a particular register number
72   // within the register class.  External users should use the public
73   // versions of this function below.
74   inline void markColorUsed(unsigned classRegNum) {
75     assert(classRegNum < IsColorUsedArr.size() && "Invalid register used?");
76     IsColorUsedArr[classRegNum] = true;
77   }
78
79   inline bool isColorUsed(unsigned regNum) const {
80     assert(regNum < IsColorUsedArr.size() && "Invalid register used?");
81     return IsColorUsedArr[regNum];
82   }
83
84  public:
85
86   RegClass(const Function *M,
87            const TargetRegInfo *_MRI_,
88            const TargetRegClassInfo *_MRC_);
89
90   inline void createInterferenceGraph() { IG.createGraph(); }
91
92   inline InterferenceGraph &getIG() { return IG; }
93
94   inline const unsigned getID() const { return RegClassID; }
95
96   inline const TargetRegClassInfo* getTargetRegClass() const { return MRC; }
97
98   // main method called for coloring regs
99   //
100   void colorAllRegs();                 
101
102   inline unsigned getNumOfAvailRegs() const 
103     { return MRC->getNumOfAvailRegs(); }
104
105
106   // --- following methods are provided to access the IG contained within this
107   // ---- RegClass easilly.
108
109   inline void addLRToIG(LiveRange *const LR) 
110     { IG.addLRToIG(LR); }
111
112   inline void setInterference(const LiveRange *const LR1,
113                               const LiveRange *const LR2)  
114     { IG.setInterference(LR1, LR2); }
115
116   inline unsigned getInterference(const LiveRange *const LR1,
117                               const LiveRange *const LR2) const 
118     { return IG.getInterference(LR1, LR2); }
119
120   inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
121                                 LiveRange *const LR2) 
122     { IG.mergeIGNodesOfLRs(LR1, LR2); }
123
124
125   inline void clearColorsUsed() {
126     IsColorUsedArr.clear();
127     IsColorUsedArr.resize(MRC->getNumOfAllRegs());
128   }
129   inline void markColorsUsed(unsigned ClassRegNum,
130                              int UserRegType,
131                              int RegTypeWanted) {
132     MRC->markColorsUsed(ClassRegNum, UserRegType, RegTypeWanted,IsColorUsedArr);
133   }
134   inline int getUnusedColor(int machineRegType) const {
135     return MRC->findUnusedColor(machineRegType, IsColorUsedArr);
136   }
137
138   void printIGNodeList() const;
139   void printIG();
140 };
141
142 #endif