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