LLVM API Documentation

RegClass.h

Go to the documentation of this file.
00001 //===-- RegClass.h - Machine Independent register coloring ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 /* Title:   RegClass.h   -*- C++ -*-
00011    Author:  Ruchira Sasanka
00012    Date:    Aug 20, 01
00013    Purpose: Contains machine independent methods for register coloring.
00014 
00015 */
00016 
00017 #ifndef REGCLASS_H
00018 #define REGCLASS_H
00019 
00020 #include "../SparcV9RegInfo.h"
00021 #include "InterferenceGraph.h"
00022 #include <stack>
00023 
00024 namespace llvm {
00025 
00026 class TargetRegClassInfo;
00027 
00028 
00029 //-----------------------------------------------------------------------------
00030 // Class RegClass
00031 //
00032 //   Implements a machine independent register class.
00033 //
00034 //   This is the class that contains all data structures and common algos
00035 //   for coloring a particular register class (e.g., int class, fp class).
00036 //   This class is hardware independent. This class accepts a hardware
00037 //   dependent description of machine registers (TargetRegInfo class) to
00038 //   get hardware specific info and to color an individual IG node.
00039 //
00040 //   This class contains the InterferenceGraph (IG).
00041 //   Also it contains an IGNode stack that can be used for coloring.
00042 //   The class provides some easy access methods to the IG methods, since these
00043 //   methods are called thru a register class.
00044 //
00045 //-----------------------------------------------------------------------------
00046 class RegClass {
00047   const Function *const Meth;           // Function we are working on
00048   const SparcV9RegInfo *MRI;            // Machine register information
00049   const TargetRegClassInfo *const MRC;  // Machine reg. class for this RegClass
00050   const unsigned RegClassID;            // my int ID
00051 
00052   InterferenceGraph IG;                 // Interference graph - constructed by
00053                                         // buildInterferenceGraph
00054   std::stack<IGNode *> IGNodeStack;     // the stack used for coloring
00055 
00056   // IsColorUsedArr - An array used for coloring each node. This array must be
00057   // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
00058   // efficiency.
00059   //
00060   std::vector<bool> IsColorUsedArr;
00061 
00062 
00063 
00064   //--------------------------- private methods ------------------------------
00065 
00066   void pushAllIGNodes();
00067 
00068   bool  pushUnconstrainedIGNodes();
00069 
00070   IGNode * getIGNodeWithMinSpillCost();
00071 
00072   void colorIGNode(IGNode *const Node);
00073 
00074   // This directly marks the colors used by a particular register number
00075   // within the register class.  External users should use the public
00076   // versions of this function below.
00077   inline void markColorUsed(unsigned classRegNum) {
00078     assert(classRegNum < IsColorUsedArr.size() && "Invalid register used?");
00079     IsColorUsedArr[classRegNum] = true;
00080   }
00081 
00082   inline bool isColorUsed(unsigned regNum) const {
00083     assert(regNum < IsColorUsedArr.size() && "Invalid register used?");
00084     return IsColorUsedArr[regNum];
00085   }
00086 
00087  public:
00088 
00089   RegClass(const Function *M,
00090            const SparcV9RegInfo *_MRI_,
00091            const TargetRegClassInfo *_MRC_);
00092 
00093   inline void createInterferenceGraph() { IG.createGraph(); }
00094 
00095   inline InterferenceGraph &getIG() { return IG; }
00096 
00097   inline const unsigned getID() const { return RegClassID; }
00098 
00099   inline const TargetRegClassInfo* getTargetRegClass() const { return MRC; }
00100 
00101   // main method called for coloring regs
00102   //
00103   void colorAllRegs();
00104 
00105   inline unsigned getNumOfAvailRegs() const
00106     { return MRC->getNumOfAvailRegs(); }
00107 
00108 
00109   // --- following methods are provided to access the IG contained within this
00110   // ---- RegClass easilly.
00111 
00112   inline void addLRToIG(V9LiveRange *const LR)
00113     { IG.addLRToIG(LR); }
00114 
00115   inline void setInterference(const V9LiveRange *const LR1,
00116                               const V9LiveRange *const LR2)
00117     { IG.setInterference(LR1, LR2); }
00118 
00119   inline unsigned getInterference(const V9LiveRange *const LR1,
00120                               const V9LiveRange *const LR2) const
00121     { return IG.getInterference(LR1, LR2); }
00122 
00123   inline void mergeIGNodesOfLRs(const V9LiveRange *const LR1,
00124                                 V9LiveRange *const LR2)
00125     { IG.mergeIGNodesOfLRs(LR1, LR2); }
00126 
00127 
00128   inline void clearColorsUsed() {
00129     IsColorUsedArr.clear();
00130     IsColorUsedArr.resize(MRC->getNumOfAllRegs());
00131   }
00132   inline void markColorsUsed(unsigned ClassRegNum,
00133                              int UserRegType,
00134                              int RegTypeWanted) {
00135     MRC->markColorsUsed(ClassRegNum, UserRegType, RegTypeWanted,IsColorUsedArr);
00136   }
00137   inline int getUnusedColor(int machineRegType) const {
00138     return MRC->findUnusedColor(machineRegType, IsColorUsedArr);
00139   }
00140 
00141   void printIGNodeList() const;
00142   void printIG();
00143 };
00144 
00145 } // End llvm namespace
00146 
00147 #endif