2004-08-16 03:09:52 +02:00
|
|
|
//===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===//
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2004-08-16 03:09:52 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:37:13 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2004-08-16 03:09:52 +02: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
|
|
|
|
|
2008-02-20 12:08:44 +01:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2010-05-24 23:46:58 +02:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2004-08-16 03:09:52 +02:00
|
|
|
#include <string>
|
2004-08-21 06:05:00 +02:00
|
|
|
#include <vector>
|
2010-08-25 02:41:18 +02:00
|
|
|
#include <set>
|
2008-02-20 12:08:44 +01:00
|
|
|
#include <cstdlib>
|
2004-08-16 03:09:52 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Record;
|
|
|
|
|
|
|
|
/// CodeGenRegister - Represents a register definition.
|
|
|
|
struct CodeGenRegister {
|
|
|
|
Record *TheDef;
|
|
|
|
const std::string &getName() const;
|
2004-08-21 04:24:57 +02:00
|
|
|
unsigned DeclaredSpillSize, DeclaredSpillAlignment;
|
|
|
|
CodeGenRegister(Record *R);
|
2004-08-16 03:09:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct CodeGenRegisterClass {
|
2004-08-21 06:05:00 +02:00
|
|
|
Record *TheDef;
|
2005-08-19 20:45:20 +02:00
|
|
|
std::string Namespace;
|
2004-08-21 06:05:00 +02:00
|
|
|
std::vector<Record*> Elements;
|
2009-08-11 22:47:22 +02:00
|
|
|
std::vector<MVT::SimpleValueType> VTs;
|
2004-08-21 06:05:00 +02:00
|
|
|
unsigned SpillSize;
|
|
|
|
unsigned SpillAlignment;
|
2007-09-19 03:35:01 +02:00
|
|
|
int CopyCost;
|
2010-05-24 23:46:58 +02:00
|
|
|
// Map SubRegIndex -> RegisterClass
|
|
|
|
DenseMap<Record*,Record*> SubRegClasses;
|
2005-08-19 21:12:51 +02:00
|
|
|
std::string MethodProtos, MethodBodies;
|
2004-08-21 06:05:00 +02:00
|
|
|
|
|
|
|
const std::string &getName() const;
|
2009-08-11 22:47:22 +02:00
|
|
|
const std::vector<MVT::SimpleValueType> &getValueTypes() const {return VTs;}
|
2005-12-05 03:35:08 +01:00
|
|
|
unsigned getNumValueTypes() const { return VTs.size(); }
|
|
|
|
|
2009-08-11 22:47:22 +02:00
|
|
|
MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const {
|
2005-12-01 05:51:06 +01:00
|
|
|
if (VTNum < VTs.size())
|
|
|
|
return VTs[VTNum];
|
|
|
|
assert(0 && "VTNum greater than number of ValueTypes in RegClass!");
|
|
|
|
abort();
|
|
|
|
}
|
2010-08-25 02:41:18 +02:00
|
|
|
|
2010-11-06 20:57:21 +01:00
|
|
|
bool containsRegister(Record *R) const {
|
|
|
|
for (unsigned i = 0, e = Elements.size(); i != e; ++i)
|
|
|
|
if (Elements[i] == R) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-25 02:41:18 +02:00
|
|
|
// Returns true if RC is a strict subclass.
|
|
|
|
// RC is a sub-class of this class if it is a valid replacement for any
|
|
|
|
// instruction operand where a register of this classis required. It must
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
bool hasSubClass(const CodeGenRegisterClass *RC) const {
|
|
|
|
|
|
|
|
if (RC->Elements.size() > Elements.size() ||
|
|
|
|
(SpillAlignment && RC->SpillAlignment % SpillAlignment) ||
|
|
|
|
SpillSize > RC->SpillSize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::set<Record*> RegSet;
|
|
|
|
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
|
|
|
Record *Reg = Elements[i];
|
|
|
|
RegSet.insert(Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = RC->Elements.size(); i != e; ++i) {
|
|
|
|
Record *Reg = RC->Elements[i];
|
|
|
|
if (!RegSet.count(Reg))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2005-12-01 05:51:06 +01:00
|
|
|
|
2004-08-21 06:05:00 +02:00
|
|
|
CodeGenRegisterClass(Record *R);
|
2004-08-16 03:09:52 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|