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