ARMInstrThumb2.td revision 9fe72bcd3714d136b371aa85d293e16363c29914
1//===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===// 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 : Operand<i32> { 16 let PrintMethod = "printMandatoryPredicateOperand"; 17} 18 19// IT block condition mask 20def it_mask : Operand<i32> { 21 let PrintMethod = "printThumbITMask"; 22} 23 24// Shifted operands. No register controlled shifts for Thumb2. 25// Note: We do not support rrx shifted operands yet. 26def t2_so_reg : Operand<i32>, // reg imm 27 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg", 28 [shl,srl,sra,rotr]> { 29 let EncoderMethod = "getT2SORegOpValue"; 30 let PrintMethod = "printT2SOOperand"; 31 let MIOperandInfo = (ops rGPR, i32imm); 32} 33 34// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value 35def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{ 36 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32); 37}]>; 38 39// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value 40def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{ 41 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32); 42}]>; 43 44// t2_so_imm - Match a 32-bit immediate operand, which is an 45// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit 46// immediate splatted into multiple bytes of the word. 47def t2_so_imm_asmoperand : AsmOperandClass { let Name = "T2SOImm"; } 48def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{ 49 return ARM_AM::getT2SOImmVal(Imm) != -1; 50 }]> { 51 let ParserMatchClass = t2_so_imm_asmoperand; 52 let EncoderMethod = "getT2SOImmOpValue"; 53 let DecoderMethod = "DecodeT2SOImm"; 54} 55 56// t2_so_imm_not - Match an immediate that is a complement 57// of a t2_so_imm. 58def t2_so_imm_not : Operand<i32>, 59 PatLeaf<(imm), [{ 60 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1; 61}], t2_so_imm_not_XFORM>; 62 63// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm. 64def t2_so_imm_neg : Operand<i32>, 65 PatLeaf<(imm), [{ 66 return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1; 67}], t2_so_imm_neg_XFORM>; 68 69/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31]. 70def imm1_31 : Operand<i32>, ImmLeaf<i32, [{ 71 return (int32_t)Imm >= 1 && (int32_t)Imm < 32; 72}]>; 73 74/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095]. 75def imm0_4095 : Operand<i32>, 76 ImmLeaf<i32, [{ 77 return Imm >= 0 && Imm < 4096; 78}]>; 79 80def imm0_4095_neg : PatLeaf<(i32 imm), [{ 81 return (uint32_t)(-N->getZExtValue()) < 4096; 82}], imm_neg_XFORM>; 83 84def imm0_255_neg : PatLeaf<(i32 imm), [{ 85 return (uint32_t)(-N->getZExtValue()) < 255; 86}], imm_neg_XFORM>; 87 88def imm0_255_not : PatLeaf<(i32 imm), [{ 89 return (uint32_t)(~N->getZExtValue()) < 255; 90}], imm_comp_XFORM>; 91 92def lo5AllOne : PatLeaf<(i32 imm), [{ 93 // Returns true if all low 5-bits are 1. 94 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL; 95}]>; 96 97// Define Thumb2 specific addressing modes. 98 99// t2addrmode_imm12 := reg + imm12 100def t2addrmode_imm12 : Operand<i32>, 101 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> { 102 let PrintMethod = "printAddrModeImm12Operand"; 103 let EncoderMethod = "getAddrModeImm12OpValue"; 104 let DecoderMethod = "DecodeT2AddrModeImm12"; 105 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 106} 107 108// t2ldrlabel := imm12 109def t2ldrlabel : Operand<i32> { 110 let EncoderMethod = "getAddrModeImm12OpValue"; 111} 112 113 114// ADR instruction labels. 115def t2adrlabel : Operand<i32> { 116 let EncoderMethod = "getT2AdrLabelOpValue"; 117} 118 119 120// t2addrmode_imm8 := reg +/- imm8 121def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; } 122def t2addrmode_imm8 : Operand<i32>, 123 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> { 124 let PrintMethod = "printT2AddrModeImm8Operand"; 125 let EncoderMethod = "getT2AddrModeImm8OpValue"; 126 let DecoderMethod = "DecodeT2AddrModeImm8"; 127 let ParserMatchClass = MemImm8OffsetAsmOperand; 128 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 129} 130 131def t2am_imm8_offset : Operand<i32>, 132 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset", 133 [], [SDNPWantRoot]> { 134 let PrintMethod = "printT2AddrModeImm8OffsetOperand"; 135 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue"; 136 let DecoderMethod = "DecodeT2Imm8"; 137} 138 139// t2addrmode_imm8s4 := reg +/- (imm8 << 2) 140def t2addrmode_imm8s4 : Operand<i32> { 141 let PrintMethod = "printT2AddrModeImm8s4Operand"; 142 let EncoderMethod = "getT2AddrModeImm8s4OpValue"; 143 let DecoderMethod = "DecodeT2AddrModeImm8s4"; 144 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 145} 146 147def t2am_imm8s4_offset : Operand<i32> { 148 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand"; 149 let DecoderMethod = "DecodeT2Imm8S4"; 150} 151 152// t2addrmode_so_reg := reg + (reg << imm2) 153def t2addrmode_so_reg : Operand<i32>, 154 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> { 155 let PrintMethod = "printT2AddrModeSoRegOperand"; 156 let EncoderMethod = "getT2AddrModeSORegOpValue"; 157 let DecoderMethod = "DecodeT2AddrModeSOReg"; 158 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm); 159} 160 161// t2addrmode_reg := reg 162// Used by load/store exclusive instructions. Useful to enable right assembly 163// parsing and printing. Not used for any codegen matching. 164// 165def t2addrmode_reg : Operand<i32> { 166 let PrintMethod = "printAddrMode7Operand"; 167 let DecoderMethod = "DecodeGPRRegisterClass"; 168 let MIOperandInfo = (ops GPR); 169} 170 171//===----------------------------------------------------------------------===// 172// Multiclass helpers... 173// 174 175 176class T2OneRegImm<dag oops, dag iops, InstrItinClass itin, 177 string opc, string asm, list<dag> pattern> 178 : T2I<oops, iops, itin, opc, asm, pattern> { 179 bits<4> Rd; 180 bits<12> imm; 181 182 let Inst{11-8} = Rd; 183 let Inst{26} = imm{11}; 184 let Inst{14-12} = imm{10-8}; 185 let Inst{7-0} = imm{7-0}; 186} 187 188 189class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin, 190 string opc, string asm, list<dag> pattern> 191 : T2sI<oops, iops, itin, opc, asm, pattern> { 192 bits<4> Rd; 193 bits<4> Rn; 194 bits<12> imm; 195 196 let Inst{11-8} = Rd; 197 let Inst{26} = imm{11}; 198 let Inst{14-12} = imm{10-8}; 199 let Inst{7-0} = imm{7-0}; 200} 201 202class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin, 203 string opc, string asm, list<dag> pattern> 204 : T2I<oops, iops, itin, opc, asm, pattern> { 205 bits<4> Rn; 206 bits<12> imm; 207 208 let Inst{19-16} = Rn; 209 let Inst{26} = imm{11}; 210 let Inst{14-12} = imm{10-8}; 211 let Inst{7-0} = imm{7-0}; 212} 213 214 215class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 216 string opc, string asm, list<dag> pattern> 217 : T2I<oops, iops, itin, opc, asm, pattern> { 218 bits<4> Rd; 219 bits<12> ShiftedRm; 220 221 let Inst{11-8} = Rd; 222 let Inst{3-0} = ShiftedRm{3-0}; 223 let Inst{5-4} = ShiftedRm{6-5}; 224 let Inst{14-12} = ShiftedRm{11-9}; 225 let Inst{7-6} = ShiftedRm{8-7}; 226} 227 228class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 229 string opc, string asm, list<dag> pattern> 230 : T2sI<oops, iops, itin, opc, asm, pattern> { 231 bits<4> Rd; 232 bits<12> ShiftedRm; 233 234 let Inst{11-8} = Rd; 235 let Inst{3-0} = ShiftedRm{3-0}; 236 let Inst{5-4} = ShiftedRm{6-5}; 237 let Inst{14-12} = ShiftedRm{11-9}; 238 let Inst{7-6} = ShiftedRm{8-7}; 239} 240 241class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin, 242 string opc, string asm, list<dag> pattern> 243 : T2I<oops, iops, itin, opc, asm, pattern> { 244 bits<4> Rn; 245 bits<12> ShiftedRm; 246 247 let Inst{19-16} = Rn; 248 let Inst{3-0} = ShiftedRm{3-0}; 249 let Inst{5-4} = ShiftedRm{6-5}; 250 let Inst{14-12} = ShiftedRm{11-9}; 251 let Inst{7-6} = ShiftedRm{8-7}; 252} 253 254class T2TwoReg<dag oops, dag iops, InstrItinClass itin, 255 string opc, string asm, list<dag> pattern> 256 : T2I<oops, iops, itin, opc, asm, pattern> { 257 bits<4> Rd; 258 bits<4> Rm; 259 260 let Inst{11-8} = Rd; 261 let Inst{3-0} = Rm; 262} 263 264class T2sTwoReg<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> Rm; 269 270 let Inst{11-8} = Rd; 271 let Inst{3-0} = Rm; 272} 273 274class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin, 275 string opc, string asm, list<dag> pattern> 276 : T2I<oops, iops, itin, opc, asm, pattern> { 277 bits<4> Rn; 278 bits<4> Rm; 279 280 let Inst{19-16} = Rn; 281 let Inst{3-0} = Rm; 282} 283 284 285class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin, 286 string opc, string asm, list<dag> pattern> 287 : T2I<oops, iops, itin, opc, asm, pattern> { 288 bits<4> Rd; 289 bits<4> Rn; 290 bits<12> imm; 291 292 let Inst{11-8} = Rd; 293 let Inst{19-16} = Rn; 294 let Inst{26} = imm{11}; 295 let Inst{14-12} = imm{10-8}; 296 let Inst{7-0} = imm{7-0}; 297} 298 299class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin, 300 string opc, string asm, list<dag> pattern> 301 : T2sI<oops, iops, itin, opc, asm, pattern> { 302 bits<4> Rd; 303 bits<4> Rn; 304 bits<12> imm; 305 306 let Inst{11-8} = Rd; 307 let Inst{19-16} = Rn; 308 let Inst{26} = imm{11}; 309 let Inst{14-12} = imm{10-8}; 310 let Inst{7-0} = imm{7-0}; 311} 312 313class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin, 314 string opc, string asm, list<dag> pattern> 315 : T2I<oops, iops, itin, opc, asm, pattern> { 316 bits<4> Rd; 317 bits<4> Rm; 318 bits<5> imm; 319 320 let Inst{11-8} = Rd; 321 let Inst{3-0} = Rm; 322 let Inst{14-12} = imm{4-2}; 323 let Inst{7-6} = imm{1-0}; 324} 325 326class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin, 327 string opc, string asm, list<dag> pattern> 328 : T2sI<oops, iops, itin, opc, asm, pattern> { 329 bits<4> Rd; 330 bits<4> Rm; 331 bits<5> imm; 332 333 let Inst{11-8} = Rd; 334 let Inst{3-0} = Rm; 335 let Inst{14-12} = imm{4-2}; 336 let Inst{7-6} = imm{1-0}; 337} 338 339class T2ThreeReg<dag oops, dag iops, InstrItinClass itin, 340 string opc, string asm, list<dag> pattern> 341 : T2I<oops, iops, itin, opc, asm, pattern> { 342 bits<4> Rd; 343 bits<4> Rn; 344 bits<4> Rm; 345 346 let Inst{11-8} = Rd; 347 let Inst{19-16} = Rn; 348 let Inst{3-0} = Rm; 349} 350 351class T2sThreeReg<dag oops, dag iops, InstrItinClass itin, 352 string opc, string asm, list<dag> pattern> 353 : T2sI<oops, iops, itin, opc, asm, pattern> { 354 bits<4> Rd; 355 bits<4> Rn; 356 bits<4> Rm; 357 358 let Inst{11-8} = Rd; 359 let Inst{19-16} = Rn; 360 let Inst{3-0} = Rm; 361} 362 363class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 364 string opc, string asm, list<dag> pattern> 365 : T2I<oops, iops, itin, opc, asm, pattern> { 366 bits<4> Rd; 367 bits<4> Rn; 368 bits<12> ShiftedRm; 369 370 let Inst{11-8} = Rd; 371 let Inst{19-16} = Rn; 372 let Inst{3-0} = ShiftedRm{3-0}; 373 let Inst{5-4} = ShiftedRm{6-5}; 374 let Inst{14-12} = ShiftedRm{11-9}; 375 let Inst{7-6} = ShiftedRm{8-7}; 376} 377 378class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin, 379 string opc, string asm, list<dag> pattern> 380 : T2sI<oops, iops, itin, opc, asm, pattern> { 381 bits<4> Rd; 382 bits<4> Rn; 383 bits<12> ShiftedRm; 384 385 let Inst{11-8} = Rd; 386 let Inst{19-16} = Rn; 387 let Inst{3-0} = ShiftedRm{3-0}; 388 let Inst{5-4} = ShiftedRm{6-5}; 389 let Inst{14-12} = ShiftedRm{11-9}; 390 let Inst{7-6} = ShiftedRm{8-7}; 391} 392 393class T2FourReg<dag oops, dag iops, InstrItinClass itin, 394 string opc, string asm, list<dag> pattern> 395 : T2I<oops, iops, itin, opc, asm, pattern> { 396 bits<4> Rd; 397 bits<4> Rn; 398 bits<4> Rm; 399 bits<4> Ra; 400 401 let Inst{19-16} = Rn; 402 let Inst{15-12} = Ra; 403 let Inst{11-8} = Rd; 404 let Inst{3-0} = Rm; 405} 406 407class T2MulLong<bits<3> opc22_20, bits<4> opc7_4, 408 dag oops, dag iops, InstrItinClass itin, 409 string opc, string asm, list<dag> pattern> 410 : T2I<oops, iops, itin, opc, asm, pattern> { 411 bits<4> RdLo; 412 bits<4> RdHi; 413 bits<4> Rn; 414 bits<4> Rm; 415 416 let Inst{31-23} = 0b111110111; 417 let Inst{22-20} = opc22_20; 418 let Inst{19-16} = Rn; 419 let Inst{15-12} = RdLo; 420 let Inst{11-8} = RdHi; 421 let Inst{7-4} = opc7_4; 422 let Inst{3-0} = Rm; 423} 424 425 426/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a 427/// unary operation that produces a value. These are predicable and can be 428/// changed to modify CPSR. 429multiclass T2I_un_irs<bits<4> opcod, string opc, 430 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 431 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> { 432 // shifted imm 433 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii, 434 opc, "\t$Rd, $imm", 435 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> { 436 let isAsCheapAsAMove = Cheap; 437 let isReMaterializable = ReMat; 438 let Inst{31-27} = 0b11110; 439 let Inst{25} = 0; 440 let Inst{24-21} = opcod; 441 let Inst{19-16} = 0b1111; // Rn 442 let Inst{15} = 0; 443 } 444 // register 445 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir, 446 opc, ".w\t$Rd, $Rm", 447 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> { 448 let Inst{31-27} = 0b11101; 449 let Inst{26-25} = 0b01; 450 let Inst{24-21} = opcod; 451 let Inst{19-16} = 0b1111; // Rn 452 let Inst{14-12} = 0b000; // imm3 453 let Inst{7-6} = 0b00; // imm2 454 let Inst{5-4} = 0b00; // type 455 } 456 // shifted register 457 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis, 458 opc, ".w\t$Rd, $ShiftedRm", 459 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> { 460 let Inst{31-27} = 0b11101; 461 let Inst{26-25} = 0b01; 462 let Inst{24-21} = opcod; 463 let Inst{19-16} = 0b1111; // Rn 464 } 465} 466 467/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a 468/// binary operation that produces a value. These are predicable and can be 469/// changed to modify CPSR. 470multiclass T2I_bin_irs<bits<4> opcod, string opc, 471 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 472 PatFrag opnode, string baseOpc, bit Commutable = 0, 473 string wide = ""> { 474 // shifted imm 475 def ri : T2sTwoRegImm< 476 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii, 477 opc, "\t$Rd, $Rn, $imm", 478 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> { 479 let Inst{31-27} = 0b11110; 480 let Inst{25} = 0; 481 let Inst{24-21} = opcod; 482 let Inst{15} = 0; 483 } 484 // register 485 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir, 486 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"), 487 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> { 488 let isCommutable = Commutable; 489 let Inst{31-27} = 0b11101; 490 let Inst{26-25} = 0b01; 491 let Inst{24-21} = opcod; 492 let Inst{14-12} = 0b000; // imm3 493 let Inst{7-6} = 0b00; // imm2 494 let Inst{5-4} = 0b00; // type 495 } 496 // shifted register 497 def rs : T2sTwoRegShiftedReg< 498 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis, 499 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"), 500 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> { 501 let Inst{31-27} = 0b11101; 502 let Inst{26-25} = 0b01; 503 let Inst{24-21} = opcod; 504 } 505 // Assembly aliases for optional destination operand when it's the same 506 // as the source operand. 507 def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"), 508 (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn, 509 t2_so_imm:$imm, pred:$p, 510 cc_out:$s)>, 511 Requires<[IsThumb2]>; 512 def : InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"), 513 (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn, 514 rGPR:$Rm, pred:$p, 515 cc_out:$s)>, 516 Requires<[IsThumb2]>; 517 def : InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"), 518 (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn, 519 t2_so_reg:$shift, pred:$p, 520 cc_out:$s)>, 521 Requires<[IsThumb2]>; 522} 523 524/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need 525// the ".w" suffix to indicate that they are wide. 526multiclass T2I_bin_w_irs<bits<4> opcod, string opc, 527 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 528 PatFrag opnode, string baseOpc, bit Commutable = 0> : 529 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, baseOpc, Commutable, ".w">; 530 531/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are 532/// reversed. The 'rr' form is only defined for the disassembler; for codegen 533/// it is equivalent to the T2I_bin_irs counterpart. 534multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> { 535 // shifted imm 536 def ri : T2sTwoRegImm< 537 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi, 538 opc, ".w\t$Rd, $Rn, $imm", 539 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> { 540 let Inst{31-27} = 0b11110; 541 let Inst{25} = 0; 542 let Inst{24-21} = opcod; 543 let Inst{15} = 0; 544 } 545 // register 546 def rr : T2sThreeReg< 547 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr, 548 opc, "\t$Rd, $Rn, $Rm", 549 [/* For disassembly only; pattern left blank */]> { 550 let Inst{31-27} = 0b11101; 551 let Inst{26-25} = 0b01; 552 let Inst{24-21} = opcod; 553 let Inst{14-12} = 0b000; // imm3 554 let Inst{7-6} = 0b00; // imm2 555 let Inst{5-4} = 0b00; // type 556 } 557 // shifted register 558 def rs : T2sTwoRegShiftedReg< 559 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), 560 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm", 561 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> { 562 let Inst{31-27} = 0b11101; 563 let Inst{26-25} = 0b01; 564 let Inst{24-21} = opcod; 565 } 566} 567 568/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the 569/// instruction modifies the CPSR register. 570let isCodeGenOnly = 1, Defs = [CPSR] in { 571multiclass T2I_bin_s_irs<bits<4> opcod, string opc, 572 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 573 PatFrag opnode, bit Commutable = 0> { 574 // shifted imm 575 def ri : T2TwoRegImm< 576 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii, 577 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm", 578 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> { 579 let Inst{31-27} = 0b11110; 580 let Inst{25} = 0; 581 let Inst{24-21} = opcod; 582 let Inst{20} = 1; // The S bit. 583 let Inst{15} = 0; 584 } 585 // register 586 def rr : T2ThreeReg< 587 (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir, 588 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $Rm", 589 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> { 590 let isCommutable = Commutable; 591 let Inst{31-27} = 0b11101; 592 let Inst{26-25} = 0b01; 593 let Inst{24-21} = opcod; 594 let Inst{20} = 1; // The S bit. 595 let Inst{14-12} = 0b000; // imm3 596 let Inst{7-6} = 0b00; // imm2 597 let Inst{5-4} = 0b00; // type 598 } 599 // shifted register 600 def rs : T2TwoRegShiftedReg< 601 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis, 602 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $ShiftedRm", 603 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> { 604 let Inst{31-27} = 0b11101; 605 let Inst{26-25} = 0b01; 606 let Inst{24-21} = opcod; 607 let Inst{20} = 1; // The S bit. 608 } 609} 610} 611 612/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg}) 613/// patterns for a binary operation that produces a value. 614multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode, 615 bit Commutable = 0> { 616 // shifted imm 617 // The register-immediate version is re-materializable. This is useful 618 // in particular for taking the address of a local. 619 let isReMaterializable = 1 in { 620 def ri : T2sTwoRegImm< 621 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), IIC_iALUi, 622 opc, ".w\t$Rd, $Rn, $imm", 623 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> { 624 let Inst{31-27} = 0b11110; 625 let Inst{25} = 0; 626 let Inst{24} = 1; 627 let Inst{23-21} = op23_21; 628 let Inst{15} = 0; 629 } 630 } 631 // 12-bit imm 632 def ri12 : T2I< 633 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi, 634 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm", 635 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> { 636 bits<4> Rd; 637 bits<4> Rn; 638 bits<12> imm; 639 let Inst{31-27} = 0b11110; 640 let Inst{26} = imm{11}; 641 let Inst{25-24} = 0b10; 642 let Inst{23-21} = op23_21; 643 let Inst{20} = 0; // The S bit. 644 let Inst{19-16} = Rn; 645 let Inst{15} = 0; 646 let Inst{14-12} = imm{10-8}; 647 let Inst{11-8} = Rd; 648 let Inst{7-0} = imm{7-0}; 649 } 650 // register 651 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), IIC_iALUr, 652 opc, ".w\t$Rd, $Rn, $Rm", 653 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> { 654 let isCommutable = Commutable; 655 let Inst{31-27} = 0b11101; 656 let Inst{26-25} = 0b01; 657 let Inst{24} = 1; 658 let Inst{23-21} = op23_21; 659 let Inst{14-12} = 0b000; // imm3 660 let Inst{7-6} = 0b00; // imm2 661 let Inst{5-4} = 0b00; // type 662 } 663 // shifted register 664 def rs : T2sTwoRegShiftedReg< 665 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), 666 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm", 667 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> { 668 let Inst{31-27} = 0b11101; 669 let Inst{26-25} = 0b01; 670 let Inst{24} = 1; 671 let Inst{23-21} = op23_21; 672 } 673} 674 675/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns 676/// for a binary operation that produces a value and use the carry 677/// bit. It's not predicable. 678let Uses = [CPSR] in { 679multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode, 680 bit Commutable = 0> { 681 // shifted imm 682 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), 683 IIC_iALUi, opc, "\t$Rd, $Rn, $imm", 684 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>, 685 Requires<[IsThumb2]> { 686 let Inst{31-27} = 0b11110; 687 let Inst{25} = 0; 688 let Inst{24-21} = opcod; 689 let Inst{15} = 0; 690 } 691 // register 692 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr, 693 opc, ".w\t$Rd, $Rn, $Rm", 694 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>, 695 Requires<[IsThumb2]> { 696 let isCommutable = Commutable; 697 let Inst{31-27} = 0b11101; 698 let Inst{26-25} = 0b01; 699 let Inst{24-21} = opcod; 700 let Inst{14-12} = 0b000; // imm3 701 let Inst{7-6} = 0b00; // imm2 702 let Inst{5-4} = 0b00; // type 703 } 704 // shifted register 705 def rs : T2sTwoRegShiftedReg< 706 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), 707 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm", 708 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>, 709 Requires<[IsThumb2]> { 710 let Inst{31-27} = 0b11101; 711 let Inst{26-25} = 0b01; 712 let Inst{24-21} = opcod; 713 } 714} 715} 716 717// Carry setting variants 718// NOTE: CPSR def omitted because it will be handled by the custom inserter. 719let usesCustomInserter = 1 in { 720multiclass T2I_adde_sube_s_irs<PatFrag opnode, bit Commutable = 0> { 721 // shifted imm 722 def ri : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), 723 4, IIC_iALUi, 724 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>; 725 // register 726 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 727 4, IIC_iALUr, 728 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> { 729 let isCommutable = Commutable; 730 } 731 // shifted register 732 def rs : t2PseudoInst< 733 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), 734 4, IIC_iALUsi, 735 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>; 736} 737} 738 739/// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register 740/// version is not needed since this is only for codegen. 741let isCodeGenOnly = 1, Defs = [CPSR] in { 742multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> { 743 // shifted imm 744 def ri : T2TwoRegImm< 745 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi, 746 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm", 747 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> { 748 let Inst{31-27} = 0b11110; 749 let Inst{25} = 0; 750 let Inst{24-21} = opcod; 751 let Inst{20} = 1; // The S bit. 752 let Inst{15} = 0; 753 } 754 // shifted register 755 def rs : T2TwoRegShiftedReg< 756 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), 757 IIC_iALUsi, !strconcat(opc, "s"), "\t$Rd, $Rn, $ShiftedRm", 758 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> { 759 let Inst{31-27} = 0b11101; 760 let Inst{26-25} = 0b01; 761 let Inst{24-21} = opcod; 762 let Inst{20} = 1; // The S bit. 763 } 764} 765} 766 767/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift / 768// rotate operation that produces a value. 769multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode> { 770 // 5-bit imm 771 def ri : T2sTwoRegShiftImm< 772 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi, 773 opc, ".w\t$Rd, $Rm, $imm", 774 [(set rGPR:$Rd, (opnode rGPR:$Rm, ty:$imm))]> { 775 let Inst{31-27} = 0b11101; 776 let Inst{26-21} = 0b010010; 777 let Inst{19-16} = 0b1111; // Rn 778 let Inst{5-4} = opcod; 779 } 780 // register 781 def rr : T2sThreeReg< 782 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr, 783 opc, ".w\t$Rd, $Rn, $Rm", 784 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> { 785 let Inst{31-27} = 0b11111; 786 let Inst{26-23} = 0b0100; 787 let Inst{22-21} = opcod; 788 let Inst{15-12} = 0b1111; 789 let Inst{7-4} = 0b0000; 790 } 791} 792 793/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test 794/// patterns. Similar to T2I_bin_irs except the instruction does not produce 795/// a explicit result, only implicitly set CPSR. 796let isCompare = 1, Defs = [CPSR] in { 797multiclass T2I_cmp_irs<bits<4> opcod, string opc, 798 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis, 799 PatFrag opnode> { 800 // shifted imm 801 def ri : T2OneRegCmpImm< 802 (outs), (ins GPR:$Rn, t2_so_imm:$imm), iii, 803 opc, ".w\t$Rn, $imm", 804 [(opnode GPR:$Rn, t2_so_imm:$imm)]> { 805 let Inst{31-27} = 0b11110; 806 let Inst{25} = 0; 807 let Inst{24-21} = opcod; 808 let Inst{20} = 1; // The S bit. 809 let Inst{15} = 0; 810 let Inst{11-8} = 0b1111; // Rd 811 } 812 // register 813 def rr : T2TwoRegCmp< 814 (outs), (ins GPR:$lhs, rGPR:$rhs), iir, 815 opc, ".w\t$lhs, $rhs", 816 [(opnode GPR:$lhs, rGPR:$rhs)]> { 817 let Inst{31-27} = 0b11101; 818 let Inst{26-25} = 0b01; 819 let Inst{24-21} = opcod; 820 let Inst{20} = 1; // The S bit. 821 let Inst{14-12} = 0b000; // imm3 822 let Inst{11-8} = 0b1111; // Rd 823 let Inst{7-6} = 0b00; // imm2 824 let Inst{5-4} = 0b00; // type 825 } 826 // shifted register 827 def rs : T2OneRegCmpShiftedReg< 828 (outs), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis, 829 opc, ".w\t$Rn, $ShiftedRm", 830 [(opnode GPR:$Rn, t2_so_reg:$ShiftedRm)]> { 831 let Inst{31-27} = 0b11101; 832 let Inst{26-25} = 0b01; 833 let Inst{24-21} = opcod; 834 let Inst{20} = 1; // The S bit. 835 let Inst{11-8} = 0b1111; // Rd 836 } 837} 838} 839 840/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns. 841multiclass T2I_ld<bit signed, bits<2> opcod, string opc, 842 InstrItinClass iii, InstrItinClass iis, RegisterClass target, 843 PatFrag opnode> { 844 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii, 845 opc, ".w\t$Rt, $addr", 846 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> { 847 let Inst{31-27} = 0b11111; 848 let Inst{26-25} = 0b00; 849 let Inst{24} = signed; 850 let Inst{23} = 1; 851 let Inst{22-21} = opcod; 852 let Inst{20} = 1; // load 853 854 bits<4> Rt; 855 let Inst{15-12} = Rt; 856 857 bits<17> addr; 858 let addr{12} = 1; // add = TRUE 859 let Inst{19-16} = addr{16-13}; // Rn 860 let Inst{23} = addr{12}; // U 861 let Inst{11-0} = addr{11-0}; // imm 862 } 863 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_imm8:$addr), iii, 864 opc, "\t$Rt, $addr", 865 [(set target:$Rt, (opnode t2addrmode_imm8:$addr))]> { 866 let Inst{31-27} = 0b11111; 867 let Inst{26-25} = 0b00; 868 let Inst{24} = signed; 869 let Inst{23} = 0; 870 let Inst{22-21} = opcod; 871 let Inst{20} = 1; // load 872 let Inst{11} = 1; 873 // Offset: index==TRUE, wback==FALSE 874 let Inst{10} = 1; // The P bit. 875 let Inst{8} = 0; // The W bit. 876 877 bits<4> Rt; 878 let Inst{15-12} = Rt; 879 880 bits<13> addr; 881 let Inst{19-16} = addr{12-9}; // Rn 882 let Inst{9} = addr{8}; // U 883 let Inst{7-0} = addr{7-0}; // imm 884 } 885 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis, 886 opc, ".w\t$Rt, $addr", 887 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> { 888 let Inst{31-27} = 0b11111; 889 let Inst{26-25} = 0b00; 890 let Inst{24} = signed; 891 let Inst{23} = 0; 892 let Inst{22-21} = opcod; 893 let Inst{20} = 1; // load 894 let Inst{11-6} = 0b000000; 895 896 bits<4> Rt; 897 let Inst{15-12} = Rt; 898 899 bits<10> addr; 900 let Inst{19-16} = addr{9-6}; // Rn 901 let Inst{3-0} = addr{5-2}; // Rm 902 let Inst{5-4} = addr{1-0}; // imm 903 904 let DecoderMethod = "DecodeT2LoadShift"; 905 } 906 907 // FIXME: Is the pci variant actually needed? 908 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii, 909 opc, ".w\t$Rt, $addr", 910 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> { 911 let isReMaterializable = 1; 912 let Inst{31-27} = 0b11111; 913 let Inst{26-25} = 0b00; 914 let Inst{24} = signed; 915 let Inst{23} = ?; // add = (U == '1') 916 let Inst{22-21} = opcod; 917 let Inst{20} = 1; // load 918 let Inst{19-16} = 0b1111; // Rn 919 bits<4> Rt; 920 bits<12> addr; 921 let Inst{15-12} = Rt{3-0}; 922 let Inst{11-0} = addr{11-0}; 923 } 924} 925 926/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns. 927multiclass T2I_st<bits<2> opcod, string opc, 928 InstrItinClass iii, InstrItinClass iis, RegisterClass target, 929 PatFrag opnode> { 930 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii, 931 opc, ".w\t$Rt, $addr", 932 [(opnode target:$Rt, t2addrmode_imm12:$addr)]> { 933 let Inst{31-27} = 0b11111; 934 let Inst{26-23} = 0b0001; 935 let Inst{22-21} = opcod; 936 let Inst{20} = 0; // !load 937 938 bits<4> Rt; 939 let Inst{15-12} = Rt; 940 941 bits<17> addr; 942 let addr{12} = 1; // add = TRUE 943 let Inst{19-16} = addr{16-13}; // Rn 944 let Inst{23} = addr{12}; // U 945 let Inst{11-0} = addr{11-0}; // imm 946 } 947 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_imm8:$addr), iii, 948 opc, "\t$Rt, $addr", 949 [(opnode target:$Rt, t2addrmode_imm8:$addr)]> { 950 let Inst{31-27} = 0b11111; 951 let Inst{26-23} = 0b0000; 952 let Inst{22-21} = opcod; 953 let Inst{20} = 0; // !load 954 let Inst{11} = 1; 955 // Offset: index==TRUE, wback==FALSE 956 let Inst{10} = 1; // The P bit. 957 let Inst{8} = 0; // The W bit. 958 959 bits<4> Rt; 960 let Inst{15-12} = Rt; 961 962 bits<13> addr; 963 let Inst{19-16} = addr{12-9}; // Rn 964 let Inst{9} = addr{8}; // U 965 let Inst{7-0} = addr{7-0}; // imm 966 } 967 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis, 968 opc, ".w\t$Rt, $addr", 969 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> { 970 let Inst{31-27} = 0b11111; 971 let Inst{26-23} = 0b0000; 972 let Inst{22-21} = opcod; 973 let Inst{20} = 0; // !load 974 let Inst{11-6} = 0b000000; 975 976 bits<4> Rt; 977 let Inst{15-12} = Rt; 978 979 bits<10> addr; 980 let Inst{19-16} = addr{9-6}; // Rn 981 let Inst{3-0} = addr{5-2}; // Rm 982 let Inst{5-4} = addr{1-0}; // imm 983 } 984} 985 986/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a 987/// register and one whose operand is a register rotated by 8/16/24. 988class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> 989 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr, 990 opc, ".w\t$Rd, $Rm$rot", 991 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>, 992 Requires<[IsThumb2]> { 993 let Inst{31-27} = 0b11111; 994 let Inst{26-23} = 0b0100; 995 let Inst{22-20} = opcod; 996 let Inst{19-16} = 0b1111; // Rn 997 let Inst{15-12} = 0b1111; 998 let Inst{7} = 1; 999 1000 bits<2> rot; 1001 let Inst{5-4} = rot{1-0}; // rotate 1002} 1003 1004// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier. 1005class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> 1006 : T2TwoReg<(outs rGPR:$dst), (ins rGPR:$Rm, rot_imm:$rot), 1007 IIC_iEXTr, opc, "\t$dst, $Rm$rot", 1008 [(set rGPR:$dst, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>, 1009 Requires<[HasT2ExtractPack, IsThumb2]> { 1010 bits<2> rot; 1011 let Inst{31-27} = 0b11111; 1012 let Inst{26-23} = 0b0100; 1013 let Inst{22-20} = opcod; 1014 let Inst{19-16} = 0b1111; // Rn 1015 let Inst{15-12} = 0b1111; 1016 let Inst{7} = 1; 1017 let Inst{5-4} = rot; 1018} 1019 1020// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern 1021// supported yet. 1022class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> 1023 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr, 1024 opc, "\t$Rd, $Rm$rot", []>, 1025 Requires<[IsThumb2, HasT2ExtractPack]> { 1026 bits<2> rot; 1027 let Inst{31-27} = 0b11111; 1028 let Inst{26-23} = 0b0100; 1029 let Inst{22-20} = opcod; 1030 let Inst{19-16} = 0b1111; // Rn 1031 let Inst{15-12} = 0b1111; 1032 let Inst{7} = 1; 1033 let Inst{5-4} = rot; 1034} 1035 1036/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a 1037/// register and one whose operand is a register rotated by 8/16/24. 1038class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> 1039 : T2ThreeReg<(outs rGPR:$Rd), 1040 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot), 1041 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", 1042 [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>, 1043 Requires<[HasT2ExtractPack, IsThumb2]> { 1044 bits<2> rot; 1045 let Inst{31-27} = 0b11111; 1046 let Inst{26-23} = 0b0100; 1047 let Inst{22-20} = opcod; 1048 let Inst{15-12} = 0b1111; 1049 let Inst{7} = 1; 1050 let Inst{5-4} = rot; 1051} 1052 1053class T2I_exta_rrot_np<bits<3> opcod, string opc> 1054 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot), 1055 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []> { 1056 bits<2> rot; 1057 let Inst{31-27} = 0b11111; 1058 let Inst{26-23} = 0b0100; 1059 let Inst{22-20} = opcod; 1060 let Inst{15-12} = 0b1111; 1061 let Inst{7} = 1; 1062 let Inst{5-4} = rot; 1063} 1064 1065//===----------------------------------------------------------------------===// 1066// Instructions 1067//===----------------------------------------------------------------------===// 1068 1069//===----------------------------------------------------------------------===// 1070// Miscellaneous Instructions. 1071// 1072 1073class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin, 1074 string asm, list<dag> pattern> 1075 : T2XI<oops, iops, itin, asm, pattern> { 1076 bits<4> Rd; 1077 bits<12> label; 1078 1079 let Inst{11-8} = Rd; 1080 let Inst{26} = label{11}; 1081 let Inst{14-12} = label{10-8}; 1082 let Inst{7-0} = label{7-0}; 1083} 1084 1085// LEApcrel - Load a pc-relative address into a register without offending the 1086// assembler. 1087def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd), 1088 (ins t2adrlabel:$addr, pred:$p), 1089 IIC_iALUi, "adr{$p}.w\t$Rd, #$addr", []> { 1090 let Inst{31-27} = 0b11110; 1091 let Inst{25-24} = 0b10; 1092 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE) 1093 let Inst{22} = 0; 1094 let Inst{20} = 0; 1095 let Inst{19-16} = 0b1111; // Rn 1096 let Inst{15} = 0; 1097 1098 bits<4> Rd; 1099 bits<13> addr; 1100 let Inst{11-8} = Rd; 1101 let Inst{23} = addr{12}; 1102 let Inst{21} = addr{12}; 1103 let Inst{26} = addr{11}; 1104 let Inst{14-12} = addr{10-8}; 1105 let Inst{7-0} = addr{7-0}; 1106} 1107 1108let neverHasSideEffects = 1, isReMaterializable = 1 in 1109def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p), 1110 4, IIC_iALUi, []>; 1111def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd), 1112 (ins i32imm:$label, nohash_imm:$id, pred:$p), 1113 4, IIC_iALUi, 1114 []>; 1115 1116 1117//===----------------------------------------------------------------------===// 1118// Load / store Instructions. 1119// 1120 1121// Load 1122let canFoldAsLoad = 1, isReMaterializable = 1 in 1123defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, 1124 UnOpFrag<(load node:$Src)>>; 1125 1126// Loads with zero extension 1127defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1128 rGPR, UnOpFrag<(zextloadi16 node:$Src)>>; 1129defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1130 rGPR, UnOpFrag<(zextloadi8 node:$Src)>>; 1131 1132// Loads with sign extension 1133defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1134 rGPR, UnOpFrag<(sextloadi16 node:$Src)>>; 1135defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si, 1136 rGPR, UnOpFrag<(sextloadi8 node:$Src)>>; 1137 1138let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in { 1139// Load doubleword 1140def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2), 1141 (ins t2addrmode_imm8s4:$addr), 1142 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", []>; 1143} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 1144 1145// zextload i1 -> zextload i8 1146def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr), 1147 (t2LDRBi12 t2addrmode_imm12:$addr)>; 1148def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr), 1149 (t2LDRBi8 t2addrmode_imm8:$addr)>; 1150def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr), 1151 (t2LDRBs t2addrmode_so_reg:$addr)>; 1152def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)), 1153 (t2LDRBpci tconstpool:$addr)>; 1154 1155// extload -> zextload 1156// FIXME: Reduce the number of patterns by legalizing extload to zextload 1157// earlier? 1158def : T2Pat<(extloadi1 t2addrmode_imm12:$addr), 1159 (t2LDRBi12 t2addrmode_imm12:$addr)>; 1160def : T2Pat<(extloadi1 t2addrmode_imm8:$addr), 1161 (t2LDRBi8 t2addrmode_imm8:$addr)>; 1162def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr), 1163 (t2LDRBs t2addrmode_so_reg:$addr)>; 1164def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)), 1165 (t2LDRBpci tconstpool:$addr)>; 1166 1167def : T2Pat<(extloadi8 t2addrmode_imm12:$addr), 1168 (t2LDRBi12 t2addrmode_imm12:$addr)>; 1169def : T2Pat<(extloadi8 t2addrmode_imm8:$addr), 1170 (t2LDRBi8 t2addrmode_imm8:$addr)>; 1171def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr), 1172 (t2LDRBs t2addrmode_so_reg:$addr)>; 1173def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)), 1174 (t2LDRBpci tconstpool:$addr)>; 1175 1176def : T2Pat<(extloadi16 t2addrmode_imm12:$addr), 1177 (t2LDRHi12 t2addrmode_imm12:$addr)>; 1178def : T2Pat<(extloadi16 t2addrmode_imm8:$addr), 1179 (t2LDRHi8 t2addrmode_imm8:$addr)>; 1180def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr), 1181 (t2LDRHs t2addrmode_so_reg:$addr)>; 1182def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)), 1183 (t2LDRHpci tconstpool:$addr)>; 1184 1185// FIXME: The destination register of the loads and stores can't be PC, but 1186// can be SP. We need another regclass (similar to rGPR) to represent 1187// that. Not a pressing issue since these are selected manually, 1188// not via pattern. 1189 1190// Indexed loads 1191 1192let mayLoad = 1, neverHasSideEffects = 1 in { 1193def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn), 1194 (ins t2addrmode_imm8:$addr), 1195 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu, 1196 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn", 1197 []>; 1198 1199def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn), 1200 (ins GPR:$base, t2am_imm8_offset:$addr), 1201 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu, 1202 "ldr", "\t$Rt, [$Rn], $addr", "$base = $Rn", 1203 []>; 1204 1205def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn), 1206 (ins t2addrmode_imm8:$addr), 1207 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1208 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn", 1209 []>; 1210def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn), 1211 (ins GPR:$base, t2am_imm8_offset:$addr), 1212 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1213 "ldrb", "\t$Rt, [$Rn], $addr", "$base = $Rn", 1214 []>; 1215 1216def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn), 1217 (ins t2addrmode_imm8:$addr), 1218 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1219 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn", 1220 []>; 1221def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn), 1222 (ins GPR:$base, t2am_imm8_offset:$addr), 1223 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1224 "ldrh", "\t$Rt, [$Rn], $addr", "$base = $Rn", 1225 []>; 1226 1227def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn), 1228 (ins t2addrmode_imm8:$addr), 1229 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1230 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn", 1231 []>; 1232def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn), 1233 (ins GPR:$base, t2am_imm8_offset:$addr), 1234 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1235 "ldrsb", "\t$Rt, [$Rn], $addr", "$base = $Rn", 1236 []>; 1237 1238def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn), 1239 (ins t2addrmode_imm8:$addr), 1240 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu, 1241 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn", 1242 []>; 1243def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$dst, GPR:$Rn), 1244 (ins GPR:$base, t2am_imm8_offset:$addr), 1245 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu, 1246 "ldrsh", "\t$dst, [$Rn], $addr", "$base = $Rn", 1247 []>; 1248} // mayLoad = 1, neverHasSideEffects = 1 1249 1250// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are 1251// for disassembly only. 1252// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4 1253class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii> 1254 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc, 1255 "\t$Rt, $addr", []> { 1256 let Inst{31-27} = 0b11111; 1257 let Inst{26-25} = 0b00; 1258 let Inst{24} = signed; 1259 let Inst{23} = 0; 1260 let Inst{22-21} = type; 1261 let Inst{20} = 1; // load 1262 let Inst{11} = 1; 1263 let Inst{10-8} = 0b110; // PUW. 1264 1265 bits<4> Rt; 1266 bits<13> addr; 1267 let Inst{15-12} = Rt; 1268 let Inst{19-16} = addr{12-9}; 1269 let Inst{7-0} = addr{7-0}; 1270} 1271 1272def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>; 1273def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>; 1274def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>; 1275def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>; 1276def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>; 1277 1278// Store 1279defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, 1280 BinOpFrag<(store node:$LHS, node:$RHS)>>; 1281defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si, 1282 rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>; 1283defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si, 1284 rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>; 1285 1286// Store doubleword 1287let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in 1288def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs), 1289 (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr), 1290 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", []>; 1291 1292// Indexed stores 1293def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPRnopc:$base_wb), 1294 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr), 1295 AddrModeT2_i8, IndexModePre, IIC_iStore_iu, 1296 "str", "\t$Rt, [$Rn, $addr]!", 1297 "$Rn = $base_wb,@earlyclobber $base_wb", 1298 [(set GPRnopc:$base_wb, 1299 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>; 1300 1301def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPRnopc:$base_wb), 1302 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr), 1303 AddrModeT2_i8, IndexModePost, IIC_iStore_iu, 1304 "str", "\t$Rt, [$Rn], $addr", 1305 "$Rn = $base_wb,@earlyclobber $base_wb", 1306 [(set GPRnopc:$base_wb, 1307 (post_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>; 1308 1309def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPRnopc:$base_wb), 1310 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr), 1311 AddrModeT2_i8, IndexModePre, IIC_iStore_iu, 1312 "strh", "\t$Rt, [$Rn, $addr]!", 1313 "$Rn = $base_wb,@earlyclobber $base_wb", 1314 [(set GPRnopc:$base_wb, 1315 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>; 1316 1317def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPRnopc:$base_wb), 1318 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr), 1319 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu, 1320 "strh", "\t$Rt, [$Rn], $addr", 1321 "$Rn = $base_wb,@earlyclobber $base_wb", 1322 [(set GPRnopc:$base_wb, 1323 (post_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>; 1324 1325def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPRnopc:$base_wb), 1326 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr), 1327 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu, 1328 "strb", "\t$Rt, [$Rn, $addr]!", 1329 "$Rn = $base_wb,@earlyclobber $base_wb", 1330 [(set GPRnopc:$base_wb, 1331 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>; 1332 1333def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPRnopc:$base_wb), 1334 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr), 1335 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu, 1336 "strb", "\t$Rt, [$Rn], $addr", 1337 "$Rn = $base_wb,@earlyclobber $base_wb", 1338 [(set GPRnopc:$base_wb, 1339 (post_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>; 1340 1341// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly 1342// only. 1343// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4 1344class T2IstT<bits<2> type, string opc, InstrItinClass ii> 1345 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc, 1346 "\t$Rt, $addr", []> { 1347 let Inst{31-27} = 0b11111; 1348 let Inst{26-25} = 0b00; 1349 let Inst{24} = 0; // not signed 1350 let Inst{23} = 0; 1351 let Inst{22-21} = type; 1352 let Inst{20} = 0; // store 1353 let Inst{11} = 1; 1354 let Inst{10-8} = 0b110; // PUW 1355 1356 bits<4> Rt; 1357 bits<13> addr; 1358 let Inst{15-12} = Rt; 1359 let Inst{19-16} = addr{12-9}; 1360 let Inst{7-0} = addr{7-0}; 1361} 1362 1363def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>; 1364def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>; 1365def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>; 1366 1367// ldrd / strd pre / post variants 1368// For disassembly only. 1369 1370def t2LDRD_PRE : T2Ii8s4Tied<1, 1, 1, 1371 (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb), 1372 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru, 1373 "ldrd", "\t$Rt, $Rt2, [$base, $imm]!", []>; 1374 1375def t2LDRD_POST : T2Ii8s4Tied<0, 1, 1, 1376 (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb), 1377 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru, 1378 "ldrd", "\t$Rt, $Rt2, [$base], $imm", []>; 1379 1380def t2STRD_PRE : T2Ii8s4Tied<1, 1, 0, (outs GPR:$wb), 1381 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm), 1382 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base, $imm]!", []>; 1383 1384def t2STRD_POST : T2Ii8s4Tied<0, 1, 0, (outs GPR:$wb), 1385 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm), 1386 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base], $imm", []>; 1387 1388// T2Ipl (Preload Data/Instruction) signals the memory system of possible future 1389// data/instruction access. These are for disassembly only. 1390// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0), 1391// (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1). 1392multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> { 1393 1394 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc, 1395 "\t$addr", 1396 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> { 1397 let Inst{31-25} = 0b1111100; 1398 let Inst{24} = instr; 1399 let Inst{22} = 0; 1400 let Inst{21} = write; 1401 let Inst{20} = 1; 1402 let Inst{15-12} = 0b1111; 1403 1404 bits<17> addr; 1405 let addr{12} = 1; // add = TRUE 1406 let Inst{19-16} = addr{16-13}; // Rn 1407 let Inst{23} = addr{12}; // U 1408 let Inst{11-0} = addr{11-0}; // imm12 1409 } 1410 1411 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc, 1412 "\t$addr", 1413 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> { 1414 let Inst{31-25} = 0b1111100; 1415 let Inst{24} = instr; 1416 let Inst{23} = 0; // U = 0 1417 let Inst{22} = 0; 1418 let Inst{21} = write; 1419 let Inst{20} = 1; 1420 let Inst{15-12} = 0b1111; 1421 let Inst{11-8} = 0b1100; 1422 1423 bits<13> addr; 1424 let Inst{19-16} = addr{12-9}; // Rn 1425 let Inst{7-0} = addr{7-0}; // imm8 1426 } 1427 1428 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc, 1429 "\t$addr", 1430 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> { 1431 let Inst{31-25} = 0b1111100; 1432 let Inst{24} = instr; 1433 let Inst{23} = 0; // add = TRUE for T1 1434 let Inst{22} = 0; 1435 let Inst{21} = write; 1436 let Inst{20} = 1; 1437 let Inst{15-12} = 0b1111; 1438 let Inst{11-6} = 0000000; 1439 1440 bits<10> addr; 1441 let Inst{19-16} = addr{9-6}; // Rn 1442 let Inst{3-0} = addr{5-2}; // Rm 1443 let Inst{5-4} = addr{1-0}; // imm2 1444 1445 let DecoderMethod = "DecodeT2LoadShift"; 1446 } 1447} 1448 1449defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>; 1450defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>; 1451defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>; 1452 1453//===----------------------------------------------------------------------===// 1454// Load / store multiple Instructions. 1455// 1456 1457multiclass thumb2_ldst_mult<string asm, InstrItinClass itin, 1458 InstrItinClass itin_upd, bit L_bit> { 1459 def IA : 1460 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1461 itin, !strconcat(asm, "ia${p}.w\t$Rn, $regs"), []> { 1462 bits<4> Rn; 1463 bits<16> regs; 1464 1465 let Inst{31-27} = 0b11101; 1466 let Inst{26-25} = 0b00; 1467 let Inst{24-23} = 0b01; // Increment After 1468 let Inst{22} = 0; 1469 let Inst{21} = 0; // No writeback 1470 let Inst{20} = L_bit; 1471 let Inst{19-16} = Rn; 1472 let Inst{15-0} = regs; 1473 } 1474 def IA_UPD : 1475 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1476 itin_upd, !strconcat(asm, "ia${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> { 1477 bits<4> Rn; 1478 bits<16> regs; 1479 1480 let Inst{31-27} = 0b11101; 1481 let Inst{26-25} = 0b00; 1482 let Inst{24-23} = 0b01; // Increment After 1483 let Inst{22} = 0; 1484 let Inst{21} = 1; // Writeback 1485 let Inst{20} = L_bit; 1486 let Inst{19-16} = Rn; 1487 let Inst{15-0} = regs; 1488 } 1489 def DB : 1490 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1491 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> { 1492 bits<4> Rn; 1493 bits<16> regs; 1494 1495 let Inst{31-27} = 0b11101; 1496 let Inst{26-25} = 0b00; 1497 let Inst{24-23} = 0b10; // Decrement Before 1498 let Inst{22} = 0; 1499 let Inst{21} = 0; // No writeback 1500 let Inst{20} = L_bit; 1501 let Inst{19-16} = Rn; 1502 let Inst{15-0} = regs; 1503 } 1504 def DB_UPD : 1505 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops), 1506 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> { 1507 bits<4> Rn; 1508 bits<16> regs; 1509 1510 let Inst{31-27} = 0b11101; 1511 let Inst{26-25} = 0b00; 1512 let Inst{24-23} = 0b10; // Decrement Before 1513 let Inst{22} = 0; 1514 let Inst{21} = 1; // Writeback 1515 let Inst{20} = L_bit; 1516 let Inst{19-16} = Rn; 1517 let Inst{15-0} = regs; 1518 } 1519} 1520 1521let neverHasSideEffects = 1 in { 1522 1523let mayLoad = 1, hasExtraDefRegAllocReq = 1 in 1524defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>; 1525 1526let mayStore = 1, hasExtraSrcRegAllocReq = 1 in 1527defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>; 1528 1529} // neverHasSideEffects 1530 1531 1532//===----------------------------------------------------------------------===// 1533// Move Instructions. 1534// 1535 1536let neverHasSideEffects = 1 in 1537def t2MOVr : T2sTwoReg<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr, 1538 "mov", ".w\t$Rd, $Rm", []> { 1539 let Inst{31-27} = 0b11101; 1540 let Inst{26-25} = 0b01; 1541 let Inst{24-21} = 0b0010; 1542 let Inst{19-16} = 0b1111; // Rn 1543 let Inst{14-12} = 0b000; 1544 let Inst{7-4} = 0b0000; 1545} 1546 1547// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16. 1548let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1, 1549 AddedComplexity = 1 in 1550def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi, 1551 "mov", ".w\t$Rd, $imm", 1552 [(set rGPR:$Rd, t2_so_imm:$imm)]> { 1553 let Inst{31-27} = 0b11110; 1554 let Inst{25} = 0; 1555 let Inst{24-21} = 0b0010; 1556 let Inst{19-16} = 0b1111; // Rn 1557 let Inst{15} = 0; 1558} 1559 1560def : InstAlias<"mov${s}${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm, 1561 pred:$p, cc_out:$s)>, 1562 Requires<[IsThumb2]>; 1563 1564let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in 1565def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi, 1566 "movw", "\t$Rd, $imm", 1567 [(set rGPR:$Rd, imm0_65535:$imm)]> { 1568 let Inst{31-27} = 0b11110; 1569 let Inst{25} = 1; 1570 let Inst{24-21} = 0b0010; 1571 let Inst{20} = 0; // The S bit. 1572 let Inst{15} = 0; 1573 1574 bits<4> Rd; 1575 bits<16> imm; 1576 1577 let Inst{11-8} = Rd; 1578 let Inst{19-16} = imm{15-12}; 1579 let Inst{26} = imm{11}; 1580 let Inst{14-12} = imm{10-8}; 1581 let Inst{7-0} = imm{7-0}; 1582} 1583 1584def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd), 1585 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>; 1586 1587let Constraints = "$src = $Rd" in { 1588def t2MOVTi16 : T2I<(outs rGPR:$Rd), 1589 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi, 1590 "movt", "\t$Rd, $imm", 1591 [(set rGPR:$Rd, 1592 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> { 1593 let Inst{31-27} = 0b11110; 1594 let Inst{25} = 1; 1595 let Inst{24-21} = 0b0110; 1596 let Inst{20} = 0; // The S bit. 1597 let Inst{15} = 0; 1598 1599 bits<4> Rd; 1600 bits<16> imm; 1601 1602 let Inst{11-8} = Rd; 1603 let Inst{19-16} = imm{15-12}; 1604 let Inst{26} = imm{11}; 1605 let Inst{14-12} = imm{10-8}; 1606 let Inst{7-0} = imm{7-0}; 1607} 1608 1609def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd), 1610 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>; 1611} // Constraints 1612 1613def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>; 1614 1615//===----------------------------------------------------------------------===// 1616// Extend Instructions. 1617// 1618 1619// Sign extenders 1620 1621def t2SXTB : T2I_ext_rrot<0b100, "sxtb", 1622 UnOpFrag<(sext_inreg node:$Src, i8)>>; 1623def t2SXTH : T2I_ext_rrot<0b000, "sxth", 1624 UnOpFrag<(sext_inreg node:$Src, i16)>>; 1625def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">; 1626 1627def t2SXTAB : T2I_exta_rrot<0b100, "sxtab", 1628 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>; 1629def t2SXTAH : T2I_exta_rrot<0b000, "sxtah", 1630 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>; 1631def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">; 1632 1633// TODO: SXT(A){B|H}16 1634 1635// Zero extenders 1636 1637let AddedComplexity = 16 in { 1638def t2UXTB : T2I_ext_rrot<0b101, "uxtb", 1639 UnOpFrag<(and node:$Src, 0x000000FF)>>; 1640def t2UXTH : T2I_ext_rrot<0b001, "uxth", 1641 UnOpFrag<(and node:$Src, 0x0000FFFF)>>; 1642def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16", 1643 UnOpFrag<(and node:$Src, 0x00FF00FF)>>; 1644 1645// FIXME: This pattern incorrectly assumes the shl operator is a rotate. 1646// The transformation should probably be done as a combiner action 1647// instead so we can include a check for masking back in the upper 1648// eight bits of the source into the lower eight bits of the result. 1649//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF), 1650// (t2UXTB16 rGPR:$Src, 3)>, 1651// Requires<[HasT2ExtractPack, IsThumb2]>; 1652def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF), 1653 (t2UXTB16 rGPR:$Src, 1)>, 1654 Requires<[HasT2ExtractPack, IsThumb2]>; 1655 1656def t2UXTAB : T2I_exta_rrot<0b101, "uxtab", 1657 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>; 1658def t2UXTAH : T2I_exta_rrot<0b001, "uxtah", 1659 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>; 1660def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">; 1661} 1662 1663//===----------------------------------------------------------------------===// 1664// Arithmetic Instructions. 1665// 1666 1667defm t2ADD : T2I_bin_ii12rs<0b000, "add", 1668 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>; 1669defm t2SUB : T2I_bin_ii12rs<0b101, "sub", 1670 BinOpFrag<(sub node:$LHS, node:$RHS)>>; 1671 1672// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants. 1673defm t2ADDS : T2I_bin_s_irs <0b1000, "add", 1674 IIC_iALUi, IIC_iALUr, IIC_iALUsi, 1675 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>; 1676defm t2SUBS : T2I_bin_s_irs <0b1101, "sub", 1677 IIC_iALUi, IIC_iALUr, IIC_iALUsi, 1678 BinOpFrag<(subc node:$LHS, node:$RHS)>>; 1679 1680defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", 1681 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>; 1682defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", 1683 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>; 1684defm t2ADCS : T2I_adde_sube_s_irs<BinOpFrag<(adde_live_carry node:$LHS, 1685 node:$RHS)>, 1>; 1686defm t2SBCS : T2I_adde_sube_s_irs<BinOpFrag<(sube_live_carry node:$LHS, 1687 node:$RHS)>>; 1688 1689// RSB 1690defm t2RSB : T2I_rbin_irs <0b1110, "rsb", 1691 BinOpFrag<(sub node:$LHS, node:$RHS)>>; 1692defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb", 1693 BinOpFrag<(subc node:$LHS, node:$RHS)>>; 1694 1695// (sub X, imm) gets canonicalized to (add X, -imm). Match this form. 1696// The assume-no-carry-in form uses the negation of the input since add/sub 1697// assume opposite meanings of the carry flag (i.e., carry == !borrow). 1698// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory 1699// details. 1700// The AddedComplexity preferences the first variant over the others since 1701// it can be shrunk to a 16-bit wide encoding, while the others cannot. 1702let AddedComplexity = 1 in 1703def : T2Pat<(add GPR:$src, imm0_255_neg:$imm), 1704 (t2SUBri GPR:$src, imm0_255_neg:$imm)>; 1705def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm), 1706 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>; 1707def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm), 1708 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>; 1709let AddedComplexity = 1 in 1710def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm), 1711 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>; 1712def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm), 1713 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>; 1714// The with-carry-in form matches bitwise not instead of the negation. 1715// Effectively, the inverse interpretation of the carry flag already accounts 1716// for part of the negation. 1717let AddedComplexity = 1 in 1718def : T2Pat<(adde_dead_carry rGPR:$src, imm0_255_not:$imm), 1719 (t2SBCri rGPR:$src, imm0_255_not:$imm)>; 1720def : T2Pat<(adde_dead_carry rGPR:$src, t2_so_imm_not:$imm), 1721 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>; 1722let AddedComplexity = 1 in 1723def : T2Pat<(adde_live_carry rGPR:$src, imm0_255_not:$imm), 1724 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>; 1725def : T2Pat<(adde_live_carry rGPR:$src, t2_so_imm_not:$imm), 1726 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>; 1727 1728// Select Bytes -- for disassembly only 1729 1730def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), 1731 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>, 1732 Requires<[IsThumb2, HasThumb2DSP]> { 1733 let Inst{31-27} = 0b11111; 1734 let Inst{26-24} = 0b010; 1735 let Inst{23} = 0b1; 1736 let Inst{22-20} = 0b010; 1737 let Inst{15-12} = 0b1111; 1738 let Inst{7} = 0b1; 1739 let Inst{6-4} = 0b000; 1740} 1741 1742// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned) 1743// And Miscellaneous operations -- for disassembly only 1744class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc, 1745 list<dag> pat = [/* For disassembly only; pattern left blank */], 1746 dag iops = (ins rGPR:$Rn, rGPR:$Rm), 1747 string asm = "\t$Rd, $Rn, $Rm"> 1748 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>, 1749 Requires<[IsThumb2, HasThumb2DSP]> { 1750 let Inst{31-27} = 0b11111; 1751 let Inst{26-23} = 0b0101; 1752 let Inst{22-20} = op22_20; 1753 let Inst{15-12} = 0b1111; 1754 let Inst{7-4} = op7_4; 1755 1756 bits<4> Rd; 1757 bits<4> Rn; 1758 bits<4> Rm; 1759 1760 let Inst{11-8} = Rd; 1761 let Inst{19-16} = Rn; 1762 let Inst{3-0} = Rm; 1763} 1764 1765// Saturating add/subtract -- for disassembly only 1766 1767def t2QADD : T2I_pam<0b000, 0b1000, "qadd", 1768 [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))], 1769 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 1770def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">; 1771def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">; 1772def t2QASX : T2I_pam<0b010, 0b0001, "qasx">; 1773def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd", [], 1774 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 1775def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub", [], 1776 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 1777def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">; 1778def t2QSUB : T2I_pam<0b000, 0b1010, "qsub", 1779 [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))], 1780 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">; 1781def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">; 1782def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">; 1783def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">; 1784def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">; 1785def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">; 1786def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">; 1787def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">; 1788def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">; 1789 1790// Signed/Unsigned add/subtract -- for disassembly only 1791 1792def t2SASX : T2I_pam<0b010, 0b0000, "sasx">; 1793def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">; 1794def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">; 1795def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">; 1796def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">; 1797def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">; 1798def t2UASX : T2I_pam<0b010, 0b0100, "uasx">; 1799def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">; 1800def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">; 1801def t2USAX : T2I_pam<0b110, 0b0100, "usax">; 1802def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">; 1803def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">; 1804 1805// Signed/Unsigned halving add/subtract -- for disassembly only 1806 1807def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">; 1808def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">; 1809def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">; 1810def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">; 1811def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">; 1812def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">; 1813def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">; 1814def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">; 1815def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">; 1816def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">; 1817def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">; 1818def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">; 1819 1820// Helper class for disassembly only 1821// A6.3.16 & A6.3.17 1822// T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions. 1823class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops, 1824 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern> 1825 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> { 1826 let Inst{31-27} = 0b11111; 1827 let Inst{26-24} = 0b011; 1828 let Inst{23} = long; 1829 let Inst{22-20} = op22_20; 1830 let Inst{7-4} = op7_4; 1831} 1832 1833class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops, 1834 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern> 1835 : T2FourReg<oops, iops, itin, opc, asm, pattern> { 1836 let Inst{31-27} = 0b11111; 1837 let Inst{26-24} = 0b011; 1838 let Inst{23} = long; 1839 let Inst{22-20} = op22_20; 1840 let Inst{7-4} = op7_4; 1841} 1842 1843// Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only 1844 1845def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd), 1846 (ins rGPR:$Rn, rGPR:$Rm), 1847 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>, 1848 Requires<[IsThumb2, HasThumb2DSP]> { 1849 let Inst{15-12} = 0b1111; 1850} 1851def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd), 1852 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary, 1853 "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>, 1854 Requires<[IsThumb2, HasThumb2DSP]>; 1855 1856// Signed/Unsigned saturate -- for disassembly only 1857 1858class T2SatI<dag oops, dag iops, InstrItinClass itin, 1859 string opc, string asm, list<dag> pattern> 1860 : T2I<oops, iops, itin, opc, asm, pattern> { 1861 bits<4> Rd; 1862 bits<4> Rn; 1863 bits<5> sat_imm; 1864 bits<7> sh; 1865 1866 let Inst{11-8} = Rd; 1867 let Inst{19-16} = Rn; 1868 let Inst{4-0} = sat_imm; 1869 let Inst{21} = sh{5}; 1870 let Inst{14-12} = sh{4-2}; 1871 let Inst{7-6} = sh{1-0}; 1872} 1873 1874def t2SSAT: T2SatI< 1875 (outs rGPR:$Rd), (ins imm1_32:$sat_imm, rGPR:$Rn, shift_imm:$sh), 1876 NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", 1877 [/* For disassembly only; pattern left blank */]> { 1878 let Inst{31-27} = 0b11110; 1879 let Inst{25-22} = 0b1100; 1880 let Inst{20} = 0; 1881 let Inst{15} = 0; 1882} 1883 1884def t2SSAT16: T2SatI< 1885 (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary, 1886 "ssat16", "\t$Rd, $sat_imm, $Rn", 1887 [/* For disassembly only; pattern left blank */]>, 1888 Requires<[IsThumb2, HasThumb2DSP]> { 1889 let Inst{31-27} = 0b11110; 1890 let Inst{25-22} = 0b1100; 1891 let Inst{20} = 0; 1892 let Inst{15} = 0; 1893 let Inst{21} = 1; // sh = '1' 1894 let Inst{14-12} = 0b000; // imm3 = '000' 1895 let Inst{7-6} = 0b00; // imm2 = '00' 1896} 1897 1898def t2USAT: T2SatI< 1899 (outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn, shift_imm:$sh), 1900 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", 1901 [/* For disassembly only; pattern left blank */]> { 1902 let Inst{31-27} = 0b11110; 1903 let Inst{25-22} = 0b1110; 1904 let Inst{20} = 0; 1905 let Inst{15} = 0; 1906} 1907 1908def t2USAT16: T2SatI<(outs rGPR:$dst), (ins i32imm:$sat_imm, rGPR:$Rn), 1909 NoItinerary, 1910 "usat16", "\t$dst, $sat_imm, $Rn", 1911 [/* For disassembly only; pattern left blank */]>, 1912 Requires<[IsThumb2, HasThumb2DSP]> { 1913 let Inst{31-27} = 0b11110; 1914 let Inst{25-22} = 0b1110; 1915 let Inst{20} = 0; 1916 let Inst{15} = 0; 1917 let Inst{21} = 1; // sh = '1' 1918 let Inst{14-12} = 0b000; // imm3 = '000' 1919 let Inst{7-6} = 0b00; // imm2 = '00' 1920} 1921 1922def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>; 1923def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>; 1924 1925//===----------------------------------------------------------------------===// 1926// Shift and rotate Instructions. 1927// 1928 1929defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, BinOpFrag<(shl node:$LHS, node:$RHS)>>; 1930defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, BinOpFrag<(srl node:$LHS, node:$RHS)>>; 1931defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, BinOpFrag<(sra node:$LHS, node:$RHS)>>; 1932defm t2ROR : T2I_sh_ir<0b11, "ror", imm1_31, BinOpFrag<(rotr node:$LHS, node:$RHS)>>; 1933 1934// (rotr x, (and y, 0x...1f)) ==> (ROR x, y) 1935def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)), 1936 (t2RORrr rGPR:$lhs, rGPR:$rhs)>; 1937 1938let Uses = [CPSR] in { 1939def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, 1940 "rrx", "\t$Rd, $Rm", 1941 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> { 1942 let Inst{31-27} = 0b11101; 1943 let Inst{26-25} = 0b01; 1944 let Inst{24-21} = 0b0010; 1945 let Inst{19-16} = 0b1111; // Rn 1946 let Inst{14-12} = 0b000; 1947 let Inst{7-4} = 0b0011; 1948} 1949} 1950 1951let isCodeGenOnly = 1, Defs = [CPSR] in { 1952def t2MOVsrl_flag : T2TwoRegShiftImm< 1953 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, 1954 "lsrs", ".w\t$Rd, $Rm, #1", 1955 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> { 1956 let Inst{31-27} = 0b11101; 1957 let Inst{26-25} = 0b01; 1958 let Inst{24-21} = 0b0010; 1959 let Inst{20} = 1; // The S bit. 1960 let Inst{19-16} = 0b1111; // Rn 1961 let Inst{5-4} = 0b01; // Shift type. 1962 // Shift amount = Inst{14-12:7-6} = 1. 1963 let Inst{14-12} = 0b000; 1964 let Inst{7-6} = 0b01; 1965} 1966def t2MOVsra_flag : T2TwoRegShiftImm< 1967 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, 1968 "asrs", ".w\t$Rd, $Rm, #1", 1969 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> { 1970 let Inst{31-27} = 0b11101; 1971 let Inst{26-25} = 0b01; 1972 let Inst{24-21} = 0b0010; 1973 let Inst{20} = 1; // The S bit. 1974 let Inst{19-16} = 0b1111; // Rn 1975 let Inst{5-4} = 0b10; // Shift type. 1976 // Shift amount = Inst{14-12:7-6} = 1. 1977 let Inst{14-12} = 0b000; 1978 let Inst{7-6} = 0b01; 1979} 1980} 1981 1982//===----------------------------------------------------------------------===// 1983// Bitwise Instructions. 1984// 1985 1986defm t2AND : T2I_bin_w_irs<0b0000, "and", 1987 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 1988 BinOpFrag<(and node:$LHS, node:$RHS)>, "t2AND", 1>; 1989defm t2ORR : T2I_bin_w_irs<0b0010, "orr", 1990 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 1991 BinOpFrag<(or node:$LHS, node:$RHS)>, "t2ORR", 1>; 1992defm t2EOR : T2I_bin_w_irs<0b0100, "eor", 1993 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 1994 BinOpFrag<(xor node:$LHS, node:$RHS)>, "t2EOR", 1>; 1995 1996defm t2BIC : T2I_bin_w_irs<0b0001, "bic", 1997 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 1998 BinOpFrag<(and node:$LHS, (not node:$RHS))>, 1999 "t2BIC">; 2000 2001class T2BitFI<dag oops, dag iops, InstrItinClass itin, 2002 string opc, string asm, list<dag> pattern> 2003 : T2I<oops, iops, itin, opc, asm, pattern> { 2004 bits<4> Rd; 2005 bits<5> msb; 2006 bits<5> lsb; 2007 2008 let Inst{11-8} = Rd; 2009 let Inst{4-0} = msb{4-0}; 2010 let Inst{14-12} = lsb{4-2}; 2011 let Inst{7-6} = lsb{1-0}; 2012} 2013 2014class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin, 2015 string opc, string asm, list<dag> pattern> 2016 : T2BitFI<oops, iops, itin, opc, asm, pattern> { 2017 bits<4> Rn; 2018 2019 let Inst{19-16} = Rn; 2020} 2021 2022let Constraints = "$src = $Rd" in 2023def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm), 2024 IIC_iUNAsi, "bfc", "\t$Rd, $imm", 2025 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> { 2026 let Inst{31-27} = 0b11110; 2027 let Inst{26} = 0; // should be 0. 2028 let Inst{25} = 1; 2029 let Inst{24-20} = 0b10110; 2030 let Inst{19-16} = 0b1111; // Rn 2031 let Inst{15} = 0; 2032 let Inst{5} = 0; // should be 0. 2033 2034 bits<10> imm; 2035 let msb{4-0} = imm{9-5}; 2036 let lsb{4-0} = imm{4-0}; 2037} 2038 2039def t2SBFX: T2TwoRegBitFI< 2040 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb), 2041 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> { 2042 let Inst{31-27} = 0b11110; 2043 let Inst{25} = 1; 2044 let Inst{24-20} = 0b10100; 2045 let Inst{15} = 0; 2046} 2047 2048def t2UBFX: T2TwoRegBitFI< 2049 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb), 2050 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> { 2051 let Inst{31-27} = 0b11110; 2052 let Inst{25} = 1; 2053 let Inst{24-20} = 0b11100; 2054 let Inst{15} = 0; 2055} 2056 2057// A8.6.18 BFI - Bitfield insert (Encoding T1) 2058let Constraints = "$src = $Rd" in { 2059 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd), 2060 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm), 2061 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm", 2062 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn, 2063 bf_inv_mask_imm:$imm))]> { 2064 let Inst{31-27} = 0b11110; 2065 let Inst{26} = 0; // should be 0. 2066 let Inst{25} = 1; 2067 let Inst{24-20} = 0b10110; 2068 let Inst{15} = 0; 2069 let Inst{5} = 0; // should be 0. 2070 2071 bits<10> imm; 2072 let msb{4-0} = imm{9-5}; 2073 let lsb{4-0} = imm{4-0}; 2074 } 2075 2076 // GNU as only supports this form of bfi (w/ 4 arguments) 2077 let isAsmParserOnly = 1 in 2078 def t2BFI4p : T2TwoRegBitFI<(outs rGPR:$Rd), 2079 (ins rGPR:$src, rGPR:$Rn, lsb_pos_imm:$lsbit, 2080 width_imm:$width), 2081 IIC_iBITi, "bfi", "\t$Rd, $Rn, $lsbit, $width", 2082 []> { 2083 let Inst{31-27} = 0b11110; 2084 let Inst{26} = 0; // should be 0. 2085 let Inst{25} = 1; 2086 let Inst{24-20} = 0b10110; 2087 let Inst{15} = 0; 2088 let Inst{5} = 0; // should be 0. 2089 2090 bits<5> lsbit; 2091 bits<5> width; 2092 let msb{4-0} = width; // Custom encoder => lsb+width-1 2093 let lsb{4-0} = lsbit; 2094 } 2095} 2096 2097defm t2ORN : T2I_bin_irs<0b0011, "orn", 2098 IIC_iBITi, IIC_iBITr, IIC_iBITsi, 2099 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 2100 "t2ORN", 0, "">; 2101 2102// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version 2103let AddedComplexity = 1 in 2104defm t2MVN : T2I_un_irs <0b0011, "mvn", 2105 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi, 2106 UnOpFrag<(not node:$Src)>, 1, 1>; 2107 2108 2109let AddedComplexity = 1 in 2110def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm), 2111 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>; 2112 2113// FIXME: Disable this pattern on Darwin to workaround an assembler bug. 2114def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm), 2115 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>, 2116 Requires<[IsThumb2]>; 2117 2118def : T2Pat<(t2_so_imm_not:$src), 2119 (t2MVNi t2_so_imm_not:$src)>; 2120 2121//===----------------------------------------------------------------------===// 2122// Multiply Instructions. 2123// 2124let isCommutable = 1 in 2125def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32, 2126 "mul", "\t$Rd, $Rn, $Rm", 2127 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> { 2128 let Inst{31-27} = 0b11111; 2129 let Inst{26-23} = 0b0110; 2130 let Inst{22-20} = 0b000; 2131 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2132 let Inst{7-4} = 0b0000; // Multiply 2133} 2134 2135def t2MLA: T2FourReg< 2136 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2137 "mla", "\t$Rd, $Rn, $Rm, $Ra", 2138 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]> { 2139 let Inst{31-27} = 0b11111; 2140 let Inst{26-23} = 0b0110; 2141 let Inst{22-20} = 0b000; 2142 let Inst{7-4} = 0b0000; // Multiply 2143} 2144 2145def t2MLS: T2FourReg< 2146 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2147 "mls", "\t$Rd, $Rn, $Rm, $Ra", 2148 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]> { 2149 let Inst{31-27} = 0b11111; 2150 let Inst{26-23} = 0b0110; 2151 let Inst{22-20} = 0b000; 2152 let Inst{7-4} = 0b0001; // Multiply and Subtract 2153} 2154 2155// Extra precision multiplies with low / high results 2156let neverHasSideEffects = 1 in { 2157let isCommutable = 1 in { 2158def t2SMULL : T2MulLong<0b000, 0b0000, 2159 (outs rGPR:$Rd, rGPR:$Ra), 2160 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64, 2161 "smull", "\t$Rd, $Ra, $Rn, $Rm", []>; 2162 2163def t2UMULL : T2MulLong<0b010, 0b0000, 2164 (outs rGPR:$RdLo, rGPR:$RdHi), 2165 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64, 2166 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>; 2167} // isCommutable 2168 2169// Multiply + accumulate 2170def t2SMLAL : T2MulLong<0b100, 0b0000, 2171 (outs rGPR:$RdLo, rGPR:$RdHi), 2172 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, 2173 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>; 2174 2175def t2UMLAL : T2MulLong<0b110, 0b0000, 2176 (outs rGPR:$RdLo, rGPR:$RdHi), 2177 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, 2178 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>; 2179 2180def t2UMAAL : T2MulLong<0b110, 0b0110, 2181 (outs rGPR:$RdLo, rGPR:$RdHi), 2182 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, 2183 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>, 2184 Requires<[IsThumb2, HasThumb2DSP]>; 2185} // neverHasSideEffects 2186 2187// Rounding variants of the below included for disassembly only 2188 2189// Most significant word multiply 2190def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32, 2191 "smmul", "\t$Rd, $Rn, $Rm", 2192 [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>, 2193 Requires<[IsThumb2, HasThumb2DSP]> { 2194 let Inst{31-27} = 0b11111; 2195 let Inst{26-23} = 0b0110; 2196 let Inst{22-20} = 0b101; 2197 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2198 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0) 2199} 2200 2201def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32, 2202 "smmulr", "\t$Rd, $Rn, $Rm", []>, 2203 Requires<[IsThumb2, HasThumb2DSP]> { 2204 let Inst{31-27} = 0b11111; 2205 let Inst{26-23} = 0b0110; 2206 let Inst{22-20} = 0b101; 2207 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2208 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1) 2209} 2210 2211def t2SMMLA : T2FourReg< 2212 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2213 "smmla", "\t$Rd, $Rn, $Rm, $Ra", 2214 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>, 2215 Requires<[IsThumb2, HasThumb2DSP]> { 2216 let Inst{31-27} = 0b11111; 2217 let Inst{26-23} = 0b0110; 2218 let Inst{22-20} = 0b101; 2219 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0) 2220} 2221 2222def t2SMMLAR: T2FourReg< 2223 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2224 "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>, 2225 Requires<[IsThumb2, HasThumb2DSP]> { 2226 let Inst{31-27} = 0b11111; 2227 let Inst{26-23} = 0b0110; 2228 let Inst{22-20} = 0b101; 2229 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1) 2230} 2231 2232def t2SMMLS: T2FourReg< 2233 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2234 "smmls", "\t$Rd, $Rn, $Rm, $Ra", 2235 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>, 2236 Requires<[IsThumb2, HasThumb2DSP]> { 2237 let Inst{31-27} = 0b11111; 2238 let Inst{26-23} = 0b0110; 2239 let Inst{22-20} = 0b110; 2240 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0) 2241} 2242 2243def t2SMMLSR:T2FourReg< 2244 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, 2245 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>, 2246 Requires<[IsThumb2, HasThumb2DSP]> { 2247 let Inst{31-27} = 0b11111; 2248 let Inst{26-23} = 0b0110; 2249 let Inst{22-20} = 0b110; 2250 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1) 2251} 2252 2253multiclass T2I_smul<string opc, PatFrag opnode> { 2254 def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2255 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm", 2256 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16), 2257 (sext_inreg rGPR:$Rm, i16)))]>, 2258 Requires<[IsThumb2, HasThumb2DSP]> { 2259 let Inst{31-27} = 0b11111; 2260 let Inst{26-23} = 0b0110; 2261 let Inst{22-20} = 0b001; 2262 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2263 let Inst{7-6} = 0b00; 2264 let Inst{5-4} = 0b00; 2265 } 2266 2267 def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2268 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm", 2269 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16), 2270 (sra rGPR:$Rm, (i32 16))))]>, 2271 Requires<[IsThumb2, HasThumb2DSP]> { 2272 let Inst{31-27} = 0b11111; 2273 let Inst{26-23} = 0b0110; 2274 let Inst{22-20} = 0b001; 2275 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2276 let Inst{7-6} = 0b00; 2277 let Inst{5-4} = 0b01; 2278 } 2279 2280 def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2281 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm", 2282 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)), 2283 (sext_inreg rGPR:$Rm, i16)))]>, 2284 Requires<[IsThumb2, HasThumb2DSP]> { 2285 let Inst{31-27} = 0b11111; 2286 let Inst{26-23} = 0b0110; 2287 let Inst{22-20} = 0b001; 2288 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2289 let Inst{7-6} = 0b00; 2290 let Inst{5-4} = 0b10; 2291 } 2292 2293 def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2294 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm", 2295 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)), 2296 (sra rGPR:$Rm, (i32 16))))]>, 2297 Requires<[IsThumb2, HasThumb2DSP]> { 2298 let Inst{31-27} = 0b11111; 2299 let Inst{26-23} = 0b0110; 2300 let Inst{22-20} = 0b001; 2301 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2302 let Inst{7-6} = 0b00; 2303 let Inst{5-4} = 0b11; 2304 } 2305 2306 def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2307 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm", 2308 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn, 2309 (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>, 2310 Requires<[IsThumb2, HasThumb2DSP]> { 2311 let Inst{31-27} = 0b11111; 2312 let Inst{26-23} = 0b0110; 2313 let Inst{22-20} = 0b011; 2314 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2315 let Inst{7-6} = 0b00; 2316 let Inst{5-4} = 0b00; 2317 } 2318 2319 def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, 2320 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm", 2321 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn, 2322 (sra rGPR:$Rm, (i32 16))), (i32 16)))]>, 2323 Requires<[IsThumb2, HasThumb2DSP]> { 2324 let Inst{31-27} = 0b11111; 2325 let Inst{26-23} = 0b0110; 2326 let Inst{22-20} = 0b011; 2327 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate) 2328 let Inst{7-6} = 0b00; 2329 let Inst{5-4} = 0b01; 2330 } 2331} 2332 2333 2334multiclass T2I_smla<string opc, PatFrag opnode> { 2335 def BB : T2FourReg< 2336 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2337 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra", 2338 [(set rGPR:$Rd, (add rGPR:$Ra, 2339 (opnode (sext_inreg rGPR:$Rn, i16), 2340 (sext_inreg rGPR:$Rm, i16))))]>, 2341 Requires<[IsThumb2, HasThumb2DSP]> { 2342 let Inst{31-27} = 0b11111; 2343 let Inst{26-23} = 0b0110; 2344 let Inst{22-20} = 0b001; 2345 let Inst{7-6} = 0b00; 2346 let Inst{5-4} = 0b00; 2347 } 2348 2349 def BT : T2FourReg< 2350 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2351 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra", 2352 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16), 2353 (sra rGPR:$Rm, (i32 16)))))]>, 2354 Requires<[IsThumb2, HasThumb2DSP]> { 2355 let Inst{31-27} = 0b11111; 2356 let Inst{26-23} = 0b0110; 2357 let Inst{22-20} = 0b001; 2358 let Inst{7-6} = 0b00; 2359 let Inst{5-4} = 0b01; 2360 } 2361 2362 def TB : T2FourReg< 2363 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2364 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra", 2365 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)), 2366 (sext_inreg rGPR:$Rm, i16))))]>, 2367 Requires<[IsThumb2, HasThumb2DSP]> { 2368 let Inst{31-27} = 0b11111; 2369 let Inst{26-23} = 0b0110; 2370 let Inst{22-20} = 0b001; 2371 let Inst{7-6} = 0b00; 2372 let Inst{5-4} = 0b10; 2373 } 2374 2375 def TT : T2FourReg< 2376 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2377 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra", 2378 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)), 2379 (sra rGPR:$Rm, (i32 16)))))]>, 2380 Requires<[IsThumb2, HasThumb2DSP]> { 2381 let Inst{31-27} = 0b11111; 2382 let Inst{26-23} = 0b0110; 2383 let Inst{22-20} = 0b001; 2384 let Inst{7-6} = 0b00; 2385 let Inst{5-4} = 0b11; 2386 } 2387 2388 def WB : T2FourReg< 2389 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2390 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra", 2391 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn, 2392 (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>, 2393 Requires<[IsThumb2, HasThumb2DSP]> { 2394 let Inst{31-27} = 0b11111; 2395 let Inst{26-23} = 0b0110; 2396 let Inst{22-20} = 0b011; 2397 let Inst{7-6} = 0b00; 2398 let Inst{5-4} = 0b00; 2399 } 2400 2401 def WT : T2FourReg< 2402 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16, 2403 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra", 2404 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn, 2405 (sra rGPR:$Rm, (i32 16))), (i32 16))))]>, 2406 Requires<[IsThumb2, HasThumb2DSP]> { 2407 let Inst{31-27} = 0b11111; 2408 let Inst{26-23} = 0b0110; 2409 let Inst{22-20} = 0b011; 2410 let Inst{7-6} = 0b00; 2411 let Inst{5-4} = 0b01; 2412 } 2413} 2414 2415defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>; 2416defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>; 2417 2418// Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only 2419def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd), 2420 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm", 2421 [/* For disassembly only; pattern left blank */]>, 2422 Requires<[IsThumb2, HasThumb2DSP]>; 2423def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd), 2424 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm", 2425 [/* For disassembly only; pattern left blank */]>, 2426 Requires<[IsThumb2, HasThumb2DSP]>; 2427def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd), 2428 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm", 2429 [/* For disassembly only; pattern left blank */]>, 2430 Requires<[IsThumb2, HasThumb2DSP]>; 2431def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd), 2432 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm", 2433 [/* For disassembly only; pattern left blank */]>, 2434 Requires<[IsThumb2, HasThumb2DSP]>; 2435 2436// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD 2437// These are for disassembly only. 2438 2439def t2SMUAD: T2ThreeReg_mac< 2440 0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2441 IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>, 2442 Requires<[IsThumb2, HasThumb2DSP]> { 2443 let Inst{15-12} = 0b1111; 2444} 2445def t2SMUADX:T2ThreeReg_mac< 2446 0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2447 IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>, 2448 Requires<[IsThumb2, HasThumb2DSP]> { 2449 let Inst{15-12} = 0b1111; 2450} 2451def t2SMUSD: T2ThreeReg_mac< 2452 0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2453 IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>, 2454 Requires<[IsThumb2, HasThumb2DSP]> { 2455 let Inst{15-12} = 0b1111; 2456} 2457def t2SMUSDX:T2ThreeReg_mac< 2458 0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), 2459 IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>, 2460 Requires<[IsThumb2, HasThumb2DSP]> { 2461 let Inst{15-12} = 0b1111; 2462} 2463def t2SMLAD : T2ThreeReg_mac< 2464 0, 0b010, 0b0000, (outs rGPR:$Rd), 2465 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad", 2466 "\t$Rd, $Rn, $Rm, $Ra", []>, 2467 Requires<[IsThumb2, HasThumb2DSP]>; 2468def t2SMLADX : T2FourReg_mac< 2469 0, 0b010, 0b0001, (outs rGPR:$Rd), 2470 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx", 2471 "\t$Rd, $Rn, $Rm, $Ra", []>, 2472 Requires<[IsThumb2, HasThumb2DSP]>; 2473def t2SMLSD : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd), 2474 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd", 2475 "\t$Rd, $Rn, $Rm, $Ra", []>, 2476 Requires<[IsThumb2, HasThumb2DSP]>; 2477def t2SMLSDX : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd), 2478 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx", 2479 "\t$Rd, $Rn, $Rm, $Ra", []>, 2480 Requires<[IsThumb2, HasThumb2DSP]>; 2481def t2SMLALD : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd), 2482 (ins rGPR:$Rm, rGPR:$Rn), IIC_iMAC64, "smlald", 2483 "\t$Ra, $Rd, $Rm, $Rn", []>, 2484 Requires<[IsThumb2, HasThumb2DSP]>; 2485def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd), 2486 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlaldx", 2487 "\t$Ra, $Rd, $Rm, $Rn", []>, 2488 Requires<[IsThumb2, HasThumb2DSP]>; 2489def t2SMLSLD : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd), 2490 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsld", 2491 "\t$Ra, $Rd, $Rm, $Rn", []>, 2492 Requires<[IsThumb2, HasThumb2DSP]>; 2493def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd), 2494 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx", 2495 "\t$Ra, $Rd, $Rm, $Rn", []>, 2496 Requires<[IsThumb2, HasThumb2DSP]>; 2497 2498//===----------------------------------------------------------------------===// 2499// Division Instructions. 2500// Signed and unsigned division on v7-M 2501// 2502def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi, 2503 "sdiv", "\t$Rd, $Rn, $Rm", 2504 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>, 2505 Requires<[HasDivide, IsThumb2]> { 2506 let Inst{31-27} = 0b11111; 2507 let Inst{26-21} = 0b011100; 2508 let Inst{20} = 0b1; 2509 let Inst{15-12} = 0b1111; 2510 let Inst{7-4} = 0b1111; 2511} 2512 2513def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi, 2514 "udiv", "\t$Rd, $Rn, $Rm", 2515 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>, 2516 Requires<[HasDivide, IsThumb2]> { 2517 let Inst{31-27} = 0b11111; 2518 let Inst{26-21} = 0b011101; 2519 let Inst{20} = 0b1; 2520 let Inst{15-12} = 0b1111; 2521 let Inst{7-4} = 0b1111; 2522} 2523 2524//===----------------------------------------------------------------------===// 2525// Misc. Arithmetic Instructions. 2526// 2527 2528class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops, 2529 InstrItinClass itin, string opc, string asm, list<dag> pattern> 2530 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> { 2531 let Inst{31-27} = 0b11111; 2532 let Inst{26-22} = 0b01010; 2533 let Inst{21-20} = op1; 2534 let Inst{15-12} = 0b1111; 2535 let Inst{7-6} = 0b10; 2536 let Inst{5-4} = op2; 2537 let Rn{3-0} = Rm; 2538} 2539 2540def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2541 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>; 2542 2543def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2544 "rbit", "\t$Rd, $Rm", 2545 [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>; 2546 2547def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2548 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>; 2549 2550def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2551 "rev16", ".w\t$Rd, $Rm", 2552 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>; 2553 2554def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr, 2555 "revsh", ".w\t$Rd, $Rm", 2556 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>; 2557 2558def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)), 2559 (and (srl rGPR:$Rm, (i32 8)), 0xFF)), 2560 (t2REVSH rGPR:$Rm)>; 2561 2562def t2PKHBT : T2ThreeReg< 2563 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, i32imm:$sh), 2564 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm, lsl $sh", 2565 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF), 2566 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh), 2567 0xFFFF0000)))]>, 2568 Requires<[HasT2ExtractPack, IsThumb2]> { 2569 let Inst{31-27} = 0b11101; 2570 let Inst{26-25} = 0b01; 2571 let Inst{24-20} = 0b01100; 2572 let Inst{5} = 0; // BT form 2573 let Inst{4} = 0; 2574 2575 bits<5> sh; 2576 let Inst{14-12} = sh{4-2}; 2577 let Inst{7-6} = sh{1-0}; 2578} 2579 2580// Alternate cases for PKHBT where identities eliminate some nodes. 2581def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)), 2582 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>, 2583 Requires<[HasT2ExtractPack, IsThumb2]>; 2584def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)), 2585 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>, 2586 Requires<[HasT2ExtractPack, IsThumb2]>; 2587 2588// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and 2589// will match the pattern below. 2590def t2PKHTB : T2ThreeReg< 2591 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, i32imm:$sh), 2592 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm, asr $sh", 2593 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000), 2594 (and (sra rGPR:$Rm, pkh_asr_amt:$sh), 2595 0xFFFF)))]>, 2596 Requires<[HasT2ExtractPack, IsThumb2]> { 2597 let Inst{31-27} = 0b11101; 2598 let Inst{26-25} = 0b01; 2599 let Inst{24-20} = 0b01100; 2600 let Inst{5} = 1; // TB form 2601 let Inst{4} = 0; 2602 2603 bits<5> sh; 2604 let Inst{14-12} = sh{4-2}; 2605 let Inst{7-6} = sh{1-0}; 2606} 2607 2608// Alternate cases for PKHTB where identities eliminate some nodes. Note that 2609// a shift amount of 0 is *not legal* here, it is PKHBT instead. 2610def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)), 2611 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>, 2612 Requires<[HasT2ExtractPack, IsThumb2]>; 2613def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), 2614 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)), 2615 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>, 2616 Requires<[HasT2ExtractPack, IsThumb2]>; 2617 2618//===----------------------------------------------------------------------===// 2619// Comparison Instructions... 2620// 2621defm t2CMP : T2I_cmp_irs<0b1101, "cmp", 2622 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, 2623 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>; 2624 2625def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_imm:$imm), 2626 (t2CMPri GPR:$lhs, t2_so_imm:$imm)>; 2627def : T2Pat<(ARMcmpZ GPR:$lhs, rGPR:$rhs), 2628 (t2CMPrr GPR:$lhs, rGPR:$rhs)>; 2629def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_reg:$rhs), 2630 (t2CMPrs GPR:$lhs, t2_so_reg:$rhs)>; 2631 2632//FIXME: Disable CMN, as CCodes are backwards from compare expectations 2633// Compare-to-zero still works out, just not the relationals 2634//defm t2CMN : T2I_cmp_irs<0b1000, "cmn", 2635// BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>; 2636defm t2CMNz : T2I_cmp_irs<0b1000, "cmn", 2637 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, 2638 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>; 2639 2640//def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm), 2641// (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>; 2642 2643def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm), 2644 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>; 2645 2646defm t2TST : T2I_cmp_irs<0b0000, "tst", 2647 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi, 2648 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>; 2649defm t2TEQ : T2I_cmp_irs<0b0100, "teq", 2650 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi, 2651 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>; 2652 2653// Conditional moves 2654// FIXME: should be able to write a pattern for ARMcmov, but can't use 2655// a two-value operand where a dag node expects two operands. :( 2656let neverHasSideEffects = 1 in { 2657def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd), 2658 (ins rGPR:$false, rGPR:$Rm, pred:$p), 2659 4, IIC_iCMOVr, 2660 [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>, 2661 RegConstraint<"$false = $Rd">; 2662 2663let isMoveImm = 1 in 2664def t2MOVCCi : t2PseudoInst<(outs rGPR:$Rd), 2665 (ins rGPR:$false, t2_so_imm:$imm, pred:$p), 2666 4, IIC_iCMOVi, 2667[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>, 2668 RegConstraint<"$false = $Rd">; 2669 2670// FIXME: Pseudo-ize these. For now, just mark codegen only. 2671let isCodeGenOnly = 1 in { 2672let isMoveImm = 1 in 2673def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, imm0_65535_expr:$imm), 2674 IIC_iCMOVi, 2675 "movw", "\t$Rd, $imm", []>, 2676 RegConstraint<"$false = $Rd"> { 2677 let Inst{31-27} = 0b11110; 2678 let Inst{25} = 1; 2679 let Inst{24-21} = 0b0010; 2680 let Inst{20} = 0; // The S bit. 2681 let Inst{15} = 0; 2682 2683 bits<4> Rd; 2684 bits<16> imm; 2685 2686 let Inst{11-8} = Rd; 2687 let Inst{19-16} = imm{15-12}; 2688 let Inst{26} = imm{11}; 2689 let Inst{14-12} = imm{10-8}; 2690 let Inst{7-0} = imm{7-0}; 2691} 2692 2693let isMoveImm = 1 in 2694def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst), 2695 (ins rGPR:$false, i32imm:$src, pred:$p), 2696 IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">; 2697 2698let isMoveImm = 1 in 2699def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm), 2700 IIC_iCMOVi, "mvn", ".w\t$Rd, $imm", 2701[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm, 2702 imm:$cc, CCR:$ccr))*/]>, 2703 RegConstraint<"$false = $Rd"> { 2704 let Inst{31-27} = 0b11110; 2705 let Inst{25} = 0; 2706 let Inst{24-21} = 0b0011; 2707 let Inst{20} = 0; // The S bit. 2708 let Inst{19-16} = 0b1111; // Rn 2709 let Inst{15} = 0; 2710} 2711 2712class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin, 2713 string opc, string asm, list<dag> pattern> 2714 : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> { 2715 let Inst{31-27} = 0b11101; 2716 let Inst{26-25} = 0b01; 2717 let Inst{24-21} = 0b0010; 2718 let Inst{20} = 0; // The S bit. 2719 let Inst{19-16} = 0b1111; // Rn 2720 let Inst{5-4} = opcod; // Shift type. 2721} 2722def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd), 2723 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm), 2724 IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>, 2725 RegConstraint<"$false = $Rd">; 2726def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd), 2727 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm), 2728 IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>, 2729 RegConstraint<"$false = $Rd">; 2730def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd), 2731 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm), 2732 IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>, 2733 RegConstraint<"$false = $Rd">; 2734def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd), 2735 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm), 2736 IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>, 2737 RegConstraint<"$false = $Rd">; 2738} // isCodeGenOnly = 1 2739} // neverHasSideEffects 2740 2741//===----------------------------------------------------------------------===// 2742// Atomic operations intrinsics 2743// 2744 2745// memory barriers protect the atomic sequences 2746let hasSideEffects = 1 in { 2747def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary, 2748 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>, 2749 Requires<[IsThumb, HasDB]> { 2750 bits<4> opt; 2751 let Inst{31-4} = 0xf3bf8f5; 2752 let Inst{3-0} = opt; 2753} 2754} 2755 2756def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary, 2757 "dsb", "\t$opt", 2758 [/* For disassembly only; pattern left blank */]>, 2759 Requires<[IsThumb, HasDB]> { 2760 bits<4> opt; 2761 let Inst{31-4} = 0xf3bf8f4; 2762 let Inst{3-0} = opt; 2763} 2764 2765// ISB has only full system option -- for disassembly only 2766def t2ISB : AInoP<(outs), (ins), ThumbFrm, NoItinerary, "isb", "", 2767 [/* For disassembly only; pattern left blank */]>, 2768 Requires<[IsThumb2, HasV7]> { 2769 let Inst{31-4} = 0xf3bf8f6; 2770 let Inst{3-0} = 0b1111; 2771} 2772 2773class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz, 2774 InstrItinClass itin, string opc, string asm, string cstr, 2775 list<dag> pattern, bits<4> rt2 = 0b1111> 2776 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> { 2777 let Inst{31-27} = 0b11101; 2778 let Inst{26-20} = 0b0001101; 2779 let Inst{11-8} = rt2; 2780 let Inst{7-6} = 0b01; 2781 let Inst{5-4} = opcod; 2782 let Inst{3-0} = 0b1111; 2783 2784 bits<4> addr; 2785 bits<4> Rt; 2786 let Inst{19-16} = addr; 2787 let Inst{15-12} = Rt; 2788} 2789class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz, 2790 InstrItinClass itin, string opc, string asm, string cstr, 2791 list<dag> pattern, bits<4> rt2 = 0b1111> 2792 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> { 2793 let Inst{31-27} = 0b11101; 2794 let Inst{26-20} = 0b0001100; 2795 let Inst{11-8} = rt2; 2796 let Inst{7-6} = 0b01; 2797 let Inst{5-4} = opcod; 2798 2799 bits<4> Rd; 2800 bits<4> addr; 2801 bits<4> Rt; 2802 let Inst{3-0} = Rd; 2803 let Inst{19-16} = addr; 2804 let Inst{15-12} = Rt; 2805} 2806 2807let mayLoad = 1 in { 2808def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr), 2809 AddrModeNone, 4, NoItinerary, 2810 "ldrexb", "\t$Rt, $addr", "", []>; 2811def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr), 2812 AddrModeNone, 4, NoItinerary, 2813 "ldrexh", "\t$Rt, $addr", "", []>; 2814def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_reg:$addr), 2815 AddrModeNone, 4, NoItinerary, 2816 "ldrex", "\t$Rt, $addr", "", []> { 2817 let Inst{31-27} = 0b11101; 2818 let Inst{26-20} = 0b0000101; 2819 let Inst{11-8} = 0b1111; 2820 let Inst{7-0} = 0b00000000; // imm8 = 0 2821 2822 bits<4> Rt; 2823 bits<4> addr; 2824 let Inst{19-16} = addr; 2825 let Inst{15-12} = Rt; 2826} 2827let hasExtraDefRegAllocReq = 1 in 2828def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2), 2829 (ins t2addrmode_reg:$addr), 2830 AddrModeNone, 4, NoItinerary, 2831 "ldrexd", "\t$Rt, $Rt2, $addr", "", 2832 [], {?, ?, ?, ?}> { 2833 bits<4> Rt2; 2834 let Inst{11-8} = Rt2; 2835} 2836} 2837 2838let mayStore = 1, Constraints = "@earlyclobber $Rd" in { 2839def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd), 2840 (ins rGPR:$Rt, t2addrmode_reg:$addr), 2841 AddrModeNone, 4, NoItinerary, 2842 "strexb", "\t$Rd, $Rt, $addr", "", []>; 2843def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd), 2844 (ins rGPR:$Rt, t2addrmode_reg:$addr), 2845 AddrModeNone, 4, NoItinerary, 2846 "strexh", "\t$Rd, $Rt, $addr", "", []>; 2847def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt, t2addrmode_reg:$addr), 2848 AddrModeNone, 4, NoItinerary, 2849 "strex", "\t$Rd, $Rt, $addr", "", 2850 []> { 2851 let Inst{31-27} = 0b11101; 2852 let Inst{26-20} = 0b0000100; 2853 let Inst{7-0} = 0b00000000; // imm8 = 0 2854 2855 bits<4> Rd; 2856 bits<4> addr; 2857 bits<4> Rt; 2858 let Inst{11-8} = Rd; 2859 let Inst{19-16} = addr; 2860 let Inst{15-12} = Rt; 2861} 2862} 2863 2864let hasExtraSrcRegAllocReq = 1, Constraints = "@earlyclobber $Rd" in 2865def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd), 2866 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_reg:$addr), 2867 AddrModeNone, 4, NoItinerary, 2868 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [], 2869 {?, ?, ?, ?}> { 2870 bits<4> Rt2; 2871 let Inst{11-8} = Rt2; 2872} 2873 2874// Clear-Exclusive is for disassembly only. 2875def t2CLREX : T2XI<(outs), (ins), NoItinerary, "clrex", 2876 [/* For disassembly only; pattern left blank */]>, 2877 Requires<[IsThumb2, HasV7]> { 2878 let Inst{31-16} = 0xf3bf; 2879 let Inst{15-14} = 0b10; 2880 let Inst{13} = 0; 2881 let Inst{12} = 0; 2882 let Inst{11-8} = 0b1111; 2883 let Inst{7-4} = 0b0010; 2884 let Inst{3-0} = 0b1111; 2885} 2886 2887//===----------------------------------------------------------------------===// 2888// SJLJ Exception handling intrinsics 2889// eh_sjlj_setjmp() is an instruction sequence to store the return 2890// address and save #0 in R0 for the non-longjmp case. 2891// Since by its nature we may be coming from some other function to get 2892// here, and we're using the stack frame for the containing function to 2893// save/restore registers, we can't keep anything live in regs across 2894// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon 2895// when we get here from a longjmp(). We force everything out of registers 2896// except for our own input by listing the relevant registers in Defs. By 2897// doing so, we also cause the prologue/epilogue code to actively preserve 2898// all of the callee-saved resgisters, which is exactly what we want. 2899// $val is a scratch register for our use. 2900let Defs = 2901 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR, 2902 QQQQ0, QQQQ1, QQQQ2, QQQQ3 ], 2903 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in { 2904 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val), 2905 AddrModeNone, 0, NoItinerary, "", "", 2906 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>, 2907 Requires<[IsThumb2, HasVFP2]>; 2908} 2909 2910let Defs = 2911 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ], 2912 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in { 2913 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val), 2914 AddrModeNone, 0, NoItinerary, "", "", 2915 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>, 2916 Requires<[IsThumb2, NoVFP]>; 2917} 2918 2919 2920//===----------------------------------------------------------------------===// 2921// Control-Flow Instructions 2922// 2923 2924// FIXME: remove when we have a way to marking a MI with these properties. 2925// FIXME: Should pc be an implicit operand like PICADD, etc? 2926let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1, 2927 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in 2928def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, 2929 reglist:$regs, variable_ops), 2930 4, IIC_iLoad_mBr, [], 2931 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>, 2932 RegConstraint<"$Rn = $wb">; 2933 2934let isBranch = 1, isTerminator = 1, isBarrier = 1 in { 2935let isPredicable = 1 in 2936def t2B : T2XI<(outs), (ins uncondbrtarget:$target), IIC_Br, 2937 "b.w\t$target", 2938 [(br bb:$target)]> { 2939 let Inst{31-27} = 0b11110; 2940 let Inst{15-14} = 0b10; 2941 let Inst{12} = 1; 2942 2943 bits<20> target; 2944 let Inst{26} = target{19}; 2945 let Inst{11} = target{18}; 2946 let Inst{13} = target{17}; 2947 let Inst{21-16} = target{16-11}; 2948 let Inst{10-0} = target{10-0}; 2949} 2950 2951let isNotDuplicable = 1, isIndirectBranch = 1 in { 2952def t2BR_JT : t2PseudoInst<(outs), 2953 (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id), 2954 0, IIC_Br, 2955 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>; 2956 2957// FIXME: Add a non-pc based case that can be predicated. 2958def t2TBB_JT : t2PseudoInst<(outs), 2959 (ins GPR:$index, i32imm:$jt, i32imm:$id), 2960 0, IIC_Br, []>; 2961 2962def t2TBH_JT : t2PseudoInst<(outs), 2963 (ins GPR:$index, i32imm:$jt, i32imm:$id), 2964 0, IIC_Br, []>; 2965 2966def t2TBB : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br, 2967 "tbb", "\t[$Rn, $Rm]", []> { 2968 bits<4> Rn; 2969 bits<4> Rm; 2970 let Inst{31-20} = 0b111010001101; 2971 let Inst{19-16} = Rn; 2972 let Inst{15-5} = 0b11110000000; 2973 let Inst{4} = 0; // B form 2974 let Inst{3-0} = Rm; 2975} 2976 2977def t2TBH : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br, 2978 "tbh", "\t[$Rn, $Rm, lsl #1]", []> { 2979 bits<4> Rn; 2980 bits<4> Rm; 2981 let Inst{31-20} = 0b111010001101; 2982 let Inst{19-16} = Rn; 2983 let Inst{15-5} = 0b11110000000; 2984 let Inst{4} = 1; // H form 2985 let Inst{3-0} = Rm; 2986} 2987} // isNotDuplicable, isIndirectBranch 2988 2989} // isBranch, isTerminator, isBarrier 2990 2991// FIXME: should be able to write a pattern for ARMBrcond, but can't use 2992// a two-value operand where a dag node expects two operands. :( 2993let isBranch = 1, isTerminator = 1 in 2994def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br, 2995 "b", ".w\t$target", 2996 [/*(ARMbrcond bb:$target, imm:$cc)*/]> { 2997 let Inst{31-27} = 0b11110; 2998 let Inst{15-14} = 0b10; 2999 let Inst{12} = 0; 3000 3001 bits<4> p; 3002 let Inst{25-22} = p; 3003 3004 bits<21> target; 3005 let Inst{26} = target{20}; 3006 let Inst{11} = target{19}; 3007 let Inst{13} = target{18}; 3008 let Inst{21-16} = target{17-12}; 3009 let Inst{10-0} = target{11-1}; 3010 3011 let DecoderMethod = "DecodeThumb2BCCInstruction"; 3012} 3013 3014// Tail calls. The Darwin version of thumb tail calls uses a t2 branch, so 3015// it goes here. 3016let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in { 3017 // Darwin version. 3018 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC], 3019 Uses = [SP] in 3020 def tTAILJMPd: tPseudoExpand<(outs), (ins uncondbrtarget:$dst, variable_ops), 3021 4, IIC_Br, [], 3022 (t2B uncondbrtarget:$dst)>, 3023 Requires<[IsThumb2, IsDarwin]>; 3024} 3025 3026// IT block 3027let Defs = [ITSTATE] in 3028def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask), 3029 AddrModeNone, 2, IIC_iALUx, 3030 "it$mask\t$cc", "", []> { 3031 // 16-bit instruction. 3032 let Inst{31-16} = 0x0000; 3033 let Inst{15-8} = 0b10111111; 3034 3035 bits<4> cc; 3036 bits<4> mask; 3037 let Inst{7-4} = cc; 3038 let Inst{3-0} = mask; 3039} 3040 3041// Branch and Exchange Jazelle -- for disassembly only 3042// Rm = Inst{19-16} 3043def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func", 3044 [/* For disassembly only; pattern left blank */]> { 3045 let Inst{31-27} = 0b11110; 3046 let Inst{26} = 0; 3047 let Inst{25-20} = 0b111100; 3048 let Inst{15-14} = 0b10; 3049 let Inst{12} = 0; 3050 3051 bits<4> func; 3052 let Inst{19-16} = func; 3053} 3054 3055// Change Processor State is a system instruction -- for disassembly and 3056// parsing only. 3057// FIXME: Since the asm parser has currently no clean way to handle optional 3058// operands, create 3 versions of the same instruction. Once there's a clean 3059// framework to represent optional operands, change this behavior. 3060class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary, 3061 !strconcat("cps", asm_op), 3062 [/* For disassembly only; pattern left blank */]> { 3063 bits<2> imod; 3064 bits<3> iflags; 3065 bits<5> mode; 3066 bit M; 3067 3068 let Inst{31-27} = 0b11110; 3069 let Inst{26} = 0; 3070 let Inst{25-20} = 0b111010; 3071 let Inst{19-16} = 0b1111; 3072 let Inst{15-14} = 0b10; 3073 let Inst{12} = 0; 3074 let Inst{10-9} = imod; 3075 let Inst{8} = M; 3076 let Inst{7-5} = iflags; 3077 let Inst{4-0} = mode; 3078} 3079 3080let M = 1 in 3081 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 3082 "$imod.w\t$iflags, $mode">; 3083let mode = 0, M = 0 in 3084 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags), 3085 "$imod.w\t$iflags">; 3086let imod = 0, iflags = 0, M = 1 in 3087 def t2CPS1p : t2CPS<(ins i32imm:$mode), "\t$mode">; 3088 3089// A6.3.4 Branches and miscellaneous control 3090// Table A6-14 Change Processor State, and hint instructions 3091// Helper class for disassembly only. 3092class T2I_hint<bits<8> op7_0, string opc, string asm> 3093 : T2I<(outs), (ins), NoItinerary, opc, asm, 3094 [/* For disassembly only; pattern left blank */]> { 3095 let Inst{31-20} = 0xf3a; 3096 let Inst{19-16} = 0b1111; 3097 let Inst{15-14} = 0b10; 3098 let Inst{12} = 0; 3099 let Inst{10-8} = 0b000; 3100 let Inst{7-0} = op7_0; 3101} 3102 3103def t2NOP : T2I_hint<0b00000000, "nop", ".w">; 3104def t2YIELD : T2I_hint<0b00000001, "yield", ".w">; 3105def t2WFE : T2I_hint<0b00000010, "wfe", ".w">; 3106def t2WFI : T2I_hint<0b00000011, "wfi", ".w">; 3107def t2SEV : T2I_hint<0b00000100, "sev", ".w">; 3108 3109def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt", []> { 3110 let Inst{31-20} = 0xf3a; 3111 let Inst{15-14} = 0b10; 3112 let Inst{12} = 0; 3113 let Inst{10-8} = 0b000; 3114 let Inst{7-4} = 0b1111; 3115 3116 bits<4> opt; 3117 let Inst{3-0} = opt; 3118} 3119 3120// Secure Monitor Call is a system instruction -- for disassembly only 3121// Option = Inst{19-16} 3122def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt", 3123 [/* For disassembly only; pattern left blank */]> { 3124 let Inst{31-27} = 0b11110; 3125 let Inst{26-20} = 0b1111111; 3126 let Inst{15-12} = 0b1000; 3127 3128 bits<4> opt; 3129 let Inst{19-16} = opt; 3130} 3131 3132class T2SRS<bits<12> op31_20, 3133 dag oops, dag iops, InstrItinClass itin, 3134 string opc, string asm, list<dag> pattern> 3135 : T2I<oops, iops, itin, opc, asm, pattern> { 3136 let Inst{31-20} = op31_20{11-0}; 3137 3138 bits<5> mode; 3139 let Inst{4-0} = mode{4-0}; 3140} 3141 3142// Store Return State is a system instruction -- for disassembly only 3143def t2SRSDBW : T2SRS<0b111010000010, 3144 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode", 3145 [/* For disassembly only; pattern left blank */]>; 3146def t2SRSDB : T2SRS<0b111010000000, 3147 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode", 3148 [/* For disassembly only; pattern left blank */]>; 3149def t2SRSIAW : T2SRS<0b111010011010, 3150 (outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode", 3151 [/* For disassembly only; pattern left blank */]>; 3152def t2SRSIA : T2SRS<0b111010011000, 3153 (outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode", 3154 [/* For disassembly only; pattern left blank */]>; 3155 3156// Return From Exception is a system instruction -- for disassembly only 3157 3158class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin, 3159 string opc, string asm, list<dag> pattern> 3160 : T2I<oops, iops, itin, opc, asm, pattern> { 3161 let Inst{31-20} = op31_20{11-0}; 3162 3163 bits<4> Rn; 3164 let Inst{19-16} = Rn; 3165 let Inst{15-0} = 0xc000; 3166} 3167 3168def t2RFEDBW : T2RFE<0b111010000011, 3169 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!", 3170 [/* For disassembly only; pattern left blank */]>; 3171def t2RFEDB : T2RFE<0b111010000001, 3172 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn", 3173 [/* For disassembly only; pattern left blank */]>; 3174def t2RFEIAW : T2RFE<0b111010011011, 3175 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!", 3176 [/* For disassembly only; pattern left blank */]>; 3177def t2RFEIA : T2RFE<0b111010011001, 3178 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn", 3179 [/* For disassembly only; pattern left blank */]>; 3180 3181//===----------------------------------------------------------------------===// 3182// Non-Instruction Patterns 3183// 3184 3185// 32-bit immediate using movw + movt. 3186// This is a single pseudo instruction to make it re-materializable. 3187// FIXME: Remove this when we can do generalized remat. 3188let isReMaterializable = 1, isMoveImm = 1 in 3189def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2, 3190 [(set rGPR:$dst, (i32 imm:$src))]>, 3191 Requires<[IsThumb, HasV6T2]>; 3192 3193// Pseudo instruction that combines movw + movt + add pc (if pic). 3194// It also makes it possible to rematerialize the instructions. 3195// FIXME: Remove this when we can do generalized remat and when machine licm 3196// can properly the instructions. 3197let isReMaterializable = 1 in { 3198def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr), 3199 IIC_iMOVix2addpc, 3200 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>, 3201 Requires<[IsThumb2, UseMovt]>; 3202 3203def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr), 3204 IIC_iMOVix2, 3205 [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>, 3206 Requires<[IsThumb2, UseMovt]>; 3207} 3208 3209// ConstantPool, GlobalAddress, and JumpTable 3210def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>, 3211 Requires<[IsThumb2, DontUseMovt]>; 3212def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>; 3213def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>, 3214 Requires<[IsThumb2, UseMovt]>; 3215 3216def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id), 3217 (t2LEApcrelJT tjumptable:$dst, imm:$id)>; 3218 3219// Pseudo instruction that combines ldr from constpool and add pc. This should 3220// be expanded into two instructions late to allow if-conversion and 3221// scheduling. 3222let canFoldAsLoad = 1, isReMaterializable = 1 in 3223def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp), 3224 IIC_iLoadiALU, 3225 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)), 3226 imm:$cp))]>, 3227 Requires<[IsThumb2]>; 3228 3229//===----------------------------------------------------------------------===// 3230// Move between special register and ARM core register -- for disassembly only 3231// 3232 3233class T2SpecialReg<bits<12> op31_20, bits<2> op15_14, bits<1> op12, 3234 dag oops, dag iops, InstrItinClass itin, 3235 string opc, string asm, list<dag> pattern> 3236 : T2I<oops, iops, itin, opc, asm, pattern> { 3237 let Inst{31-20} = op31_20{11-0}; 3238 let Inst{15-14} = op15_14{1-0}; 3239 let Inst{12} = op12{0}; 3240} 3241 3242class T2MRS<bits<12> op31_20, bits<2> op15_14, bits<1> op12, 3243 dag oops, dag iops, InstrItinClass itin, 3244 string opc, string asm, list<dag> pattern> 3245 : T2SpecialReg<op31_20, op15_14, op12, oops, iops, itin, opc, asm, pattern> { 3246 bits<4> Rd; 3247 let Inst{11-8} = Rd; 3248 let Inst{19-16} = 0b1111; 3249} 3250 3251def t2MRS : T2MRS<0b111100111110, 0b10, 0, 3252 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, cpsr", 3253 [/* For disassembly only; pattern left blank */]>; 3254def t2MRSsys : T2MRS<0b111100111111, 0b10, 0, 3255 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr", 3256 [/* For disassembly only; pattern left blank */]>; 3257 3258// Move from ARM core register to Special Register 3259// 3260// No need to have both system and application versions, the encodings are the 3261// same and the assembly parser has no way to distinguish between them. The mask 3262// operand contains the special register (R Bit) in bit 4 and bits 3-0 contains 3263// the mask with the fields to be accessed in the special register. 3264def t2MSR : T2SpecialReg<0b111100111000 /* op31-20 */, 0b10 /* op15-14 */, 3265 0 /* op12 */, (outs), (ins msr_mask:$mask, rGPR:$Rn), 3266 NoItinerary, "msr", "\t$mask, $Rn", 3267 [/* For disassembly only; pattern left blank */]> { 3268 bits<5> mask; 3269 bits<4> Rn; 3270 let Inst{19-16} = Rn; 3271 let Inst{20} = mask{4}; // R Bit 3272 let Inst{13} = 0b0; 3273 let Inst{11-8} = mask{3-0}; 3274} 3275 3276//===----------------------------------------------------------------------===// 3277// Move between coprocessor and ARM core register 3278// 3279 3280class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops, 3281 list<dag> pattern> 3282 : T2Cop<Op, oops, iops, 3283 !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"), 3284 pattern> { 3285 let Inst{27-24} = 0b1110; 3286 let Inst{20} = direction; 3287 let Inst{4} = 1; 3288 3289 bits<4> Rt; 3290 bits<4> cop; 3291 bits<3> opc1; 3292 bits<3> opc2; 3293 bits<4> CRm; 3294 bits<4> CRn; 3295 3296 let Inst{15-12} = Rt; 3297 let Inst{11-8} = cop; 3298 let Inst{23-21} = opc1; 3299 let Inst{7-5} = opc2; 3300 let Inst{3-0} = CRm; 3301 let Inst{19-16} = CRn; 3302} 3303 3304class t2MovRRCopro<bits<4> Op, string opc, bit direction, 3305 list<dag> pattern = []> 3306 : T2Cop<Op, (outs), 3307 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm), 3308 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> { 3309 let Inst{27-24} = 0b1100; 3310 let Inst{23-21} = 0b010; 3311 let Inst{20} = direction; 3312 3313 bits<4> Rt; 3314 bits<4> Rt2; 3315 bits<4> cop; 3316 bits<4> opc1; 3317 bits<4> CRm; 3318 3319 let Inst{15-12} = Rt; 3320 let Inst{19-16} = Rt2; 3321 let Inst{11-8} = cop; 3322 let Inst{7-4} = opc1; 3323 let Inst{3-0} = CRm; 3324} 3325 3326/* from ARM core register to coprocessor */ 3327def t2MCR : t2MovRCopro<0b1110, "mcr", 0, 3328 (outs), 3329 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn, 3330 c_imm:$CRm, imm0_7:$opc2), 3331 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn, 3332 imm:$CRm, imm:$opc2)]>; 3333def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0, 3334 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn, 3335 c_imm:$CRm, imm0_7:$opc2), 3336 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn, 3337 imm:$CRm, imm:$opc2)]>; 3338 3339/* from coprocessor to ARM core register */ 3340def t2MRC : t2MovRCopro<0b1110, "mrc", 1, 3341 (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, 3342 c_imm:$CRm, imm0_7:$opc2), []>; 3343 3344def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1, 3345 (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, 3346 c_imm:$CRm, imm0_7:$opc2), []>; 3347 3348def : T2v6Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2), 3349 (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>; 3350 3351def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2), 3352 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>; 3353 3354 3355/* from ARM core register to coprocessor */ 3356def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, 3357 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2, 3358 imm:$CRm)]>; 3359def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, 3360 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt, 3361 GPR:$Rt2, imm:$CRm)]>; 3362/* from coprocessor to ARM core register */ 3363def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1>; 3364 3365def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1>; 3366 3367//===----------------------------------------------------------------------===// 3368// Other Coprocessor Instructions. 3369// 3370 3371def tCDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1, 3372 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2), 3373 "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2", 3374 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn, 3375 imm:$CRm, imm:$opc2)]> { 3376 let Inst{27-24} = 0b1110; 3377 3378 bits<4> opc1; 3379 bits<4> CRn; 3380 bits<4> CRd; 3381 bits<4> cop; 3382 bits<3> opc2; 3383 bits<4> CRm; 3384 3385 let Inst{3-0} = CRm; 3386 let Inst{4} = 0; 3387 let Inst{7-5} = opc2; 3388 let Inst{11-8} = cop; 3389 let Inst{15-12} = CRd; 3390 let Inst{19-16} = CRn; 3391 let Inst{23-20} = opc1; 3392} 3393 3394def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1, 3395 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2), 3396 "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2", 3397 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn, 3398 imm:$CRm, imm:$opc2)]> { 3399 let Inst{27-24} = 0b1110; 3400 3401 bits<4> opc1; 3402 bits<4> CRn; 3403 bits<4> CRd; 3404 bits<4> cop; 3405 bits<3> opc2; 3406 bits<4> CRm; 3407 3408 let Inst{3-0} = CRm; 3409 let Inst{4} = 0; 3410 let Inst{7-5} = opc2; 3411 let Inst{11-8} = cop; 3412 let Inst{15-12} = CRd; 3413 let Inst{19-16} = CRn; 3414 let Inst{23-20} = opc1; 3415} 3416 3417 3418 3419//===----------------------------------------------------------------------===// 3420// Non-Instruction Patterns 3421// 3422 3423// SXT/UXT with no rotate 3424let AddedComplexity = 16 in { 3425def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>, 3426 Requires<[IsThumb2]>; 3427def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>, 3428 Requires<[IsThumb2]>; 3429def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>, 3430 Requires<[HasT2ExtractPack, IsThumb2]>; 3431def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)), 3432 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>, 3433 Requires<[HasT2ExtractPack, IsThumb2]>; 3434def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)), 3435 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>, 3436 Requires<[HasT2ExtractPack, IsThumb2]>; 3437} 3438 3439def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>, 3440 Requires<[IsThumb2]>; 3441def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>, 3442 Requires<[IsThumb2]>; 3443def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)), 3444 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>, 3445 Requires<[HasT2ExtractPack, IsThumb2]>; 3446def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)), 3447 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>, 3448 Requires<[HasT2ExtractPack, IsThumb2]>; 3449