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 /* Capstone Disassembly Engine */ 17 /* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */ 18 19 #ifndef CS_LLVM_MC_MCREGISTERINFO_H 20 #define CS_LLVM_MC_MCREGISTERINFO_H 21 22 #include "capstone/platform.h" 23 24 /// An unsigned integer type large enough to represent all physical registers, 25 /// but not necessarily virtual registers. 26 typedef uint16_t MCPhysReg; 27 typedef const MCPhysReg* iterator; 28 29 typedef struct MCRegisterClass { 30 iterator RegsBegin; 31 const uint8_t *RegSet; 32 uint32_t NameIdx; 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 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. 47 /// 48 typedef struct MCRegisterDesc { 49 uint32_t Name; // Printable name for the reg (for debugging) 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; 60 61 /// Index into list with lane mask sequences. The sequence contains a lanemask 62 /// for every register unit. 63 uint16_t RegUnitLaneMasks; 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 { 79 const MCRegisterDesc *Desc; // Pointer to the descriptor array 80 unsigned NumRegs; // Number of entries in the array 81 unsigned RAReg; // Return address register 82 unsigned PCReg; // Program counter register 83 const MCRegisterClass *Classes; // Pointer to the regclass array 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. 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 90 // array. 91 unsigned NumSubRegIndices; // Number of subreg indices. 92 const uint16_t *RegEncodingTable; // Pointer to array of register 93 // encodings. 94 } MCRegisterInfo; 95 96 void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, 97 const MCRegisterDesc *D, unsigned NR, unsigned RA, 98 unsigned PC, 99 const MCRegisterClass *C, unsigned NC, 100 uint16_t (*RURoots)[2], 101 unsigned NRU, 102 const MCPhysReg *DL, 103 const char *Strings, 104 const uint16_t *SubIndices, 105 unsigned NumIndices, 106 const uint16_t *RET); 107 108 unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC); 109 110 unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx); 111 112 const MCRegisterClass* MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i); 113 114 bool MCRegisterClass_contains(const MCRegisterClass *c, unsigned Reg); 115 116 #endif 117