1 //===-- RegClass.h - Machine Independent register coloring ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 /* Title: RegClass.h -*- C++ -*-
11 Author: Ruchira Sasanka
13 Purpose: Contains machine independent methods for register coloring.
20 #include "../SparcV9RegInfo.h"
21 #include "InterferenceGraph.h"
26 class TargetRegClassInfo;
29 //-----------------------------------------------------------------------------
32 // Implements a machine independent register class.
34 // This is the class that contains all data structures and common algos
35 // for coloring a particular register class (e.g., int class, fp class).
36 // This class is hardware independent. This class accepts a hardware
37 // dependent description of machine registers (TargetRegInfo class) to
38 // get hardware specific info and to color an individual IG node.
40 // This class contains the InterferenceGraph (IG).
41 // Also it contains an IGNode stack that can be used for coloring.
42 // The class provides some easy access methods to the IG methods, since these
43 // methods are called thru a register class.
45 //-----------------------------------------------------------------------------
47 const Function *const Meth; // Function we are working on
48 const SparcV9RegInfo *MRI; // Machine register information
49 const TargetRegClassInfo *const MRC; // Machine reg. class for this RegClass
50 const unsigned RegClassID; // my int ID
52 InterferenceGraph IG; // Interference graph - constructed by
53 // buildInterferenceGraph
54 std::stack<IGNode *> IGNodeStack; // the stack used for coloring
56 // IsColorUsedArr - An array used for coloring each node. This array must be
57 // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
60 std::vector<bool> IsColorUsedArr;
64 //--------------------------- private methods ------------------------------
66 void pushAllIGNodes();
68 bool pushUnconstrainedIGNodes();
70 IGNode * getIGNodeWithMinSpillCost();
72 void colorIGNode(IGNode *const Node);
74 // This directly marks the colors used by a particular register number
75 // within the register class. External users should use the public
76 // versions of this function below.
77 inline void markColorUsed(unsigned classRegNum) {
78 assert(classRegNum < IsColorUsedArr.size() && "Invalid register used?");
79 IsColorUsedArr[classRegNum] = true;
82 inline bool isColorUsed(unsigned regNum) const {
83 assert(regNum < IsColorUsedArr.size() && "Invalid register used?");
84 return IsColorUsedArr[regNum];
89 RegClass(const Function *M,
90 const SparcV9RegInfo *_MRI_,
91 const TargetRegClassInfo *_MRC_);
93 inline void createInterferenceGraph() { IG.createGraph(); }
95 inline InterferenceGraph &getIG() { return IG; }
97 inline const unsigned getID() const { return RegClassID; }
99 inline const TargetRegClassInfo* getTargetRegClass() const { return MRC; }
101 // main method called for coloring regs
105 inline unsigned getNumOfAvailRegs() const
106 { return MRC->getNumOfAvailRegs(); }
109 // --- following methods are provided to access the IG contained within this
110 // ---- RegClass easilly.
112 inline void addLRToIG(V9LiveRange *const LR)
113 { IG.addLRToIG(LR); }
115 inline void setInterference(const V9LiveRange *const LR1,
116 const V9LiveRange *const LR2)
117 { IG.setInterference(LR1, LR2); }
119 inline unsigned getInterference(const V9LiveRange *const LR1,
120 const V9LiveRange *const LR2) const
121 { return IG.getInterference(LR1, LR2); }
123 inline void mergeIGNodesOfLRs(const V9LiveRange *const LR1,
124 V9LiveRange *const LR2)
125 { IG.mergeIGNodesOfLRs(LR1, LR2); }
128 inline void clearColorsUsed() {
129 IsColorUsedArr.clear();
130 IsColorUsedArr.resize(MRC->getNumOfAllRegs());
132 inline void markColorsUsed(unsigned ClassRegNum,
135 MRC->markColorsUsed(ClassRegNum, UserRegType, RegTypeWanted,IsColorUsedArr);
137 inline int getUnusedColor(int machineRegType) const {
138 return MRC->findUnusedColor(machineRegType, IsColorUsedArr);
141 void printIGNodeList() const;
145 } // End llvm namespace