blob: 3bf6178fca23c204e160513f028e09f46591cf41 [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>
pancake9c10ace2015-02-24 04:55:55 +010023#include "capstone/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 {
Nguyen Anh Quynhcfe18ad2015-03-02 15:12:42 +080031 iterator RegsBegin;
32 uint8_t *RegSet;
33 uint32_t NameIdx;
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;
Nguyen Anh Quynhc87ccd12015-03-02 17:31:44 +080040} MCRegisterClass;
Nguyen Anh Quynhcfe18ad2015-03-02 15:12:42 +080041
Nguyen Anh Quynh462f2912013-12-11 17:35:27 +080042/// MCRegisterDesc - This record contains information about a particular
43/// register. The SubRegs field is a zero terminated array of registers that
44/// are sub-registers of the specific register, e.g. AL, AH are sub-registers
45/// of AX. The SuperRegs field is a zero terminated array of registers that are
46/// super-registers of the specific register, e.g. RAX, EAX, are
47/// super-registers of AX.
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080048///
49typedef struct MCRegisterDesc {
50 uint32_t Name; // Printable name for the reg (for debugging)
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080051 uint32_t SubRegs; // Sub-register set, described above
52 uint32_t SuperRegs; // Super-register set, described above
53
54 // Offset into MCRI::SubRegIndices of a list of sub-register indices for each
55 // sub-register in SubRegs.
56 uint32_t SubRegIndices;
57
58 // RegUnits - Points to the list of register units. The low 4 bits holds the
59 // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator.
60 uint32_t RegUnits;
Nguyen Anh Quynhc87ccd12015-03-02 17:31:44 +080061
62 /// Index into list with lane mask sequences. The sequence contains a lanemask
63 /// for every register unit.
64 uint16_t RegUnitLaneMasks;
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080065} 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
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800109unsigned MCRegisterInfo_getMatchingSuperReg(MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, MCRegisterClass *RC);
110
111unsigned MCRegisterInfo_getSubReg(MCRegisterInfo *RI, unsigned Reg, unsigned Idx);
112
113MCRegisterClass* MCRegisterInfo_getRegClass(MCRegisterInfo *RI, unsigned i);
114
115bool MCRegisterClass_contains(MCRegisterClass *c, unsigned Reg);
116
117#endif