2003-10-21 15:29:18 +00:00
|
|
|
//===-- RegClass.h - Machine Independent register coloring ------*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:29:18 +00:00
|
|
|
// 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.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:29:18 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-09-21 02:31:37 +00:00
|
|
|
#ifndef REGCLASS_H
|
|
|
|
#define REGCLASS_H
|
2001-09-08 14:22:50 +00:00
|
|
|
|
2004-04-23 18:15:47 +00:00
|
|
|
#include "../SparcV9RegInfo.h"
|
2003-01-15 21:02:16 +00:00
|
|
|
#include "InterferenceGraph.h"
|
2001-09-08 14:22:50 +00:00
|
|
|
#include <stack>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2002-12-29 03:13:05 +00:00
|
|
|
class TargetRegClassInfo;
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Class RegClass
|
|
|
|
//
|
2005-04-21 23:30:14 +00:00
|
|
|
// Implements a machine independent register class.
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
|
|
|
// This is the class that contains all data structures and common algos
|
2005-04-21 23:30:14 +00:00
|
|
|
// 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 (TargetRegInfo class) to
|
2002-01-07 19:16:26 +00:00
|
|
|
// get hardware specific info and to color an individual IG node.
|
|
|
|
//
|
|
|
|
// This class contains the InterferenceGraph (IG).
|
2005-04-21 23:30:14 +00:00
|
|
|
// Also it contains an IGNode stack that can be used for coloring.
|
2002-01-07 19:16:26 +00:00
|
|
|
// 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
|
2005-04-21 23:30:14 +00:00
|
|
|
const SparcV9RegInfo *MRI; // Machine register information
|
2003-07-25 21:06:09 +00:00
|
|
|
const TargetRegClassInfo *const MRC; // Machine reg. class for this RegClass
|
2001-09-08 14:22:50 +00:00
|
|
|
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
|
|
|
|
2002-05-23 15:50:03 +00:00
|
|
|
// IsColorUsedArr - 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
|
|
|
//
|
2002-05-23 15:50:03 +00:00
|
|
|
std::vector<bool> IsColorUsedArr;
|
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2003-07-25 21:06:09 +00:00
|
|
|
// 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];
|
|
|
|
}
|
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,
|
2005-07-27 05:53:44 +00:00
|
|
|
const SparcV9RegInfo *_MRI_,
|
|
|
|
const TargetRegClassInfo *_MRC_);
|
2001-09-08 14:22:50 +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; }
|
|
|
|
|
2003-07-25 21:06:09 +00:00
|
|
|
inline const TargetRegClassInfo* getTargetRegClass() const { return MRC; }
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
// main method called for coloring regs
|
|
|
|
//
|
2005-04-21 23:30:14 +00:00
|
|
|
void colorAllRegs();
|
2001-09-08 14:22:50 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
inline unsigned getNumOfAvailRegs() const
|
2001-09-08 14:22:50 +00:00
|
|
|
{ return MRC->getNumOfAvailRegs(); }
|
|
|
|
|
|
|
|
|
|
|
|
// --- following methods are provided to access the IG contained within this
|
|
|
|
// ---- RegClass easilly.
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
inline void addLRToIG(V9LiveRange *const LR)
|
2001-09-08 14:22:50 +00:00
|
|
|
{ IG.addLRToIG(LR); }
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
inline void setInterference(const V9LiveRange *const LR1,
|
2005-07-27 05:53:44 +00:00
|
|
|
const V9LiveRange *const LR2)
|
2001-09-08 14:22:50 +00:00
|
|
|
{ IG.setInterference(LR1, LR2); }
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
inline unsigned getInterference(const V9LiveRange *const LR1,
|
2005-07-27 05:53:44 +00:00
|
|
|
const V9LiveRange *const LR2) const
|
2001-09-08 14:22:50 +00:00
|
|
|
{ return IG.getInterference(LR1, LR2); }
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
inline void mergeIGNodesOfLRs(const V9LiveRange *const LR1,
|
2005-07-27 05:53:44 +00:00
|
|
|
V9LiveRange *const LR2)
|
2001-09-08 14:22:50 +00:00
|
|
|
{ IG.mergeIGNodesOfLRs(LR1, LR2); }
|
|
|
|
|
|
|
|
|
2003-07-25 21:06:09 +00:00
|
|
|
inline void clearColorsUsed() {
|
|
|
|
IsColorUsedArr.clear();
|
|
|
|
IsColorUsedArr.resize(MRC->getNumOfAllRegs());
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2002-10-29 16:50:33 +00:00
|
|
|
void printIGNodeList() const;
|
|
|
|
void printIG();
|
2001-09-08 14:22:50 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-08 14:22:50 +00:00
|
|
|
#endif
|