blob: 6c091c5f0fbe6ad5b86e076d1612406ee13eb2b7 [file] [log] [blame]
Jan Voungb36ad9b2015-04-21 17:01:49 -07001//===- subzero/src/IceRegistersARM32.h - Register information ---*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares the registers and their encodings for ARM32.
Andrew Scull9612d322015-07-06 14:53:25 -070012///
Jan Voungb36ad9b2015-04-21 17:01:49 -070013//===----------------------------------------------------------------------===//
14
15#ifndef SUBZERO_SRC_ICEREGISTERSARM32_H
16#define SUBZERO_SRC_ICEREGISTERSARM32_H
17
18#include "IceDefs.h"
19#include "IceInstARM32.def"
Jim Stichnothc59288b2015-11-09 11:38:40 -080020#include "IceOperand.h" // RC_Target
Jan Voungb36ad9b2015-04-21 17:01:49 -070021#include "IceTypes.h"
22
23namespace Ice {
John Porto4a566862016-01-04 09:33:41 -080024namespace ARM32 {
Karl Schimpf57ec7df2016-01-15 08:11:00 -080025namespace RegARM32 {
Jan Voungb36ad9b2015-04-21 17:01:49 -070026
Karl Schimpf57ec7df2016-01-15 08:11:00 -080027/// An enum of every register. The enum value may not match the encoding used
28/// to binary encode register operands in instructions.
29enum AllRegisters {
John Porto2187c842015-12-16 07:48:25 -080030#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
John Portodff7dbd2016-01-04 09:49:55 -080031 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
Jan Voungb36ad9b2015-04-21 17:01:49 -070032 val,
Karl Schimpf57ec7df2016-01-15 08:11:00 -080033 REGARM32_TABLE
Jan Voungb36ad9b2015-04-21 17:01:49 -070034#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -080035 Reg_NUM,
Jan Voungb36ad9b2015-04-21 17:01:49 -070036#define X(val, init) val init,
Karl Schimpf57ec7df2016-01-15 08:11:00 -080037 REGARM32_TABLE_BOUNDS
Jan Voungb36ad9b2015-04-21 17:01:49 -070038#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -080039};
Jan Voungb36ad9b2015-04-21 17:01:49 -070040
Karl Schimpf57ec7df2016-01-15 08:11:00 -080041/// An enum of GPR Registers. The enum value does match the encoding used to
42/// binary encode register operands in instructions.
43enum GPRRegister {
John Porto2187c842015-12-16 07:48:25 -080044#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
John Portodff7dbd2016-01-04 09:49:55 -080045 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
Jan Voung86ebec12015-08-09 07:58:35 -070046 Encoded_##val = encode,
Karl Schimpf57ec7df2016-01-15 08:11:00 -080047 REGARM32_GPR_TABLE
Jan Voungb36ad9b2015-04-21 17:01:49 -070048#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -080049 Encoded_Not_GPR = -1
50};
Jan Voung86ebec12015-08-09 07:58:35 -070051
Karl Schimpf57ec7df2016-01-15 08:11:00 -080052/// An enum of FP32 S-Registers. The enum value does match the encoding used
53/// to binary encode register operands in instructions.
54enum SRegister {
John Porto2187c842015-12-16 07:48:25 -080055#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
John Portodff7dbd2016-01-04 09:49:55 -080056 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
Jan Voung86ebec12015-08-09 07:58:35 -070057 Encoded_##val = encode,
Karl Schimpf57ec7df2016-01-15 08:11:00 -080058 REGARM32_FP32_TABLE
Jan Voung86ebec12015-08-09 07:58:35 -070059#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -080060 Encoded_Not_SReg = -1
61};
Jan Voung86ebec12015-08-09 07:58:35 -070062
Karl Schimpf57ec7df2016-01-15 08:11:00 -080063/// An enum of FP64 D-Registers. The enum value does match the encoding used
64/// to binary encode register operands in instructions.
65enum DRegister {
John Porto2187c842015-12-16 07:48:25 -080066#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
John Portodff7dbd2016-01-04 09:49:55 -080067 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
Jan Voung86ebec12015-08-09 07:58:35 -070068 Encoded_##val = encode,
Karl Schimpf57ec7df2016-01-15 08:11:00 -080069 REGARM32_FP64_TABLE
Jan Voung86ebec12015-08-09 07:58:35 -070070#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -080071 Encoded_Not_DReg = -1
72};
Jan Voung86ebec12015-08-09 07:58:35 -070073
Karl Schimpf57ec7df2016-01-15 08:11:00 -080074/// An enum of 128-bit Q-Registers. The enum value does match the encoding
75/// used to binary encode register operands in instructions.
76enum QRegister {
John Porto2187c842015-12-16 07:48:25 -080077#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
John Portodff7dbd2016-01-04 09:49:55 -080078 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
Jan Voung86ebec12015-08-09 07:58:35 -070079 Encoded_##val = encode,
Karl Schimpf57ec7df2016-01-15 08:11:00 -080080 REGARM32_VEC128_TABLE
Jan Voung86ebec12015-08-09 07:58:35 -070081#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -080082 Encoded_Not_QReg = -1
83};
Jan Voung86ebec12015-08-09 07:58:35 -070084
Karl Schimpf57ec7df2016-01-15 08:11:00 -080085extern struct RegTableType {
86 const char *Name;
87 unsigned Encoding : 10;
88 unsigned CCArg : 6;
89 unsigned Scratch : 1;
90 unsigned Preserved : 1;
91 unsigned StackPtr : 1;
92 unsigned FramePtr : 1;
93 unsigned IsGPR : 1;
94 unsigned IsInt : 1;
95 unsigned IsI64Pair : 1;
96 unsigned IsFP32 : 1;
97 unsigned IsFP64 : 1;
98 unsigned IsVec128 : 1;
John Porto149999e2016-01-04 13:45:26 -080099#define NUM_ALIASES_BITS 3
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800100 SizeT NumAliases : (NUM_ALIASES_BITS + 1);
101 uint16_t Aliases[1 << NUM_ALIASES_BITS];
John Porto149999e2016-01-04 13:45:26 -0800102#undef NUM_ALIASES_BITS
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800103} RegTable[Reg_NUM];
104
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800105static inline void assertValidRegNum(RegNumT RegNum) {
106 (void)RegNum;
Reed Kotler5fa0a5f2016-02-15 20:01:24 -0800107 assert(RegNum.hasValue());
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800108}
109
110static inline bool isGPRegister(RegNumT RegNum) {
111 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800112 return RegTable[RegNum].IsGPR;
113}
114
115static constexpr inline SizeT getNumGPRegs() {
116 return 0
John Porto149999e2016-01-04 13:45:26 -0800117#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
118 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800119 +(isGPR)
John Porto149999e2016-01-04 13:45:26 -0800120 REGARM32_TABLE
121#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800122 ;
123}
John Porto149999e2016-01-04 13:45:26 -0800124
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800125static inline GPRRegister getEncodedGPR(RegNumT RegNum) {
126 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800127 return GPRRegister(RegTable[RegNum].Encoding);
128}
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800129
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800130static constexpr inline SizeT getNumGPRs() {
131 return 0
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800132#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
133 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
134 +(isGPR)
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800135 REGARM32_TABLE
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800136#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800137 ;
138}
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800139
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800140static inline bool isGPR(RegNumT RegNum) {
141 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800142 return RegTable[RegNum].IsGPR;
143}
Jan Voung86ebec12015-08-09 07:58:35 -0700144
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800145static inline GPRRegister getI64PairFirstGPRNum(RegNumT RegNum) {
146 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800147 return GPRRegister(RegTable[RegNum].Encoding);
148}
Karl Schimpfc411dbf2016-01-11 09:59:19 -0800149
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800150static inline GPRRegister getI64PairSecondGPRNum(RegNumT RegNum) {
151 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800152 return GPRRegister(RegTable[RegNum].Encoding + 1);
153}
Karl Schimpfc411dbf2016-01-11 09:59:19 -0800154
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800155static inline bool isI64RegisterPair(RegNumT RegNum) {
156 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800157 return RegTable[RegNum].IsI64Pair;
158}
Karl Schimpfc411dbf2016-01-11 09:59:19 -0800159
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800160static inline bool isEncodedSReg(RegNumT RegNum) {
161 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800162 return RegTable[RegNum].IsFP32;
163}
John Portoed2c06b2015-10-01 15:27:15 -0700164
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800165static constexpr inline SizeT getNumSRegs() {
166 return 0
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800167#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
168 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
169 +(isFP32)
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800170 REGARM32_TABLE
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800171#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800172 ;
173}
Karl Schimpfa3c32142015-12-18 08:26:16 -0800174
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800175static inline SRegister getEncodedSReg(RegNumT RegNum) {
176 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800177 return SRegister(RegTable[RegNum].Encoding);
178}
Karl Schimpfc411dbf2016-01-11 09:59:19 -0800179
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800180static inline bool isEncodedDReg(RegNumT RegNum) {
181 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800182 return RegTable[RegNum].IsFP64;
183}
Jan Voung86ebec12015-08-09 07:58:35 -0700184
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800185static constexpr inline SizeT getNumDRegs() {
186 return 0
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800187#define X(val, encode, name, cc_arg, scratch, preserved, stackptr, frameptr, \
188 isGPR, isInt, isI64Pair, isFP32, isFP64, isVec128, alias_init) \
189 +(isFP64)
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800190 REGARM32_TABLE
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800191#undef X
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800192 ;
193}
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800194
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800195static inline DRegister getEncodedDReg(RegNumT RegNum) {
196 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800197 return DRegister(RegTable[RegNum].Encoding);
198}
Jan Voung86ebec12015-08-09 07:58:35 -0700199
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800200static inline bool isEncodedQReg(RegNumT RegNum) {
201 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800202 return RegTable[RegNum].IsVec128;
203}
Karl Schimpf4acf11a2016-01-07 07:31:19 -0800204
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800205static inline QRegister getEncodedQReg(RegNumT RegNum) {
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800206 assert(isEncodedQReg(RegNum));
207 return QRegister(RegTable[RegNum].Encoding);
208}
Karl Schimpf7cb2db32015-10-29 14:04:12 -0700209
Jim Stichnoth467ffe52016-03-29 15:01:06 -0700210static inline const char *getRegName(RegNumT RegNum) {
Jim Stichnoth8aa39662016-02-10 11:20:30 -0800211 RegNum.assertIsValid();
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800212 return RegTable[RegNum].Name;
213}
Jan Voungb36ad9b2015-04-21 17:01:49 -0700214
Eric Holk658bae22016-02-08 15:22:18 -0800215// Extend enum RegClass with ARM32-specific register classes.
216enum RegClassARM32 : uint8_t {
217 RCARM32_QtoS = RC_Target, // Denotes Q registers that are aliased by S
218 // registers.
219 RCARM32_NUM
220};
Jim Stichnothc59288b2015-11-09 11:38:40 -0800221
Karl Schimpf57ec7df2016-01-15 08:11:00 -0800222} // end of namespace RegARM32
John Porto4a566862016-01-04 09:33:41 -0800223} // end of namespace ARM32
Jan Voungb36ad9b2015-04-21 17:01:49 -0700224} // end of namespace Ice
225
226#endif // SUBZERO_SRC_ICEREGISTERSARM32_H