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