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"
29 /// CodeGenRegister - Represents a register definition.
30 struct CodeGenRegister {
32 const std::string &getName() const;
35 CodeGenRegister(Record *R);
39 struct CodeGenRegisterClass {
41 std::string Namespace;
42 std::vector<Record*> Elements;
43 std::vector<MVT::SimpleValueType> VTs;
45 unsigned SpillAlignment;
48 // Map SubRegIndex -> RegisterClass
49 DenseMap<Record*,Record*> SubRegClasses;
50 std::string MethodProtos, MethodBodies;
52 const std::string &getName() const;
53 const std::vector<MVT::SimpleValueType> &getValueTypes() const {return VTs;}
54 unsigned getNumValueTypes() const { return VTs.size(); }
56 MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const {
57 if (VTNum < VTs.size())
59 assert(0 && "VTNum greater than number of ValueTypes in RegClass!");
63 bool containsRegister(Record *R) const {
64 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
65 if (Elements[i] == R) return true;
69 // Returns true if RC is a strict subclass.
70 // RC is a sub-class of this class if it is a valid replacement for any
71 // instruction operand where a register of this classis required. It must
72 // satisfy these conditions:
74 // 1. All RC registers are also in this.
75 // 2. The RC spill size must not be smaller than our spill size.
76 // 3. RC spill alignment must be compatible with ours.
78 bool hasSubClass(const CodeGenRegisterClass *RC) const {
80 if (RC->Elements.size() > Elements.size() ||
81 (SpillAlignment && RC->SpillAlignment % SpillAlignment) ||
82 SpillSize > RC->SpillSize)
85 std::set<Record*> RegSet;
86 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
87 Record *Reg = Elements[i];
91 for (unsigned i = 0, e = RC->Elements.size(); i != e; ++i) {
92 Record *Reg = RC->Elements[i];
93 if (!RegSet.count(Reg))
100 CodeGenRegisterClass(Record *R);
103 // CodeGenRegBank - Represent a target's registers and the relations between
105 class CodeGenRegBank {
106 RecordKeeper &Records;
108 // Sub-register indices. The first NumNamedIndices are defined by the user
109 // in the .td files. The rest are synthesized such that all sub-registers
110 // have a unique name.
111 std::vector<Record*> SubRegIndices;
113 unsigned NumNamedIndices;
116 CodeGenRegBank(RecordKeeper&);
118 const std::vector<Record*> &getSubRegIndices() { return SubRegIndices; }
120 unsigned getNumNamedIndices() { return NumNamedIndices; }
122 // Map a SubRegIndex Record to its enum value.
123 unsigned getSubRegIndexNo(Record *idx);
125 // Create a new sub-register index representing the A+B composition.
126 Record *getCompositeSubRegIndex(Record *A, Record *B);