2004-08-16 01:09:52 +00:00
|
|
|
//===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2004-08-16 01:09:52 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2004-08-16 01:09:52 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines structures to encapsulate information gleaned from the
|
|
|
|
// target register and register class definitions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CODEGEN_REGISTERS_H
|
|
|
|
#define CODEGEN_REGISTERS_H
|
|
|
|
|
2011-06-11 00:28:06 +00:00
|
|
|
#include "Record.h"
|
2011-06-15 05:09:20 +00:00
|
|
|
#include "SetTheory.h"
|
2008-02-20 11:08:44 +00:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2011-06-15 04:50:36 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2010-05-24 21:46:58 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2011-06-12 03:05:52 +00:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2011-06-11 00:28:06 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <map>
|
2004-08-16 01:09:52 +00:00
|
|
|
#include <string>
|
2010-08-25 00:41:18 +00:00
|
|
|
#include <set>
|
2011-06-11 00:28:06 +00:00
|
|
|
#include <vector>
|
2004-08-16 01:09:52 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2011-06-11 00:28:06 +00:00
|
|
|
class CodeGenRegBank;
|
2004-08-16 01:09:52 +00:00
|
|
|
|
|
|
|
/// CodeGenRegister - Represents a register definition.
|
|
|
|
struct CodeGenRegister {
|
|
|
|
Record *TheDef;
|
2011-03-11 01:33:54 +00:00
|
|
|
unsigned EnumValue;
|
2011-04-20 18:19:48 +00:00
|
|
|
unsigned CostPerUse;
|
2011-06-11 00:28:06 +00:00
|
|
|
|
|
|
|
// Map SubRegIndex -> Register.
|
|
|
|
typedef std::map<Record*, CodeGenRegister*, LessRecord> SubRegMap;
|
|
|
|
|
|
|
|
CodeGenRegister(Record *R, unsigned Enum);
|
|
|
|
|
|
|
|
const std::string &getName() const;
|
|
|
|
|
|
|
|
// Get a map of sub-registers computed lazily.
|
|
|
|
// This includes unique entries for all sub-sub-registers.
|
|
|
|
const SubRegMap &getSubRegs(CodeGenRegBank&);
|
|
|
|
|
|
|
|
const SubRegMap &getSubRegs() const {
|
|
|
|
assert(SubRegsComplete && "Must precompute sub-registers");
|
|
|
|
return SubRegs;
|
|
|
|
}
|
|
|
|
|
2011-06-12 03:05:52 +00:00
|
|
|
// Add sub-registers to OSet following a pre-order defined by the .td file.
|
|
|
|
void addSubRegsPreOrder(SetVector<CodeGenRegister*> &OSet) const;
|
|
|
|
|
|
|
|
// List of super-registers in topological order, small to large.
|
|
|
|
typedef std::vector<CodeGenRegister*> SuperRegList;
|
|
|
|
|
|
|
|
// Get the list of super-registers.
|
|
|
|
// This is only valid after computeDerivedInfo has visited all registers.
|
|
|
|
const SuperRegList &getSuperRegs() const {
|
|
|
|
assert(SubRegsComplete && "Must precompute sub-registers");
|
|
|
|
return SuperRegs;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Order CodeGenRegister pointers by EnumValue.
|
|
|
|
struct Less {
|
2011-06-15 04:50:36 +00:00
|
|
|
bool operator()(const CodeGenRegister *A,
|
|
|
|
const CodeGenRegister *B) const {
|
2011-06-12 03:05:52 +00:00
|
|
|
return A->EnumValue < B->EnumValue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Canonically ordered set.
|
2011-06-15 04:50:36 +00:00
|
|
|
typedef std::set<const CodeGenRegister*, Less> Set;
|
2011-06-12 03:05:52 +00:00
|
|
|
|
2011-06-11 00:28:06 +00:00
|
|
|
private:
|
|
|
|
bool SubRegsComplete;
|
|
|
|
SubRegMap SubRegs;
|
2011-06-12 03:05:52 +00:00
|
|
|
SuperRegList SuperRegs;
|
2004-08-16 01:09:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-15 04:50:36 +00:00
|
|
|
class CodeGenRegisterClass {
|
|
|
|
CodeGenRegister::Set Members;
|
2011-06-15 05:09:20 +00:00
|
|
|
const std::vector<Record*> *Elements;
|
2011-06-15 04:50:36 +00:00
|
|
|
public:
|
2004-08-21 04:05:00 +00:00
|
|
|
Record *TheDef;
|
2005-08-19 18:45:20 +00:00
|
|
|
std::string Namespace;
|
2009-08-11 20:47:22 +00:00
|
|
|
std::vector<MVT::SimpleValueType> VTs;
|
2004-08-21 04:05:00 +00:00
|
|
|
unsigned SpillSize;
|
|
|
|
unsigned SpillAlignment;
|
2007-09-19 01:35:01 +00:00
|
|
|
int CopyCost;
|
2011-06-02 23:07:20 +00:00
|
|
|
bool Allocatable;
|
2010-05-24 21:46:58 +00:00
|
|
|
// Map SubRegIndex -> RegisterClass
|
|
|
|
DenseMap<Record*,Record*> SubRegClasses;
|
2005-08-19 19:12:51 +00:00
|
|
|
std::string MethodProtos, MethodBodies;
|
2004-08-21 04:05:00 +00:00
|
|
|
|
|
|
|
const std::string &getName() const;
|
2009-08-11 20:47:22 +00:00
|
|
|
const std::vector<MVT::SimpleValueType> &getValueTypes() const {return VTs;}
|
2005-12-05 02:35:08 +00:00
|
|
|
unsigned getNumValueTypes() const { return VTs.size(); }
|
2011-03-11 01:19:05 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const {
|
2005-12-01 04:51:06 +00:00
|
|
|
if (VTNum < VTs.size())
|
|
|
|
return VTs[VTNum];
|
|
|
|
assert(0 && "VTNum greater than number of ValueTypes in RegClass!");
|
|
|
|
abort();
|
|
|
|
}
|
2011-03-11 01:19:05 +00:00
|
|
|
|
2011-06-15 04:50:36 +00:00
|
|
|
// Return true if this this class contains the register.
|
|
|
|
bool contains(const CodeGenRegister*) const;
|
2011-03-11 01:19:05 +00:00
|
|
|
|
2011-06-15 04:50:36 +00:00
|
|
|
// Returns true if RC is a subclass.
|
2010-08-25 00:41:18 +00:00
|
|
|
// RC is a sub-class of this class if it is a valid replacement for any
|
2011-03-11 01:19:05 +00:00
|
|
|
// instruction operand where a register of this classis required. It must
|
2010-08-25 00:41:18 +00:00
|
|
|
// satisfy these conditions:
|
|
|
|
//
|
|
|
|
// 1. All RC registers are also in this.
|
|
|
|
// 2. The RC spill size must not be smaller than our spill size.
|
|
|
|
// 3. RC spill alignment must be compatible with ours.
|
|
|
|
//
|
2011-06-15 04:50:36 +00:00
|
|
|
bool hasSubClass(const CodeGenRegisterClass *RC) const;
|
2010-08-25 00:41:18 +00:00
|
|
|
|
2011-06-15 04:50:36 +00:00
|
|
|
// Returns an ordered list of class members.
|
|
|
|
// The order of registers is the same as in the .td file.
|
|
|
|
ArrayRef<Record*> getOrder() const {
|
2011-06-15 05:09:20 +00:00
|
|
|
return *Elements;
|
2010-08-25 00:41:18 +00:00
|
|
|
}
|
2005-12-01 04:51:06 +00:00
|
|
|
|
2011-06-15 04:50:36 +00:00
|
|
|
CodeGenRegisterClass(CodeGenRegBank&, Record *R);
|
2004-08-16 01:09:52 +00:00
|
|
|
};
|
2011-06-10 18:40:00 +00:00
|
|
|
|
|
|
|
// CodeGenRegBank - Represent a target's registers and the relations between
|
|
|
|
// them.
|
|
|
|
class CodeGenRegBank {
|
|
|
|
RecordKeeper &Records;
|
2011-06-15 05:09:20 +00:00
|
|
|
SetTheory Sets;
|
|
|
|
|
2011-06-10 18:40:00 +00:00
|
|
|
std::vector<Record*> SubRegIndices;
|
|
|
|
unsigned NumNamedIndices;
|
2011-06-11 00:28:06 +00:00
|
|
|
std::vector<CodeGenRegister> Registers;
|
|
|
|
DenseMap<Record*, CodeGenRegister*> Def2Reg;
|
|
|
|
|
2011-06-15 00:20:40 +00:00
|
|
|
std::vector<CodeGenRegisterClass> RegClasses;
|
|
|
|
DenseMap<Record*, CodeGenRegisterClass*> Def2RC;
|
|
|
|
|
2011-06-11 00:28:06 +00:00
|
|
|
// Composite SubRegIndex instances.
|
|
|
|
// Map (SubRegIndex, SubRegIndex) -> SubRegIndex.
|
|
|
|
typedef DenseMap<std::pair<Record*, Record*>, Record*> CompositeMap;
|
|
|
|
CompositeMap Composite;
|
|
|
|
|
|
|
|
// Populate the Composite map from sub-register relationships.
|
|
|
|
void computeComposites();
|
2011-06-10 18:40:00 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CodeGenRegBank(RecordKeeper&);
|
|
|
|
|
2011-06-15 05:09:20 +00:00
|
|
|
SetTheory &getSets() { return Sets; }
|
|
|
|
|
2011-06-11 00:28:06 +00:00
|
|
|
// Sub-register indices. The first NumNamedIndices are defined by the user
|
|
|
|
// in the .td files. The rest are synthesized such that all sub-registers
|
|
|
|
// have a unique name.
|
2011-06-10 18:40:00 +00:00
|
|
|
const std::vector<Record*> &getSubRegIndices() { return SubRegIndices; }
|
|
|
|
unsigned getNumNamedIndices() { return NumNamedIndices; }
|
|
|
|
|
|
|
|
// Map a SubRegIndex Record to its enum value.
|
|
|
|
unsigned getSubRegIndexNo(Record *idx);
|
|
|
|
|
2011-06-11 00:28:06 +00:00
|
|
|
// Find or create a sub-register index representing the A+B composition.
|
|
|
|
Record *getCompositeSubRegIndex(Record *A, Record *B, bool create = false);
|
|
|
|
|
|
|
|
const std::vector<CodeGenRegister> &getRegisters() { return Registers; }
|
|
|
|
|
|
|
|
// Find a register from its Record def.
|
|
|
|
CodeGenRegister *getReg(Record*);
|
|
|
|
|
2011-06-15 00:20:40 +00:00
|
|
|
const std::vector<CodeGenRegisterClass> &getRegClasses() {
|
|
|
|
return RegClasses;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find a register class from its def.
|
|
|
|
CodeGenRegisterClass *getRegClass(Record*);
|
|
|
|
|
|
|
|
/// getRegisterClassForRegister - Find the register class that contains the
|
|
|
|
/// specified physical register. If the register is not in a register
|
|
|
|
/// class, return null. If the register is in multiple classes, and the
|
|
|
|
/// classes have a superset-subset relationship and the same set of types,
|
|
|
|
/// return the superclass. Otherwise return null.
|
|
|
|
const CodeGenRegisterClass* getRegClassForRegister(Record *R);
|
|
|
|
|
2011-06-11 00:28:06 +00:00
|
|
|
// Computed derived records such as missing sub-register indices.
|
|
|
|
void computeDerivedInfo();
|
2011-06-12 03:05:52 +00:00
|
|
|
|
|
|
|
// Compute full overlap sets for every register. These sets include the
|
|
|
|
// rarely used aliases that are neither sub nor super-registers.
|
|
|
|
//
|
|
|
|
// Map[R1].count(R2) is reflexive and symmetric, but not transitive.
|
|
|
|
//
|
|
|
|
// If R1 is a sub-register of R2, Map[R1] is a subset of Map[R2].
|
|
|
|
void computeOverlaps(std::map<const CodeGenRegister*,
|
|
|
|
CodeGenRegister::Set> &Map);
|
2011-06-10 18:40:00 +00:00
|
|
|
};
|
2004-08-16 01:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|