blob: 3744ef78d42720615062f91e7dc85ccf388c1bc7 [file] [log] [blame]
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08001//=== 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 Quynh30e4d7f2014-05-08 22:54:58 +080016/* Capstone Disassembly Engine */
Nguyen Anh Quynhcfe18ad2015-03-02 15:12:42 +080017/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080018
19#ifndef CS_LLVM_MC_MCREGISTERINFO_H
20#define CS_LLVM_MC_MCREGISTERINFO_H
21
pancake9c10ace2015-02-24 04:55:55 +010022#include "capstone/platform.h"
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080023
24/// An unsigned integer type large enough to represent all physical registers,
25/// but not necessarily virtual registers.
26typedef uint16_t MCPhysReg;
Richard Henderson22ead3e2017-10-21 17:45:40 -070027typedef const MCPhysReg* iterator;
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080028
29typedef struct MCRegisterClass {
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080030 iterator RegsBegin;
Richard Henderson22ead3e2017-10-21 17:45:40 -070031 const uint8_t *RegSet;
Nguyen Anh Quynhcfe18ad2015-03-02 15:12:42 +080032 uint32_t NameIdx;
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080033 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 Quynh462f2912013-12-11 17:35:27 +080041/// 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 Quynh26ee41a2013-11-27 12:11:31 +080047///
48typedef struct MCRegisterDesc {
49 uint32_t Name; // Printable name for the reg (for debugging)
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080050 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 Quynhc87ccd12015-03-02 17:31:44 +080060
61 /// Index into list with lane mask sequences. The sequence contains a lanemask
62 /// for every register unit.
63 uint16_t RegUnitLaneMasks;
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080064} 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///
78typedef struct MCRegisterInfo {
Richard Henderson22ead3e2017-10-21 17:45:40 -070079 const MCRegisterDesc *Desc; // Pointer to the descriptor array
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080080 unsigned NumRegs; // Number of entries in the array
81 unsigned RAReg; // Return address register
82 unsigned PCReg; // Program counter register
Richard Henderson22ead3e2017-10-21 17:45:40 -070083 const MCRegisterClass *Classes; // Pointer to the regclass array
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080084 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 Henderson22ead3e2017-10-21 17:45:40 -070087 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 Quynh26ee41a2013-11-27 12:11:31 +080090 // array.
91 unsigned NumSubRegIndices; // Number of subreg indices.
Richard Henderson22ead3e2017-10-21 17:45:40 -070092 const uint16_t *RegEncodingTable; // Pointer to array of register
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080093 // encodings.
94} MCRegisterInfo;
95
96void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI,
Richard Henderson22ead3e2017-10-21 17:45:40 -070097 const MCRegisterDesc *D, unsigned NR, unsigned RA,
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080098 unsigned PC,
Richard Henderson22ead3e2017-10-21 17:45:40 -070099 const MCRegisterClass *C, unsigned NC,
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800100 uint16_t (*RURoots)[2],
101 unsigned NRU,
Richard Henderson22ead3e2017-10-21 17:45:40 -0700102 const MCPhysReg *DL,
103 const char *Strings,
104 const uint16_t *SubIndices,
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800105 unsigned NumIndices,
Richard Henderson22ead3e2017-10-21 17:45:40 -0700106 const uint16_t *RET);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800107
Richard Henderson22ead3e2017-10-21 17:45:40 -0700108unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800109
Richard Henderson22ead3e2017-10-21 17:45:40 -0700110unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800111
Richard Henderson22ead3e2017-10-21 17:45:40 -0700112const MCRegisterClass* MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800113
Richard Henderson22ead3e2017-10-21 17:45:40 -0700114bool MCRegisterClass_contains(const MCRegisterClass *c, unsigned Reg);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800115
116#endif