Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 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 | |
Nguyen Anh Quynh | 30e4d7f | 2014-05-08 22:54:58 +0800 | [diff] [blame] | 16 | /* Capstone Disassembly Engine */ |
Nguyen Anh Quynh | cfe18ad | 2015-03-02 15:12:42 +0800 | [diff] [blame] | 17 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */ |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 18 | |
| 19 | #ifndef CS_LLVM_MC_MCREGISTERINFO_H |
| 20 | #define CS_LLVM_MC_MCREGISTERINFO_H |
| 21 | |
pancake | 9c10ace | 2015-02-24 04:55:55 +0100 | [diff] [blame] | 22 | #include "capstone/platform.h" |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 23 | |
| 24 | /// An unsigned integer type large enough to represent all physical registers, |
| 25 | /// but not necessarily virtual registers. |
| 26 | typedef uint16_t MCPhysReg; |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 27 | typedef const MCPhysReg* iterator; |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 28 | |
| 29 | typedef struct MCRegisterClass { |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 30 | iterator RegsBegin; |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 31 | const uint8_t *RegSet; |
Nguyen Anh Quynh | cfe18ad | 2015-03-02 15:12:42 +0800 | [diff] [blame] | 32 | uint32_t NameIdx; |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 33 | uint16_t RegsSize; |
| 34 | uint16_t RegSetSize; |
| 35 | uint16_t ID; |
| 36 | uint16_t RegSize, Alignment; // Size & Alignment of register in bytes |
| 37 | int8_t CopyCost; |
| 38 | bool Allocatable; |
| 39 | } MCRegisterClass; |
| 40 | |
Nguyen Anh Quynh | 462f291 | 2013-12-11 17:35:27 +0800 | [diff] [blame] | 41 | /// MCRegisterDesc - This record contains information about a particular |
| 42 | /// register. The SubRegs field is a zero terminated array of registers that |
| 43 | /// are sub-registers of the specific register, e.g. AL, AH are sub-registers |
| 44 | /// of AX. The SuperRegs field is a zero terminated array of registers that are |
| 45 | /// super-registers of the specific register, e.g. RAX, EAX, are |
| 46 | /// super-registers of AX. |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 47 | /// |
| 48 | typedef struct MCRegisterDesc { |
| 49 | uint32_t Name; // Printable name for the reg (for debugging) |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 50 | uint32_t SubRegs; // Sub-register set, described above |
| 51 | uint32_t SuperRegs; // Super-register set, described above |
| 52 | |
| 53 | // Offset into MCRI::SubRegIndices of a list of sub-register indices for each |
| 54 | // sub-register in SubRegs. |
| 55 | uint32_t SubRegIndices; |
| 56 | |
| 57 | // RegUnits - Points to the list of register units. The low 4 bits holds the |
| 58 | // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator. |
| 59 | uint32_t RegUnits; |
Nguyen Anh Quynh | c87ccd1 | 2015-03-02 17:31:44 +0800 | [diff] [blame] | 60 | |
| 61 | /// Index into list with lane mask sequences. The sequence contains a lanemask |
| 62 | /// for every register unit. |
| 63 | uint16_t RegUnitLaneMasks; |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 64 | } MCRegisterDesc; |
| 65 | |
| 66 | /// MCRegisterInfo base class - We assume that the target defines a static |
| 67 | /// array of MCRegisterDesc objects that represent all of the machine |
| 68 | /// registers that the target has. As such, we simply have to track a pointer |
| 69 | /// to this array so that we can turn register number into a register |
| 70 | /// descriptor. |
| 71 | /// |
| 72 | /// Note this class is designed to be a base class of TargetRegisterInfo, which |
| 73 | /// is the interface used by codegen. However, specific targets *should never* |
| 74 | /// specialize this class. MCRegisterInfo should only contain getters to access |
| 75 | /// TableGen generated physical register data. It must not be extended with |
| 76 | /// virtual methods. |
| 77 | /// |
| 78 | typedef struct MCRegisterInfo { |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 79 | const MCRegisterDesc *Desc; // Pointer to the descriptor array |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 80 | unsigned NumRegs; // Number of entries in the array |
| 81 | unsigned RAReg; // Return address register |
| 82 | unsigned PCReg; // Program counter register |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 83 | const MCRegisterClass *Classes; // Pointer to the regclass array |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 84 | unsigned NumClasses; // Number of entries in the array |
| 85 | unsigned NumRegUnits; // Number of regunits. |
| 86 | uint16_t (*RegUnitRoots)[2]; // Pointer to regunit root table. |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 87 | const MCPhysReg *DiffLists; // Pointer to the difflists array |
| 88 | const char *RegStrings; // Pointer to the string table. |
| 89 | const uint16_t *SubRegIndices; // Pointer to the subreg lookup |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 90 | // array. |
| 91 | unsigned NumSubRegIndices; // Number of subreg indices. |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 92 | const uint16_t *RegEncodingTable; // Pointer to array of register |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 93 | // encodings. |
| 94 | } MCRegisterInfo; |
| 95 | |
| 96 | void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 97 | const MCRegisterDesc *D, unsigned NR, unsigned RA, |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 98 | unsigned PC, |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 99 | const MCRegisterClass *C, unsigned NC, |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 100 | uint16_t (*RURoots)[2], |
| 101 | unsigned NRU, |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 102 | const MCPhysReg *DL, |
| 103 | const char *Strings, |
| 104 | const uint16_t *SubIndices, |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 105 | unsigned NumIndices, |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 106 | const uint16_t *RET); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 107 | |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 108 | unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 109 | |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 110 | unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 111 | |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 112 | const MCRegisterClass* MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 113 | |
Richard Henderson | 22ead3e | 2017-10-21 17:45:40 -0700 | [diff] [blame] | 114 | bool MCRegisterClass_contains(const MCRegisterClass *c, unsigned Reg); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 115 | |
| 116 | #endif |