MCRegisterInfo.h revision a347f85dbeee37a7f2bb68df1a7d4cdfbb7b576d
1//=== MC/MCRegisterInfo.h - Target Register Description ---------*- 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 describes an abstract interface used to get information about a
11// target machines register file.  This information is used for a variety of
12// purposed, especially register allocation.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_MC_MCREGISTERINFO_H
17#define LLVM_MC_MCREGISTERINFO_H
18
19#include <cassert>
20
21namespace llvm {
22
23/// TargetRegisterDesc - This record contains all of the information known about
24/// a particular register.  The Overlaps field contains a pointer to a zero
25/// terminated array of registers that this register aliases, starting with
26/// itself. This is needed for architectures like X86 which have AL alias AX
27/// alias EAX. The SubRegs field is a zero terminated array of registers that
28/// are sub-registers of the specific register, e.g. AL, AH are sub-registers of
29/// AX. The SuperRegs field is a zero terminated array of registers that are
30/// super-registers of the specific register, e.g. RAX, EAX, are super-registers
31/// of AX.
32///
33struct TargetRegisterDesc {
34  const char     *Name;         // Printable name for the reg (for debugging)
35  const unsigned *Overlaps;     // Overlapping registers, described above
36  const unsigned *SubRegs;      // Sub-register set, described above
37  const unsigned *SuperRegs;    // Super-register set, described above
38};
39
40/// MCRegisterInfo base class - We assume that the target defines a static
41/// array of TargetRegisterDesc objects that represent all of the machine
42/// registers that the target has.  As such, we simply have to track a pointer
43/// to this array so that we can turn register number into a register
44/// descriptor.
45///
46class MCRegisterInfo {
47private:
48  const TargetRegisterDesc *Desc;             // Pointer to the descriptor array
49  unsigned NumRegs;                           // Number of entries in the array
50
51public:
52  /// InitMCRegisterInfo - Initialize MCRegisterInfo, called by TableGen
53  /// auto-generated routines. *DO NOT USE*.
54  void InitMCRegisterInfo(const TargetRegisterDesc *D, unsigned NR) {
55    Desc = D;
56    NumRegs = NR;
57  }
58
59  const TargetRegisterDesc &operator[](unsigned RegNo) const {
60    assert(RegNo < NumRegs &&
61           "Attempting to access record for invalid register number!");
62    return Desc[RegNo];
63  }
64
65  /// Provide a get method, equivalent to [], but more useful if we have a
66  /// pointer to this object.
67  ///
68  const TargetRegisterDesc &get(unsigned RegNo) const {
69    return operator[](RegNo);
70  }
71
72  /// getAliasSet - Return the set of registers aliased by the specified
73  /// register, or a null list of there are none.  The list returned is zero
74  /// terminated.
75  ///
76  const unsigned *getAliasSet(unsigned RegNo) const {
77    // The Overlaps set always begins with Reg itself.
78    return get(RegNo).Overlaps + 1;
79  }
80
81  /// getOverlaps - Return a list of registers that overlap Reg, including
82  /// itself. This is the same as the alias set except Reg is included in the
83  /// list.
84  /// These are exactly the registers in { x | regsOverlap(x, Reg) }.
85  ///
86  const unsigned *getOverlaps(unsigned RegNo) const {
87    return get(RegNo).Overlaps;
88  }
89
90  /// getSubRegisters - Return the list of registers that are sub-registers of
91  /// the specified register, or a null list of there are none. The list
92  /// returned is zero terminated and sorted according to super-sub register
93  /// relations. e.g. X86::RAX's sub-register list is EAX, AX, AL, AH.
94  ///
95  const unsigned *getSubRegisters(unsigned RegNo) const {
96    return get(RegNo).SubRegs;
97  }
98
99  /// getSuperRegisters - Return the list of registers that are super-registers
100  /// of the specified register, or a null list of there are none. The list
101  /// returned is zero terminated and sorted according to super-sub register
102  /// relations. e.g. X86::AL's super-register list is AX, EAX, RAX.
103  ///
104  const unsigned *getSuperRegisters(unsigned RegNo) const {
105    return get(RegNo).SuperRegs;
106  }
107
108  /// getName - Return the human-readable symbolic target-specific name for the
109  /// specified physical register.
110  const char *getName(unsigned RegNo) const {
111    return get(RegNo).Name;
112  }
113
114  /// getNumRegs - Return the number of registers this target has (useful for
115  /// sizing arrays holding per register information)
116  unsigned getNumRegs() const {
117    return NumRegs;
118  }
119};
120
121} // End llvm namespace
122
123#endif
124