Fold assert-only-used variable into the assert.
[llvm/stm8.git] / utils / TableGen / CodeGenRegisters.h
blob8727340bd1e84bf8257f5af144b33fe1f4827541
1 //===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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"
20 #include <string>
21 #include <vector>
22 #include <set>
23 #include <cstdlib>
25 namespace llvm {
26 class Record;
28 /// CodeGenRegister - Represents a register definition.
29 struct CodeGenRegister {
30 Record *TheDef;
31 const std::string &getName() const;
32 unsigned EnumValue;
33 unsigned CostPerUse;
34 CodeGenRegister(Record *R);
38 struct CodeGenRegisterClass {
39 Record *TheDef;
40 std::string Namespace;
41 std::vector<Record*> Elements;
42 std::vector<MVT::SimpleValueType> VTs;
43 unsigned SpillSize;
44 unsigned SpillAlignment;
45 int CopyCost;
46 bool Allocatable;
47 // Map SubRegIndex -> RegisterClass
48 DenseMap<Record*,Record*> SubRegClasses;
49 std::string MethodProtos, MethodBodies;
51 const std::string &getName() const;
52 const std::vector<MVT::SimpleValueType> &getValueTypes() const {return VTs;}
53 unsigned getNumValueTypes() const { return VTs.size(); }
55 MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const {
56 if (VTNum < VTs.size())
57 return VTs[VTNum];
58 assert(0 && "VTNum greater than number of ValueTypes in RegClass!");
59 abort();
62 bool containsRegister(Record *R) const {
63 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
64 if (Elements[i] == R) return true;
65 return false;
68 // Returns true if RC is a strict subclass.
69 // RC is a sub-class of this class if it is a valid replacement for any
70 // instruction operand where a register of this classis required. It must
71 // satisfy these conditions:
73 // 1. All RC registers are also in this.
74 // 2. The RC spill size must not be smaller than our spill size.
75 // 3. RC spill alignment must be compatible with ours.
77 bool hasSubClass(const CodeGenRegisterClass *RC) const {
79 if (RC->Elements.size() > Elements.size() ||
80 (SpillAlignment && RC->SpillAlignment % SpillAlignment) ||
81 SpillSize > RC->SpillSize)
82 return false;
84 std::set<Record*> RegSet;
85 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
86 Record *Reg = Elements[i];
87 RegSet.insert(Reg);
90 for (unsigned i = 0, e = RC->Elements.size(); i != e; ++i) {
91 Record *Reg = RC->Elements[i];
92 if (!RegSet.count(Reg))
93 return false;
96 return true;
99 CodeGenRegisterClass(Record *R);
103 #endif