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