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