2001-09-14 06:08:03 +00:00
|
|
|
/* Title: RegClass.h -*- C++ -*-
|
2001-09-08 14:22:50 +00:00
|
|
|
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/CodeGen/IGNode.h"
|
|
|
|
#include "llvm/CodeGen/InterferenceGraph.h"
|
2001-09-18 12:41:43 +00:00
|
|
|
#include "llvm/Target/MachineRegInfo.h"
|
2001-09-08 14:22:50 +00:00
|
|
|
#include <stack>
|
2002-01-20 22:54:45 +00:00
|
|
|
#include <iostream>
|
2002-02-04 05:52:08 +00:00
|
|
|
class MachineRegClassInfo;
|
2001-09-08 14:22:50 +00:00
|
|
|
|
2002-02-04 05:52:08 +00:00
|
|
|
typedef std::vector<unsigned> ReservedColorListType;
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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 (MachineRegInfo 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.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-04 05:52:08 +00:00
|
|
|
class RegClass {
|
2002-04-08 22:03:57 +00:00
|
|
|
const Function *const Meth; // Function we are working on
|
2001-09-08 14:22:50 +00:00
|
|
|
const MachineRegClassInfo *const MRC; // corresponding MRC
|
|
|
|
const unsigned RegClassID; // my int ID
|
|
|
|
|
|
|
|
InterferenceGraph IG; // Interference graph - constructed by
|
|
|
|
// buildInterferenceGraph
|
2002-01-20 22:54:45 +00:00
|
|
|
std::stack<IGNode *> IGNodeStack; // the stack used for coloring
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
const ReservedColorListType *const ReservedColorList;
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
|
|
|
// for passing registers that are pre-allocated and cannot be used by the
|
2002-04-08 22:03:57 +00:00
|
|
|
// register allocator for this function.
|
2002-01-07 19:16:26 +00:00
|
|
|
|
|
|
|
bool *IsColorUsedArr;
|
|
|
|
//
|
2001-09-08 14:22:50 +00:00
|
|
|
// An array used for coloring each node. This array must be of size
|
|
|
|
// MRC->getNumOfAllRegs(). Allocated once in the constructor
|
|
|
|
// for efficiency.
|
|
|
|
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
//--------------------------- private methods ------------------------------
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
void pushAllIGNodes();
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
bool pushUnconstrainedIGNodes();
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
IGNode * getIGNodeWithMinSpillCost();
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
void colorIGNode(IGNode *const Node);
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
public:
|
|
|
|
|
2002-04-08 22:03:57 +00:00
|
|
|
RegClass(const Function *M,
|
|
|
|
const MachineRegClassInfo *MRC,
|
|
|
|
const ReservedColorListType *RCL = 0);
|
2001-09-08 14:22:50 +00:00
|
|
|
|
2002-04-08 22:03:57 +00:00
|
|
|
~RegClass() { delete[] IsColorUsedArr; }
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2002-04-08 22:03:57 +00:00
|
|
|
inline void createInterferenceGraph() { IG.createGraph(); }
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
inline InterferenceGraph &getIG() { return IG; }
|
|
|
|
|
|
|
|
inline const unsigned getID() const { return RegClassID; }
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
// main method called for coloring regs
|
|
|
|
//
|
|
|
|
void colorAllRegs();
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
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); }
|
|
|
|
|
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
|
|
|
|
|
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
inline void printIGNodeList() const {
|
2002-01-20 22:54:45 +00:00
|
|
|
std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n";
|
2001-09-08 14:22:50 +00:00
|
|
|
IG.printIGNodeList();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void printIG() {
|
2002-01-20 22:54:45 +00:00
|
|
|
std::cerr << "IG for Register Class " << RegClassID << ":" << "\n";
|
2001-09-08 14:22:50 +00:00
|
|
|
IG.printIG();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|