blob: 91e9fd1f9b87cde81b0d36bb966089a4b7ede55c [file] [log] [blame]
Jim Grosbach91fbd8f2010-09-15 19:26:06 +00001//===-- ARMBaseInfo.h - Top level definitions for ARM -------- --*- 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 contains small standalone helper functions and enum definitions for
11// the ARM target useful for the compiler back-end and the MC libraries.
12// As such, it deliberately does not include references to LLVM core
13// code gen types, passes, etc..
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef ARMBASEINFO_H
18#define ARMBASEINFO_H
19
20#include "llvm/Support/ErrorHandling.h"
21
Jim Grosbach40e85fb2010-09-15 20:26:25 +000022// Note that the following auto-generated files only defined enum types, and
23// so are safe to include here.
24
25// Defines symbolic names for ARM registers. This defines a mapping from
26// register name to register number.
27//
Evan Chengd9997ac2011-06-27 18:32:37 +000028#define GET_REGINFO_ENUM
29#include "ARMGenRegisterInfo.inc"
Jim Grosbach40e85fb2010-09-15 20:26:25 +000030
31// Defines symbolic names for the ARM instructions.
32//
33#include "ARMGenInstrNames.inc"
34
Jim Grosbach91fbd8f2010-09-15 19:26:06 +000035namespace llvm {
36
37// Enums corresponding to ARM condition codes
38namespace ARMCC {
39 // The CondCodes constants map directly to the 4-bit encoding of the
40 // condition field for predicated instructions.
41 enum CondCodes { // Meaning (integer) Meaning (floating-point)
42 EQ, // Equal Equal
43 NE, // Not equal Not equal, or unordered
44 HS, // Carry set >, ==, or unordered
45 LO, // Carry clear Less than
46 MI, // Minus, negative Less than
47 PL, // Plus, positive or zero >, ==, or unordered
48 VS, // Overflow Unordered
49 VC, // No overflow Not unordered
50 HI, // Unsigned higher Greater than, or unordered
51 LS, // Unsigned lower or same Less than or equal
52 GE, // Greater than or equal Greater than or equal
53 LT, // Less than Less than, or unordered
54 GT, // Greater than Greater than
55 LE, // Less than or equal <, ==, or unordered
56 AL // Always (unconditional) Always (unconditional)
57 };
58
59 inline static CondCodes getOppositeCondition(CondCodes CC) {
60 switch (CC) {
61 default: llvm_unreachable("Unknown condition code");
62 case EQ: return NE;
63 case NE: return EQ;
64 case HS: return LO;
65 case LO: return HS;
66 case MI: return PL;
67 case PL: return MI;
68 case VS: return VC;
69 case VC: return VS;
70 case HI: return LS;
71 case LS: return HI;
72 case GE: return LT;
73 case LT: return GE;
74 case GT: return LE;
75 case LE: return GT;
76 }
77 }
78} // namespace ARMCC
79
80inline static const char *ARMCondCodeToString(ARMCC::CondCodes CC) {
81 switch (CC) {
82 default: llvm_unreachable("Unknown condition code");
83 case ARMCC::EQ: return "eq";
84 case ARMCC::NE: return "ne";
85 case ARMCC::HS: return "hs";
86 case ARMCC::LO: return "lo";
87 case ARMCC::MI: return "mi";
88 case ARMCC::PL: return "pl";
89 case ARMCC::VS: return "vs";
90 case ARMCC::VC: return "vc";
91 case ARMCC::HI: return "hi";
92 case ARMCC::LS: return "ls";
93 case ARMCC::GE: return "ge";
94 case ARMCC::LT: return "lt";
95 case ARMCC::GT: return "gt";
96 case ARMCC::LE: return "le";
97 case ARMCC::AL: return "al";
98 }
99}
100
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000101namespace ARM_PROC {
102 enum IMod {
103 IE = 2,
104 ID = 3
105 };
106
107 enum IFlags {
108 F = 1,
109 I = 2,
110 A = 4
111 };
112
113 inline static const char *IFlagsToString(unsigned val) {
114 switch (val) {
115 default: llvm_unreachable("Unknown iflags operand");
116 case F: return "f";
117 case I: return "i";
118 case A: return "a";
119 }
120 }
121
122 inline static const char *IModToString(unsigned val) {
123 switch (val) {
124 default: llvm_unreachable("Unknown imod operand");
125 case IE: return "ie";
126 case ID: return "id";
127 }
128 }
129}
130
Jim Grosbach91fbd8f2010-09-15 19:26:06 +0000131namespace ARM_MB {
132 // The Memory Barrier Option constants map directly to the 4-bit encoding of
133 // the option field for memory barrier operations.
134 enum MemBOpt {
Bob Wilson7ed59712010-10-30 00:54:37 +0000135 SY = 15,
Jim Grosbach91fbd8f2010-09-15 19:26:06 +0000136 ST = 14,
137 ISH = 11,
138 ISHST = 10,
139 NSH = 7,
140 NSHST = 6,
141 OSH = 3,
142 OSHST = 2
143 };
144
145 inline static const char *MemBOptToString(unsigned val) {
146 switch (val) {
Jim Grosbach2b48b552010-09-15 19:26:50 +0000147 default: llvm_unreachable("Unknown memory operation");
Bob Wilson7ed59712010-10-30 00:54:37 +0000148 case SY: return "sy";
Jim Grosbach91fbd8f2010-09-15 19:26:06 +0000149 case ST: return "st";
150 case ISH: return "ish";
151 case ISHST: return "ishst";
152 case NSH: return "nsh";
153 case NSHST: return "nshst";
154 case OSH: return "osh";
155 case OSHST: return "oshst";
156 }
157 }
158} // namespace ARM_MB
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000159
160/// getARMRegisterNumbering - Given the enum value for some register, e.g.
161/// ARM::LR, return the number that it corresponds to (e.g. 14).
162inline static unsigned getARMRegisterNumbering(unsigned Reg) {
163 using namespace ARM;
164 switch (Reg) {
165 default:
166 llvm_unreachable("Unknown ARM register!");
167 case R0: case S0: case D0: case Q0: return 0;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000168 case R1: case S1: case D1: case Q1: return 1;
169 case R2: case S2: case D2: case Q2: return 2;
170 case R3: case S3: case D3: case Q3: return 3;
171 case R4: case S4: case D4: case Q4: return 4;
172 case R5: case S5: case D5: case Q5: return 5;
173 case R6: case S6: case D6: case Q6: return 6;
174 case R7: case S7: case D7: case Q7: return 7;
175 case R8: case S8: case D8: case Q8: return 8;
176 case R9: case S9: case D9: case Q9: return 9;
177 case R10: case S10: case D10: case Q10: return 10;
178 case R11: case S11: case D11: case Q11: return 11;
179 case R12: case S12: case D12: case Q12: return 12;
180 case SP: case S13: case D13: case Q13: return 13;
181 case LR: case S14: case D14: case Q14: return 14;
182 case PC: case S15: case D15: case Q15: return 15;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000183
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000184 case S16: case D16: return 16;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000185 case S17: case D17: return 17;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000186 case S18: case D18: return 18;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000187 case S19: case D19: return 19;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000188 case S20: case D20: return 20;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000189 case S21: case D21: return 21;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000190 case S22: case D22: return 22;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000191 case S23: case D23: return 23;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000192 case S24: case D24: return 24;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000193 case S25: case D25: return 25;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000194 case S26: case D26: return 26;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000195 case S27: case D27: return 27;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000196 case S28: case D28: return 28;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000197 case S29: case D29: return 29;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000198 case S30: case D30: return 30;
Jim Grosbach40e85fb2010-09-15 20:26:25 +0000199 case S31: case D31: return 31;
200 }
201}
202
Jim Grosbach0d35df12010-09-17 18:25:25 +0000203namespace ARMII {
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000204
205 /// ARM Index Modes
206 enum IndexMode {
207 IndexModeNone = 0,
208 IndexModePre = 1,
209 IndexModePost = 2,
210 IndexModeUpd = 3
211 };
212
213 /// ARM Addressing Modes
214 enum AddrMode {
215 AddrModeNone = 0,
216 AddrMode1 = 1,
217 AddrMode2 = 2,
218 AddrMode3 = 3,
219 AddrMode4 = 4,
220 AddrMode5 = 5,
221 AddrMode6 = 6,
222 AddrModeT1_1 = 7,
223 AddrModeT1_2 = 8,
224 AddrModeT1_4 = 9,
225 AddrModeT1_s = 10, // i8 * 4 for pc and sp relative data
226 AddrModeT2_i12 = 11,
227 AddrModeT2_i8 = 12,
228 AddrModeT2_so = 13,
229 AddrModeT2_pc = 14, // +/- i12 for pc relative data
230 AddrModeT2_i8s4 = 15, // i8 * 4
231 AddrMode_i12 = 16
232 };
233
234 inline static const char *AddrModeToString(AddrMode addrmode) {
235 switch (addrmode) {
236 default: llvm_unreachable("Unknown memory operation");
237 case AddrModeNone: return "AddrModeNone";
238 case AddrMode1: return "AddrMode1";
239 case AddrMode2: return "AddrMode2";
240 case AddrMode3: return "AddrMode3";
241 case AddrMode4: return "AddrMode4";
242 case AddrMode5: return "AddrMode5";
243 case AddrMode6: return "AddrMode6";
244 case AddrModeT1_1: return "AddrModeT1_1";
245 case AddrModeT1_2: return "AddrModeT1_2";
246 case AddrModeT1_4: return "AddrModeT1_4";
247 case AddrModeT1_s: return "AddrModeT1_s";
248 case AddrModeT2_i12: return "AddrModeT2_i12";
249 case AddrModeT2_i8: return "AddrModeT2_i8";
250 case AddrModeT2_so: return "AddrModeT2_so";
251 case AddrModeT2_pc: return "AddrModeT2_pc";
252 case AddrModeT2_i8s4: return "AddrModeT2_i8s4";
253 case AddrMode_i12: return "AddrMode_i12";
254 }
255 }
256
Jim Grosbach0d35df12010-09-17 18:25:25 +0000257 /// Target Operand Flag enum.
258 enum TOF {
259 //===------------------------------------------------------------------===//
260 // ARM Specific MachineOperand flags.
261
262 MO_NO_FLAG,
263
264 /// MO_LO16 - On a symbol operand, this represents a relocation containing
265 /// lower 16 bit of the address. Used only via movw instruction.
266 MO_LO16,
267
268 /// MO_HI16 - On a symbol operand, this represents a relocation containing
269 /// higher 16 bit of the address. Used only via movt instruction.
Jim Grosbach85dcd3d2010-09-22 23:27:36 +0000270 MO_HI16,
271
Evan Cheng2f2435d2011-01-21 18:55:51 +0000272 /// MO_LO16_NONLAZY - On a symbol operand "FOO", this represents a
273 /// relocation containing lower 16 bit of the non-lazy-ptr indirect symbol,
274 /// i.e. "FOO$non_lazy_ptr".
275 /// Used only via movw instruction.
276 MO_LO16_NONLAZY,
277
278 /// MO_HI16_NONLAZY - On a symbol operand "FOO", this represents a
279 /// relocation containing lower 16 bit of the non-lazy-ptr indirect symbol,
280 /// i.e. "FOO$non_lazy_ptr". Used only via movt instruction.
281 MO_HI16_NONLAZY,
282
Evan Chengdfce83c2011-01-17 08:03:18 +0000283 /// MO_LO16_NONLAZY_PIC - On a symbol operand "FOO", this represents a
284 /// relocation containing lower 16 bit of the PC relative address of the
285 /// non-lazy-ptr indirect symbol, i.e. "FOO$non_lazy_ptr - LABEL".
286 /// Used only via movw instruction.
287 MO_LO16_NONLAZY_PIC,
288
289 /// MO_HI16_NONLAZY_PIC - On a symbol operand "FOO", this represents a
290 /// relocation containing lower 16 bit of the PC relative address of the
291 /// non-lazy-ptr indirect symbol, i.e. "FOO$non_lazy_ptr - LABEL".
292 /// Used only via movt instruction.
293 MO_HI16_NONLAZY_PIC,
294
Jim Grosbach85dcd3d2010-09-22 23:27:36 +0000295 /// MO_PLT - On a symbol operand, this represents an ELF PLT reference on a
296 /// call operand.
297 MO_PLT
Jim Grosbach0d35df12010-09-17 18:25:25 +0000298 };
299} // end namespace ARMII
300
Jim Grosbach91fbd8f2010-09-15 19:26:06 +0000301} // end namespace llvm;
302
Jim Grosbach91fbd8f2010-09-15 19:26:06 +0000303#endif