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