//=== MC/MCRegisterInfo.h - Target Register Description ---------*- C++ -*-===//1//2// The LLVM Compiler Infrastructure3//4// This file is distributed under the University of Illinois Open Source5// License. See LICENSE.TXT for details.6//7//===----------------------------------------------------------------------===//8//9// This file describes an abstract interface used to get information about a10// target machines register file. This information is used for a variety of11// purposed, especially register allocation.12//13//===----------------------------------------------------------------------===//1415/* Capstone Disassembly Engine */16/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */1718#ifndef CS_LLVM_MC_MCREGISTERINFO_H19#define CS_LLVM_MC_MCREGISTERINFO_H2021#include "capstone/platform.h"2223/// An unsigned integer type large enough to represent all physical registers,24/// but not necessarily virtual registers.25typedef uint16_t MCPhysReg;26typedef const MCPhysReg* iterator;2728typedef struct MCRegisterClass2 {29iterator RegsBegin;30const uint8_t *RegSet;31uint8_t RegsSize;32uint8_t RegSetSize;33} MCRegisterClass2;3435typedef struct MCRegisterClass {36iterator RegsBegin;37const uint8_t *RegSet;38uint16_t RegSetSize;39} MCRegisterClass;4041/// MCRegisterDesc - This record contains information about a particular42/// register. The SubRegs field is a zero terminated array of registers that43/// are sub-registers of the specific register, e.g. AL, AH are sub-registers44/// of AX. The SuperRegs field is a zero terminated array of registers that are45/// super-registers of AX.46typedef struct MCRegisterDesc {47uint32_t Name; // Printable name for the reg (for debugging)48uint32_t SubRegs; // Sub-register set, described above49uint32_t SuperRegs; // Super-register set, described above5051// Offset into MCRI::SubRegIndices of a list of sub-register indices for each52// sub-register in SubRegs.53uint32_t SubRegIndices;5455// RegUnits - Points to the list of register units. The low 4 bits holds the56// Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator.57uint32_t RegUnits;5859/// Index into list with lane mask sequences. The sequence contains a lanemask60/// for every register unit.61uint16_t RegUnitLaneMasks; // ???62} MCRegisterDesc;6364/// MCRegisterInfo base class - We assume that the target defines a static65/// array of MCRegisterDesc objects that represent all of the machine66/// registers that the target has. As such, we simply have to track a pointer67/// to this array so that we can turn register number into a register68/// descriptor.69///70/// Note this class is designed to be a base class of TargetRegisterInfo, which71/// is the interface used by codegen. However, specific targets *should never*72/// specialize this class. MCRegisterInfo should only contain getters to access73/// TableGen generated physical register data. It must not be extended with74/// virtual methods.75typedef struct MCRegisterInfo {76const MCRegisterDesc *Desc; // Pointer to the descriptor array77unsigned NumRegs; // Number of entries in the array78unsigned RAReg; // Return address register79unsigned PCReg; // Program counter register80const MCRegisterClass *Classes; // Pointer to the regclass array81unsigned NumClasses; // Number of entries in the array82unsigned NumRegUnits; // Number of regunits.83uint16_t (*RegUnitRoots)[2]; // Pointer to regunit root table.84const MCPhysReg *DiffLists; // Pointer to the difflists array85// const LaneBitmask *RegUnitMaskSequences; // Pointer to lane mask sequences86const char *RegStrings; // Pointer to the string table.87// const char *RegClassStrings; // Pointer to the class strings.88const uint16_t *SubRegIndices; // Pointer to the subreg lookup89// array.90unsigned NumSubRegIndices; // Number of subreg indices.91const uint16_t *RegEncodingTable; // Pointer to array of register92// encodings.93} MCRegisterInfo;9495void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI,96const MCRegisterDesc *D, unsigned NR, unsigned RA,97unsigned PC,98const MCRegisterClass *C, unsigned NC,99uint16_t (*RURoots)[2],100unsigned NRU,101const MCPhysReg *DL,102const char *Strings,103const uint16_t *SubIndices,104unsigned NumIndices,105const uint16_t *RET);106107unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC);108109unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx);110111const MCRegisterClass* MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i);112113bool MCRegisterClass_contains(const MCRegisterClass *c, unsigned Reg);114115#endif116117118