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