1 //===-- ARMInstrThumb2.td - Thumb2 support for ARM ---------*- tablegen -*-===// 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 describes the Thumb2 instruction set. 11 // 12 //===----------------------------------------------------------------------===// 13 14 // IT block predicate field 15 def it_pred_asmoperand : AsmOperandClass { 16 let Name = "ITCondCode"; 17 let ParserMethod = "parseITCondCode"; 18 } 19 def it_pred : Operand<i32> { 20 let PrintMethod = "printMandatoryPredicateOperand"; 21 let ParserMatchClass = it_pred_asmoperand; 22 } 23 24 // IT block condition mask 25 def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; } 26 def it_mask : Operand<i32> { 27 let PrintMethod = "printThumbITMask"; 28 let ParserMatchClass = it_mask_asmoperand; 29 } 30 31 // t2_shift_imm: An integer that encodes a shift amount and the type of shift 32 // (asr or lsl). The 6-bit immediate encodes as: 33 // {5} 0 ==> lsl 34 // 1 asr 35 // {4-0} imm5 shift amount. 36 // asr #32 not allowed 37 def t2_shift_imm : Operand<i32> { 38 let PrintMethod = "printShiftImmOperand"; 39 let ParserMatchClass = ShifterImmAsmOperand; 40 let DecoderMethod = "DecodeT2ShifterImmOperand"; 41 } 42 43 // Shifted operands. No register controlled shifts for Thumb2. 44 // Note: We do not support rrx shifted operands yet. 45 def t2_so_reg : Operand<i32>, // reg imm 46 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg", 47 [shl,srl,sra,rotr]> { 48 let EncoderMethod = "getT2SORegOpValue"; 49 let PrintMethod = "printT2SOOperand"; 50 let DecoderMethod = "DecodeSORegImmOperand"; 51 let ParserMatchClass = ShiftedImmAsmOperand; 52 let MIOperandInfo = (ops rGPR, i32imm); 53 } 54 55 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value 56 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{ 57 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32); 58 }]>; 59 60 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value 61 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{ 62 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32); 63 }]>; 64 65 // so_imm_notSext_XFORM - Return a so_imm value packed into the format 66 // described for so_imm_notSext def below, with sign extension from 16 67 // bits. 68 def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{ 69 APInt apIntN = N->getAPIntValue(); 70 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue(); 71 return CurDAG->getTargetConstant(~N16bitSignExt, MVT::i32); 72 }]>; 73 74 // t2_so_imm - Match a 32-bit immediate operand, which is an 75 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit 76 // immediate splatted into multiple bytes of the word. 77 def t2_so_imm_asmoperand : ImmAsmOperand { let Name = "T2SOImm"; } 78 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{ 79 return ARM_AM::getT2SOImmVal(Imm) != -1; 80 }]> { 81 let ParserMatchClass = t2_so_imm_asmoperand; 82 let EncoderMethod = "getT2SOImmOpValue"; 83 let DecoderMethod = "DecodeT2SOImm"; 84 } 85 86 // t2_so_imm_not - Match an immediate that is a complement 87 // of a t2_so_imm. 88 // Note: this pattern doesn't require an encoder method and such, as it's 89 // only used on aliases (Pat<> and InstAlias<>). The actual encoding 90 // is handled by the destination instructions, which use t2_so_imm. 91 def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; } 92 def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{ 93 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1; 94 }], t2_so_imm_not_XFORM> { 95 let ParserMatchClass = t2_so_imm_not_asmoperand; 96 } 97 98 // t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm 99 // if the upper 16 bits are zero. 100 def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{ 101 APInt apIntN = N->getAPIntValue(); 102 if (!apIntN.isIntN(16)) return false; 103 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue(); 104 return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1; 105 }], t2_so_imm_notSext16_XFORM> { 106 let ParserMatchClass = t2_so_imm_not_asmoperand; 107 } 108 109 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm. 110 def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; } 111 def t2_so_imm_neg : Operand<i32>, PatLeaf<(imm), [{ 112 int64_t Value = -(int)N->getZExtValue(); 113 return Value && ARM_AM::getT2SOImmVal(Value) != -1; 114 }], t2_so_imm_neg_XFORM> { 115 let ParserMatchClass = t2_so_imm_neg_asmoperand; 116 } 117 118 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095]. 119 def imm0_4095_asmoperand: ImmAsmOperand { let Name = "Imm0_4095"; } 120 def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{ 121 return Imm >= 0 && Imm < 4096; 122 }]> { 123 let ParserMatchClass = imm0_4095_asmoperand; 124 } 125 126 def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; } 127 def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{ 128 return (uint32_t)(-N->getZExtValue()) < 4096; 129 }], imm_neg_XFORM> { 130 let ParserMatchClass = imm0_4095_neg_asmoperand; 131 } 132 133 def imm1_255_neg : PatLeaf<(i32 imm), [{ 134 uint32_t Val = -N->getZExtValue(); 135 return (Val > 0 && Val < 255); 136 }], imm_neg_XFORM>; 137 138 def imm0_255_not : PatLeaf<(i32 imm), [{ 139 return (uint32_t)(~N->getZExtValue()) < 255; 140 }], imm_comp_XFORM>; 141 142 def lo5AllOne : PatLeaf<(i32 imm), [{ 143 // Returns true if all low 5-bits are 1. 144 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL; 145 }]>; 146 147 // Define Thumb2 specific addressing modes. 148 149 // t2addrmode_imm12 := reg + imm12 150 def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";} 151 def t2addrmode_imm12 : Operand<i32>, 152 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> { 153 let PrintMethod = "printAddrModeImm12Operand<false>"; 154 let EncoderMethod = "getAddrModeImm12OpValue"; 155 let DecoderMethod = "DecodeT2AddrModeImm12"; 156 let ParserMatchClass = t2addrmode_imm12_asmoperand; 157 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 158 } 159 160 // t2ldrlabel := imm12 161 def t2ldrlabel : Operand<i32> { 162 let EncoderMethod = "getAddrModeImm12OpValue"; 163 let PrintMethod = "printThumbLdrLabelOperand"; 164 } 165 166 def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";} 167 def t2ldr_pcrel_imm12 : Operand<i32> { 168 let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand; 169 // used for assembler pseudo instruction and maps to t2ldrlabel, so 170 // doesn't need encoder or print methods of its own. 171 } 172 173 // ADR instruction labels. 174 def t2adrlabel : Operand<i32> { 175 let EncoderMethod = "getT2AdrLabelOpValue"; 176 let PrintMethod = "printAdrLabelOperand<0>"; 177 } 178 179 // t2addrmode_posimm8 := reg + imm8 180 def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";} 181 def t2addrmode_posimm8 : Operand<i32> { 182 let PrintMethod = "printT2AddrModeImm8Operand<false>"; 183 let EncoderMethod = "getT2AddrModeImm8OpValue"; 184 let DecoderMethod = "DecodeT2AddrModeImm8"; 185 let ParserMatchClass = MemPosImm8OffsetAsmOperand; 186 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 187 } 188 189 // t2addrmode_negimm8 := reg - imm8 190 def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";} 191 def t2addrmode_negimm8 : Operand<i32>, 192 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> { 193 let PrintMethod = "printT2AddrModeImm8Operand<false>"; 194 let EncoderMethod = "getT2AddrModeImm8OpValue"; 195 let DecoderMethod = "DecodeT2AddrModeImm8"; 196 let ParserMatchClass = MemNegImm8OffsetAsmOperand; 197 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 198 } 199 200 // t2addrmode_imm8 := reg +/- imm8 201 def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; } 202 class T2AddrMode_Imm8 : Operand<i32>, 203 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> { 204 let EncoderMethod = "getT2AddrModeImm8OpValue"; 205 let DecoderMethod = "DecodeT2AddrModeImm8"; 206 let ParserMatchClass = MemImm8OffsetAsmOperand; 207 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 208 } 209 210 def t2addrmode_imm8 : T2AddrMode_Imm8 { 211 let PrintMethod = "printT2AddrModeImm8Operand<false>"; 212 } 213 214 def t2addrmode_imm8_pre : T2AddrMode_Imm8 { 215 let PrintMethod = "printT2AddrModeImm8Operand<true>"; 216 } 217 218 def t2am_imm8_offset : Operand<i32>, 219 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset", 220 [], [SDNPWantRoot]> { 221 let PrintMethod = "printT2AddrModeImm8OffsetOperand"; 222 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue"; 223 let DecoderMethod = "DecodeT2Imm8"; 224 } 225 226 // t2addrmode_imm8s4 := reg +/- (imm8 << 2) 227 def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";} 228 class T2AddrMode_Imm8s4 : Operand<i32> { 229 let EncoderMethod = "getT2AddrModeImm8s4OpValue"; 230 let DecoderMethod = "DecodeT2AddrModeImm8s4"; 231 let ParserMatchClass = MemImm8s4OffsetAsmOperand; 232 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 233 } 234 235 def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 { 236 let PrintMethod = "printT2AddrModeImm8s4Operand<false>"; 237 } 238 239 def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 { 240 let PrintMethod = "printT2AddrModeImm8s4Operand<true>"; 241 } 242 243 def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; } 244 def t2am_imm8s4_offset : Operand<i32> { 245 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand"; 246 let EncoderMethod = "getT2Imm8s4OpValue"; 247 let DecoderMethod = "DecodeT2Imm8S4"; 248 } 249 250 // t2addrmode_imm0_1020s4 := reg + (imm8 << 2) 251 def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass { 252 let Name = "MemImm0_1020s4Offset"; 253 } 254 def t2addrmode_imm0_1020s4 : Operand<i32>, 255 ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> { 256 let PrintMethod = "printT2AddrModeImm0_1020s4Operand"; 257 let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue"; 258 let DecoderMethod = "DecodeT2AddrModeImm0_1020s4"; 259 let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand; 260 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm); 261 } 262 263 // t2addrmode_so_reg := reg + (reg << imm2) 264 def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";} 265 def t2addrmode_so_reg : Operand<i32>, 266 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> { 267 let PrintMethod = "printT2AddrModeSoRegOperand"; 268 let EncoderMethod = "getT2AddrModeSORegOpValue"; 269 let DecoderMethod = "DecodeT2AddrModeSOReg"; 270 let ParserMatchClass = t2addrmode_so_reg_asmoperand; 271 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm); 272 } 273 274 // Addresses for the TBB/TBH instructions. 275 def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; } 276 def addrmode_tbb : Operand<i32> { 277 let PrintMethod = "printAddrModeTBB"; 278 let ParserMatchClass = addrmode_tbb_asmoperand; 279 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm); 280 } 281 def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; } 282 def addrmode_tbh : Operand<i32> { 283 let PrintMethod = "printAddrModeTBH"; 284 let ParserMatchClass = addrmode_tbh_asmoperand; 285 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm); 286 } 287 288 //===----------------------------------------------------------------------===// 289 // Multiclass helpers... 290 // 291 292 293 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin, 294 string opc, string asm, list<dag> pattern> 295 : T2I<oops, iops, itin, opc, asm, pattern> { 296 bits<4> Rd; 297 bits<12> imm; 298 299 let Inst{11-8} = Rd; 300 let Inst{26} = imm{11}; 301 let Inst{14-12} = imm{10-8}; 302 let Inst{7-0} = imm{7-0}; 303 } 304 305 306 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin, 307 string opc, string asm, list<dag> pattern> 308 : T2sI<oops, iops, itin, opc, asm, pattern> { 309 bits<4> Rd; 310 bits<4> Rn; 311 bits<12> imm; 312 313 let Inst{11-8} = Rd; 314 let Inst{26} = imm{11}; 315 let Inst{14-12} = imm{10-8}; 316 let Inst{7-0} = imm{7-0}; 317 } 318 319 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin, 320 string opc, string asm, list<dag> pattern> 321 : T2I<oops, iops, itin, opc, asm, pattern> { 322 bits<4> Rn; 323 bits<12> imm; 324 325 let Inst{19-16} = Rn; 326 let Inst{26} = imm{11}; 327 let Inst{14-12} = imm{10-8}; 328 let Inst{7-0} = imm{7-0}; 329 } 330 331 332 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 333 string opc, string asm, list<dag> pattern> 334 : T2I<oops, iops, itin, opc, asm, pattern> { 335 bits<4> Rd; 336 bits<12> ShiftedRm; 337 338 let Inst{11-8} = Rd; 339 let Inst{3-0} = ShiftedRm{3-0}; 340 let Inst{5-4} = ShiftedRm{6-5}; 341 let Inst{14-12} = ShiftedRm{11-9}; 342 let Inst{7-6} = ShiftedRm{8-7}; 343 } 344 345 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 346 string opc, string asm, list<dag> pattern> 347 : T2sI<oops, iops, itin, opc, asm, pattern> { 348 bits<4> Rd; 349 bits<12> ShiftedRm; 350 351 let Inst{11-8} = Rd; 352 let Inst{3-0} = ShiftedRm{3-0}; 353 let Inst{5-4} = ShiftedRm{6-5}; 354 let Inst{14-12} = ShiftedRm{11-9}; 355 let Inst{7-6} = ShiftedRm{8-7}; 356 } 357 358 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin, 359 string opc, string asm, list<dag> pattern> 360 : T2I<oops, iops, itin, opc, asm, pattern> { 361 bits<4> Rn; 362 bits<12> ShiftedRm; 363 364 let Inst{19-16} = Rn; 365 let Inst{3-0} = ShiftedRm{3-0}; 366 let Inst{5-4} = ShiftedRm{6-5}; 367 let Inst{14-12} = ShiftedRm{11-9}; 368 let Inst{7-6} = ShiftedRm{8-7}; 369 } 370 371 class T2TwoReg<dag oops, dag iops, InstrItinClass itin, 372 string opc, string asm, list<dag> pattern> 373 : T2I<oops, iops, itin, opc, asm, pattern> { 374 bits<4> Rd; 375 bits<4> Rm; 376 377 let Inst{11-8} = Rd; 378 let Inst{3-0} = Rm; 379 } 380 381 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin, 382 string opc, string asm, list<dag> pattern> 383 : T2sI<oops, iops, itin, opc, asm, pattern> { 384 bits<4> Rd; 385 bits<4> Rm; 386 387 let Inst{11-8} = Rd; 388 let Inst{3-0} = Rm; 389 } 390 391 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin, 392 string opc, string asm, list<dag> pattern> 393 : T2I<oops, iops, itin, opc, asm, pattern> { 394 bits<4> Rn; 395 bits<4> Rm; 396 397 let Inst{19-16} = Rn; 398 let Inst{3-0} = Rm; 399 } 400 401 402 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin, 403 string opc, string asm, list<dag> pattern> 404 : T2I<oops, iops, itin, opc, asm, pattern> { 405 bits<4> Rd; 406 bits<4> Rn; 407 bits<12> imm; 408 409 let Inst{11-8} = Rd; 410 let Inst{19-16} = Rn; 411 let Inst{26} = imm{11}; 412 let Inst{14-12} = imm{10-8}; 413 let Inst{7-0} = imm{7-0}; 414 } 415 416 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin, 417 string opc, string asm, list<dag> pattern> 418 : T2sI<oops, iops, itin, opc, asm, pattern> { 419 bits<4> Rd; 420 bits<4> Rn; 421 bits<12> imm; 422 423 let Inst{11-8} = Rd; 424 let Inst{19-16} = Rn; 425 let Inst{26} = imm{11}; 426 let Inst{14-12} = imm{10-8}; 427 let Inst{7-0} = imm{7-0}; 428 } 429 430 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin, 431 string opc, string asm, list<dag> pattern> 432 : T2I<oops, iops, itin, opc, asm, pattern> { 433 bits<4> Rd; 434 bits<4> Rm; 435 bits<5> imm; 436 437 let Inst{11-8} = Rd; 438 let Inst{3-0} = Rm; 439 let Inst{14-12} = imm{4-2}; 440 let Inst{7-6} = imm{1-0}; 441 } 442 443 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin, 444 string opc, string asm, list<dag> pattern> 445 : T2sI<oops, iops, itin, opc, asm, pattern> { 446 bits<4> Rd; 447 bits<4> Rm; 448 bits<5> imm; 449 450 let Inst{11-8} = Rd; 451 let Inst{3-0} = Rm; 452 let Inst{14-12} = imm{4-2}; 453 let Inst{7-6} = imm{1-0}; 454 } 455 456 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin, 457 string opc, string asm, list<dag> pattern> 458 : T2I<oops, iops, itin, opc, asm, pattern> { 459 bits<4> Rd; 460 bits<4> Rn; 461 bits<4> Rm; 462 463 let Inst{11-8} = Rd; 464 let Inst{19-16} = Rn; 465 let Inst{3-0} = Rm; 466 } 467 468 class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin, 469 string asm, list<dag> pattern> 470 : T2XI<oops, iops, itin, asm, pattern> { 471 bits<4> Rd; 472 bits<4> Rn; 473 bits<4> Rm; 474 475 let Inst{11-8} = Rd; 476 let Inst{19-16} = Rn; 477 let Inst{3-0} = Rm; 478 } 479 480 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin, 481 string opc, string asm, list<dag> pattern> 482 : T2sI<oops, iops, itin, opc, asm, pattern> { 483 bits<4> Rd; 484 bits<4> Rn; 485 bits<4> Rm; 486 487 let Inst{11-8} = Rd; 488 let Inst{19-16} = Rn; 489 let Inst{3-0} = Rm; 490 } 491 492 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 493 string opc, string asm, list<dag> pattern> 494 : T2I<oops, iops, itin, opc, asm, pattern> { 495 bits<4> Rd; 496 bits<4> Rn; 497 bits<12> ShiftedRm; 498 499 let Inst{11-8} = Rd; 500 let Inst{19-16} = Rn; 501 let Inst{3-0} = ShiftedRm{3-0}; 502 let Inst{5-4} = ShiftedRm{6-5}; 503 let Inst{14-12} = ShiftedRm{11-9}; 504 let Inst{7-6} = ShiftedRm{8-7}; 505 } 506 507 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 508 string opc, string asm, list<dag> pattern> 509 : T2sI<oops, iops, itin, opc, asm, pattern> { 510 bits<4> Rd; 511 bits<4> Rn; 512 bits<12> ShiftedRm; 513 514 let Inst{11-8} = Rd; 515 let Inst{19-16} = Rn; 516 let Inst{3-0} = ShiftedRm{3-0}; 517 let Inst{5-4} = ShiftedRm{6-5}; 518 let Inst{14-12} = ShiftedRm{11-9}; 519 let Inst{7-6} = ShiftedRm{8-7}; 520 } 521 522 class T2FourReg<dag oops, dag iops, InstrItinClass itin, 523 string opc, string asm, list<dag> pattern> 524 : T2I<oops, iops, itin, opc, asm, pattern> { 525 bits<4> Rd; 526 bits<4> Rn; 527 bits<4> Rm; 528 bits<4> Ra; 529 530 let Inst{19-16} = Rn; 531 let Inst{15-12} = Ra; 532 let Inst{11-8} = Rd; 533 let Inst{3-0} = Rm; 534 } 535 536 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4, 537 dag oops, dag iops, InstrItinClass itin, 538 string opc, string asm, list<dag> pattern> 539 : T2I<oops, iops, itin, opc, asm, pattern> { 540 bits<4> RdLo; 541 bits<4> RdHi; 542 bits<4> Rn; 543 bits<4> Rm; 544 545 let Inst{31-23} = 0b111110111; 546 let Inst{22-20} = opc22_20; 547 let Inst{19-16} = Rn; 548 let Inst{15-12} = RdLo; 549 let Inst{11-8} = RdHi; 550 let Inst{7-4} = opc7_4; 551 let Inst{3-0} = Rm; 552 } 553 class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4, 554 dag oops, dag iops, InstrItinClass itin, 555 string opc, string asm, list<dag> pattern> 556 : T2I<oops, iops, itin, opc, asm, pattern> { 557 bits<4> RdLo; 558 bits<4> RdHi; 559 bits<4> Rn; 560 bits<4> Rm; 561 562 let Inst{31-23} = 0b111110111; 563 let Inst{22-20} = opc22_20; 564 let Inst{19-16} = Rn; 565 let Inst{15-12} = RdLo; 566 let Inst{11-8} = RdHi; 567 let Inst{7-4} = opc7_4; 568 let Inst{3-0} = Rm; 569 } 570 571 572 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a 573 /// binary operation that produces a value. These are predicable and can be 574 /// changed to modify CPSR. 575 multiclass T2I_bin_irs<bits<4> opcod, string opc, 576 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 577 PatFrag opnode, bit Commutable = 0, 578 string wide = ""> { 579 // shifted imm 580 def ri : T2sTwoRegImm< 581 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii, 582 opc, "\t$Rd, $Rn, $imm", 583 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>, 584 Sched<[WriteALU, ReadALU]> { 585 let Inst{31-27} = 0b11110; 586 let Inst{25} = 0; 587 let Inst{24-21} = opcod; 588 let Inst{15} = 0; 589 } 590 // register 591 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir, 592 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"), 593 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>, 594 Sched<[WriteALU, ReadALU, ReadALU]> { 595 let isCommutable = Commutable; 596 let Inst{31-27} = 0b11101; 597 let Inst{26-25} = 0b01; 598 let Inst{24-21} = opcod; 599 let Inst{14-12} = 0b000; // imm3 600 let Inst{7-6} = 0b00; // imm2 601 let Inst{5-4} = 0b00; // type 602 } 603 // shifted register 604 def rs : T2sTwoRegShiftedReg< 605 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis, 606 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"), 607 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>, 608 Sched<[WriteALUsi, ReadALU]> { 609 let Inst{31-27} = 0b11101; 610 let Inst{26-25} = 0b01; 611 let Inst{24-21} = opcod; 612 } 613 // Assembly aliases for optional destination operand when it's the same 614 // as the source operand. 615 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"), 616 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, 617 t2_so_imm:$imm, pred:$p, 618 cc_out:$s)>; 619 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"), 620 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, 621 rGPR:$Rm, pred:$p, 622 cc_out:$s)>; 623 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"), 624 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, 625 t2_so_reg:$shift, pred:$p, 626 cc_out:$s)>; 627 } 628 629 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need 630 // the ".w" suffix to indicate that they are wide. 631 multiclass T2I_bin_w_irs<bits<4> opcod, string opc, 632 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 633 PatFrag opnode, bit Commutable = 0> : 634 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> { 635 // Assembler aliases w/ the ".w" suffix. 636 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"), 637 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, 638 cc_out:$s)>; 639 // Assembler aliases w/o the ".w" suffix. 640 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"), 641 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, 642 cc_out:$s)>; 643 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"), 644 (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift, 645 pred:$p, cc_out:$s)>; 646 647 // and with the optional destination operand, too. 648 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"), 649 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, 650 pred:$p, cc_out:$s)>; 651 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"), 652 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, 653 cc_out:$s)>; 654 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"), 655 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift, 656 pred:$p, cc_out:$s)>; 657 } 658 659 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are 660 /// reversed. The 'rr' form is only defined for the disassembler; for codegen 661 /// it is equivalent to the T2I_bin_irs counterpart. 662 multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> { 663 // shifted imm 664 def ri : T2sTwoRegImm< 665 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi, 666 opc, ".w\t$Rd, $Rn, $imm", 667 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>, 668 Sched<[WriteALU, ReadALU]> { 669 let Inst{31-27} = 0b11110; 670 let Inst{25} = 0; 671 let Inst{24-21} = opcod; 672 let Inst{15} = 0; 673 } 674 // register 675 def rr : T2sThreeReg< 676 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr, 677 opc, "\t$Rd, $Rn, $Rm", 678 [/* For disassembly only; pattern left blank */]>, 679 Sched<[WriteALU, ReadALU, ReadALU]> { 680 let Inst{31-27} = 0b11101; 681 let Inst{26-25} = 0b01; 682 let Inst{24-21} = opcod; 683 let Inst{14-12} = 0b000; // imm3 684 let Inst{7-6} = 0b00; // imm2 685 let Inst{5-4} = 0b00; // type 686 } 687 // shifted register 688 def rs : T2sTwoRegShiftedReg< 689 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), 690 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm", 691 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>, 692 Sched<[WriteALUsi, ReadALU]> { 693 let Inst{31-27} = 0b11101; 694 let Inst{26-25} = 0b01; 695 let Inst{24-21} = opcod; 696 } 697 } 698 699 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the 700 /// instruction modifies the CPSR register. 701 /// 702 /// These opcodes will be converted to the real non-S opcodes by 703 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand. 704 let hasPostISelHook = 1, Defs = [CPSR] in { 705 multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir, 706 InstrItinClass iis, PatFrag opnode, 707 bit Commutable = 0> { 708 // shifted imm 709 def ri : t2PseudoInst<(outs rGPR:$Rd), 710 (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p), 711 4, iii, 712 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn, 713 t2_so_imm:$imm))]>, 714 Sched<[WriteALU, ReadALU]>; 715 // register 716 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p), 717 4, iir, 718 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn, 719 rGPR:$Rm))]>, 720 Sched<[WriteALU, ReadALU, ReadALU]> { 721 let isCommutable = Commutable; 722 } 723 // shifted register 724 def rs : t2PseudoInst<(outs rGPR:$Rd), 725 (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p), 726 4, iis, 727 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn, 728 t2_so_reg:$ShiftedRm))]>, 729 Sched<[WriteALUsi, ReadALUsr]>; 730 } 731 } 732 733 /// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG 734 /// operands are reversed. 735 let hasPostISelHook = 1, Defs = [CPSR] in { 736 multiclass T2I_rbin_s_is<PatFrag opnode> { 737 // shifted imm 738 def ri : t2PseudoInst<(outs rGPR:$Rd), 739 (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p), 740 4, IIC_iALUi, 741 [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm, 742 rGPR:$Rn))]>, 743 Sched<[WriteALU, ReadALU]>; 744 // shifted register 745 def rs : t2PseudoInst<(outs rGPR:$Rd), 746 (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p), 747 4, IIC_iALUsi, 748 [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm, 749 rGPR:$Rn))]>, 750 Sched<[WriteALUsi, ReadALU]>; 751 } 752 } 753 754 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg}) 755 /// patterns for a binary operation that produces a value. 756 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode, 757 bit Commutable = 0> { 758 // shifted imm 759 // The register-immediate version is re-materializable. This is useful 760 // in particular for taking the address of a local. 761 let isReMaterializable = 1 in { 762 def ri : T2sTwoRegImm< 763 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi, 764 opc, ".w\t$Rd, $Rn, $imm", 765 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>, 766 Sched<[WriteALU, ReadALU]> { 767 let Inst{31-27} = 0b11110; 768 let Inst{25} = 0; 769 let Inst{24} = 1; 770 let Inst{23-21} = op23_21; 771 let Inst{15} = 0; 772 } 773 } 774 // 12-bit imm 775 def ri12 : T2I< 776 (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi, 777 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm", 778 [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>, 779 Sched<[WriteALU, ReadALU]> { 780 bits<4> Rd; 781 bits<4> Rn; 782 bits<12> imm; 783 let Inst{31-27} = 0b11110; 784 let Inst{26} = imm{11}; 785 let Inst{25-24} = 0b10; 786 let Inst{23-21} = op23_21; 787 let Inst{20} = 0; // The S bit. 788 let Inst{19-16} = Rn; 789 let Inst{15} = 0; 790 let Inst{14-12} = imm{10-8}; 791 let Inst{11-8} = Rd; 792 let Inst{7-0} = imm{7-0}; 793 } 794 // register 795 def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm), 796 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm", 797 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>, 798 Sched<[WriteALU, ReadALU, ReadALU]> { 799 let isCommutable = Commutable; 800 let Inst{31-27} = 0b11101; 801 let Inst{26-25} = 0b01; 802 let Inst{24} = 1; 803 let Inst{23-21} = op23_21; 804 let Inst{14-12} = 0b000; // imm3 805 let Inst{7-6} = 0b00; // imm2 806 let Inst{5-4} = 0b00; // type 807 } 808 // shifted register 809 def rs : T2sTwoRegShiftedReg< 810 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), 811 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm", 812 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>, 813 Sched<[WriteALUsi, ReadALU]> { 814 let Inst{31-27} = 0b11101; 815 let Inst{26-25} = 0b01; 816 let Inst{24} = 1; 817 let Inst{23-21} = op23_21; 818 } 819 } 820 821 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns 822 /// for a binary operation that produces a value and use the carry 823 /// bit. It's not predicable. 824 let Defs = [CPSR], Uses = [CPSR] in { 825 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode, 826 bit Commutable = 0> { 827 // shifted imm 828 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), 829 IIC_iALUi, opc, "\t$Rd, $Rn, $imm", 830 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>, 831 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> { 832 let Inst{31-27} = 0b11110; 833 let Inst{25} = 0; 834 let Inst{24-21} = opcod; 835 let Inst{15} = 0; 836 } 837 // register 838 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr, 839 opc, ".w\t$Rd, $Rn, $Rm", 840 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>, 841 Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> { 842 let isCommutable = Commutable; 843 let Inst{31-27} = 0b11101; 844 let Inst{26-25} = 0b01; 845 let Inst{24-21} = opcod; 846 let Inst{14-12} = 0b000; // imm3 847 let Inst{7-6} = 0b00; // imm2 848 let Inst{5-4} = 0b00; // type 849 } 850 // shifted register 851 def rs : T2sTwoRegShiftedReg< 852 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), 853 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm", 854 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>, 855 Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> { 856 let Inst{31-27} = 0b11101; 857 let Inst{26-25} = 0b01; 858 let Inst{24-21} = opcod; 859 } 860 } 861 } 862 863 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift / 864 // rotate operation that produces a value. 865 multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode> { 866 // 5-bit imm 867 def ri : T2sTwoRegShiftImm< 868 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi, 869 opc, ".w\t$Rd, $Rm, $imm", 870 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>, 871 Sched<[WriteALU]> { 872 let Inst{31-27} = 0b11101; 873 let Inst{26-21} = 0b010010; 874 let Inst{19-16} = 0b1111; // Rn 875 let Inst{5-4} = opcod; 876 } 877 // register 878 def rr : T2sThreeReg< 879 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr, 880 opc, ".w\t$Rd, $Rn, $Rm", 881 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>, 882 Sched<[WriteALU]> { 883 let Inst{31-27} = 0b11111; 884 let Inst{26-23} = 0b0100; 885 let Inst{22-21} = opcod; 886 let Inst{15-12} = 0b1111; 887 let Inst{7-4} = 0b0000; 888 } 889 890 // Optional destination register 891 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"), 892 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p, 893 cc_out:$s)>; 894 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"), 895 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, 896 cc_out:$s)>; 897 898 // Assembler aliases w/o the ".w" suffix. 899 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"), 900 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p, 901 cc_out:$s)>; 902 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"), 903 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, 904 cc_out:$s)>; 905 906 // and with the optional destination operand, too. 907 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"), 908 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p, 909 cc_out:$s)>; 910 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"), 911 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, 912 cc_out:$s)>; 913 } 914 915 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test 916 /// patterns. Similar to T2I_bin_irs except the instruction does not produce 917 /// a explicit result, only implicitly set CPSR. 918 multiclass T2I_cmp_irs<bits<4> opcod, string opc, 919 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 920 PatFrag opnode> { 921 let isCompare = 1, Defs = [CPSR] in { 922 // shifted imm 923 def ri : T2OneRegCmpImm< 924 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), iii, 925 opc, ".w\t$Rn, $imm", 926 [(opnode GPRnopc:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> { 927 let Inst{31-27} = 0b11110; 928 let Inst{25} = 0; 929 let Inst{24-21} = opcod; 930 let Inst{20} = 1; // The S bit. 931 let Inst{15} = 0; 932 let Inst{11-8} = 0b1111; // Rd 933 } 934 // register 935 def rr : T2TwoRegCmp< 936 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), iir, 937 opc, ".w\t$Rn, $Rm", 938 [(opnode GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> { 939 let Inst{31-27} = 0b11101; 940 let Inst{26-25} = 0b01; 941 let Inst{24-21} = opcod; 942 let Inst{20} = 1; // The S bit. 943 let Inst{14-12} = 0b000; // imm3 944 let Inst{11-8} = 0b1111; // Rd 945 let Inst{7-6} = 0b00; // imm2 946 let Inst{5-4} = 0b00; // type 947 } 948 // shifted register 949 def rs : T2OneRegCmpShiftedReg< 950 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), iis, 951 opc, ".w\t$Rn, $ShiftedRm", 952 [(opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>, 953 Sched<[WriteCMPsi]> { 954 let Inst{31-27} = 0b11101; 955 let Inst{26-25} = 0b01; 956 let Inst{24-21} = opcod; 957 let Inst{20} = 1; // The S bit. 958 let Inst{11-8} = 0b1111; // Rd 959 } 960 } 961 962 // Assembler aliases w/o the ".w" suffix. 963 // No alias here for 'rr' version as not all instantiations of this 964 // multiclass want one (CMP in particular, does not). 965 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"), 966 (!cast<Instruction>(NAME#"ri") GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>; 967 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"), 968 (!cast<Instruction>(NAME#"rs") GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>; 969 } 970 971 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns. 972 multiclass T2I_ld<bit signed, bits<2> opcod, string opc, 973 InstrItinClass iii, InstrItinClass iis, RegisterClass target, 974 PatFrag opnode> { 975 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii, 976 opc, ".w\t$Rt, $addr", 977 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> { 978 bits<4> Rt; 979 bits<17> addr; 980 let Inst{31-25} = 0b1111100; 981 let Inst{24} = signed; 982 let Inst{23} = 1; 983 let Inst{22-21} = opcod; 984 let Inst{20} = 1; // load 985 let Inst{19-16} = addr{16-13}; // Rn 986 let Inst{15-12} = Rt; 987 let Inst{11-0} = addr{11-0}; // imm 988 989 let DecoderMethod = "DecodeT2LoadImm12"; 990 } 991 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii, 992 opc, "\t$Rt, $addr", 993 [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]> { 994 bits<4> Rt; 995 bits<13> addr; 996 let Inst{31-27} = 0b11111; 997 let Inst{26-25} = 0b00; 998 let Inst{24} = signed; 999 let Inst{23} = 0; 1000 let Inst{22-21} = opcod; 1001 let Inst{20} = 1; // load 1002 let Inst{19-16} = addr{12-9}; // Rn 1003 let Inst{15-12} = Rt; 1004 let Inst{11} = 1; 1005 // Offset: index==TRUE, wback==FALSE 1006 let Inst{10} = 1; // The P bit. 1007 let Inst{9} = addr{8}; // U 1008 let Inst{8} = 0; // The W bit. 1009 let Inst{7-0} = addr{7-0}; // imm 1010 1011 let DecoderMethod = "DecodeT2LoadImm8"; 1012 } 1013 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis, 1014 opc, ".w\t$Rt, $addr", 1015 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> { 1016 let Inst{31-27} = 0b11111; 1017 let Inst{26-25} = 0b00; 1018 let Inst{24} = signed; 1019 let Inst{23} = 0; 1020 let Inst{22-21} = opcod; 1021 let Inst{20} = 1; // load 1022 let Inst{11-6} = 0b000000; 1023 1024 bits<4> Rt; 1025 let Inst{15-12} = Rt; 1026 1027 bits<10> addr; 1028 let Inst{19-16} = addr{9-6}; // Rn 1029 let Inst{3-0} = addr{5-2}; // Rm 1030 let Inst{5-4} = addr{1-0}; // imm 1031 1032 let DecoderMethod = "DecodeT2LoadShift"; 1033 } 1034 1035 // pci variant is very similar to i12, but supports negative offsets 1036 // from the PC. 1037 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii, 1038 opc, ".w\t$Rt, $addr", 1039 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> { 1040 let isReMaterializable = 1; 1041 let Inst{31-27} = 0b11111; 1042 let Inst{26-25} = 0b00; 1043 let Inst{24} = signed; 1044 let Inst{22-21} = opcod; 1045 let Inst{20} = 1; // load 1046 let Inst{19-16} = 0b1111; // Rn 1047 1048 bits<4> Rt; 1049 let Inst{15-12} = Rt{3-0}; 1050 1051 bits<13> addr; 1052 let Inst{23} = addr{12}; // add = (U == '1') 1053 let Inst{11-0} = addr{11-0}; 1054 1055 let DecoderMethod = "DecodeT2LoadLabel"; 1056 } 1057 } 1058 1059 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns. 1060 multiclass T2I_st<bits<2> opcod, string opc, 1061 InstrItinClass iii, InstrItinClass iis, RegisterClass target, 1062 PatFrag opnode> { 1063 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii, 1064 opc, ".w\t$Rt, $addr", 1065 [(opnode target:$Rt, t2addrmode_imm12:$addr)]> { 1066 let Inst{31-27} = 0b11111; 1067 let Inst{26-23} = 0b0001; 1068 let Inst{22-21} = opcod; 1069 let Inst{20} = 0; // !load 1070 1071 bits<4> Rt; 1072 let Inst{15-12} = Rt; 1073 1074 bits<17> addr; 1075 let addr{12} = 1; // add = TRUE 1076 let Inst{19-16} = addr{16-13}; // Rn 1077 let Inst{23} = addr{12}; // U 1078 let Inst{11-0} = addr{11-0}; // imm 1079 } 1080 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii, 1081 opc, "\t$Rt, $addr", 1082 [(opnode target:$Rt, t2addrmode_negimm8:$addr)]> { 1083 let Inst{31-27} = 0b11111; 1084 let Inst{26-23} = 0b0000; 1085 let Inst{22-21} = opcod; 1086 let Inst{20} = 0; // !load 1087 let Inst{11} = 1; 1088 // Offset: index==TRUE, wback==FALSE 1089 let Inst{10} = 1; // The P bit. 1090 let Inst{8} = 0; // The W bit. 1091 1092 bits<4> Rt; 1093 let Inst{15-12} = Rt; 1094 1095 bits<13> addr; 1096 let Inst{19-16} = addr{12-9}; // Rn 1097 let Inst{9} = addr{8}; // U 1098 let Inst{7-0} = addr{7-0}; // imm 1099 } 1100 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis, 1101 opc, ".w\t$Rt, $addr", 1102 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> { 1103 let Inst{31-27} = 0b11111; 1104 let Inst{26-23} = 0b0000; 1105 let Inst{22-21} = opcod; 1106 let Inst{20} = 0; // !load 1107 let Inst{11-6} = 0b000000; 1108 1109 bits<4> Rt; 1110 let Inst{15-12} = Rt; 1111 1112 bits<10> addr; 1113 let Inst{19-16} = addr{9-6}; // Rn 1114 let Inst{3-0} = addr{5-2}; // Rm 1115 let Inst{5-4} = addr{1-0}; // imm 1116 } 1117 } 1118 1119 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a 1120 /// register and one whose operand is a register rotated by 8/16/24. 1121 class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> 1122 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr, 1123 opc, ".w\t$Rd, $Rm$rot", 1124 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>, 1125 Requires<[IsThumb2]> { 1126 let Inst{31-27} = 0b11111; 1127 let Inst{26-23} = 0b0100; 1128 let Inst{22-20} = opcod; 1129 let Inst{19-16} = 0b1111; // Rn 1130 let Inst{15-12} = 0b1111; 1131 let Inst{7} = 1; 1132 1133 bits<2> rot; 1134 let Inst{5-4} = rot{1-0}; // rotate 1135 } 1136 1137 // UXTB16 - Requres T2ExtractPack, does not need the .w qualifier. 1138 class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> 1139 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), 1140 IIC_iEXTr, opc, "\t$Rd, $Rm$rot", 1141 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>, 1142 Requires<[HasT2ExtractPack, IsThumb2]> { 1143 bits<2> rot; 1144 let Inst{31-27} = 0b11111; 1145 let Inst{26-23} = 0b0100; 1146 let Inst{22-20} = opcod; 1147 let Inst{19-16} = 0b1111; // Rn 1148 let Inst{15-12} = 0b1111; 1149 let Inst{7} = 1; 1150 let Inst{5-4} = rot; 1151 } 1152 1153 // SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern 1154 // supported yet. 1155 class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> 1156 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr, 1157 opc, "\t$Rd, $Rm$rot", []>, 1158 Requires<[IsThumb2, HasT2ExtractPack]> { 1159 bits<2> rot; 1160 let Inst{31-27} = 0b11111; 1161 let Inst{26-23} = 0b0100; 1162 let Inst{22-20} = opcod; 1163 let Inst{19-16} = 0b1111; // Rn 1164 let Inst{15-12} = 0b1111; 1165 let Inst{7} = 1; 1166 let Inst{5-4} = rot; 1167 } 1168 1169 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a 1170 /// register and one whose operand is a register rotated by 8/16/24. 1171 class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> 1172 : T2ThreeReg<(outs rGPR:$Rd), 1173 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot), 1174 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", 1175 [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>, 1176 Requires<[HasT2ExtractPack, IsThumb2]> { 1177 bits<2> rot; 1178 let Inst{31-27} = 0b11111; 1179 let Inst{26-23} = 0b0100; 1180 let Inst{22-20} = opcod; 1181 let Inst{15-12} = 0b1111; 1182 let Inst{7} = 1; 1183 let Inst{5-4} = rot; 1184 } 1185 1186 class T2I_exta_rrot_np<bits<3> opcod, string opc> 1187 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot), 1188 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []> { 1189 bits<2> rot; 1190 let Inst{31-27} = 0b11111; 1191 let Inst{26-23} = 0b0100; 1192 let Inst{22-20} = opcod; 1193 let Inst{15-12} = 0b1111; 1194 let Inst{7} = 1; 1195 let Inst{5-4} = rot; 1196 } 1197 1198 //===----------------------------------------------------------------------===// 1199 // Instructions 1200 //===----------------------------------------------------------------------===// 1201 1202 //===----------------------------------------------------------------------===// 1203 // Miscellaneous Instructions. 1204 // 1205 1206 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin, 1207 string asm, list<dag> pattern> 1208 : T2XI<oops, iops, itin, asm, pattern> { 1209 bits<4> Rd; 1210 bits<12> label; 1211 1212 let Inst{11-8} = Rd; 1213 let Inst{26} = label{11}; 1214 let Inst{14-12} = label{10-8}; 1215 let Inst{7-0} = label{7-0}; 1216 } 1217 1218 // LEApcrel - Load a pc-relative address into a register without offending the 1219 // assembler. 1220 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd), 1221 (ins t2adrlabel:$addr, pred:$p), 1222 IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>, 1223 Sched<[WriteALU, ReadALU]> { 1224 let Inst{31-27} = 0b11110; 1225 let Inst{25-24} = 0b10; 1226 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE) 1227 let Inst{22} = 0; 1228 let Inst{20} = 0; 1229 let Inst{19-16} = 0b1111; // Rn 1230 let Inst{15} = 0; 1231 1232 bits<4> Rd; 1233 bits<13> addr; 1234 let Inst{11-8} = Rd; 1235 let Inst{23} = addr{12}; 1236 let Inst{21} = addr{12}; 1237 let Inst{26} = addr{11}; 1238 let Inst{14-12} = addr{10-8}; 1239 let Inst{7-0} = addr{7-0}; 1240 1241 let DecoderMethod = "DecodeT2Adr"; 1242 } 1243 1244 let neverHasSideEffects = 1, isReMaterializable = 1 in 1245 def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p), 1246 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>; 1247 let hasSideEffects = 1 in 1248 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd), 1249 (ins i32imm:$label, nohash_imm:$id, pred:$p), 1250 4, IIC_iALUi, 1251 []>, Sched<[WriteALU, ReadALU]>; 1252 1253 1254 //===----------------------------------------------------------------------===// 1255 // Load / store Instructions. 1256 // 1257 1258 // Load 1259 let canFoldAsLoad = 1, isReMaterializable = 1 in 1260 defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, 1261 UnOpFrag<(load node:$Src)>>; 1262 1263 // Loads with zero extension 1264 defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1265 GPR, UnOpFrag<(zextloadi16 node:$Src)>>; 1266 defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1267 GPR, UnOpFrag<(zextloadi8 node:$Src)>>; 1268 1269 // Loads with sign extension 1270 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1271 GPR, UnOpFrag<(sextloadi16 node:$Src)>>; 1272 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1273 GPR, UnOpFrag<(sextloadi8 node:$Src)>>; 1274 1275 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in { 1276 // Load doubleword 1277 def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2), 1278 (ins t2addrmode_imm8s4:$addr), 1279 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>; 1280 } // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 1281 1282 // zextload i1 -> zextload i8 1283 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr), 1284 (t2LDRBi12 t2addrmode_imm12:$addr)>; 1285 def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr), 1286 (t2LDRBi8 t2addrmode_negimm8:$addr)>; 1287 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr), 1288 (t2LDRBs t2addrmode_so_reg:$addr)>; 1289 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)), 1290 (t2LDRBpci tconstpool:$addr)>; 1291 1292 // extload -> zextload 1293 // FIXME: Reduce the number of patterns by legalizing extload to zextload 1294 // earlier? 1295 def : T2Pat<(extloadi1 t2addrmode_imm12:$addr), 1296 (t2LDRBi12 t2addrmode_imm12:$addr)>; 1297 def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr), 1298 (t2LDRBi8 t2addrmode_negimm8:$addr)>; 1299 def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr), 1300 (t2LDRBs t2addrmode_so_reg:$addr)>; 1301 def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)), 1302 (t2LDRBpci tconstpool:$addr)>; 1303 1304 def : T2Pat<(extloadi8 t2addrmode_imm12:$addr), 1305 (t2LDRBi12 t2addrmode_imm12:$addr)>; 1306 def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr), 1307 (t2LDRBi8 t2addrmode_negimm8:$addr)>; 1308 def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr), 1309 (t2LDRBs t2addrmode_so_reg:$addr)>; 1310 def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)), 1311 (t2LDRBpci tconstpool:$addr)>; 1312 1313 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr), 1314 (t2LDRHi12 t2addrmode_imm12:$addr)>; 1315 def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr), 1316 (t2LDRHi8 t2addrmode_negimm8:$addr)>; 1317 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr), 1318 (t2LDRHs t2addrmode_so_reg:$addr)>; 1319 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)), 1320 (t2LDRHpci tconstpool:$addr)>; 1321 1322 // FIXME: The destination register of the loads and stores can't be PC, but 1323 // can be SP. We need another regclass (similar to rGPR) to represent 1324 // that. Not a pressing issue since these are selected manually, 1325 // not via pattern. 1326 1327 // Indexed loads 1328 1329 let mayLoad = 1, neverHasSideEffects = 1 in { 1330 def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb), 1331 (ins t2addrmode_imm8_pre:$addr), 1332 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu, 1333 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>; 1334 1335 def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb), 1336 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset), 1337 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu, 1338 "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>; 1339 1340 def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb), 1341 (ins t2addrmode_imm8_pre:$addr), 1342 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1343 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>; 1344 1345 def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb), 1346 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset), 1347 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1348 "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>; 1349 1350 def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb), 1351 (ins t2addrmode_imm8_pre:$addr), 1352 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1353 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>; 1354 1355 def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb), 1356 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset), 1357 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1358 "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>; 1359 1360 def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb), 1361 (ins t2addrmode_imm8_pre:$addr), 1362 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1363 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", 1364 []>; 1365 1366 def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb), 1367 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset), 1368 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1369 "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>; 1370 1371 def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb), 1372 (ins t2addrmode_imm8_pre:$addr), 1373 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1374 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", 1375 []>; 1376 1377 def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb), 1378 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset), 1379 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1380 "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>; 1381 } // mayLoad = 1, neverHasSideEffects = 1 1382 1383 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110). 1384 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4 1385 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii> 1386 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc, 1387 "\t$Rt, $addr", []> { 1388 bits<4> Rt; 1389 bits<13> addr; 1390 let Inst{31-27} = 0b11111; 1391 let Inst{26-25} = 0b00; 1392 let Inst{24} = signed; 1393 let Inst{23} = 0; 1394 let Inst{22-21} = type; 1395 let Inst{20} = 1; // load 1396 let Inst{19-16} = addr{12-9}; 1397 let Inst{15-12} = Rt; 1398 let Inst{11} = 1; 1399 let Inst{10-8} = 0b110; // PUW. 1400 let Inst{7-0} = addr{7-0}; 1401 1402 let DecoderMethod = "DecodeT2LoadT"; 1403 } 1404 1405 def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>; 1406 def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>; 1407 def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>; 1408 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>; 1409 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>; 1410 1411 class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops, 1412 string opc, string asm, list<dag> pattern> 1413 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, 1414 opc, asm, "", pattern>, Requires<[IsThumb, HasV8]> { 1415 bits<4> Rt; 1416 bits<4> addr; 1417 1418 let Inst{31-27} = 0b11101; 1419 let Inst{26-24} = 0b000; 1420 let Inst{23-20} = bits23_20; 1421 let Inst{11-6} = 0b111110; 1422 let Inst{5-4} = bit54; 1423 let Inst{3-0} = 0b1111; 1424 1425 // Encode instruction operands 1426 let Inst{19-16} = addr; 1427 let Inst{15-12} = Rt; 1428 } 1429 1430 def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt), 1431 (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>; 1432 def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt), 1433 (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>; 1434 def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt), 1435 (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>; 1436 1437 // Store 1438 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, 1439 BinOpFrag<(store node:$LHS, node:$RHS)>>; 1440 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si, 1441 rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>; 1442 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si, 1443 rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>; 1444 1445 // Store doubleword 1446 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in 1447 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs), 1448 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr), 1449 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>; 1450 1451 // Indexed stores 1452 1453 let mayStore = 1, neverHasSideEffects = 1 in { 1454 def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb), 1455 (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr), 1456 AddrModeT2_i8, IndexModePre, IIC_iStore_iu, 1457 "str", "\t$Rt, $addr!", 1458 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>; 1459 1460 def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb), 1461 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr), 1462 AddrModeT2_i8, IndexModePre, IIC_iStore_iu, 1463 "strh", "\t$Rt, $addr!", 1464 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>; 1465 1466 def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb), 1467 (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr), 1468 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu, 1469 "strb", "\t$Rt, $addr!", 1470 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>; 1471 } // mayStore = 1, neverHasSideEffects = 1 1472 1473 def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb), 1474 (ins GPRnopc:$Rt, addr_offset_none:$Rn, 1475 t2am_imm8_offset:$offset), 1476 AddrModeT2_i8, IndexModePost, IIC_iStore_iu, 1477 "str", "\t$Rt, $Rn$offset", 1478 "$Rn = $Rn_wb,@earlyclobber $Rn_wb", 1479 [(set GPRnopc:$Rn_wb, 1480 (post_store GPRnopc:$Rt, addr_offset_none:$Rn, 1481 t2am_imm8_offset:$offset))]>; 1482 1483 def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb), 1484 (ins rGPR:$Rt, addr_offset_none:$Rn, 1485 t2am_imm8_offset:$offset), 1486 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu, 1487 "strh", "\t$Rt, $Rn$offset", 1488 "$Rn = $Rn_wb,@earlyclobber $Rn_wb", 1489 [(set GPRnopc:$Rn_wb, 1490 (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn, 1491 t2am_imm8_offset:$offset))]>; 1492 1493 def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb), 1494 (ins rGPR:$Rt, addr_offset_none:$Rn, 1495 t2am_imm8_offset:$offset), 1496 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu, 1497 "strb", "\t$Rt, $Rn$offset", 1498 "$Rn = $Rn_wb,@earlyclobber $Rn_wb", 1499 [(set GPRnopc:$Rn_wb, 1500 (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn, 1501 t2am_imm8_offset:$offset))]>; 1502 1503 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't 1504 // put the patterns on the instruction definitions directly as ISel wants 1505 // the address base and offset to be separate operands, not a single 1506 // complex operand like we represent the instructions themselves. The 1507 // pseudos map between the two. 1508 let usesCustomInserter = 1, 1509 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in { 1510 def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb), 1511 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p), 1512 4, IIC_iStore_ru, 1513 [(set GPRnopc:$Rn_wb, 1514 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>; 1515 def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb), 1516 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p), 1517 4, IIC_iStore_ru, 1518 [(set GPRnopc:$Rn_wb, 1519 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>; 1520 def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb), 1521 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p), 1522 4, IIC_iStore_ru, 1523 [(set GPRnopc:$Rn_wb, 1524 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>; 1525 } 1526 1527 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly 1528 // only. 1529 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4 1530 class T2IstT<bits<2> type, string opc, InstrItinClass ii> 1531 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc, 1532 "\t$Rt, $addr", []> { 1533 let Inst{31-27} = 0b11111; 1534 let Inst{26-25} = 0b00; 1535 let Inst{24} = 0; // not signed 1536 let Inst{23} = 0; 1537 let Inst{22-21} = type; 1538 let Inst{20} = 0; // store 1539 let Inst{11} = 1; 1540 let Inst{10-8} = 0b110; // PUW 1541 1542 bits<4> Rt; 1543 bits<13> addr; 1544 let Inst{15-12} = Rt; 1545 let Inst{19-16} = addr{12-9}; 1546 let Inst{7-0} = addr{7-0}; 1547 } 1548 1549 def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>; 1550 def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>; 1551 def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>; 1552 1553 // ldrd / strd pre / post variants 1554 // For disassembly only. 1555 1556 def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb), 1557 (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru, 1558 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []> { 1559 let DecoderMethod = "DecodeT2LDRDPreInstruction"; 1560 } 1561 1562 def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb), 1563 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm), 1564 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm", 1565 "$addr.base = $wb", []>; 1566 1567 def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb), 1568 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr), 1569 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!", 1570 "$addr.base = $wb", []> { 1571 let DecoderMethod = "DecodeT2STRDPreInstruction"; 1572 } 1573 1574 def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb), 1575 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr, 1576 t2am_imm8s4_offset:$imm), 1577 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm", 1578 "$addr.base = $wb", []>; 1579 1580 class T2Istrrel<bits<2> bit54, dag oops, dag iops, 1581 string opc, string asm, list<dag> pattern> 1582 : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc, 1583 asm, "", pattern>, Requires<[IsThumb, HasV8]> { 1584 bits<4> Rt; 1585 bits<4> addr; 1586 1587 let Inst{31-27} = 0b11101; 1588 let Inst{26-20} = 0b0001100; 1589 let Inst{11-6} = 0b111110; 1590 let Inst{5-4} = bit54; 1591 let Inst{3-0} = 0b1111; 1592 1593 // Encode instruction operands 1594 let Inst{19-16} = addr; 1595 let Inst{15-12} = Rt; 1596 } 1597 1598 def t2STL : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr), 1599 "stl", "\t$Rt, $addr", []>; 1600 def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr), 1601 "stlb", "\t$Rt, $addr", []>; 1602 def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr), 1603 "stlh", "\t$Rt, $addr", []>; 1604 1605 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future 1606 // data/instruction access. 1607 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0), 1608 // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1). 1609 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> { 1610 1611 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc, 1612 "\t$addr", 1613 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>, 1614 Sched<[WritePreLd]> { 1615 let Inst{31-25} = 0b1111100; 1616 let Inst{24} = instr; 1617 let Inst{23} = 1; 1618 let Inst{22} = 0; 1619 let Inst{21} = write; 1620 let Inst{20} = 1; 1621 let Inst{15-12} = 0b1111; 1622 1623 bits<17> addr; 1624 let Inst{19-16} = addr{16-13}; // Rn 1625 let Inst{11-0} = addr{11-0}; // imm12 1626 1627 let DecoderMethod = "DecodeT2LoadImm12"; 1628 } 1629 1630 def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc, 1631 "\t$addr", 1632 [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>, 1633 Sched<[WritePreLd]> { 1634 let Inst{31-25} = 0b1111100; 1635 let Inst{24} = instr; 1636 let Inst{23} = 0; // U = 0 1637 let Inst{22} = 0; 1638 let Inst{21} = write; 1639 let Inst{20} = 1; 1640 let Inst{15-12} = 0b1111; 1641 let Inst{11-8} = 0b1100; 1642 1643 bits<13> addr; 1644 let Inst{19-16} = addr{12-9}; // Rn 1645 let Inst{7-0} = addr{7-0}; // imm8 1646 1647 let DecoderMethod = "DecodeT2LoadImm8"; 1648 } 1649 1650 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc, 1651 "\t$addr", 1652 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>, 1653 Sched<[WritePreLd]> { 1654 let Inst{31-25} = 0b1111100; 1655 let Inst{24} = instr; 1656 let Inst{23} = 0; // add = TRUE for T1 1657 let Inst{22} = 0; 1658 let Inst{21} = write; 1659 let Inst{20} = 1; 1660 let Inst{15-12} = 0b1111; 1661 let Inst{11-6} = 0b000000; 1662 1663 bits<10> addr; 1664 let Inst{19-16} = addr{9-6}; // Rn 1665 let Inst{3-0} = addr{5-2}; // Rm 1666 let Inst{5-4} = addr{1-0}; // imm2 1667 1668 let DecoderMethod = "DecodeT2LoadShift"; 1669 } 1670 } 1671 1672 defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>; 1673 defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>; 1674 defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>; 1675 1676 // pci variant is very similar to i12, but supports negative offsets 1677 // from the PC. Only PLD and PLI have pci variants (not PLDW) 1678 class T2Iplpci<bits<1> inst, string opc> : T2Iso<(outs), (ins t2ldrlabel:$addr), 1679 IIC_Preload, opc, "\t$addr", 1680 [(ARMPreload (ARMWrapper tconstpool:$addr), 1681 (i32 0), (i32 inst))]>, Sched<[WritePreLd]> { 1682 let Inst{31-25} = 0b1111100; 1683 let Inst{24} = inst; 1684 let Inst{22-20} = 0b001; 1685 let Inst{19-16} = 0b1111; 1686 let Inst{15-12} = 0b1111; 1687 1688 bits<13> addr; 1689 let Inst{23} = addr{12}; // add = (U == '1') 1690 let Inst{11-0} = addr{11-0}; // imm12 1691 1692 let DecoderMethod = "DecodeT2LoadLabel"; 1693 } 1694 1695 def t2PLDpci : T2Iplpci<0, "pld">, Requires<[IsThumb2]>; 1696 def t2PLIpci : T2Iplpci<1, "pli">, Requires<[IsThumb2,HasV7]>; 1697 1698 //===----------------------------------------------------------------------===// 1699 // Load / store multiple Instructions. 1700 // 1701 1702 multiclass thumb2_ld_mult<string asm, InstrItinClass itin, 1703 InstrItinClass itin_upd, bit L_bit> { 1704 def IA : 1705 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1706 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> { 1707 bits<4> Rn; 1708 bits<16> regs; 1709 1710 let Inst{31-27} = 0b11101; 1711 let Inst{26-25} = 0b00; 1712 let Inst{24-23} = 0b01; // Increment After 1713 let Inst{22} = 0; 1714 let Inst{21} = 0; // No writeback 1715 let Inst{20} = L_bit; 1716 let Inst{19-16} = Rn; 1717 let Inst{15-0} = regs; 1718 } 1719 def IA_UPD : 1720 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1721 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> { 1722 bits<4> Rn; 1723 bits<16> regs; 1724 1725 let Inst{31-27} = 0b11101; 1726 let Inst{26-25} = 0b00; 1727 let Inst{24-23} = 0b01; // Increment After 1728 let Inst{22} = 0; 1729 let Inst{21} = 1; // Writeback 1730 let Inst{20} = L_bit; 1731 let Inst{19-16} = Rn; 1732 let Inst{15-0} = regs; 1733 } 1734 def DB : 1735 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1736 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> { 1737 bits<4> Rn; 1738 bits<16> regs; 1739 1740 let Inst{31-27} = 0b11101; 1741 let Inst{26-25} = 0b00; 1742 let Inst{24-23} = 0b10; // Decrement Before 1743 let Inst{22} = 0; 1744 let Inst{21} = 0; // No writeback 1745 let Inst{20} = L_bit; 1746 let Inst{19-16} = Rn; 1747 let Inst{15-0} = regs; 1748 } 1749 def DB_UPD : 1750 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1751 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> { 1752 bits<4> Rn; 1753 bits<16> regs; 1754 1755 let Inst{31-27} = 0b11101; 1756 let Inst{26-25} = 0b00; 1757 let Inst{24-23} = 0b10; // Decrement Before 1758 let Inst{22} = 0; 1759 let Inst{21} = 1; // Writeback 1760 let Inst{20} = L_bit; 1761 let Inst{19-16} = Rn; 1762 let Inst{15-0} = regs; 1763 } 1764 } 1765 1766 let neverHasSideEffects = 1 in { 1767 1768 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in 1769 defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>; 1770 1771 multiclass thumb2_st_mult<string asm, InstrItinClass itin, 1772 InstrItinClass itin_upd, bit L_bit> { 1773 def IA : 1774 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1775 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> { 1776 bits<4> Rn; 1777 bits<16> regs; 1778 1779 let Inst{31-27} = 0b11101; 1780 let Inst{26-25} = 0b00; 1781 let Inst{24-23} = 0b01; // Increment After 1782 let Inst{22} = 0; 1783 let Inst{21} = 0; // No writeback 1784 let Inst{20} = L_bit; 1785 let Inst{19-16} = Rn; 1786 let Inst{15} = 0; 1787 let Inst{14} = regs{14}; 1788 let Inst{13} = 0; 1789 let Inst{12-0} = regs{12-0}; 1790 } 1791 def IA_UPD : 1792 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1793 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> { 1794 bits<4> Rn; 1795 bits<16> regs; 1796 1797 let Inst{31-27} = 0b11101; 1798 let Inst{26-25} = 0b00; 1799 let Inst{24-23} = 0b01; // Increment After 1800 let Inst{22} = 0; 1801 let Inst{21} = 1; // Writeback 1802 let Inst{20} = L_bit; 1803 let Inst{19-16} = Rn; 1804 let Inst{15} = 0; 1805 let Inst{14} = regs{14}; 1806 let Inst{13} = 0; 1807 let Inst{12-0} = regs{12-0}; 1808 } 1809 def DB : 1810 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1811 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> { 1812 bits<4> Rn; 1813 bits<16> regs; 1814 1815 let Inst{31-27} = 0b11101; 1816 let Inst{26-25} = 0b00; 1817 let Inst{24-23} = 0b10; // Decrement Before 1818 let Inst{22} = 0; 1819 let Inst{21} = 0; // No writeback 1820 let Inst{20} = L_bit; 1821 let Inst{19-16} = Rn; 1822 let Inst{15} = 0; 1823 let Inst{14} = regs{14}; 1824 let Inst{13} = 0; 1825 let Inst{12-0} = regs{12-0}; 1826 } 1827 def DB_UPD : 1828 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1829 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> { 1830 bits<4> Rn; 1831 bits<16> regs; 1832 1833 let Inst{31-27} = 0b11101; 1834 let Inst{26-25} = 0b00; 1835 let Inst{24-23} = 0b10; // Decrement Before 1836 let Inst{22} = 0; 1837 let Inst{21} = 1; // Writeback 1838 let Inst{20} = L_bit; 1839 let Inst{19-16} = Rn; 1840 let Inst{15} = 0; 1841 let Inst{14} = regs{14}; 1842 let Inst{13} = 0; 1843 let Inst{12-0} = regs{12-0}; 1844 } 1845 } 1846 1847 1848 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in 1849 defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>; 1850 1851 } // neverHasSideEffects 1852 1853 1854 //===----------------------------------------------------------------------===// 1855 // Move Instructions. 1856 // 1857 1858 let neverHasSideEffects = 1 in 1859 def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPR:$Rm), IIC_iMOVr, 1860 "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> { 1861 let Inst{31-27} = 0b11101; 1862 let Inst{26-25} = 0b01; 1863 let Inst{24-21} = 0b0010; 1864 let Inst{19-16} = 0b1111; // Rn 1865 let Inst{14-12} = 0b000; 1866 let Inst{7-4} = 0b0000; 1867 } 1868 def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm, 1869 pred:$p, zero_reg)>; 1870 def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm, 1871 pred:$p, CPSR)>; 1872 def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm, 1873 pred:$p, CPSR)>; 1874 1875 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16. 1876 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1, 1877 AddedComplexity = 1 in 1878 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi, 1879 "mov", ".w\t$Rd, $imm", 1880 [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> { 1881 let Inst{31-27} = 0b11110; 1882 let Inst{25} = 0; 1883 let Inst{24-21} = 0b0010; 1884 let Inst{19-16} = 0b1111; // Rn 1885 let Inst{15} = 0; 1886 } 1887 1888 // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'. 1889 // Use aliases to get that to play nice here. 1890 def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm, 1891 pred:$p, CPSR)>; 1892 def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm, 1893 pred:$p, CPSR)>; 1894 1895 def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm, 1896 pred:$p, zero_reg)>; 1897 def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm, 1898 pred:$p, zero_reg)>; 1899 1900 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in 1901 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi, 1902 "movw", "\t$Rd, $imm", 1903 [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]> { 1904 let Inst{31-27} = 0b11110; 1905 let Inst{25} = 1; 1906 let Inst{24-21} = 0b0010; 1907 let Inst{20} = 0; // The S bit. 1908 let Inst{15} = 0; 1909 1910 bits<4> Rd; 1911 bits<16> imm; 1912 1913 let Inst{11-8} = Rd; 1914 let Inst{19-16} = imm{15-12}; 1915 let Inst{26} = imm{11}; 1916 let Inst{14-12} = imm{10-8}; 1917 let Inst{7-0} = imm{7-0}; 1918 let DecoderMethod = "DecodeT2MOVTWInstruction"; 1919 } 1920 1921 def : t2InstAlias<"mov${p} $Rd, $imm", 1922 (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p)>; 1923 1924 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd), 1925 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>; 1926 1927 let Constraints = "$src = $Rd" in { 1928 def t2MOVTi16 : T2I<(outs rGPR:$Rd), 1929 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi, 1930 "movt", "\t$Rd, $imm", 1931 [(set rGPR:$Rd, 1932 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>, 1933 Sched<[WriteALU]> { 1934 let Inst{31-27} = 0b11110; 1935 let Inst{25} = 1; 1936 let Inst{24-21} = 0b0110; 1937 let Inst{20} = 0; // The S bit. 1938 let Inst{15} = 0; 1939 1940 bits<4> Rd; 1941 bits<16> imm; 1942 1943 let Inst{11-8} = Rd; 1944 let Inst{19-16} = imm{15-12}; 1945 let Inst{26} = imm{11}; 1946 let Inst{14-12} = imm{10-8}; 1947 let Inst{7-0} = imm{7-0}; 1948 let DecoderMethod = "DecodeT2MOVTWInstruction"; 1949 } 1950 1951 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd), 1952 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>, 1953 Sched<[WriteALU]>; 1954 } // Constraints 1955 1956 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>; 1957 1958 //===----------------------------------------------------------------------===// 1959 // Extend Instructions. 1960 // 1961 1962 // Sign extenders 1963 1964 def t2SXTB : T2I_ext_rrot<0b100, "sxtb", 1965 UnOpFrag<(sext_inreg node:$Src, i8)>>; 1966 def t2SXTH : T2I_ext_rrot<0b000, "sxth", 1967 UnOpFrag<(sext_inreg node:$Src, i16)>>; 1968 def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">; 1969 1970 def t2SXTAB : T2I_exta_rrot<0b100, "sxtab", 1971 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>; 1972 def t2SXTAH : T2I_exta_rrot<0b000, "sxtah", 1973 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>; 1974 def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">; 1975 1976 // Zero extenders 1977 1978 let AddedComplexity = 16 in { 1979 def t2UXTB : T2I_ext_rrot<0b101, "uxtb", 1980 UnOpFrag<(and node:$Src, 0x000000FF)>>; 1981 def t2UXTH : T2I_ext_rrot<0b001, "uxth", 1982 UnOpFrag<(and node:$Src, 0x0000FFFF)>>; 1983 def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16", 1984 UnOpFrag<(and node:$Src, 0x00FF00FF)>>; 1985 1986 // FIXME: This pattern incorrectly assumes the shl operator is a rotate. 1987 // The transformation should probably be done as a combiner action 1988 // instead so we can include a check for masking back in the upper 1989 // eight bits of the source into the lower eight bits of the result. 1990 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF), 1991 // (t2UXTB16 rGPR:$Src, 3)>, 1992 // Requires<[HasT2ExtractPack, IsThumb2]>; 1993 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF), 1994 (t2UXTB16 rGPR:$Src, 1)>, 1995 Requires<[HasT2ExtractPack, IsThumb2]>; 1996 1997 def t2UXTAB : T2I_exta_rrot<0b101, "uxtab", 1998 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>; 1999 def t2UXTAH : T2I_exta_rrot<0b001, "uxtah", 2000 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>; 2001 def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">; 2002 } 2003 2004 //===----------------------------------------------------------------------===// 2005 // Arithmetic Instructions. 2006 // 2007 2008 defm t2ADD : T2I_bin_ii12rs<0b000, "add", 2009 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>; 2010 defm t2SUB : T2I_bin_ii12rs<0b101, "sub", 2011 BinOpFrag<(sub node:$LHS, node:$RHS)>>; 2012 2013 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants. 2014 // 2015 // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the 2016 // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by 2017 // AdjustInstrPostInstrSelection where we determine whether or not to 2018 // set the "s" bit based on CPSR liveness. 2019 // 2020 // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen 2021 // support for an optional CPSR definition that corresponds to the DAG 2022 // node's second value. We can then eliminate the implicit def of CPSR. 2023 defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, 2024 BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>; 2025 defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, 2026 BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>; 2027 2028 let hasPostISelHook = 1 in { 2029 defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", 2030 BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>, 1>; 2031 defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", 2032 BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>; 2033 } 2034 2035 // RSB 2036 defm t2RSB : T2I_rbin_irs <0b1110, "rsb", 2037 BinOpFrag<(sub node:$LHS, node:$RHS)>>; 2038 2039 // FIXME: Eliminate them if we can write def : Pat patterns which defines 2040 // CPSR and the implicit def of CPSR is not needed. 2041 defm t2RSBS : T2I_rbin_s_is <BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>; 2042 2043 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form. 2044 // The assume-no-carry-in form uses the negation of the input since add/sub 2045 // assume opposite meanings of the carry flag (i.e., carry == !borrow). 2046 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory 2047 // details. 2048 // The AddedComplexity preferences the first variant over the others since 2049 // it can be shrunk to a 16-bit wide encoding, while the others cannot. 2050 let AddedComplexity = 1 in 2051 def : T2Pat<(add GPR:$src, imm1_255_neg:$imm), 2052 (t2SUBri GPR:$src, imm1_255_neg:$imm)>; 2053 def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm), 2054 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>; 2055 def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm), 2056 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>; 2057 def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm), 2058 (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>; 2059 2060 let AddedComplexity = 1 in 2061 def : T2Pat<(ARMaddc rGPR:$src, imm1_255_neg:$imm), 2062 (t2SUBSri rGPR:$src, imm1_255_neg:$imm)>; 2063 def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm), 2064 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>; 2065 def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm), 2066 (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>; 2067 // The with-carry-in form matches bitwise not instead of the negation. 2068 // Effectively, the inverse interpretation of the carry flag already accounts 2069 // for part of the negation. 2070 let AddedComplexity = 1 in 2071 def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR), 2072 (t2SBCri rGPR:$src, imm0_255_not:$imm)>; 2073 def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR), 2074 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>; 2075 def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR), 2076 (t2SBCrr rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>; 2077 2078 // Select Bytes -- for disassembly only 2079 2080 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), 2081 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>, 2082 Requires<[IsThumb2, HasThumb2DSP]> { 2083 let Inst{31-27} = 0b11111; 2084 let Inst{26-24} = 0b010; 2085 let Inst{23} = 0b1; 2086 let Inst{22-20} = 0b010; 2087 let Inst{15-12} = 0b1111; 2088 let Inst{7} = 0b1; 2089 let Inst{6-4} = 0b000; 2090 } 2091 2092 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned) 2093 // And Miscellaneous operations -- for disassembly only 2094 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc, 2095 list<dag> pat = [/* For disassembly only; pattern left blank */], 2096 dag iops = (ins rGPR:$Rn, rGPR:$Rm), 2097 string asm = "\t$Rd, $Rn, $Rm"> 2098 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>, 2099 Requires<[IsThumb2, HasThumb2DSP]> { 2100 let Inst{31-27} = 0b11111; 2101 let Inst{26-23} = 0b0101; 2102 let Inst{22-20} = op22_20; 2103 let Inst{15-12} = 0b1111; 2104 let Inst{7-4} = op7_4; 2105 2106 bits<4> Rd; 2107 bits<4> Rn; 2108 bits<4> Rm; 2109 2110 let Inst{11-8} = Rd; 2111 let Inst{19-16} = Rn; 2112 let Inst{3-0} = Rm; 2113 } 2114 2115 // Saturating add/subtract -- for disassembly only 2116 2117 def t2QADD : T2I_pam<0b000, 0b1000, "qadd", 2118 [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))], 2119 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 2120 def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">; 2121 def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">; 2122 def t2QASX : T2I_pam<0b010, 0b0001, "qasx">; 2123 def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd", [], 2124 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 2125 def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub", [], 2126 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 2127 def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">; 2128 def t2QSUB : T2I_pam<0b000, 0b1010, "qsub", 2129 [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))], 2130 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 2131 def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">; 2132 def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">; 2133 def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">; 2134 def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">; 2135 def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">; 2136 def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">; 2137 def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">; 2138 def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">; 2139 2140 // Signed/Unsigned add/subtract -- for disassembly only 2141 2142 def t2SASX : T2I_pam<0b010, 0b0000, "sasx">; 2143 def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">; 2144 def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">; 2145 def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">; 2146 def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">; 2147 def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">; 2148 def t2UASX : T2I_pam<0b010, 0b0100, "uasx">; 2149 def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">; 2150 def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">; 2151 def t2USAX : T2I_pam<0b110, 0b0100, "usax">; 2152 def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">; 2153 def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">; 2154 2155 // Signed/Unsigned halving add/subtract -- for disassembly only 2156 2157 def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">; 2158 def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">; 2159 def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">; 2160 def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">; 2161 def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">; 2162 def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">; 2163 def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">; 2164 def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">; 2165 def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">; 2166 def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">; 2167 def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">; 2168 def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">; 2169 2170 // Helper class for disassembly only 2171 // A6.3.16 & A6.3.17 2172 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions. 2173 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops, 2174 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern> 2175 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> { 2176 let Inst{31-27} = 0b11111; 2177 let Inst{26-24} = 0b011; 2178 let Inst{23} = long; 2179 let Inst{22-20} = op22_20; 2180 let Inst{7-4} = op7_4; 2181 } 2182 2183 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops, 2184 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern> 2185 : T2FourReg<oops, iops, itin, opc, asm, pattern> { 2186 let Inst{31-27} = 0b11111; 2187 let Inst{26-24} = 0b011; 2188 let Inst{23} = long; 2189 let Inst{22-20} = op22_20; 2190 let Inst{7-4} = op7_4; 2191 } 2192 2193 // Unsigned Sum of Absolute Differences [and Accumulate]. 2194 def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd), 2195 (ins rGPR:$Rn, rGPR:$Rm), 2196 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>, 2197 Requires<[IsThumb2, HasThumb2DSP]> { 2198 let Inst{15-12} = 0b1111; 2199 } 2200 def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd), 2201 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary, 2202 "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>, 2203 Requires<[IsThumb2, HasThumb2DSP]>; 2204 2205 // Signed/Unsigned saturate. 2206 class T2SatI<dag oops, dag iops, InstrItinClass itin, 2207 string opc, string asm, list<dag> pattern> 2208 : T2I<oops, iops, itin, opc, asm, pattern> { 2209 bits<4> Rd; 2210 bits<4> Rn; 2211 bits<5> sat_imm; 2212 bits<7> sh; 2213 2214 let Inst{11-8} = Rd; 2215 let Inst{19-16} = Rn; 2216 let Inst{4-0} = sat_imm; 2217 let Inst{21} = sh{5}; 2218 let Inst{14-12} = sh{4-2}; 2219 let Inst{7-6} = sh{1-0}; 2220 } 2221 2222 def t2SSAT: T2SatI< 2223 (outs rGPR:$Rd), 2224 (ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh), 2225 NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> { 2226 let Inst{31-27} = 0b11110; 2227 let Inst{25-22} = 0b1100; 2228 let Inst{20} = 0; 2229 let Inst{15} = 0; 2230 let Inst{5} = 0; 2231 } 2232 2233 def t2SSAT16: T2SatI< 2234 (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary, 2235 "ssat16", "\t$Rd, $sat_imm, $Rn", []>, 2236 Requires<[IsThumb2, HasThumb2DSP]> { 2237 let Inst{31-27} = 0b11110; 2238 let Inst{25-22} = 0b1100; 2239 let Inst{20} = 0; 2240 let Inst{15} = 0; 2241 let Inst{21} = 1; // sh = '1' 2242 let Inst{14-12} = 0b000; // imm3 = '000' 2243 let Inst{7-6} = 0b00; // imm2 = '00' 2244 let Inst{5-4} = 0b00; 2245 } 2246 2247 def t2USAT: T2SatI< 2248 (outs rGPR:$Rd), 2249 (ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh), 2250 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> { 2251 let Inst{31-27} = 0b11110; 2252 let Inst{25-22} = 0b1110; 2253 let Inst{20} = 0; 2254 let Inst{15} = 0; 2255 } 2256 2257 def t2USAT16: T2SatI<(outs rGPR:$Rd), (ins imm0_15:$sat_imm, rGPR:$Rn), 2258 NoItinerary, 2259 "usat16", "\t$Rd, $sat_imm, $Rn", []>, 2260 Requires<[IsThumb2, HasThumb2DSP]> { 2261 let Inst{31-22} = 0b1111001110; 2262 let Inst{20} = 0; 2263 let Inst{15} = 0; 2264 let Inst{21} = 1; // sh = '1' 2265 let Inst{14-12} = 0b000; // imm3 = '000' 2266 let Inst{7-6} = 0b00; // imm2 = '00' 2267 let Inst{5-4} = 0b00; 2268 } 2269 2270 def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>; 2271 def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>; 2272 2273 //===----------------------------------------------------------------------===// 2274 // Shift and rotate Instructions. 2275 // 2276 2277 defm t2LSL : T2I_sh_ir<0b00, "lsl", imm0_31, 2278 BinOpFrag<(shl node:$LHS, node:$RHS)>>; 2279 defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, 2280 BinOpFrag<(srl node:$LHS, node:$RHS)>>; 2281 defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, 2282 BinOpFrag<(sra node:$LHS, node:$RHS)>>; 2283 defm t2ROR : T2I_sh_ir<0b11, "ror", imm0_31, 2284 BinOpFrag<(rotr node:$LHS, node:$RHS)>>; 2285 2286 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y) 2287 def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)), 2288 (t2RORrr rGPR:$lhs, rGPR:$rhs)>; 2289 2290 let Uses = [CPSR] in { 2291 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, 2292 "rrx", "\t$Rd, $Rm", 2293 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> { 2294 let Inst{31-27} = 0b11101; 2295 let Inst{26-25} = 0b01; 2296 let Inst{24-21} = 0b0010; 2297 let Inst{19-16} = 0b1111; // Rn 2298 let Inst{14-12} = 0b000; 2299 let Inst{7-4} = 0b0011; 2300 } 2301 } 2302 2303 let isCodeGenOnly = 1, Defs = [CPSR] in { 2304 def t2MOVsrl_flag : T2TwoRegShiftImm< 2305 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, 2306 "lsrs", ".w\t$Rd, $Rm, #1", 2307 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>, 2308 Sched<[WriteALU]> { 2309 let Inst{31-27} = 0b11101; 2310 let Inst{26-25} = 0b01; 2311 let Inst{24-21} = 0b0010; 2312 let Inst{20} = 1; // The S bit. 2313 let Inst{19-16} = 0b1111; // Rn 2314 let Inst{5-4} = 0b01; // Shift type. 2315 // Shift amount = Inst{14-12:7-6} = 1. 2316 let Inst{14-12} = 0b000; 2317 let Inst{7-6} = 0b01; 2318 } 2319 def t2MOVsra_flag : T2TwoRegShiftImm< 2320 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, 2321 "asrs", ".w\t$Rd, $Rm, #1", 2322 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>, 2323 Sched<[WriteALU]> { 2324 let Inst{31-27} = 0b11101; 2325 let Inst{26-25} = 0b01; 2326 let Inst{24-21} = 0b0010; 2327 let Inst{20} = 1; // The S bit. 2328 let Inst{19-16} = 0b1111; // Rn 2329 let Inst{5-4} = 0b10; // Shift type. 2330 // Shift amount = Inst{14-12:7-6} = 1. 2331 let Inst{14-12} = 0b000; 2332 let Inst{7-6} = 0b01; 2333 } 2334 } 2335 2336 //===----------------------------------------------------------------------===// 2337 // Bitwise Instructions. 2338 // 2339 2340 defm t2AND : T2I_bin_w_irs<0b0000, "and", 2341 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 2342 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>; 2343 defm t2ORR : T2I_bin_w_irs<0b0010, "orr", 2344 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 2345 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>; 2346 defm t2EOR : T2I_bin_w_irs<0b0100, "eor", 2347 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 2348 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>; 2349 2350 defm t2BIC : T2I_bin_w_irs<0b0001, "bic", 2351 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 2352 BinOpFrag<(and node:$LHS, (not node:$RHS))>>; 2353 2354 class T2BitFI<dag oops, dag iops, InstrItinClass itin, 2355 string opc, string asm, list<dag> pattern> 2356 : T2I<oops, iops, itin, opc, asm, pattern> { 2357 bits<4> Rd; 2358 bits<5> msb; 2359 bits<5> lsb; 2360 2361 let Inst{11-8} = Rd; 2362 let Inst{4-0} = msb{4-0}; 2363 let Inst{14-12} = lsb{4-2}; 2364 let Inst{7-6} = lsb{1-0}; 2365 } 2366 2367 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin, 2368 string opc, string asm, list<dag> pattern> 2369 : T2BitFI<oops, iops, itin, opc, asm, pattern> { 2370 bits<4> Rn; 2371 2372 let Inst{19-16} = Rn; 2373 } 2374 2375 let Constraints = "$src = $Rd" in 2376 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm), 2377 IIC_iUNAsi, "bfc", "\t$Rd, $imm", 2378 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> { 2379 let Inst{31-27} = 0b11110; 2380 let Inst{26} = 0; // should be 0. 2381 let Inst{25} = 1; 2382 let Inst{24-20} = 0b10110; 2383 let Inst{19-16} = 0b1111; // Rn 2384 let Inst{15} = 0; 2385 let Inst{5} = 0; // should be 0. 2386 2387 bits<10> imm; 2388 let msb{4-0} = imm{9-5}; 2389 let lsb{4-0} = imm{4-0}; 2390 } 2391 2392 def t2SBFX: T2TwoRegBitFI< 2393 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb), 2394 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> { 2395 let Inst{31-27} = 0b11110; 2396 let Inst{25} = 1; 2397 let Inst{24-20} = 0b10100; 2398 let Inst{15} = 0; 2399 } 2400 2401 def t2UBFX: T2TwoRegBitFI< 2402 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb), 2403 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> { 2404 let Inst{31-27} = 0b11110; 2405 let Inst{25} = 1; 2406 let Inst{24-20} = 0b11100; 2407 let Inst{15} = 0; 2408 } 2409 2410 // A8.8.247 UDF - Undefined (Encoding T2) 2411 def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16", 2412 [(int_arm_undefined imm0_65535:$imm16)]> { 2413 bits<16> imm16; 2414 let Inst{31-29} = 0b111; 2415 let Inst{28-27} = 0b10; 2416 let Inst{26-20} = 0b1111111; 2417 let Inst{19-16} = imm16{15-12}; 2418 let Inst{15} = 0b1; 2419 let Inst{14-12} = 0b010; 2420 let Inst{11-0} = imm16{11-0}; 2421 } 2422 2423 // A8.6.18 BFI - Bitfield insert (Encoding T1) 2424 let Constraints = "$src = $Rd" in { 2425 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd), 2426 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm), 2427 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm", 2428 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn, 2429 bf_inv_mask_imm:$imm))]> { 2430 let Inst{31-27} = 0b11110; 2431 let Inst{26} = 0; // should be 0. 2432 let Inst{25} = 1; 2433 let Inst{24-20} = 0b10110; 2434 let Inst{15} = 0; 2435 let Inst{5} = 0; // should be 0. 2436 2437 bits<10> imm; 2438 let msb{4-0} = imm{9-5}; 2439 let lsb{4-0} = imm{4-0}; 2440 } 2441 } 2442 2443 defm t2ORN : T2I_bin_irs<0b0011, "orn", 2444 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 2445 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">; 2446 2447 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a 2448 /// unary operation that produces a value. These are predicable and can be 2449 /// changed to modify CPSR. 2450 multiclass T2I_un_irs<bits<4> opcod, string opc, 2451 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 2452 PatFrag opnode, 2453 bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> { 2454 // shifted imm 2455 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii, 2456 opc, "\t$Rd, $imm", 2457 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> { 2458 let isAsCheapAsAMove = Cheap; 2459 let isReMaterializable = ReMat; 2460 let isMoveImm = MoveImm; 2461 let Inst{31-27} = 0b11110; 2462 let Inst{25} = 0; 2463 let Inst{24-21} = opcod; 2464 let Inst{19-16} = 0b1111; // Rn 2465 let Inst{15} = 0; 2466 } 2467 // register 2468 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir, 2469 opc, ".w\t$Rd, $Rm", 2470 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> { 2471 let Inst{31-27} = 0b11101; 2472 let Inst{26-25} = 0b01; 2473 let Inst{24-21} = opcod; 2474 let Inst{19-16} = 0b1111; // Rn 2475 let Inst{14-12} = 0b000; // imm3 2476 let Inst{7-6} = 0b00; // imm2 2477 let Inst{5-4} = 0b00; // type 2478 } 2479 // shifted register 2480 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis, 2481 opc, ".w\t$Rd, $ShiftedRm", 2482 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>, 2483 Sched<[WriteALU]> { 2484 let Inst{31-27} = 0b11101; 2485 let Inst{26-25} = 0b01; 2486 let Inst{24-21} = opcod; 2487 let Inst{19-16} = 0b1111; // Rn 2488 } 2489 } 2490 2491 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version 2492 let AddedComplexity = 1 in 2493 defm t2MVN : T2I_un_irs <0b0011, "mvn", 2494 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi, 2495 UnOpFrag<(not node:$Src)>, 1, 1, 1>; 2496 2497 let AddedComplexity = 1 in 2498 def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm), 2499 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>; 2500 2501 // top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise 2502 def top16Zero: PatLeaf<(i32 rGPR:$src), [{ 2503 return CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16)); 2504 }]>; 2505 2506 // so_imm_notSext is needed instead of so_imm_not, as the value of imm 2507 // will match the extended, not the original bitWidth for $src. 2508 def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm), 2509 (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>; 2510 2511 2512 // FIXME: Disable this pattern on Darwin to workaround an assembler bug. 2513 def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm), 2514 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>, 2515 Requires<[IsThumb2]>; 2516 2517 def : T2Pat<(t2_so_imm_not:$src), 2518 (t2MVNi t2_so_imm_not:$src)>; 2519 2520 //===----------------------------------------------------------------------===// 2521 // Multiply Instructions. 2522 // 2523 let isCommutable = 1 in 2524 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32, 2525 "mul", "\t$Rd, $Rn, $Rm", 2526 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> { 2527 let Inst{31-27} = 0b11111; 2528 let Inst{26-23} = 0b0110; 2529 let Inst{22-20} = 0b000; 2530 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2531 let Inst{7-4} = 0b0000; // Multiply 2532 } 2533 2534 def t2MLA: T2FourReg< 2535 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2536 "mla", "\t$Rd, $Rn, $Rm, $Ra", 2537 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]>, 2538 Requires<[IsThumb2, UseMulOps]> { 2539 let Inst{31-27} = 0b11111; 2540 let Inst{26-23} = 0b0110; 2541 let Inst{22-20} = 0b000; 2542 let Inst{7-4} = 0b0000; // Multiply 2543 } 2544 2545 def t2MLS: T2FourReg< 2546 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2547 "mls", "\t$Rd, $Rn, $Rm, $Ra", 2548 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]>, 2549 Requires<[IsThumb2, UseMulOps]> { 2550 let Inst{31-27} = 0b11111; 2551 let Inst{26-23} = 0b0110; 2552 let Inst{22-20} = 0b000; 2553 let Inst{7-4} = 0b0001; // Multiply and Subtract 2554 } 2555 2556 // Extra precision multiplies with low / high results 2557 let neverHasSideEffects = 1 in { 2558 let isCommutable = 1 in { 2559 def t2SMULL : T2MulLong<0b000, 0b0000, 2560 (outs rGPR:$RdLo, rGPR:$RdHi), 2561 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64, 2562 "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>; 2563 2564 def t2UMULL : T2MulLong<0b010, 0b0000, 2565 (outs rGPR:$RdLo, rGPR:$RdHi), 2566 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64, 2567 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>; 2568 } // isCommutable 2569 2570 // Multiply + accumulate 2571 def t2SMLAL : T2MlaLong<0b100, 0b0000, 2572 (outs rGPR:$RdLo, rGPR:$RdHi), 2573 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64, 2574 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>, 2575 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">; 2576 2577 def t2UMLAL : T2MlaLong<0b110, 0b0000, 2578 (outs rGPR:$RdLo, rGPR:$RdHi), 2579 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64, 2580 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>, 2581 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">; 2582 2583 def t2UMAAL : T2MulLong<0b110, 0b0110, 2584 (outs rGPR:$RdLo, rGPR:$RdHi), 2585 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, 2586 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>, 2587 Requires<[IsThumb2, HasThumb2DSP]>; 2588 } // neverHasSideEffects 2589 2590 // Rounding variants of the below included for disassembly only 2591 2592 // Most significant word multiply 2593 def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32, 2594 "smmul", "\t$Rd, $Rn, $Rm", 2595 [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>, 2596 Requires<[IsThumb2, HasThumb2DSP]> { 2597 let Inst{31-27} = 0b11111; 2598 let Inst{26-23} = 0b0110; 2599 let Inst{22-20} = 0b101; 2600 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2601 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0) 2602 } 2603 2604 def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32, 2605 "smmulr", "\t$Rd, $Rn, $Rm", []>, 2606 Requires<[IsThumb2, HasThumb2DSP]> { 2607 let Inst{31-27} = 0b11111; 2608 let Inst{26-23} = 0b0110; 2609 let Inst{22-20} = 0b101; 2610 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2611 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1) 2612 } 2613 2614 def t2SMMLA : T2FourReg< 2615 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2616 "smmla", "\t$Rd, $Rn, $Rm, $Ra", 2617 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>, 2618 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2619 let Inst{31-27} = 0b11111; 2620 let Inst{26-23} = 0b0110; 2621 let Inst{22-20} = 0b101; 2622 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0) 2623 } 2624 2625 def t2SMMLAR: T2FourReg< 2626 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2627 "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>, 2628 Requires<[IsThumb2, HasThumb2DSP]> { 2629 let Inst{31-27} = 0b11111; 2630 let Inst{26-23} = 0b0110; 2631 let Inst{22-20} = 0b101; 2632 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1) 2633 } 2634 2635 def t2SMMLS: T2FourReg< 2636 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2637 "smmls", "\t$Rd, $Rn, $Rm, $Ra", 2638 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>, 2639 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2640 let Inst{31-27} = 0b11111; 2641 let Inst{26-23} = 0b0110; 2642 let Inst{22-20} = 0b110; 2643 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0) 2644 } 2645 2646 def t2SMMLSR:T2FourReg< 2647 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2648 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>, 2649 Requires<[IsThumb2, HasThumb2DSP]> { 2650 let Inst{31-27} = 0b11111; 2651 let Inst{26-23} = 0b0110; 2652 let Inst{22-20} = 0b110; 2653 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1) 2654 } 2655 2656 multiclass T2I_smul<string opc, PatFrag opnode> { 2657 def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2658 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm", 2659 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16), 2660 (sext_inreg rGPR:$Rm, i16)))]>, 2661 Requires<[IsThumb2, HasThumb2DSP]> { 2662 let Inst{31-27} = 0b11111; 2663 let Inst{26-23} = 0b0110; 2664 let Inst{22-20} = 0b001; 2665 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2666 let Inst{7-6} = 0b00; 2667 let Inst{5-4} = 0b00; 2668 } 2669 2670 def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2671 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm", 2672 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16), 2673 (sra rGPR:$Rm, (i32 16))))]>, 2674 Requires<[IsThumb2, HasThumb2DSP]> { 2675 let Inst{31-27} = 0b11111; 2676 let Inst{26-23} = 0b0110; 2677 let Inst{22-20} = 0b001; 2678 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2679 let Inst{7-6} = 0b00; 2680 let Inst{5-4} = 0b01; 2681 } 2682 2683 def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2684 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm", 2685 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)), 2686 (sext_inreg rGPR:$Rm, i16)))]>, 2687 Requires<[IsThumb2, HasThumb2DSP]> { 2688 let Inst{31-27} = 0b11111; 2689 let Inst{26-23} = 0b0110; 2690 let Inst{22-20} = 0b001; 2691 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2692 let Inst{7-6} = 0b00; 2693 let Inst{5-4} = 0b10; 2694 } 2695 2696 def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2697 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm", 2698 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)), 2699 (sra rGPR:$Rm, (i32 16))))]>, 2700 Requires<[IsThumb2, HasThumb2DSP]> { 2701 let Inst{31-27} = 0b11111; 2702 let Inst{26-23} = 0b0110; 2703 let Inst{22-20} = 0b001; 2704 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2705 let Inst{7-6} = 0b00; 2706 let Inst{5-4} = 0b11; 2707 } 2708 2709 def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2710 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm", 2711 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn, 2712 (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>, 2713 Requires<[IsThumb2, HasThumb2DSP]> { 2714 let Inst{31-27} = 0b11111; 2715 let Inst{26-23} = 0b0110; 2716 let Inst{22-20} = 0b011; 2717 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2718 let Inst{7-6} = 0b00; 2719 let Inst{5-4} = 0b00; 2720 } 2721 2722 def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2723 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm", 2724 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn, 2725 (sra rGPR:$Rm, (i32 16))), (i32 16)))]>, 2726 Requires<[IsThumb2, HasThumb2DSP]> { 2727 let Inst{31-27} = 0b11111; 2728 let Inst{26-23} = 0b0110; 2729 let Inst{22-20} = 0b011; 2730 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2731 let Inst{7-6} = 0b00; 2732 let Inst{5-4} = 0b01; 2733 } 2734 } 2735 2736 2737 multiclass T2I_smla<string opc, PatFrag opnode> { 2738 def BB : T2FourReg< 2739 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2740 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra", 2741 [(set rGPR:$Rd, (add rGPR:$Ra, 2742 (opnode (sext_inreg rGPR:$Rn, i16), 2743 (sext_inreg rGPR:$Rm, i16))))]>, 2744 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2745 let Inst{31-27} = 0b11111; 2746 let Inst{26-23} = 0b0110; 2747 let Inst{22-20} = 0b001; 2748 let Inst{7-6} = 0b00; 2749 let Inst{5-4} = 0b00; 2750 } 2751 2752 def BT : T2FourReg< 2753 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2754 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra", 2755 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16), 2756 (sra rGPR:$Rm, (i32 16)))))]>, 2757 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2758 let Inst{31-27} = 0b11111; 2759 let Inst{26-23} = 0b0110; 2760 let Inst{22-20} = 0b001; 2761 let Inst{7-6} = 0b00; 2762 let Inst{5-4} = 0b01; 2763 } 2764 2765 def TB : T2FourReg< 2766 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2767 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra", 2768 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)), 2769 (sext_inreg rGPR:$Rm, i16))))]>, 2770 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2771 let Inst{31-27} = 0b11111; 2772 let Inst{26-23} = 0b0110; 2773 let Inst{22-20} = 0b001; 2774 let Inst{7-6} = 0b00; 2775 let Inst{5-4} = 0b10; 2776 } 2777 2778 def TT : T2FourReg< 2779 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2780 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra", 2781 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)), 2782 (sra rGPR:$Rm, (i32 16)))))]>, 2783 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2784 let Inst{31-27} = 0b11111; 2785 let Inst{26-23} = 0b0110; 2786 let Inst{22-20} = 0b001; 2787 let Inst{7-6} = 0b00; 2788 let Inst{5-4} = 0b11; 2789 } 2790 2791 def WB : T2FourReg< 2792 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2793 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra", 2794 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn, 2795 (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>, 2796 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2797 let Inst{31-27} = 0b11111; 2798 let Inst{26-23} = 0b0110; 2799 let Inst{22-20} = 0b011; 2800 let Inst{7-6} = 0b00; 2801 let Inst{5-4} = 0b00; 2802 } 2803 2804 def WT : T2FourReg< 2805 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2806 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra", 2807 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn, 2808 (sra rGPR:$Rm, (i32 16))), (i32 16))))]>, 2809 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> { 2810 let Inst{31-27} = 0b11111; 2811 let Inst{26-23} = 0b0110; 2812 let Inst{22-20} = 0b011; 2813 let Inst{7-6} = 0b00; 2814 let Inst{5-4} = 0b01; 2815 } 2816 } 2817 2818 defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>; 2819 defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>; 2820 2821 // Halfword multiple accumulate long: SMLAL<x><y> 2822 def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd), 2823 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm", 2824 [/* For disassembly only; pattern left blank */]>, 2825 Requires<[IsThumb2, HasThumb2DSP]>; 2826 def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd), 2827 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm", 2828 [/* For disassembly only; pattern left blank */]>, 2829 Requires<[IsThumb2, HasThumb2DSP]>; 2830 def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd), 2831 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm", 2832 [/* For disassembly only; pattern left blank */]>, 2833 Requires<[IsThumb2, HasThumb2DSP]>; 2834 def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd), 2835 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm", 2836 [/* For disassembly only; pattern left blank */]>, 2837 Requires<[IsThumb2, HasThumb2DSP]>; 2838 2839 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD 2840 def t2SMUAD: T2ThreeReg_mac< 2841 0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2842 IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>, 2843 Requires<[IsThumb2, HasThumb2DSP]> { 2844 let Inst{15-12} = 0b1111; 2845 } 2846 def t2SMUADX:T2ThreeReg_mac< 2847 0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2848 IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>, 2849 Requires<[IsThumb2, HasThumb2DSP]> { 2850 let Inst{15-12} = 0b1111; 2851 } 2852 def t2SMUSD: T2ThreeReg_mac< 2853 0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2854 IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>, 2855 Requires<[IsThumb2, HasThumb2DSP]> { 2856 let Inst{15-12} = 0b1111; 2857 } 2858 def t2SMUSDX:T2ThreeReg_mac< 2859 0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2860 IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>, 2861 Requires<[IsThumb2, HasThumb2DSP]> { 2862 let Inst{15-12} = 0b1111; 2863 } 2864 def t2SMLAD : T2FourReg_mac< 2865 0, 0b010, 0b0000, (outs rGPR:$Rd), 2866 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad", 2867 "\t$Rd, $Rn, $Rm, $Ra", []>, 2868 Requires<[IsThumb2, HasThumb2DSP]>; 2869 def t2SMLADX : T2FourReg_mac< 2870 0, 0b010, 0b0001, (outs rGPR:$Rd), 2871 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx", 2872 "\t$Rd, $Rn, $Rm, $Ra", []>, 2873 Requires<[IsThumb2, HasThumb2DSP]>; 2874 def t2SMLSD : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd), 2875 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd", 2876 "\t$Rd, $Rn, $Rm, $Ra", []>, 2877 Requires<[IsThumb2, HasThumb2DSP]>; 2878 def t2SMLSDX : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd), 2879 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx", 2880 "\t$Rd, $Rn, $Rm, $Ra", []>, 2881 Requires<[IsThumb2, HasThumb2DSP]>; 2882 def t2SMLALD : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd), 2883 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, "smlald", 2884 "\t$Ra, $Rd, $Rn, $Rm", []>, 2885 Requires<[IsThumb2, HasThumb2DSP]>; 2886 def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd), 2887 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaldx", 2888 "\t$Ra, $Rd, $Rn, $Rm", []>, 2889 Requires<[IsThumb2, HasThumb2DSP]>; 2890 def t2SMLSLD : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd), 2891 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlsld", 2892 "\t$Ra, $Rd, $Rn, $Rm", []>, 2893 Requires<[IsThumb2, HasThumb2DSP]>; 2894 def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd), 2895 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx", 2896 "\t$Ra, $Rd, $Rn, $Rm", []>, 2897 Requires<[IsThumb2, HasThumb2DSP]>; 2898 2899 //===----------------------------------------------------------------------===// 2900 // Division Instructions. 2901 // Signed and unsigned division on v7-M 2902 // 2903 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV, 2904 "sdiv", "\t$Rd, $Rn, $Rm", 2905 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>, 2906 Requires<[HasDivide, IsThumb2]> { 2907 let Inst{31-27} = 0b11111; 2908 let Inst{26-21} = 0b011100; 2909 let Inst{20} = 0b1; 2910 let Inst{15-12} = 0b1111; 2911 let Inst{7-4} = 0b1111; 2912 } 2913 2914 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV, 2915 "udiv", "\t$Rd, $Rn, $Rm", 2916 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>, 2917 Requires<[HasDivide, IsThumb2]> { 2918 let Inst{31-27} = 0b11111; 2919 let Inst{26-21} = 0b011101; 2920 let Inst{20} = 0b1; 2921 let Inst{15-12} = 0b1111; 2922 let Inst{7-4} = 0b1111; 2923 } 2924 2925 //===----------------------------------------------------------------------===// 2926 // Misc. Arithmetic Instructions. 2927 // 2928 2929 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops, 2930 InstrItinClass itin, string opc, string asm, list<dag> pattern> 2931 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> { 2932 let Inst{31-27} = 0b11111; 2933 let Inst{26-22} = 0b01010; 2934 let Inst{21-20} = op1; 2935 let Inst{15-12} = 0b1111; 2936 let Inst{7-6} = 0b10; 2937 let Inst{5-4} = op2; 2938 let Rn{3-0} = Rm; 2939 } 2940 2941 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2942 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>, 2943 Sched<[WriteALU]>; 2944 2945 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2946 "rbit", "\t$Rd, $Rm", 2947 [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>, 2948 Sched<[WriteALU]>; 2949 2950 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2951 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>, 2952 Sched<[WriteALU]>; 2953 2954 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2955 "rev16", ".w\t$Rd, $Rm", 2956 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>, 2957 Sched<[WriteALU]>; 2958 2959 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2960 "revsh", ".w\t$Rd, $Rm", 2961 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>, 2962 Sched<[WriteALU]>; 2963 2964 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)), 2965 (and (srl rGPR:$Rm, (i32 8)), 0xFF)), 2966 (t2REVSH rGPR:$Rm)>; 2967 2968 def t2PKHBT : T2ThreeReg< 2969 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh), 2970 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh", 2971 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF), 2972 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh), 2973 0xFFFF0000)))]>, 2974 Requires<[HasT2ExtractPack, IsThumb2]>, 2975 Sched<[WriteALUsi, ReadALU]> { 2976 let Inst{31-27} = 0b11101; 2977 let Inst{26-25} = 0b01; 2978 let Inst{24-20} = 0b01100; 2979 let Inst{5} = 0; // BT form 2980 let Inst{4} = 0; 2981 2982 bits<5> sh; 2983 let Inst{14-12} = sh{4-2}; 2984 let Inst{7-6} = sh{1-0}; 2985 } 2986 2987 // Alternate cases for PKHBT where identities eliminate some nodes. 2988 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)), 2989 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>, 2990 Requires<[HasT2ExtractPack, IsThumb2]>; 2991 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)), 2992 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>, 2993 Requires<[HasT2ExtractPack, IsThumb2]>; 2994 2995 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and 2996 // will match the pattern below. 2997 def t2PKHTB : T2ThreeReg< 2998 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh), 2999 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh", 3000 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000), 3001 (and (sra rGPR:$Rm, pkh_asr_amt:$sh), 3002 0xFFFF)))]>, 3003 Requires<[HasT2ExtractPack, IsThumb2]>, 3004 Sched<[WriteALUsi, ReadALU]> { 3005 let Inst{31-27} = 0b11101; 3006 let Inst{26-25} = 0b01; 3007 let Inst{24-20} = 0b01100; 3008 let Inst{5} = 1; // TB form 3009 let Inst{4} = 0; 3010 3011 bits<5> sh; 3012 let Inst{14-12} = sh{4-2}; 3013 let Inst{7-6} = sh{1-0}; 3014 } 3015 3016 // Alternate cases for PKHTB where identities eliminate some nodes. Note that 3017 // a shift amount of 0 is *not legal* here, it is PKHBT instead. 3018 // We also can not replace a srl (17..31) by an arithmetic shift we would use in 3019 // pkhtb src1, src2, asr (17..31). 3020 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)), 3021 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>, 3022 Requires<[HasT2ExtractPack, IsThumb2]>; 3023 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)), 3024 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>, 3025 Requires<[HasT2ExtractPack, IsThumb2]>; 3026 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), 3027 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)), 3028 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>, 3029 Requires<[HasT2ExtractPack, IsThumb2]>; 3030 3031 //===----------------------------------------------------------------------===// 3032 // CRC32 Instructions 3033 // 3034 // Polynomials: 3035 // + CRC32{B,H,W} 0x04C11DB7 3036 // + CRC32C{B,H,W} 0x1EDC6F41 3037 // 3038 3039 class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin> 3040 : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary, 3041 !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"), 3042 [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>, 3043 Requires<[IsThumb2, HasV8, HasCRC]> { 3044 let Inst{31-27} = 0b11111; 3045 let Inst{26-21} = 0b010110; 3046 let Inst{20} = C; 3047 let Inst{15-12} = 0b1111; 3048 let Inst{7-6} = 0b10; 3049 let Inst{5-4} = sz; 3050 } 3051 3052 def t2CRC32B : T2I_crc32<0, 0b00, "b", int_arm_crc32b>; 3053 def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>; 3054 def t2CRC32H : T2I_crc32<0, 0b01, "h", int_arm_crc32h>; 3055 def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>; 3056 def t2CRC32W : T2I_crc32<0, 0b10, "w", int_arm_crc32w>; 3057 def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>; 3058 3059 //===----------------------------------------------------------------------===// 3060 // Comparison Instructions... 3061 // 3062 defm t2CMP : T2I_cmp_irs<0b1101, "cmp", 3063 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, 3064 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>; 3065 3066 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm), 3067 (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>; 3068 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs), 3069 (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>; 3070 def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg:$rhs), 3071 (t2CMPrs GPRnopc:$lhs, t2_so_reg:$rhs)>; 3072 3073 let isCompare = 1, Defs = [CPSR] in { 3074 // shifted imm 3075 def t2CMNri : T2OneRegCmpImm< 3076 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi, 3077 "cmn", ".w\t$Rn, $imm", 3078 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>, 3079 Sched<[WriteCMP, ReadALU]> { 3080 let Inst{31-27} = 0b11110; 3081 let Inst{25} = 0; 3082 let Inst{24-21} = 0b1000; 3083 let Inst{20} = 1; // The S bit. 3084 let Inst{15} = 0; 3085 let Inst{11-8} = 0b1111; // Rd 3086 } 3087 // register 3088 def t2CMNzrr : T2TwoRegCmp< 3089 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr, 3090 "cmn", ".w\t$Rn, $Rm", 3091 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))> 3092 GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> { 3093 let Inst{31-27} = 0b11101; 3094 let Inst{26-25} = 0b01; 3095 let Inst{24-21} = 0b1000; 3096 let Inst{20} = 1; // The S bit. 3097 let Inst{14-12} = 0b000; // imm3 3098 let Inst{11-8} = 0b1111; // Rd 3099 let Inst{7-6} = 0b00; // imm2 3100 let Inst{5-4} = 0b00; // type 3101 } 3102 // shifted register 3103 def t2CMNzrs : T2OneRegCmpShiftedReg< 3104 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi, 3105 "cmn", ".w\t$Rn, $ShiftedRm", 3106 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))> 3107 GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>, 3108 Sched<[WriteCMPsi, ReadALU, ReadALU]> { 3109 let Inst{31-27} = 0b11101; 3110 let Inst{26-25} = 0b01; 3111 let Inst{24-21} = 0b1000; 3112 let Inst{20} = 1; // The S bit. 3113 let Inst{11-8} = 0b1111; // Rd 3114 } 3115 } 3116 3117 // Assembler aliases w/o the ".w" suffix. 3118 // No alias here for 'rr' version as not all instantiations of this multiclass 3119 // want one (CMP in particular, does not). 3120 def : t2InstAlias<"cmn${p} $Rn, $imm", 3121 (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>; 3122 def : t2InstAlias<"cmn${p} $Rn, $shift", 3123 (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>; 3124 3125 def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm), 3126 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>; 3127 3128 def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm), 3129 (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>; 3130 3131 defm t2TST : T2I_cmp_irs<0b0000, "tst", 3132 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi, 3133 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>; 3134 defm t2TEQ : T2I_cmp_irs<0b0100, "teq", 3135 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi, 3136 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>; 3137 3138 // Conditional moves 3139 let neverHasSideEffects = 1 in { 3140 3141 let isCommutable = 1, isSelect = 1 in 3142 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd), 3143 (ins rGPR:$false, rGPR:$Rm, cmovpred:$p), 3144 4, IIC_iCMOVr, 3145 [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, 3146 cmovpred:$p))]>, 3147 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>; 3148 3149 let isMoveImm = 1 in 3150 def t2MOVCCi 3151 : t2PseudoInst<(outs rGPR:$Rd), 3152 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p), 3153 4, IIC_iCMOVi, 3154 [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm, 3155 cmovpred:$p))]>, 3156 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>; 3157 3158 let isCodeGenOnly = 1 in { 3159 let isMoveImm = 1 in 3160 def t2MOVCCi16 3161 : t2PseudoInst<(outs rGPR:$Rd), 3162 (ins rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p), 3163 4, IIC_iCMOVi, 3164 [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm, 3165 cmovpred:$p))]>, 3166 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>; 3167 3168 let isMoveImm = 1 in 3169 def t2MVNCCi 3170 : t2PseudoInst<(outs rGPR:$Rd), 3171 (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p), 3172 4, IIC_iCMOVi, 3173 [(set rGPR:$Rd, 3174 (ARMcmov rGPR:$false, t2_so_imm_not:$imm, 3175 cmovpred:$p))]>, 3176 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>; 3177 3178 class MOVCCShPseudo<SDPatternOperator opnode, Operand ty> 3179 : t2PseudoInst<(outs rGPR:$Rd), 3180 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p), 3181 4, IIC_iCMOVsi, 3182 [(set rGPR:$Rd, (ARMcmov rGPR:$false, 3183 (opnode rGPR:$Rm, (i32 ty:$imm)), 3184 cmovpred:$p))]>, 3185 RegConstraint<"$false = $Rd">, Sched<[WriteALU]>; 3186 3187 def t2MOVCClsl : MOVCCShPseudo<shl, imm0_31>; 3188 def t2MOVCClsr : MOVCCShPseudo<srl, imm_sr>; 3189 def t2MOVCCasr : MOVCCShPseudo<sra, imm_sr>; 3190 def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>; 3191 3192 let isMoveImm = 1 in 3193 def t2MOVCCi32imm 3194 : t2PseudoInst<(outs rGPR:$dst), 3195 (ins rGPR:$false, i32imm:$src, cmovpred:$p), 3196 8, IIC_iCMOVix2, 3197 [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src, 3198 cmovpred:$p))]>, 3199 RegConstraint<"$false = $dst">; 3200 } // isCodeGenOnly = 1 3201 3202 } // neverHasSideEffects 3203 3204 //===----------------------------------------------------------------------===// 3205 // Atomic operations intrinsics 3206 // 3207 3208 // memory barriers protect the atomic sequences 3209 let hasSideEffects = 1 in { 3210 def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary, 3211 "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>, 3212 Requires<[IsThumb, HasDB]> { 3213 bits<4> opt; 3214 let Inst{31-4} = 0xf3bf8f5; 3215 let Inst{3-0} = opt; 3216 } 3217 3218 def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary, 3219 "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>, 3220 Requires<[IsThumb, HasDB]> { 3221 bits<4> opt; 3222 let Inst{31-4} = 0xf3bf8f4; 3223 let Inst{3-0} = opt; 3224 } 3225 3226 def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary, 3227 "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>, 3228 Requires<[IsThumb, HasDB]> { 3229 bits<4> opt; 3230 let Inst{31-4} = 0xf3bf8f6; 3231 let Inst{3-0} = opt; 3232 } 3233 } 3234 3235 class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz, 3236 InstrItinClass itin, string opc, string asm, string cstr, 3237 list<dag> pattern, bits<4> rt2 = 0b1111> 3238 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> { 3239 let Inst{31-27} = 0b11101; 3240 let Inst{26-20} = 0b0001101; 3241 let Inst{11-8} = rt2; 3242 let Inst{7-4} = opcod; 3243 let Inst{3-0} = 0b1111; 3244 3245 bits<4> addr; 3246 bits<4> Rt; 3247 let Inst{19-16} = addr; 3248 let Inst{15-12} = Rt; 3249 } 3250 class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz, 3251 InstrItinClass itin, string opc, string asm, string cstr, 3252 list<dag> pattern, bits<4> rt2 = 0b1111> 3253 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> { 3254 let Inst{31-27} = 0b11101; 3255 let Inst{26-20} = 0b0001100; 3256 let Inst{11-8} = rt2; 3257 let Inst{7-4} = opcod; 3258 3259 bits<4> Rd; 3260 bits<4> addr; 3261 bits<4> Rt; 3262 let Inst{3-0} = Rd; 3263 let Inst{19-16} = addr; 3264 let Inst{15-12} = Rt; 3265 } 3266 3267 let mayLoad = 1 in { 3268 def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr), 3269 AddrModeNone, 4, NoItinerary, 3270 "ldrexb", "\t$Rt, $addr", "", 3271 [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>; 3272 def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr), 3273 AddrModeNone, 4, NoItinerary, 3274 "ldrexh", "\t$Rt, $addr", "", 3275 [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>; 3276 def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr), 3277 AddrModeNone, 4, NoItinerary, 3278 "ldrex", "\t$Rt, $addr", "", 3279 [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]> { 3280 bits<4> Rt; 3281 bits<12> addr; 3282 let Inst{31-27} = 0b11101; 3283 let Inst{26-20} = 0b0000101; 3284 let Inst{19-16} = addr{11-8}; 3285 let Inst{15-12} = Rt; 3286 let Inst{11-8} = 0b1111; 3287 let Inst{7-0} = addr{7-0}; 3288 } 3289 let hasExtraDefRegAllocReq = 1 in 3290 def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2), 3291 (ins addr_offset_none:$addr), 3292 AddrModeNone, 4, NoItinerary, 3293 "ldrexd", "\t$Rt, $Rt2, $addr", "", 3294 [], {?, ?, ?, ?}> { 3295 bits<4> Rt2; 3296 let Inst{11-8} = Rt2; 3297 } 3298 def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr), 3299 AddrModeNone, 4, NoItinerary, 3300 "ldaexb", "\t$Rt, $addr", "", 3301 [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>, 3302 Requires<[IsThumb, HasV8]>; 3303 def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr), 3304 AddrModeNone, 4, NoItinerary, 3305 "ldaexh", "\t$Rt, $addr", "", 3306 [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>, 3307 Requires<[IsThumb, HasV8]>; 3308 def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr), 3309 AddrModeNone, 4, NoItinerary, 3310 "ldaex", "\t$Rt, $addr", "", 3311 [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>, 3312 Requires<[IsThumb, HasV8]> { 3313 bits<4> Rt; 3314 bits<4> addr; 3315 let Inst{31-27} = 0b11101; 3316 let Inst{26-20} = 0b0001101; 3317 let Inst{19-16} = addr; 3318 let Inst{15-12} = Rt; 3319 let Inst{11-8} = 0b1111; 3320 let Inst{7-0} = 0b11101111; 3321 } 3322 let hasExtraDefRegAllocReq = 1 in 3323 def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2), 3324 (ins addr_offset_none:$addr), 3325 AddrModeNone, 4, NoItinerary, 3326 "ldaexd", "\t$Rt, $Rt2, $addr", "", 3327 [], {?, ?, ?, ?}>, Requires<[IsThumb, HasV8]> { 3328 bits<4> Rt2; 3329 let Inst{11-8} = Rt2; 3330 3331 let Inst{7} = 1; 3332 } 3333 } 3334 3335 let mayStore = 1, Constraints = "@earlyclobber $Rd" in { 3336 def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd), 3337 (ins rGPR:$Rt, addr_offset_none:$addr), 3338 AddrModeNone, 4, NoItinerary, 3339 "strexb", "\t$Rd, $Rt, $addr", "", 3340 [(set rGPR:$Rd, 3341 (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>; 3342 def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd), 3343 (ins rGPR:$Rt, addr_offset_none:$addr), 3344 AddrModeNone, 4, NoItinerary, 3345 "strexh", "\t$Rd, $Rt, $addr", "", 3346 [(set rGPR:$Rd, 3347 (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>; 3348 3349 def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt, 3350 t2addrmode_imm0_1020s4:$addr), 3351 AddrModeNone, 4, NoItinerary, 3352 "strex", "\t$Rd, $Rt, $addr", "", 3353 [(set rGPR:$Rd, 3354 (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]> { 3355 bits<4> Rd; 3356 bits<4> Rt; 3357 bits<12> addr; 3358 let Inst{31-27} = 0b11101; 3359 let Inst{26-20} = 0b0000100; 3360 let Inst{19-16} = addr{11-8}; 3361 let Inst{15-12} = Rt; 3362 let Inst{11-8} = Rd; 3363 let Inst{7-0} = addr{7-0}; 3364 } 3365 let hasExtraSrcRegAllocReq = 1 in 3366 def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd), 3367 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr), 3368 AddrModeNone, 4, NoItinerary, 3369 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [], 3370 {?, ?, ?, ?}> { 3371 bits<4> Rt2; 3372 let Inst{11-8} = Rt2; 3373 } 3374 def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd), 3375 (ins rGPR:$Rt, addr_offset_none:$addr), 3376 AddrModeNone, 4, NoItinerary, 3377 "stlexb", "\t$Rd, $Rt, $addr", "", 3378 [(set rGPR:$Rd, 3379 (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>, 3380 Requires<[IsThumb, HasV8]>; 3381 3382 def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd), 3383 (ins rGPR:$Rt, addr_offset_none:$addr), 3384 AddrModeNone, 4, NoItinerary, 3385 "stlexh", "\t$Rd, $Rt, $addr", "", 3386 [(set rGPR:$Rd, 3387 (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>, 3388 Requires<[IsThumb, HasV8]>; 3389 3390 def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt, 3391 addr_offset_none:$addr), 3392 AddrModeNone, 4, NoItinerary, 3393 "stlex", "\t$Rd, $Rt, $addr", "", 3394 [(set rGPR:$Rd, 3395 (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>, 3396 Requires<[IsThumb, HasV8]> { 3397 bits<4> Rd; 3398 bits<4> Rt; 3399 bits<4> addr; 3400 let Inst{31-27} = 0b11101; 3401 let Inst{26-20} = 0b0001100; 3402 let Inst{19-16} = addr; 3403 let Inst{15-12} = Rt; 3404 let Inst{11-4} = 0b11111110; 3405 let Inst{3-0} = Rd; 3406 } 3407 let hasExtraSrcRegAllocReq = 1 in 3408 def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd), 3409 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr), 3410 AddrModeNone, 4, NoItinerary, 3411 "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [], 3412 {?, ?, ?, ?}>, Requires<[IsThumb, HasV8]> { 3413 bits<4> Rt2; 3414 let Inst{11-8} = Rt2; 3415 } 3416 } 3417 3418 def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>, 3419 Requires<[IsThumb2, HasV7]> { 3420 let Inst{31-16} = 0xf3bf; 3421 let Inst{15-14} = 0b10; 3422 let Inst{13} = 0; 3423 let Inst{12} = 0; 3424 let Inst{11-8} = 0b1111; 3425 let Inst{7-4} = 0b0010; 3426 let Inst{3-0} = 0b1111; 3427 } 3428 3429 def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff), 3430 (t2LDREXB addr_offset_none:$addr)>; 3431 def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff), 3432 (t2LDREXH addr_offset_none:$addr)>; 3433 def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr), 3434 (t2STREXB GPR:$Rt, addr_offset_none:$addr)>; 3435 def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr), 3436 (t2STREXH GPR:$Rt, addr_offset_none:$addr)>; 3437 3438 def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff), 3439 (t2LDAEXB addr_offset_none:$addr)>; 3440 def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff), 3441 (t2LDAEXH addr_offset_none:$addr)>; 3442 def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr), 3443 (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>; 3444 def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr), 3445 (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>; 3446 3447 //===----------------------------------------------------------------------===// 3448 // SJLJ Exception handling intrinsics 3449 // eh_sjlj_setjmp() is an instruction sequence to store the return 3450 // address and save #0 in R0 for the non-longjmp case. 3451 // Since by its nature we may be coming from some other function to get 3452 // here, and we're using the stack frame for the containing function to 3453 // save/restore registers, we can't keep anything live in regs across 3454 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon 3455 // when we get here from a longjmp(). We force everything out of registers 3456 // except for our own input by listing the relevant registers in Defs. By 3457 // doing so, we also cause the prologue/epilogue code to actively preserve 3458 // all of the callee-saved resgisters, which is exactly what we want. 3459 // $val is a scratch register for our use. 3460 let Defs = 3461 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR, 3462 Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15], 3463 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, 3464 usesCustomInserter = 1 in { 3465 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val), 3466 AddrModeNone, 0, NoItinerary, "", "", 3467 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>, 3468 Requires<[IsThumb2, HasVFP2]>; 3469 } 3470 3471 let Defs = 3472 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ], 3473 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, 3474 usesCustomInserter = 1 in { 3475 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val), 3476 AddrModeNone, 0, NoItinerary, "", "", 3477 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>, 3478 Requires<[IsThumb2, NoVFP]>; 3479 } 3480 3481 3482 //===----------------------------------------------------------------------===// 3483 // Control-Flow Instructions 3484 // 3485 3486 // FIXME: remove when we have a way to marking a MI with these properties. 3487 // FIXME: Should pc be an implicit operand like PICADD, etc? 3488 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1, 3489 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in 3490 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, 3491 reglist:$regs, variable_ops), 3492 4, IIC_iLoad_mBr, [], 3493 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>, 3494 RegConstraint<"$Rn = $wb">; 3495 3496 let isBranch = 1, isTerminator = 1, isBarrier = 1 in { 3497 let isPredicable = 1 in 3498 def t2B : T2I<(outs), (ins uncondbrtarget:$target), IIC_Br, 3499 "b", ".w\t$target", 3500 [(br bb:$target)]>, Sched<[WriteBr]> { 3501 let Inst{31-27} = 0b11110; 3502 let Inst{15-14} = 0b10; 3503 let Inst{12} = 1; 3504 3505 bits<24> target; 3506 let Inst{26} = target{23}; 3507 let Inst{13} = target{22}; 3508 let Inst{11} = target{21}; 3509 let Inst{25-16} = target{20-11}; 3510 let Inst{10-0} = target{10-0}; 3511 let DecoderMethod = "DecodeT2BInstruction"; 3512 let AsmMatchConverter = "cvtThumbBranches"; 3513 } 3514 3515 let isNotDuplicable = 1, isIndirectBranch = 1 in { 3516 def t2BR_JT : t2PseudoInst<(outs), 3517 (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id), 3518 0, IIC_Br, 3519 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>, 3520 Sched<[WriteBr]>; 3521 3522 // FIXME: Add a non-pc based case that can be predicated. 3523 def t2TBB_JT : t2PseudoInst<(outs), 3524 (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>, 3525 Sched<[WriteBr]>; 3526 3527 def t2TBH_JT : t2PseudoInst<(outs), 3528 (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>, 3529 Sched<[WriteBr]>; 3530 3531 def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br, 3532 "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> { 3533 bits<4> Rn; 3534 bits<4> Rm; 3535 let Inst{31-20} = 0b111010001101; 3536 let Inst{19-16} = Rn; 3537 let Inst{15-5} = 0b11110000000; 3538 let Inst{4} = 0; // B form 3539 let Inst{3-0} = Rm; 3540 3541 let DecoderMethod = "DecodeThumbTableBranch"; 3542 } 3543 3544 def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br, 3545 "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> { 3546 bits<4> Rn; 3547 bits<4> Rm; 3548 let Inst{31-20} = 0b111010001101; 3549 let Inst{19-16} = Rn; 3550 let Inst{15-5} = 0b11110000000; 3551 let Inst{4} = 1; // H form 3552 let Inst{3-0} = Rm; 3553 3554 let DecoderMethod = "DecodeThumbTableBranch"; 3555 } 3556 } // isNotDuplicable, isIndirectBranch 3557 3558 } // isBranch, isTerminator, isBarrier 3559 3560 // FIXME: should be able to write a pattern for ARMBrcond, but can't use 3561 // a two-value operand where a dag node expects ", "two operands. :( 3562 let isBranch = 1, isTerminator = 1 in 3563 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br, 3564 "b", ".w\t$target", 3565 [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> { 3566 let Inst{31-27} = 0b11110; 3567 let Inst{15-14} = 0b10; 3568 let Inst{12} = 0; 3569 3570 bits<4> p; 3571 let Inst{25-22} = p; 3572 3573 bits<21> target; 3574 let Inst{26} = target{20}; 3575 let Inst{11} = target{19}; 3576 let Inst{13} = target{18}; 3577 let Inst{21-16} = target{17-12}; 3578 let Inst{10-0} = target{11-1}; 3579 3580 let DecoderMethod = "DecodeThumb2BCCInstruction"; 3581 let AsmMatchConverter = "cvtThumbBranches"; 3582 } 3583 3584 // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so 3585 // it goes here. 3586 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in { 3587 // IOS version. 3588 let Uses = [SP] in 3589 def tTAILJMPd: tPseudoExpand<(outs), 3590 (ins uncondbrtarget:$dst, pred:$p), 3591 4, IIC_Br, [], 3592 (t2B uncondbrtarget:$dst, pred:$p)>, 3593 Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>; 3594 } 3595 3596 // IT block 3597 let Defs = [ITSTATE] in 3598 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask), 3599 AddrModeNone, 2, IIC_iALUx, 3600 "it$mask\t$cc", "", []>, 3601 ComplexDeprecationPredicate<"IT"> { 3602 // 16-bit instruction. 3603 let Inst{31-16} = 0x0000; 3604 let Inst{15-8} = 0b10111111; 3605 3606 bits<4> cc; 3607 bits<4> mask; 3608 let Inst{7-4} = cc; 3609 let Inst{3-0} = mask; 3610 3611 let DecoderMethod = "DecodeIT"; 3612 } 3613 3614 // Branch and Exchange Jazelle -- for disassembly only 3615 // Rm = Inst{19-16} 3616 def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func", []>, 3617 Sched<[WriteBr]> { 3618 bits<4> func; 3619 let Inst{31-27} = 0b11110; 3620 let Inst{26} = 0; 3621 let Inst{25-20} = 0b111100; 3622 let Inst{19-16} = func; 3623 let Inst{15-0} = 0b1000111100000000; 3624 } 3625 3626 // Compare and branch on zero / non-zero 3627 let isBranch = 1, isTerminator = 1 in { 3628 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br, 3629 "cbz\t$Rn, $target", []>, 3630 T1Misc<{0,0,?,1,?,?,?}>, 3631 Requires<[IsThumb2]>, Sched<[WriteBr]> { 3632 // A8.6.27 3633 bits<6> target; 3634 bits<3> Rn; 3635 let Inst{9} = target{5}; 3636 let Inst{7-3} = target{4-0}; 3637 let Inst{2-0} = Rn; 3638 } 3639 3640 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br, 3641 "cbnz\t$Rn, $target", []>, 3642 T1Misc<{1,0,?,1,?,?,?}>, 3643 Requires<[IsThumb2]>, Sched<[WriteBr]> { 3644 // A8.6.27 3645 bits<6> target; 3646 bits<3> Rn; 3647 let Inst{9} = target{5}; 3648 let Inst{7-3} = target{4-0}; 3649 let Inst{2-0} = Rn; 3650 } 3651 } 3652 3653 3654 // Change Processor State is a system instruction. 3655 // FIXME: Since the asm parser has currently no clean way to handle optional 3656 // operands, create 3 versions of the same instruction. Once there's a clean 3657 // framework to represent optional operands, change this behavior. 3658 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary, 3659 !strconcat("cps", asm_op), []> { 3660 bits<2> imod; 3661 bits<3> iflags; 3662 bits<5> mode; 3663 bit M; 3664 3665 let Inst{31-11} = 0b111100111010111110000; 3666 let Inst{10-9} = imod; 3667 let Inst{8} = M; 3668 let Inst{7-5} = iflags; 3669 let Inst{4-0} = mode; 3670 let DecoderMethod = "DecodeT2CPSInstruction"; 3671 } 3672 3673 let M = 1 in 3674 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 3675 "$imod\t$iflags, $mode">; 3676 let mode = 0, M = 0 in 3677 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags), 3678 "$imod.w\t$iflags">; 3679 let imod = 0, iflags = 0, M = 1 in 3680 def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">; 3681 3682 def : t2InstAlias<"cps$imod.w $iflags, $mode", 3683 (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>; 3684 def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>; 3685 3686 // A6.3.4 Branches and miscellaneous control 3687 // Table A6-14 Change Processor State, and hint instructions 3688 def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm", 3689 [(int_arm_hint imm0_239:$imm)]> { 3690 bits<8> imm; 3691 let Inst{31-3} = 0b11110011101011111000000000000; 3692 let Inst{7-0} = imm; 3693 } 3694 3695 def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p)>; 3696 def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p)>; 3697 def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p)>; 3698 def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p)>; 3699 def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p)>; 3700 def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p)>; 3701 def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p)> { 3702 let Predicates = [IsThumb2, HasV8]; 3703 } 3704 3705 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt", []> { 3706 bits<4> opt; 3707 let Inst{31-20} = 0b111100111010; 3708 let Inst{19-16} = 0b1111; 3709 let Inst{15-8} = 0b10000000; 3710 let Inst{7-4} = 0b1111; 3711 let Inst{3-0} = opt; 3712 } 3713 3714 // Secure Monitor Call is a system instruction. 3715 // Option = Inst{19-16} 3716 def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt", 3717 []>, Requires<[IsThumb2, HasTrustZone]> { 3718 let Inst{31-27} = 0b11110; 3719 let Inst{26-20} = 0b1111111; 3720 let Inst{15-12} = 0b1000; 3721 3722 bits<4> opt; 3723 let Inst{19-16} = opt; 3724 } 3725 3726 class T2DCPS<bits<2> opt, string opc> 3727 : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> { 3728 let Inst{31-27} = 0b11110; 3729 let Inst{26-20} = 0b1111000; 3730 let Inst{19-16} = 0b1111; 3731 let Inst{15-12} = 0b1000; 3732 let Inst{11-2} = 0b0000000000; 3733 let Inst{1-0} = opt; 3734 } 3735 3736 def t2DCPS1 : T2DCPS<0b01, "dcps1">; 3737 def t2DCPS2 : T2DCPS<0b10, "dcps2">; 3738 def t2DCPS3 : T2DCPS<0b11, "dcps3">; 3739 3740 class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin, 3741 string opc, string asm, list<dag> pattern> 3742 : T2I<oops, iops, itin, opc, asm, pattern> { 3743 bits<5> mode; 3744 let Inst{31-25} = 0b1110100; 3745 let Inst{24-23} = Op; 3746 let Inst{22} = 0; 3747 let Inst{21} = W; 3748 let Inst{20-16} = 0b01101; 3749 let Inst{15-5} = 0b11000000000; 3750 let Inst{4-0} = mode{4-0}; 3751 } 3752 3753 // Store Return State is a system instruction. 3754 def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary, 3755 "srsdb", "\tsp!, $mode", []>; 3756 def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary, 3757 "srsdb","\tsp, $mode", []>; 3758 def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary, 3759 "srsia","\tsp!, $mode", []>; 3760 def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary, 3761 "srsia","\tsp, $mode", []>; 3762 3763 3764 def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>; 3765 def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>; 3766 3767 def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>; 3768 def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>; 3769 3770 // Return From Exception is a system instruction. 3771 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin, 3772 string opc, string asm, list<dag> pattern> 3773 : T2I<oops, iops, itin, opc, asm, pattern> { 3774 let Inst{31-20} = op31_20{11-0}; 3775 3776 bits<4> Rn; 3777 let Inst{19-16} = Rn; 3778 let Inst{15-0} = 0xc000; 3779 } 3780 3781 def t2RFEDBW : T2RFE<0b111010000011, 3782 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!", 3783 [/* For disassembly only; pattern left blank */]>; 3784 def t2RFEDB : T2RFE<0b111010000001, 3785 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn", 3786 [/* For disassembly only; pattern left blank */]>; 3787 def t2RFEIAW : T2RFE<0b111010011011, 3788 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!", 3789 [/* For disassembly only; pattern left blank */]>; 3790 def t2RFEIA : T2RFE<0b111010011001, 3791 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn", 3792 [/* For disassembly only; pattern left blank */]>; 3793 3794 // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction. 3795 // Exception return instruction is "subs pc, lr, #imm". 3796 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in 3797 def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary, 3798 "subs", "\tpc, lr, $imm", 3799 [(ARMintretflag imm0_255:$imm)]>, 3800 Requires<[IsThumb2]> { 3801 let Inst{31-8} = 0b111100111101111010001111; 3802 3803 bits<8> imm; 3804 let Inst{7-0} = imm; 3805 } 3806 3807 //===----------------------------------------------------------------------===// 3808 // Non-Instruction Patterns 3809 // 3810 3811 // 32-bit immediate using movw + movt. 3812 // This is a single pseudo instruction to make it re-materializable. 3813 // FIXME: Remove this when we can do generalized remat. 3814 let isReMaterializable = 1, isMoveImm = 1 in 3815 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2, 3816 [(set rGPR:$dst, (i32 imm:$src))]>, 3817 Requires<[IsThumb, UseMovt]>; 3818 3819 // Pseudo instruction that combines movw + movt + add pc (if pic). 3820 // It also makes it possible to rematerialize the instructions. 3821 // FIXME: Remove this when we can do generalized remat and when machine licm 3822 // can properly the instructions. 3823 let isReMaterializable = 1 in { 3824 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr), 3825 IIC_iMOVix2addpc, 3826 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>, 3827 Requires<[IsThumb2, UseMovt]>; 3828 3829 } 3830 3831 // ConstantPool, GlobalAddress, and JumpTable 3832 def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>; 3833 def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>, 3834 Requires<[IsThumb2, UseMovt]>; 3835 3836 def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id), 3837 (t2LEApcrelJT tjumptable:$dst, imm:$id)>; 3838 3839 // Pseudo instruction that combines ldr from constpool and add pc. This should 3840 // be expanded into two instructions late to allow if-conversion and 3841 // scheduling. 3842 let canFoldAsLoad = 1, isReMaterializable = 1 in 3843 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp), 3844 IIC_iLoadiALU, 3845 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)), 3846 imm:$cp))]>, 3847 Requires<[IsThumb2]>; 3848 3849 // Pseudo isntruction that combines movs + predicated rsbmi 3850 // to implement integer ABS 3851 let usesCustomInserter = 1, Defs = [CPSR] in { 3852 def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src), 3853 NoItinerary, []>, Requires<[IsThumb2]>; 3854 } 3855 3856 //===----------------------------------------------------------------------===// 3857 // Coprocessor load/store -- for disassembly only 3858 // 3859 class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm> 3860 : T2I<oops, iops, NoItinerary, opc, asm, []> { 3861 let Inst{31-28} = op31_28; 3862 let Inst{27-25} = 0b110; 3863 } 3864 3865 multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm> { 3866 def _OFFSET : T2CI<op31_28, 3867 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr), 3868 asm, "\t$cop, $CRd, $addr"> { 3869 bits<13> addr; 3870 bits<4> cop; 3871 bits<4> CRd; 3872 let Inst{24} = 1; // P = 1 3873 let Inst{23} = addr{8}; 3874 let Inst{22} = Dbit; 3875 let Inst{21} = 0; // W = 0 3876 let Inst{20} = load; 3877 let Inst{19-16} = addr{12-9}; 3878 let Inst{15-12} = CRd; 3879 let Inst{11-8} = cop; 3880 let Inst{7-0} = addr{7-0}; 3881 let DecoderMethod = "DecodeCopMemInstruction"; 3882 } 3883 def _PRE : T2CI<op31_28, 3884 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr), 3885 asm, "\t$cop, $CRd, $addr!"> { 3886 bits<13> addr; 3887 bits<4> cop; 3888 bits<4> CRd; 3889 let Inst{24} = 1; // P = 1 3890 let Inst{23} = addr{8}; 3891 let Inst{22} = Dbit; 3892 let Inst{21} = 1; // W = 1 3893 let Inst{20} = load; 3894 let Inst{19-16} = addr{12-9}; 3895 let Inst{15-12} = CRd; 3896 let Inst{11-8} = cop; 3897 let Inst{7-0} = addr{7-0}; 3898 let DecoderMethod = "DecodeCopMemInstruction"; 3899 } 3900 def _POST: T2CI<op31_28, 3901 (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr, 3902 postidx_imm8s4:$offset), 3903 asm, "\t$cop, $CRd, $addr, $offset"> { 3904 bits<9> offset; 3905 bits<4> addr; 3906 bits<4> cop; 3907 bits<4> CRd; 3908 let Inst{24} = 0; // P = 0 3909 let Inst{23} = offset{8}; 3910 let Inst{22} = Dbit; 3911 let Inst{21} = 1; // W = 1 3912 let Inst{20} = load; 3913 let Inst{19-16} = addr; 3914 let Inst{15-12} = CRd; 3915 let Inst{11-8} = cop; 3916 let Inst{7-0} = offset{7-0}; 3917 let DecoderMethod = "DecodeCopMemInstruction"; 3918 } 3919 def _OPTION : T2CI<op31_28, (outs), 3920 (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr, 3921 coproc_option_imm:$option), 3922 asm, "\t$cop, $CRd, $addr, $option"> { 3923 bits<8> option; 3924 bits<4> addr; 3925 bits<4> cop; 3926 bits<4> CRd; 3927 let Inst{24} = 0; // P = 0 3928 let Inst{23} = 1; // U = 1 3929 let Inst{22} = Dbit; 3930 let Inst{21} = 0; // W = 0 3931 let Inst{20} = load; 3932 let Inst{19-16} = addr; 3933 let Inst{15-12} = CRd; 3934 let Inst{11-8} = cop; 3935 let Inst{7-0} = option; 3936 let DecoderMethod = "DecodeCopMemInstruction"; 3937 } 3938 } 3939 3940 defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc">; 3941 defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl">; 3942 defm t2STC : t2LdStCop<0b1110, 0, 0, "stc">; 3943 defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl">; 3944 defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2">, Requires<[PreV8]>; 3945 defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l">, Requires<[PreV8]>; 3946 defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2">, Requires<[PreV8]>; 3947 defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l">, Requires<[PreV8]>; 3948 3949 3950 //===----------------------------------------------------------------------===// 3951 // Move between special register and ARM core register -- for disassembly only 3952 // 3953 // Move to ARM core register from Special Register 3954 3955 // A/R class MRS. 3956 // 3957 // A/R class can only move from CPSR or SPSR. 3958 def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr", 3959 []>, Requires<[IsThumb2,IsNotMClass]> { 3960 bits<4> Rd; 3961 let Inst{31-12} = 0b11110011111011111000; 3962 let Inst{11-8} = Rd; 3963 let Inst{7-0} = 0b0000; 3964 } 3965 3966 def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>; 3967 3968 def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr", 3969 []>, Requires<[IsThumb2,IsNotMClass]> { 3970 bits<4> Rd; 3971 let Inst{31-12} = 0b11110011111111111000; 3972 let Inst{11-8} = Rd; 3973 let Inst{7-0} = 0b0000; 3974 } 3975 3976 // M class MRS. 3977 // 3978 // This MRS has a mask field in bits 7-0 and can take more values than 3979 // the A/R class (a full msr_mask). 3980 def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$mask), NoItinerary, 3981 "mrs", "\t$Rd, $mask", []>, 3982 Requires<[IsThumb,IsMClass]> { 3983 bits<4> Rd; 3984 bits<8> mask; 3985 let Inst{31-12} = 0b11110011111011111000; 3986 let Inst{11-8} = Rd; 3987 let Inst{19-16} = 0b1111; 3988 let Inst{7-0} = mask; 3989 } 3990 3991 3992 // Move from ARM core register to Special Register 3993 // 3994 // A/R class MSR. 3995 // 3996 // No need to have both system and application versions, the encodings are the 3997 // same and the assembly parser has no way to distinguish between them. The mask 3998 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains 3999 // the mask with the fields to be accessed in the special register. 4000 def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn), 4001 NoItinerary, "msr", "\t$mask, $Rn", []>, 4002 Requires<[IsThumb2,IsNotMClass]> { 4003 bits<5> mask; 4004 bits<4> Rn; 4005 let Inst{31-21} = 0b11110011100; 4006 let Inst{20} = mask{4}; // R Bit 4007 let Inst{19-16} = Rn; 4008 let Inst{15-12} = 0b1000; 4009 let Inst{11-8} = mask{3-0}; 4010 let Inst{7-0} = 0; 4011 } 4012 4013 // M class MSR. 4014 // 4015 // Move from ARM core register to Special Register 4016 def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn), 4017 NoItinerary, "msr", "\t$SYSm, $Rn", []>, 4018 Requires<[IsThumb,IsMClass]> { 4019 bits<12> SYSm; 4020 bits<4> Rn; 4021 let Inst{31-21} = 0b11110011100; 4022 let Inst{20} = 0b0; 4023 let Inst{19-16} = Rn; 4024 let Inst{15-12} = 0b1000; 4025 let Inst{11-0} = SYSm; 4026 } 4027 4028 4029 //===----------------------------------------------------------------------===// 4030 // Move between coprocessor and ARM core register 4031 // 4032 4033 class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops, 4034 list<dag> pattern> 4035 : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2", 4036 pattern> { 4037 let Inst{27-24} = 0b1110; 4038 let Inst{20} = direction; 4039 let Inst{4} = 1; 4040 4041 bits<4> Rt; 4042 bits<4> cop; 4043 bits<3> opc1; 4044 bits<3> opc2; 4045 bits<4> CRm; 4046 bits<4> CRn; 4047 4048 let Inst{15-12} = Rt; 4049 let Inst{11-8} = cop; 4050 let Inst{23-21} = opc1; 4051 let Inst{7-5} = opc2; 4052 let Inst{3-0} = CRm; 4053 let Inst{19-16} = CRn; 4054 } 4055 4056 class t2MovRRCopro<bits<4> Op, string opc, bit direction, 4057 list<dag> pattern = []> 4058 : T2Cop<Op, (outs), 4059 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm), 4060 opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> { 4061 let Inst{27-24} = 0b1100; 4062 let Inst{23-21} = 0b010; 4063 let Inst{20} = direction; 4064 4065 bits<4> Rt; 4066 bits<4> Rt2; 4067 bits<4> cop; 4068 bits<4> opc1; 4069 bits<4> CRm; 4070 4071 let Inst{15-12} = Rt; 4072 let Inst{19-16} = Rt2; 4073 let Inst{11-8} = cop; 4074 let Inst{7-4} = opc1; 4075 let Inst{3-0} = CRm; 4076 } 4077 4078 /* from ARM core register to coprocessor */ 4079 def t2MCR : t2MovRCopro<0b1110, "mcr", 0, 4080 (outs), 4081 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn, 4082 c_imm:$CRm, imm0_7:$opc2), 4083 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn, 4084 imm:$CRm, imm:$opc2)]>, 4085 ComplexDeprecationPredicate<"MCR">; 4086 def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm", 4087 (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn, 4088 c_imm:$CRm, 0, pred:$p)>; 4089 def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0, 4090 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn, 4091 c_imm:$CRm, imm0_7:$opc2), 4092 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn, 4093 imm:$CRm, imm:$opc2)]> { 4094 let Predicates = [IsThumb2, PreV8]; 4095 } 4096 def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm", 4097 (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn, 4098 c_imm:$CRm, 0, pred:$p)>; 4099 4100 /* from coprocessor to ARM core register */ 4101 def t2MRC : t2MovRCopro<0b1110, "mrc", 1, 4102 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, 4103 c_imm:$CRm, imm0_7:$opc2), []>; 4104 def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm", 4105 (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, 4106 c_imm:$CRm, 0, pred:$p)>; 4107 4108 def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1, 4109 (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, 4110 c_imm:$CRm, imm0_7:$opc2), []> { 4111 let Predicates = [IsThumb2, PreV8]; 4112 } 4113 def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm", 4114 (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, 4115 c_imm:$CRm, 0, pred:$p)>; 4116 4117 def : T2v6Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2), 4118 (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>; 4119 4120 def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2), 4121 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>; 4122 4123 4124 /* from ARM core register to coprocessor */ 4125 def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, 4126 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2, 4127 imm:$CRm)]>; 4128 def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, 4129 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt, 4130 GPR:$Rt2, imm:$CRm)]> { 4131 let Predicates = [IsThumb2, PreV8]; 4132 } 4133 4134 /* from coprocessor to ARM core register */ 4135 def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1>; 4136 4137 def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1> { 4138 let Predicates = [IsThumb2, PreV8]; 4139 } 4140 4141 //===----------------------------------------------------------------------===// 4142 // Other Coprocessor Instructions. 4143 // 4144 4145 def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1, 4146 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2), 4147 "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2", 4148 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn, 4149 imm:$CRm, imm:$opc2)]> { 4150 let Inst{27-24} = 0b1110; 4151 4152 bits<4> opc1; 4153 bits<4> CRn; 4154 bits<4> CRd; 4155 bits<4> cop; 4156 bits<3> opc2; 4157 bits<4> CRm; 4158 4159 let Inst{3-0} = CRm; 4160 let Inst{4} = 0; 4161 let Inst{7-5} = opc2; 4162 let Inst{11-8} = cop; 4163 let Inst{15-12} = CRd; 4164 let Inst{19-16} = CRn; 4165 let Inst{23-20} = opc1; 4166 4167 let Predicates = [IsThumb2, PreV8]; 4168 } 4169 4170 def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1, 4171 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2), 4172 "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2", 4173 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn, 4174 imm:$CRm, imm:$opc2)]> { 4175 let Inst{27-24} = 0b1110; 4176 4177 bits<4> opc1; 4178 bits<4> CRn; 4179 bits<4> CRd; 4180 bits<4> cop; 4181 bits<3> opc2; 4182 bits<4> CRm; 4183 4184 let Inst{3-0} = CRm; 4185 let Inst{4} = 0; 4186 let Inst{7-5} = opc2; 4187 let Inst{11-8} = cop; 4188 let Inst{15-12} = CRd; 4189 let Inst{19-16} = CRn; 4190 let Inst{23-20} = opc1; 4191 4192 let Predicates = [IsThumb2, PreV8]; 4193 } 4194 4195 4196 4197 //===----------------------------------------------------------------------===// 4198 // Non-Instruction Patterns 4199 // 4200 4201 // SXT/UXT with no rotate 4202 let AddedComplexity = 16 in { 4203 def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>, 4204 Requires<[IsThumb2]>; 4205 def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>, 4206 Requires<[IsThumb2]>; 4207 def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>, 4208 Requires<[HasT2ExtractPack, IsThumb2]>; 4209 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)), 4210 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>, 4211 Requires<[HasT2ExtractPack, IsThumb2]>; 4212 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)), 4213 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>, 4214 Requires<[HasT2ExtractPack, IsThumb2]>; 4215 } 4216 4217 def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>, 4218 Requires<[IsThumb2]>; 4219 def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>, 4220 Requires<[IsThumb2]>; 4221 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)), 4222 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>, 4223 Requires<[HasT2ExtractPack, IsThumb2]>; 4224 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)), 4225 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>, 4226 Requires<[HasT2ExtractPack, IsThumb2]>; 4227 4228 // Atomic load/store patterns 4229 def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr), 4230 (t2LDRBi12 t2addrmode_imm12:$addr)>; 4231 def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr), 4232 (t2LDRBi8 t2addrmode_negimm8:$addr)>; 4233 def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr), 4234 (t2LDRBs t2addrmode_so_reg:$addr)>; 4235 def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr), 4236 (t2LDRHi12 t2addrmode_imm12:$addr)>; 4237 def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr), 4238 (t2LDRHi8 t2addrmode_negimm8:$addr)>; 4239 def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr), 4240 (t2LDRHs t2addrmode_so_reg:$addr)>; 4241 def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr), 4242 (t2LDRi12 t2addrmode_imm12:$addr)>; 4243 def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr), 4244 (t2LDRi8 t2addrmode_negimm8:$addr)>; 4245 def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr), 4246 (t2LDRs t2addrmode_so_reg:$addr)>; 4247 def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val), 4248 (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>; 4249 def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val), 4250 (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>; 4251 def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val), 4252 (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>; 4253 def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val), 4254 (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>; 4255 def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val), 4256 (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>; 4257 def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val), 4258 (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>; 4259 def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val), 4260 (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>; 4261 def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val), 4262 (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>; 4263 def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val), 4264 (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>; 4265 4266 let AddedComplexity = 8 in { 4267 def : T2Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>; 4268 def : T2Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>; 4269 def : T2Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>; 4270 def : T2Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>; 4271 def : T2Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>; 4272 def : T2Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>; 4273 } 4274 4275 4276 //===----------------------------------------------------------------------===// 4277 // Assembler aliases 4278 // 4279 4280 // Aliases for ADC without the ".w" optional width specifier. 4281 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm", 4282 (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4283 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm", 4284 (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm, 4285 pred:$p, cc_out:$s)>; 4286 4287 // Aliases for SBC without the ".w" optional width specifier. 4288 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm", 4289 (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4290 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm", 4291 (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm, 4292 pred:$p, cc_out:$s)>; 4293 4294 // Aliases for ADD without the ".w" optional width specifier. 4295 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm", 4296 (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, 4297 cc_out:$s)>; 4298 def : t2InstAlias<"add${p} $Rd, $Rn, $imm", 4299 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>; 4300 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm", 4301 (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4302 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm", 4303 (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm, 4304 pred:$p, cc_out:$s)>; 4305 // ... and with the destination and source register combined. 4306 def : t2InstAlias<"add${s}${p} $Rdn, $imm", 4307 (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>; 4308 def : t2InstAlias<"add${p} $Rdn, $imm", 4309 (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>; 4310 def : t2InstAlias<"add${s}${p} $Rdn, $Rm", 4311 (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4312 def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm", 4313 (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm, 4314 pred:$p, cc_out:$s)>; 4315 4316 // add w/ negative immediates is just a sub. 4317 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm", 4318 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p, 4319 cc_out:$s)>; 4320 def : t2InstAlias<"add${p} $Rd, $Rn, $imm", 4321 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>; 4322 def : t2InstAlias<"add${s}${p} $Rdn, $imm", 4323 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p, 4324 cc_out:$s)>; 4325 def : t2InstAlias<"add${p} $Rdn, $imm", 4326 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>; 4327 4328 def : t2InstAlias<"add${s}${p}.w $Rd, $Rn, $imm", 4329 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p, 4330 cc_out:$s)>; 4331 def : t2InstAlias<"addw${p} $Rd, $Rn, $imm", 4332 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>; 4333 def : t2InstAlias<"add${s}${p}.w $Rdn, $imm", 4334 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p, 4335 cc_out:$s)>; 4336 def : t2InstAlias<"addw${p} $Rdn, $imm", 4337 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>; 4338 4339 4340 // Aliases for SUB without the ".w" optional width specifier. 4341 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm", 4342 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>; 4343 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm", 4344 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>; 4345 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm", 4346 (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4347 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm", 4348 (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm, 4349 pred:$p, cc_out:$s)>; 4350 // ... and with the destination and source register combined. 4351 def : t2InstAlias<"sub${s}${p} $Rdn, $imm", 4352 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>; 4353 def : t2InstAlias<"sub${p} $Rdn, $imm", 4354 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>; 4355 def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm", 4356 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4357 def : t2InstAlias<"sub${s}${p} $Rdn, $Rm", 4358 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4359 def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm", 4360 (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm, 4361 pred:$p, cc_out:$s)>; 4362 4363 // Alias for compares without the ".w" optional width specifier. 4364 def : t2InstAlias<"cmn${p} $Rn, $Rm", 4365 (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>; 4366 def : t2InstAlias<"teq${p} $Rn, $Rm", 4367 (t2TEQrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>; 4368 def : t2InstAlias<"tst${p} $Rn, $Rm", 4369 (t2TSTrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>; 4370 4371 // Memory barriers 4372 def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p)>, Requires<[HasDB]>; 4373 def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p)>, Requires<[HasDB]>; 4374 def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p)>, Requires<[HasDB]>; 4375 4376 // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional 4377 // width specifier. 4378 def : t2InstAlias<"ldr${p} $Rt, $addr", 4379 (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4380 def : t2InstAlias<"ldrb${p} $Rt, $addr", 4381 (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4382 def : t2InstAlias<"ldrh${p} $Rt, $addr", 4383 (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4384 def : t2InstAlias<"ldrsb${p} $Rt, $addr", 4385 (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4386 def : t2InstAlias<"ldrsh${p} $Rt, $addr", 4387 (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4388 4389 def : t2InstAlias<"ldr${p} $Rt, $addr", 4390 (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4391 def : t2InstAlias<"ldrb${p} $Rt, $addr", 4392 (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4393 def : t2InstAlias<"ldrh${p} $Rt, $addr", 4394 (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4395 def : t2InstAlias<"ldrsb${p} $Rt, $addr", 4396 (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4397 def : t2InstAlias<"ldrsh${p} $Rt, $addr", 4398 (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4399 4400 def : t2InstAlias<"ldr${p} $Rt, $addr", 4401 (t2LDRpci GPRnopc:$Rt, t2ldrlabel:$addr, pred:$p)>; 4402 def : t2InstAlias<"ldrb${p} $Rt, $addr", 4403 (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>; 4404 def : t2InstAlias<"ldrh${p} $Rt, $addr", 4405 (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>; 4406 def : t2InstAlias<"ldrsb${p} $Rt, $addr", 4407 (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>; 4408 def : t2InstAlias<"ldrsh${p} $Rt, $addr", 4409 (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>; 4410 4411 // Alias for MVN with(out) the ".w" optional width specifier. 4412 def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm", 4413 (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>; 4414 def : t2InstAlias<"mvn${s}${p} $Rd, $Rm", 4415 (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>; 4416 def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm", 4417 (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>; 4418 4419 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the 4420 // shift amount is zero (i.e., unspecified). 4421 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm", 4422 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>, 4423 Requires<[HasT2ExtractPack, IsThumb2]>; 4424 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm", 4425 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>, 4426 Requires<[HasT2ExtractPack, IsThumb2]>; 4427 4428 // PUSH/POP aliases for STM/LDM 4429 def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>; 4430 def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>; 4431 def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>; 4432 def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>; 4433 4434 // STMIA/STMIA_UPD aliases w/o the optional .w suffix 4435 def : t2InstAlias<"stm${p} $Rn, $regs", 4436 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>; 4437 def : t2InstAlias<"stm${p} $Rn!, $regs", 4438 (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>; 4439 4440 // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix 4441 def : t2InstAlias<"ldm${p} $Rn, $regs", 4442 (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>; 4443 def : t2InstAlias<"ldm${p} $Rn!, $regs", 4444 (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>; 4445 4446 // STMDB/STMDB_UPD aliases w/ the optional .w suffix 4447 def : t2InstAlias<"stmdb${p}.w $Rn, $regs", 4448 (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>; 4449 def : t2InstAlias<"stmdb${p}.w $Rn!, $regs", 4450 (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>; 4451 4452 // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix 4453 def : t2InstAlias<"ldmdb${p}.w $Rn, $regs", 4454 (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>; 4455 def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs", 4456 (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>; 4457 4458 // Alias for REV/REV16/REVSH without the ".w" optional width specifier. 4459 def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>; 4460 def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>; 4461 def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>; 4462 4463 4464 // Alias for RSB without the ".w" optional width specifier, and with optional 4465 // implied destination register. 4466 def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm", 4467 (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>; 4468 def : t2InstAlias<"rsb${s}${p} $Rdn, $imm", 4469 (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>; 4470 def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm", 4471 (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>; 4472 def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm", 4473 (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p, 4474 cc_out:$s)>; 4475 4476 // SSAT/USAT optional shift operand. 4477 def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn", 4478 (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>; 4479 def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn", 4480 (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>; 4481 4482 // STM w/o the .w suffix. 4483 def : t2InstAlias<"stm${p} $Rn, $regs", 4484 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>; 4485 4486 // Alias for STR, STRB, and STRH without the ".w" optional 4487 // width specifier. 4488 def : t2InstAlias<"str${p} $Rt, $addr", 4489 (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4490 def : t2InstAlias<"strb${p} $Rt, $addr", 4491 (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4492 def : t2InstAlias<"strh${p} $Rt, $addr", 4493 (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>; 4494 4495 def : t2InstAlias<"str${p} $Rt, $addr", 4496 (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4497 def : t2InstAlias<"strb${p} $Rt, $addr", 4498 (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4499 def : t2InstAlias<"strh${p} $Rt, $addr", 4500 (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>; 4501 4502 // Extend instruction optional rotate operand. 4503 def : t2InstAlias<"sxtab${p} $Rd, $Rn, $Rm", 4504 (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>; 4505 def : t2InstAlias<"sxtah${p} $Rd, $Rn, $Rm", 4506 (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>; 4507 def : t2InstAlias<"sxtab16${p} $Rd, $Rn, $Rm", 4508 (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>; 4509 4510 def : t2InstAlias<"sxtb${p} $Rd, $Rm", 4511 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4512 def : t2InstAlias<"sxtb16${p} $Rd, $Rm", 4513 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4514 def : t2InstAlias<"sxth${p} $Rd, $Rm", 4515 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4516 def : t2InstAlias<"sxtb${p}.w $Rd, $Rm", 4517 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4518 def : t2InstAlias<"sxth${p}.w $Rd, $Rm", 4519 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4520 4521 def : t2InstAlias<"uxtab${p} $Rd, $Rn, $Rm", 4522 (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>; 4523 def : t2InstAlias<"uxtah${p} $Rd, $Rn, $Rm", 4524 (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>; 4525 def : t2InstAlias<"uxtab16${p} $Rd, $Rn, $Rm", 4526 (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>; 4527 def : t2InstAlias<"uxtb${p} $Rd, $Rm", 4528 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4529 def : t2InstAlias<"uxtb16${p} $Rd, $Rm", 4530 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4531 def : t2InstAlias<"uxth${p} $Rd, $Rm", 4532 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4533 4534 def : t2InstAlias<"uxtb${p}.w $Rd, $Rm", 4535 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4536 def : t2InstAlias<"uxth${p}.w $Rd, $Rm", 4537 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>; 4538 4539 // Extend instruction w/o the ".w" optional width specifier. 4540 def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot", 4541 (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>; 4542 def : t2InstAlias<"uxtb16${p} $Rd, $Rm$rot", 4543 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>; 4544 def : t2InstAlias<"uxth${p} $Rd, $Rm$rot", 4545 (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>; 4546 4547 def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot", 4548 (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>; 4549 def : t2InstAlias<"sxtb16${p} $Rd, $Rm$rot", 4550 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>; 4551 def : t2InstAlias<"sxth${p} $Rd, $Rm$rot", 4552 (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>; 4553 4554 4555 // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like 4556 // for isel. 4557 def : t2InstAlias<"mov${p} $Rd, $imm", 4558 (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>; 4559 def : t2InstAlias<"mvn${p} $Rd, $imm", 4560 (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>; 4561 // Same for AND <--> BIC 4562 def : t2InstAlias<"bic${s}${p} $Rd, $Rn, $imm", 4563 (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm, 4564 pred:$p, cc_out:$s)>; 4565 def : t2InstAlias<"bic${s}${p} $Rdn, $imm", 4566 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm, 4567 pred:$p, cc_out:$s)>; 4568 def : t2InstAlias<"and${s}${p} $Rd, $Rn, $imm", 4569 (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm, 4570 pred:$p, cc_out:$s)>; 4571 def : t2InstAlias<"and${s}${p} $Rdn, $imm", 4572 (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm, 4573 pred:$p, cc_out:$s)>; 4574 // Likewise, "add Rd, t2_so_imm_neg" -> sub 4575 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm", 4576 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, 4577 pred:$p, cc_out:$s)>; 4578 def : t2InstAlias<"add${s}${p} $Rd, $imm", 4579 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm, 4580 pred:$p, cc_out:$s)>; 4581 // Same for CMP <--> CMN via t2_so_imm_neg 4582 def : t2InstAlias<"cmp${p} $Rd, $imm", 4583 (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>; 4584 def : t2InstAlias<"cmn${p} $Rd, $imm", 4585 (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>; 4586 4587 4588 // Wide 'mul' encoding can be specified with only two operands. 4589 def : t2InstAlias<"mul${p} $Rn, $Rm", 4590 (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>; 4591 4592 // "neg" is and alias for "rsb rd, rn, #0" 4593 def : t2InstAlias<"neg${s}${p} $Rd, $Rm", 4594 (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>; 4595 4596 // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for 4597 // these, unfortunately. 4598 def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift", 4599 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>; 4600 def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift", 4601 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>; 4602 4603 def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift", 4604 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>; 4605 def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift", 4606 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>; 4607 4608 // ADR w/o the .w suffix 4609 def : t2InstAlias<"adr${p} $Rd, $addr", 4610 (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>; 4611 4612 // LDR(literal) w/ alternate [pc, #imm] syntax. 4613 def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr", 4614 (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4615 def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr", 4616 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4617 def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr", 4618 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4619 def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr", 4620 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4621 def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr", 4622 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4623 // Version w/ the .w suffix. 4624 def : t2InstAlias<"ldr${p}.w $Rt, $addr", 4625 (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>; 4626 def : t2InstAlias<"ldrb${p}.w $Rt, $addr", 4627 (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4628 def : t2InstAlias<"ldrh${p}.w $Rt, $addr", 4629 (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4630 def : t2InstAlias<"ldrsb${p}.w $Rt, $addr", 4631 (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4632 def : t2InstAlias<"ldrsh${p}.w $Rt, $addr", 4633 (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>; 4634 4635 def : t2InstAlias<"add${p} $Rd, pc, $imm", 4636 (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>; 4637 4638 // PLD/PLDW/PLI with alternate literal form. 4639 def : t2InstAlias<"pld${p} $addr", 4640 (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>; 4641 def : InstAlias<"pli${p} $addr", 4642 (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p)>, 4643 Requires<[IsThumb2,HasV7]>; 4644