1 //=== MC/MCRegisterInfo.h - Target Register Description ---------*- 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 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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_MC_MCREGISTERINFO_H
17 #define LLVM_MC_MCREGISTERINFO_H
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
33 struct 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
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
46 class MCRegisterInfo {
48 const TargetRegisterDesc *Desc; // Pointer to the descriptor array
49 unsigned NumRegs; // Number of entries in the array
52 /// InitMCRegisterInfo - Initialize MCRegisterInfo, called by TableGen
53 /// auto-generated routines. *DO NOT USE*.
54 void InitMCRegisterInfo(const TargetRegisterDesc *D, unsigned NR) {
59 const TargetRegisterDesc &operator[](unsigned RegNo) const {
60 assert(RegNo < NumRegs &&
61 "Attempting to access record for invalid register number!");
65 /// Provide a get method, equivalent to [], but more useful if we have a
66 /// pointer to this object.
68 const TargetRegisterDesc &get(unsigned RegNo) const {
69 return operator[](RegNo);
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
76 const unsigned *getAliasSet(unsigned RegNo) const {
77 // The Overlaps set always begins with Reg itself.
78 return get(RegNo).Overlaps + 1;
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
84 /// These are exactly the registers in { x | regsOverlap(x, Reg) }.
86 const unsigned *getOverlaps(unsigned RegNo) const {
87 return get(RegNo).Overlaps;
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.
95 const unsigned *getSubRegisters(unsigned RegNo) const {
96 return get(RegNo).SubRegs;
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.
104 const unsigned *getSuperRegisters(unsigned RegNo) const {
105 return get(RegNo).SuperRegs;
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;
114 /// getNumRegs - Return the number of registers this target has (useful for
115 /// sizing arrays holding per register information)
116 unsigned getNumRegs() const {
121 } // End llvm namespace