1 //===-- ARMBaseInfo.h - Top level definitions for ARM -------- --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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..
15 //===----------------------------------------------------------------------===//
20 #include "ARMMCTargetDesc.h"
21 #include "llvm/Support/ErrorHandling.h"
25 // Enums corresponding to ARM condition codes
27 // The CondCodes constants map directly to the 4-bit encoding of the
28 // condition field for predicated instructions.
29 enum CondCodes { // Meaning (integer) Meaning (floating-point)
31 NE, // Not equal Not equal, or unordered
32 HS, // Carry set >, ==, or unordered
33 LO, // Carry clear Less than
34 MI, // Minus, negative Less than
35 PL, // Plus, positive or zero >, ==, or unordered
36 VS, // Overflow Unordered
37 VC, // No overflow Not unordered
38 HI, // Unsigned higher Greater than, or unordered
39 LS, // Unsigned lower or same Less than or equal
40 GE, // Greater than or equal Greater than or equal
41 LT, // Less than Less than, or unordered
42 GT, // Greater than Greater than
43 LE, // Less than or equal <, ==, or unordered
44 AL // Always (unconditional) Always (unconditional)
47 inline static CondCodes getOppositeCondition(CondCodes CC) {
49 default: llvm_unreachable("Unknown condition code");
68 inline static const char *ARMCondCodeToString(ARMCC::CondCodes CC) {
70 case ARMCC::EQ: return "eq";
71 case ARMCC::NE: return "ne";
72 case ARMCC::HS: return "hs";
73 case ARMCC::LO: return "lo";
74 case ARMCC::MI: return "mi";
75 case ARMCC::PL: return "pl";
76 case ARMCC::VS: return "vs";
77 case ARMCC::VC: return "vc";
78 case ARMCC::HI: return "hi";
79 case ARMCC::LS: return "ls";
80 case ARMCC::GE: return "ge";
81 case ARMCC::LT: return "lt";
82 case ARMCC::GT: return "gt";
83 case ARMCC::LE: return "le";
84 case ARMCC::AL: return "al";
86 llvm_unreachable("Unknown condition code");
101 inline static const char *IFlagsToString(unsigned val) {
103 default: llvm_unreachable("Unknown iflags operand");
110 inline static const char *IModToString(unsigned val) {
112 default: llvm_unreachable("Unknown imod operand");
113 case IE: return "ie";
114 case ID: return "id";
120 // The Memory Barrier Option constants map directly to the 4-bit encoding of
121 // the option field for memory barrier operations.
141 inline static const char *MemBOptToString(unsigned val) {
143 default: llvm_unreachable("Unknown memory operation");
144 case SY: return "sy";
145 case ST: return "st";
146 case RESERVED_13: return "#0xd";
147 case RESERVED_12: return "#0xc";
148 case ISH: return "ish";
149 case ISHST: return "ishst";
150 case RESERVED_9: return "#0x9";
151 case RESERVED_8: return "#0x8";
152 case NSH: return "nsh";
153 case NSHST: return "nshst";
154 case RESERVED_5: return "#0x5";
155 case RESERVED_4: return "#0x4";
156 case OSH: return "osh";
157 case OSHST: return "oshst";
158 case RESERVED_1: return "#0x1";
159 case RESERVED_0: return "#0x0";
162 } // namespace ARM_MB
164 /// getARMRegisterNumbering - Given the enum value for some register, e.g.
165 /// ARM::LR, return the number that it corresponds to (e.g. 14).
166 inline static unsigned getARMRegisterNumbering(unsigned Reg) {
170 llvm_unreachable("Unknown ARM register!");
171 case R0: case S0: case D0: case Q0: return 0;
172 case R1: case S1: case D1: case Q1: return 1;
173 case R2: case S2: case D2: case Q2: return 2;
174 case R3: case S3: case D3: case Q3: return 3;
175 case R4: case S4: case D4: case Q4: return 4;
176 case R5: case S5: case D5: case Q5: return 5;
177 case R6: case S6: case D6: case Q6: return 6;
178 case R7: case S7: case D7: case Q7: return 7;
179 case R8: case S8: case D8: case Q8: return 8;
180 case R9: case S9: case D9: case Q9: return 9;
181 case R10: case S10: case D10: case Q10: return 10;
182 case R11: case S11: case D11: case Q11: return 11;
183 case R12: case S12: case D12: case Q12: return 12;
184 case SP: case S13: case D13: case Q13: return 13;
185 case LR: case S14: case D14: case Q14: return 14;
186 case PC: case S15: case D15: case Q15: return 15;
188 case S16: case D16: return 16;
189 case S17: case D17: return 17;
190 case S18: case D18: return 18;
191 case S19: case D19: return 19;
192 case S20: case D20: return 20;
193 case S21: case D21: return 21;
194 case S22: case D22: return 22;
195 case S23: case D23: return 23;
196 case S24: case D24: return 24;
197 case S25: case D25: return 25;
198 case S26: case D26: return 26;
199 case S27: case D27: return 27;
200 case S28: case D28: return 28;
201 case S29: case D29: return 29;
202 case S30: case D30: return 30;
203 case S31: case D31: return 31;
205 // Composite registers use the regnum of the first register in the list.
206 /* Q0 */ case D0_D2: return 0;
207 case D1_D2: case D1_D3: return 1;
208 /* Q1 */ case D2_D4: return 2;
209 case D3_D4: case D3_D5: return 3;
210 /* Q2 */ case D4_D6: return 4;
211 case D5_D6: case D5_D7: return 5;
212 /* Q3 */ case D6_D8: return 6;
213 case D7_D8: case D7_D9: return 7;
214 /* Q4 */ case D8_D10: return 8;
215 case D9_D10: case D9_D11: return 9;
216 /* Q5 */ case D10_D12: return 10;
217 case D11_D12: case D11_D13: return 11;
218 /* Q6 */ case D12_D14: return 12;
219 case D13_D14: case D13_D15: return 13;
220 /* Q7 */ case D14_D16: return 14;
221 case D15_D16: case D15_D17: return 15;
222 /* Q8 */ case D16_D18: return 16;
223 case D17_D18: case D17_D19: return 17;
224 /* Q9 */ case D18_D20: return 18;
225 case D19_D20: case D19_D21: return 19;
226 /* Q10 */ case D20_D22: return 20;
227 case D21_D22: case D21_D23: return 21;
228 /* Q11 */ case D22_D24: return 22;
229 case D23_D24: case D23_D25: return 23;
230 /* Q12 */ case D24_D26: return 24;
231 case D25_D26: case D25_D27: return 25;
232 /* Q13 */ case D26_D28: return 26;
233 case D27_D28: case D27_D29: return 27;
234 /* Q14 */ case D28_D30: return 28;
235 case D29_D30: case D29_D31: return 29;
240 /// isARMLowRegister - Returns true if the register is a low register (r0-r7).
242 static inline bool isARMLowRegister(unsigned Reg) {
245 case R0: case R1: case R2: case R3:
246 case R4: case R5: case R6: case R7:
253 /// ARMII - This namespace holds all of the target specific flags that
254 /// instruction info tracks.
266 /// ARM Addressing Modes
278 AddrModeT1_s = 10, // i8 * 4 for pc and sp relative data
282 AddrModeT2_pc = 14, // +/- i12 for pc relative data
283 AddrModeT2_i8s4 = 15, // i8 * 4
287 inline static const char *AddrModeToString(AddrMode addrmode) {
289 case AddrModeNone: return "AddrModeNone";
290 case AddrMode1: return "AddrMode1";
291 case AddrMode2: return "AddrMode2";
292 case AddrMode3: return "AddrMode3";
293 case AddrMode4: return "AddrMode4";
294 case AddrMode5: return "AddrMode5";
295 case AddrMode6: return "AddrMode6";
296 case AddrModeT1_1: return "AddrModeT1_1";
297 case AddrModeT1_2: return "AddrModeT1_2";
298 case AddrModeT1_4: return "AddrModeT1_4";
299 case AddrModeT1_s: return "AddrModeT1_s";
300 case AddrModeT2_i12: return "AddrModeT2_i12";
301 case AddrModeT2_i8: return "AddrModeT2_i8";
302 case AddrModeT2_so: return "AddrModeT2_so";
303 case AddrModeT2_pc: return "AddrModeT2_pc";
304 case AddrModeT2_i8s4: return "AddrModeT2_i8s4";
305 case AddrMode_i12: return "AddrMode_i12";
309 /// Target Operand Flag enum.
311 //===------------------------------------------------------------------===//
312 // ARM Specific MachineOperand flags.
316 /// MO_LO16 - On a symbol operand, this represents a relocation containing
317 /// lower 16 bit of the address. Used only via movw instruction.
320 /// MO_HI16 - On a symbol operand, this represents a relocation containing
321 /// higher 16 bit of the address. Used only via movt instruction.
324 /// MO_LO16_NONLAZY - On a symbol operand "FOO", this represents a
325 /// relocation containing lower 16 bit of the non-lazy-ptr indirect symbol,
326 /// i.e. "FOO$non_lazy_ptr".
327 /// Used only via movw instruction.
330 /// MO_HI16_NONLAZY - On a symbol operand "FOO", this represents a
331 /// relocation containing lower 16 bit of the non-lazy-ptr indirect symbol,
332 /// i.e. "FOO$non_lazy_ptr". Used only via movt instruction.
335 /// MO_LO16_NONLAZY_PIC - On a symbol operand "FOO", this represents a
336 /// relocation containing lower 16 bit of the PC relative address of the
337 /// non-lazy-ptr indirect symbol, i.e. "FOO$non_lazy_ptr - LABEL".
338 /// Used only via movw instruction.
341 /// MO_HI16_NONLAZY_PIC - On a symbol operand "FOO", this represents a
342 /// relocation containing lower 16 bit of the PC relative address of the
343 /// non-lazy-ptr indirect symbol, i.e. "FOO$non_lazy_ptr - LABEL".
344 /// Used only via movt instruction.
347 /// MO_PLT - On a symbol operand, this represents an ELF PLT reference on a
353 //===------------------------------------------------------------------===//
354 // Instruction Flags.
356 //===------------------------------------------------------------------===//
357 // This four-bit field describes the addressing mode used.
358 AddrModeMask = 0x1f, // The AddrMode enums are declared in ARMBaseInfo.h
360 // IndexMode - Unindex, pre-indexed, or post-indexed are valid for load
361 // and store ops only. Generic "updating" flag is used for ld/st multiple.
362 // The index mode enums are declared in ARMBaseInfo.h
364 IndexModeMask = 3 << IndexModeShift,
366 //===------------------------------------------------------------------===//
367 // Instruction encoding formats.
370 FormMask = 0x3f << FormShift,
372 // Pseudo instructions
373 Pseudo = 0 << FormShift,
375 // Multiply instructions
376 MulFrm = 1 << FormShift,
378 // Branch instructions
379 BrFrm = 2 << FormShift,
380 BrMiscFrm = 3 << FormShift,
382 // Data Processing instructions
383 DPFrm = 4 << FormShift,
384 DPSoRegFrm = 5 << FormShift,
387 LdFrm = 6 << FormShift,
388 StFrm = 7 << FormShift,
389 LdMiscFrm = 8 << FormShift,
390 StMiscFrm = 9 << FormShift,
391 LdStMulFrm = 10 << FormShift,
393 LdStExFrm = 11 << FormShift,
395 // Miscellaneous arithmetic instructions
396 ArithMiscFrm = 12 << FormShift,
397 SatFrm = 13 << FormShift,
399 // Extend instructions
400 ExtFrm = 14 << FormShift,
403 VFPUnaryFrm = 15 << FormShift,
404 VFPBinaryFrm = 16 << FormShift,
405 VFPConv1Frm = 17 << FormShift,
406 VFPConv2Frm = 18 << FormShift,
407 VFPConv3Frm = 19 << FormShift,
408 VFPConv4Frm = 20 << FormShift,
409 VFPConv5Frm = 21 << FormShift,
410 VFPLdStFrm = 22 << FormShift,
411 VFPLdStMulFrm = 23 << FormShift,
412 VFPMiscFrm = 24 << FormShift,
415 ThumbFrm = 25 << FormShift,
417 // Miscelleaneous format
418 MiscFrm = 26 << FormShift,
421 NGetLnFrm = 27 << FormShift,
422 NSetLnFrm = 28 << FormShift,
423 NDupFrm = 29 << FormShift,
424 NLdStFrm = 30 << FormShift,
425 N1RegModImmFrm= 31 << FormShift,
426 N2RegFrm = 32 << FormShift,
427 NVCVTFrm = 33 << FormShift,
428 NVDupLnFrm = 34 << FormShift,
429 N2RegVShLFrm = 35 << FormShift,
430 N2RegVShRFrm = 36 << FormShift,
431 N3RegFrm = 37 << FormShift,
432 N3RegVShFrm = 38 << FormShift,
433 NVExtFrm = 39 << FormShift,
434 NVMulSLFrm = 40 << FormShift,
435 NVTBLFrm = 41 << FormShift,
437 //===------------------------------------------------------------------===//
440 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
441 // it doesn't have a Rn operand.
444 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
445 // a 16-bit Thumb instruction if certain conditions are met.
446 Xform16Bit = 1 << 14,
448 // ThumbArithFlagSetting - The instruction is a 16-bit flag setting Thumb
449 // instruction. Used by the parser to determine whether to require the 'S'
450 // suffix on the mnemonic (when not in an IT block) or preclude it (when
452 ThumbArithFlagSetting = 1 << 18,
454 //===------------------------------------------------------------------===//
457 DomainMask = 7 << DomainShift,
458 DomainGeneral = 0 << DomainShift,
459 DomainVFP = 1 << DomainShift,
460 DomainNEON = 2 << DomainShift,
461 DomainNEONA8 = 4 << DomainShift,
463 //===------------------------------------------------------------------===//
464 // Field shifts - such shifts are used to set field while generating
465 // machine instructions.
467 // FIXME: This list will need adjusting/fixing as the MC code emitter
468 // takes shape and the ARMCodeEmitter.cpp bits go away.
493 } // end namespace ARMII
495 } // end namespace llvm;