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