Finegrainify namespacification
[oota-llvm.git] / lib / CodeGen / RegAlloc / RegClass.h
index 3db72b736395d1500d5abe65c769c3d2eeec24c5..0071f7c2129c34169fc516f94f4f7320ae378d64 100644 (file)
@@ -1,3 +1,12 @@
+//===-- RegClass.h - Machine Independent register coloring ------*- 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.
+// 
+//===----------------------------------------------------------------------===//
+
 /* Title:   RegClass.h   -*- C++ -*-
    Author:  Ruchira Sasanka
    Date:    Aug 20, 01
 
 */
 
-#ifndef REG_CLASS_H
-#define REG_CLASS_H
+#ifndef REGCLASS_H
+#define REGCLASS_H
 
-#include "llvm/CodeGen/IGNode.h"
-#include "llvm/CodeGen/InterferenceGraph.h"
-#include "llvm/Target/MachineRegInfo.h"
+#include "llvm/Target/TargetRegInfo.h"
+#include "InterferenceGraph.h"
 #include <stack>
-#include <iostream>
-class MachineRegClassInfo;
 
-typedef std::vector<unsigned> ReservedColorListType;
+namespace llvm {
+
+class TargetRegClassInfo;
 
 
 //-----------------------------------------------------------------------------
 // Class RegClass
 //
-//   Implements a machine independant register class. 
+//   Implements a machine independent 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 (MachineRegInfo class) to 
+//   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).
@@ -37,23 +45,20 @@ typedef std::vector<unsigned> ReservedColorListType;
 //-----------------------------------------------------------------------------
 class RegClass {
   const Function *const Meth;           // Function we are working on
-  const MachineRegClassInfo *const MRC; // corresponding MRC
+  const TargetRegInfo *MRI;             // Machine register information 
+  const TargetRegClassInfo *const MRC;  // Machine reg. class for this RegClass
   const unsigned RegClassID;            // my int ID
 
   InterferenceGraph IG;                 // Interference graph - constructed by
                                         // buildInterferenceGraph
   std::stack<IGNode *> IGNodeStack;     // the stack used for coloring
 
-  const ReservedColorListType *const ReservedColorList;
-  //
-  // for passing registers that are pre-allocated and cannot be used by the
-  // register allocator for this function.
-  
-  bool *IsColorUsedArr;
+  // IsColorUsedArr - An array used for coloring each node. This array must be
+  // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
+  // efficiency.
   //
-  // 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 ------------------------------
@@ -66,14 +71,24 @@ class RegClass {
 
   void colorIGNode(IGNode *const Node);
 
+  // This directly marks the colors used by a particular register number
+  // within the register class.  External users should use the public
+  // versions of this function below.
+  inline void markColorUsed(unsigned classRegNum) {
+    assert(classRegNum < IsColorUsedArr.size() && "Invalid register used?");
+    IsColorUsedArr[classRegNum] = true;
+  }
+
+  inline bool isColorUsed(unsigned regNum) const {
+    assert(regNum < IsColorUsedArr.size() && "Invalid register used?");
+    return IsColorUsedArr[regNum];
+  }
 
  public:
 
   RegClass(const Function *M,
-          const MachineRegClassInfo *MRC,
-          const ReservedColorListType *RCL = 0);
-
-  ~RegClass() { delete[] IsColorUsedArr; }
+          const TargetRegInfo *_MRI_,
+          const TargetRegClassInfo *_MRC_);
 
   inline void createInterferenceGraph() { IG.createGraph(); }
 
@@ -81,6 +96,8 @@ class RegClass {
 
   inline const unsigned getID() const { return RegClassID; }
 
+  inline const TargetRegClassInfo* getTargetRegClass() const { return MRC; }
+
   // main method called for coloring regs
   //
   void colorAllRegs();                 
@@ -108,18 +125,23 @@ class RegClass {
     { IG.mergeIGNodesOfLRs(LR1, LR2); }
 
 
-  inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
-
-
-  inline void printIGNodeList() const {
-    std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n";
-    IG.printIGNodeList(); 
+  inline void clearColorsUsed() {
+    IsColorUsedArr.clear();
+    IsColorUsedArr.resize(MRC->getNumOfAllRegs());
   }
-
-  inline void printIG() {  
-    std::cerr << "IG for Register Class " << RegClassID << ":" << "\n";
-    IG.printIG(); 
+  inline void markColorsUsed(unsigned ClassRegNum,
+                             int UserRegType,
+                             int RegTypeWanted) {
+    MRC->markColorsUsed(ClassRegNum, UserRegType, RegTypeWanted,IsColorUsedArr);
+  }
+  inline int getUnusedColor(int machineRegType) const {
+    return MRC->findUnusedColor(machineRegType, IsColorUsedArr);
   }
+
+  void printIGNodeList() const;
+  void printIG();
 };
 
+} // End llvm namespace
+
 #endif