1 //===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines structures to encapsulate information gleaned from the
11 // target register and register class definitions.
13 //===----------------------------------------------------------------------===//
15 #ifndef CODEGEN_REGISTERS_H
16 #define CODEGEN_REGISTERS_H
18 #include "llvm/CodeGen/ValueTypes.h"
19 #include "llvm/ADT/DenseMap.h"
28 /// CodeGenRegister - Represents a register definition.
29 struct CodeGenRegister {
31 const std::string &getName() const;
32 unsigned DeclaredSpillSize, DeclaredSpillAlignment;
33 CodeGenRegister(Record *R);
37 struct CodeGenRegisterClass {
39 std::string Namespace;
40 std::vector<Record*> Elements;
41 std::vector<MVT::SimpleValueType> VTs;
43 unsigned SpillAlignment;
45 // Map SubRegIndex -> RegisterClass
46 DenseMap<Record*,Record*> SubRegClasses;
47 std::string MethodProtos, MethodBodies;
49 const std::string &getName() const;
50 const std::vector<MVT::SimpleValueType> &getValueTypes() const {return VTs;}
51 unsigned getNumValueTypes() const { return VTs.size(); }
53 MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const {
54 if (VTNum < VTs.size())
56 assert(0 && "VTNum greater than number of ValueTypes in RegClass!");
60 bool containsRegister(Record *R) const {
61 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
62 if (Elements[i] == R) return true;
66 // Returns true if RC is a strict subclass.
67 // RC is a sub-class of this class if it is a valid replacement for any
68 // instruction operand where a register of this classis required. It must
69 // satisfy these conditions:
71 // 1. All RC registers are also in this.
72 // 2. The RC spill size must not be smaller than our spill size.
73 // 3. RC spill alignment must be compatible with ours.
75 bool hasSubClass(const CodeGenRegisterClass *RC) const {
77 if (RC->Elements.size() > Elements.size() ||
78 (SpillAlignment && RC->SpillAlignment % SpillAlignment) ||
79 SpillSize > RC->SpillSize)
82 std::set<Record*> RegSet;
83 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
84 Record *Reg = Elements[i];
88 for (unsigned i = 0, e = RC->Elements.size(); i != e; ++i) {
89 Record *Reg = RC->Elements[i];
90 if (!RegSet.count(Reg))
97 CodeGenRegisterClass(Record *R);