ARMInstrThumb.td revision 204642
1193323Sed//===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file describes the Thumb instruction set. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed//===----------------------------------------------------------------------===// 15193323Sed// Thumb specific DAG Nodes. 16193323Sed// 17193323Sed 18193323Seddef ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall, 19193323Sed [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>; 20193323Sed 21193323Seddef imm_neg_XFORM : SDNodeXForm<imm, [{ 22193323Sed return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32); 23193323Sed}]>; 24193323Seddef imm_comp_XFORM : SDNodeXForm<imm, [{ 25193323Sed return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32); 26193323Sed}]>; 27193323Sed 28193323Sed 29193323Sed/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7]. 30193323Seddef imm0_7 : PatLeaf<(i32 imm), [{ 31193323Sed return (uint32_t)N->getZExtValue() < 8; 32193323Sed}]>; 33193323Seddef imm0_7_neg : PatLeaf<(i32 imm), [{ 34193323Sed return (uint32_t)-N->getZExtValue() < 8; 35193323Sed}], imm_neg_XFORM>; 36193323Sed 37193323Seddef imm0_255 : PatLeaf<(i32 imm), [{ 38193323Sed return (uint32_t)N->getZExtValue() < 256; 39193323Sed}]>; 40193323Seddef imm0_255_comp : PatLeaf<(i32 imm), [{ 41193323Sed return ~((uint32_t)N->getZExtValue()) < 256; 42193323Sed}]>; 43193323Sed 44193323Seddef imm8_255 : PatLeaf<(i32 imm), [{ 45193323Sed return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256; 46193323Sed}]>; 47193323Seddef imm8_255_neg : PatLeaf<(i32 imm), [{ 48193323Sed unsigned Val = -N->getZExtValue(); 49193323Sed return Val >= 8 && Val < 256; 50193323Sed}], imm_neg_XFORM>; 51193323Sed 52193323Sed// Break imm's up into two pieces: an immediate + a left shift. 53193323Sed// This uses thumb_immshifted to match and thumb_immshifted_val and 54193323Sed// thumb_immshifted_shamt to get the val/shift pieces. 55193323Seddef thumb_immshifted : PatLeaf<(imm), [{ 56193323Sed return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue()); 57193323Sed}]>; 58193323Sed 59193323Seddef thumb_immshifted_val : SDNodeXForm<imm, [{ 60193323Sed unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue()); 61193323Sed return CurDAG->getTargetConstant(V, MVT::i32); 62193323Sed}]>; 63193323Sed 64193323Seddef thumb_immshifted_shamt : SDNodeXForm<imm, [{ 65193323Sed unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue()); 66193323Sed return CurDAG->getTargetConstant(V, MVT::i32); 67193323Sed}]>; 68193323Sed 69199511Srdivacky// Scaled 4 immediate. 70199511Srdivackydef t_imm_s4 : Operand<i32> { 71199511Srdivacky let PrintMethod = "printThumbS4ImmOperand"; 72199511Srdivacky} 73199511Srdivacky 74193323Sed// Define Thumb specific addressing modes. 75193323Sed 76193323Sed// t_addrmode_rr := reg + reg 77193323Sed// 78193323Seddef t_addrmode_rr : Operand<i32>, 79193323Sed ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> { 80193323Sed let PrintMethod = "printThumbAddrModeRROperand"; 81193323Sed let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg); 82193323Sed} 83193323Sed 84193323Sed// t_addrmode_s4 := reg + reg 85193323Sed// reg + imm5 * 4 86193323Sed// 87193323Seddef t_addrmode_s4 : Operand<i32>, 88193323Sed ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> { 89193323Sed let PrintMethod = "printThumbAddrModeS4Operand"; 90193323Sed let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg); 91193323Sed} 92193323Sed 93193323Sed// t_addrmode_s2 := reg + reg 94193323Sed// reg + imm5 * 2 95193323Sed// 96193323Seddef t_addrmode_s2 : Operand<i32>, 97193323Sed ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> { 98193323Sed let PrintMethod = "printThumbAddrModeS2Operand"; 99193323Sed let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg); 100193323Sed} 101193323Sed 102193323Sed// t_addrmode_s1 := reg + reg 103193323Sed// reg + imm5 104193323Sed// 105193323Seddef t_addrmode_s1 : Operand<i32>, 106193323Sed ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> { 107193323Sed let PrintMethod = "printThumbAddrModeS1Operand"; 108193323Sed let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg); 109193323Sed} 110193323Sed 111193323Sed// t_addrmode_sp := sp + imm8 * 4 112193323Sed// 113193323Seddef t_addrmode_sp : Operand<i32>, 114193323Sed ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> { 115193323Sed let PrintMethod = "printThumbAddrModeSPOperand"; 116202375Srdivacky let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm); 117193323Sed} 118193323Sed 119193323Sed//===----------------------------------------------------------------------===// 120193323Sed// Miscellaneous Instructions. 121193323Sed// 122193323Sed 123204642Srdivacky// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE 124204642Srdivacky// from removing one half of the matched pairs. That breaks PEI, which assumes 125204642Srdivacky// these will always be in pairs, and asserts if it finds otherwise. Better way? 126204642Srdivackylet Defs = [SP], Uses = [SP], hasSideEffects = 1 in { 127193323Seddef tADJCALLSTACKUP : 128198090SrdivackyPseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary, 129193323Sed "@ tADJCALLSTACKUP $amt1", 130198090Srdivacky [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb1Only]>; 131193323Sed 132193323Seddef tADJCALLSTACKDOWN : 133198090SrdivackyPseudoInst<(outs), (ins i32imm:$amt), NoItinerary, 134193323Sed "@ tADJCALLSTACKDOWN $amt", 135198090Srdivacky [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb1Only]>; 136193323Sed} 137193323Sed 138204642Srdivackydef tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "", 139204642Srdivacky [/* For disassembly only; pattern left blank */]>, 140204642Srdivacky T1Encoding<0b101111> { 141204642Srdivacky let Inst{9-8} = 0b11; 142204642Srdivacky let Inst{7-0} = 0b00000000; 143204642Srdivacky} 144204642Srdivacky 145204642Srdivackydef tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "", 146204642Srdivacky [/* For disassembly only; pattern left blank */]>, 147204642Srdivacky T1Encoding<0b101111> { 148204642Srdivacky let Inst{9-8} = 0b11; 149204642Srdivacky let Inst{7-0} = 0b00010000; 150204642Srdivacky} 151204642Srdivacky 152204642Srdivackydef tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "", 153204642Srdivacky [/* For disassembly only; pattern left blank */]>, 154204642Srdivacky T1Encoding<0b101111> { 155204642Srdivacky let Inst{9-8} = 0b11; 156204642Srdivacky let Inst{7-0} = 0b00100000; 157204642Srdivacky} 158204642Srdivacky 159204642Srdivackydef tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "", 160204642Srdivacky [/* For disassembly only; pattern left blank */]>, 161204642Srdivacky T1Encoding<0b101111> { 162204642Srdivacky let Inst{9-8} = 0b11; 163204642Srdivacky let Inst{7-0} = 0b00110000; 164204642Srdivacky} 165204642Srdivacky 166204642Srdivackydef tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "", 167204642Srdivacky [/* For disassembly only; pattern left blank */]>, 168204642Srdivacky T1Encoding<0b101111> { 169204642Srdivacky let Inst{9-8} = 0b11; 170204642Srdivacky let Inst{7-0} = 0b01000000; 171204642Srdivacky} 172204642Srdivacky 173204642Srdivackydef tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe", 174204642Srdivacky [/* For disassembly only; pattern left blank */]>, 175204642Srdivacky T1Encoding<0b101101> { 176204642Srdivacky let Inst{9-5} = 0b10010; 177204642Srdivacky let Inst{3} = 1; 178204642Srdivacky} 179204642Srdivacky 180204642Srdivackydef tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle", 181204642Srdivacky [/* For disassembly only; pattern left blank */]>, 182204642Srdivacky T1Encoding<0b101101> { 183204642Srdivacky let Inst{9-5} = 0b10010; 184204642Srdivacky let Inst{3} = 0; 185204642Srdivacky} 186204642Srdivacky 187203954Srdivacky// The i32imm operand $val can be used by a debugger to store more information 188203954Srdivacky// about the breakpoint. 189203954Srdivackydef tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val", 190203954Srdivacky [/* For disassembly only; pattern left blank */]>, 191203954Srdivacky T1Encoding<0b101111> { 192203954Srdivacky let Inst{9-8} = 0b10; 193203954Srdivacky} 194203954Srdivacky 195204642Srdivacky// Change Processor State is a system instruction -- for disassembly only. 196204642Srdivacky// The singleton $opt operand contains the following information: 197204642Srdivacky// opt{4-0} = mode ==> don't care 198204642Srdivacky// opt{5} = changemode ==> 0 (false for 16-bit Thumb instr) 199204642Srdivacky// opt{8-6} = AIF from Inst{2-0} 200204642Srdivacky// opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable 201204642Srdivacky// 202204642Srdivacky// The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM 203204642Srdivacky// CPS which has more options. 204204642Srdivackydef tCPS : T1I<(outs), (ins i32imm:$opt), NoItinerary, "cps${opt:cps}", 205204642Srdivacky [/* For disassembly only; pattern left blank */]>, 206204642Srdivacky T1Misc<0b0110011>; 207204642Srdivacky 208198090Srdivacky// For both thumb1 and thumb2. 209193323Sedlet isNotDuplicable = 1 in 210198090Srdivackydef tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, 211198892Srdivacky "\n$cp:\n\tadd\t$dst, pc", 212201360Srdivacky [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>, 213201360Srdivacky T1Special<{0,0,?,?}> { 214201360Srdivacky let Inst{6-3} = 0b1111; // A8.6.6 Rm = pc 215201360Srdivacky} 216193323Sed 217195098Sed// PC relative add. 218199511Srdivackydef tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi, 219201360Srdivacky "add\t$dst, pc, $rhs", []>, 220201360Srdivacky T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10 221195098Sed 222195098Sed// ADD rd, sp, #imm8 223199511Srdivackydef tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi, 224201360Srdivacky "add\t$dst, $sp, $rhs", []>, 225201360Srdivacky T1Encoding<{1,0,1,0,1,?}>; // A6.2 & A8.6.8 226195098Sed 227195098Sed// ADD sp, sp, #imm7 228199511Srdivackydef tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi, 229201360Srdivacky "add\t$dst, $rhs", []>, 230201360Srdivacky T1Misc<{0,0,0,0,0,?,?}>; // A6.2.5 & A8.6.8 231195098Sed 232198090Srdivacky// SUB sp, sp, #imm7 233199511Srdivackydef tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi, 234201360Srdivacky "sub\t$dst, $rhs", []>, 235201360Srdivacky T1Misc<{0,0,0,0,1,?,?}>; // A6.2.5 & A8.6.215 236198090Srdivacky 237198090Srdivacky// ADD rm, sp 238198090Srdivackydef tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr, 239201360Srdivacky "add\t$dst, $rhs", []>, 240201360Srdivacky T1Special<{0,0,?,?}> { 241201360Srdivacky let Inst{6-3} = 0b1101; // A8.6.9 Encoding T1 242201360Srdivacky} 243198090Srdivacky 244195098Sed// ADD sp, rm 245198090Srdivackydef tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr, 246201360Srdivacky "add\t$dst, $rhs", []>, 247201360Srdivacky T1Special<{0,0,?,?}> { 248201360Srdivacky // A8.6.9 Encoding T2 249201360Srdivacky let Inst{7} = 1; 250201360Srdivacky let Inst{2-0} = 0b101; 251201360Srdivacky} 252195098Sed 253198090Srdivacky// Pseudo instruction that will expand into a tSUBspi + a copy. 254198892Srdivackylet usesCustomInserter = 1 in { // Expanded after instruction selection. 255199511Srdivackydef tSUBspi_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), 256199511Srdivacky NoItinerary, "@ sub\t$dst, $rhs", []>; 257198090Srdivacky 258198090Srdivackydef tADDspr_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), 259198892Srdivacky NoItinerary, "@ add\t$dst, $rhs", []>; 260198090Srdivacky 261198090Srdivackylet Defs = [CPSR] in 262198090Srdivackydef tANDsp : PseudoInst<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), 263198892Srdivacky NoItinerary, "@ and\t$dst, $rhs", []>; 264198892Srdivacky} // usesCustomInserter 265198090Srdivacky 266193323Sed//===----------------------------------------------------------------------===// 267193323Sed// Control Flow Instructions. 268193323Sed// 269193323Sed 270198090Srdivackylet isReturn = 1, isTerminator = 1, isBarrier = 1 in { 271201360Srdivacky def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr", [(ARMretflag)]>, 272201360Srdivacky T1Special<{1,1,0,?}> { // A6.2.3 & A8.6.25 273201360Srdivacky let Inst{6-3} = 0b1110; // Rm = lr 274201360Srdivacky } 275193323Sed // Alternative return instruction used by vararg functions. 276204642Srdivacky def tBX_RET_vararg : TI<(outs), (ins tGPR:$target), IIC_Br, "bx\t$target",[]>, 277201360Srdivacky T1Special<{1,1,0,?}>; // A6.2.3 & A8.6.25 278193323Sed} 279193323Sed 280198892Srdivacky// Indirect branches 281198892Srdivackylet isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in { 282198892Srdivacky def tBRIND : TI<(outs), (ins GPR:$dst), IIC_Br, "mov\tpc, $dst", 283201360Srdivacky [(brind GPR:$dst)]>, 284202878Srdivacky T1Special<{1,0,1,?}> { 285202375Srdivacky // <Rd> = Inst{7:2-0} = pc 286201360Srdivacky let Inst{2-0} = 0b111; 287201360Srdivacky } 288198892Srdivacky} 289198892Srdivacky 290193323Sed// FIXME: remove when we have a way to marking a MI with these properties. 291198090Srdivackylet isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1, 292198090Srdivacky hasExtraDefRegAllocReq = 1 in 293198090Srdivackydef tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br, 294201360Srdivacky "pop${p}\t$wb", []>, 295201360Srdivacky T1Misc<{1,1,0,?,?,?,?}>; 296193323Sed 297193323Sedlet isCall = 1, 298198090Srdivacky Defs = [R0, R1, R2, R3, R12, LR, 299198090Srdivacky D0, D1, D2, D3, D4, D5, D6, D7, 300198090Srdivacky D16, D17, D18, D19, D20, D21, D22, D23, 301198090Srdivacky D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in { 302198090Srdivacky // Also used for Thumb2 303201360Srdivacky def tBL : TIx2<0b11110, 0b11, 1, 304204642Srdivacky (outs), (ins i32imm:$func, variable_ops), IIC_Br, 305201360Srdivacky "bl\t${func:call}", 306201360Srdivacky [(ARMtcall tglobaladdr:$func)]>, 307198090Srdivacky Requires<[IsThumb, IsNotDarwin]>; 308198090Srdivacky 309198090Srdivacky // ARMv5T and above, also used for Thumb2 310201360Srdivacky def tBLXi : TIx2<0b11110, 0b11, 0, 311204642Srdivacky (outs), (ins i32imm:$func, variable_ops), IIC_Br, 312201360Srdivacky "blx\t${func:call}", 313201360Srdivacky [(ARMcall tglobaladdr:$func)]>, 314198090Srdivacky Requires<[IsThumb, HasV5T, IsNotDarwin]>; 315198090Srdivacky 316198090Srdivacky // Also used for Thumb2 317204642Srdivacky def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br, 318198892Srdivacky "blx\t$func", 319198090Srdivacky [(ARMtcall GPR:$func)]>, 320201360Srdivacky Requires<[IsThumb, HasV5T, IsNotDarwin]>, 321201360Srdivacky T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24; 322198090Srdivacky 323193323Sed // ARMv4T 324201360Srdivacky def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?, 325204642Srdivacky (outs), (ins tGPR:$func, variable_ops), IIC_Br, 326198892Srdivacky "mov\tlr, pc\n\tbx\t$func", 327198090Srdivacky [(ARMcall_nolink tGPR:$func)]>, 328198090Srdivacky Requires<[IsThumb1Only, IsNotDarwin]>; 329193323Sed} 330193323Sed 331198090Srdivacky// On Darwin R9 is call-clobbered. 332198090Srdivackylet isCall = 1, 333198090Srdivacky Defs = [R0, R1, R2, R3, R9, R12, LR, 334198090Srdivacky D0, D1, D2, D3, D4, D5, D6, D7, 335198090Srdivacky D16, D17, D18, D19, D20, D21, D22, D23, 336198090Srdivacky D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in { 337198090Srdivacky // Also used for Thumb2 338201360Srdivacky def tBLr9 : TIx2<0b11110, 0b11, 1, 339204642Srdivacky (outs), (ins i32imm:$func, variable_ops), IIC_Br, 340198892Srdivacky "bl\t${func:call}", 341198090Srdivacky [(ARMtcall tglobaladdr:$func)]>, 342198090Srdivacky Requires<[IsThumb, IsDarwin]>; 343198090Srdivacky 344198090Srdivacky // ARMv5T and above, also used for Thumb2 345201360Srdivacky def tBLXi_r9 : TIx2<0b11110, 0b11, 0, 346204642Srdivacky (outs), (ins i32imm:$func, variable_ops), IIC_Br, 347198892Srdivacky "blx\t${func:call}", 348198090Srdivacky [(ARMcall tglobaladdr:$func)]>, 349198090Srdivacky Requires<[IsThumb, HasV5T, IsDarwin]>; 350198090Srdivacky 351198090Srdivacky // Also used for Thumb2 352204642Srdivacky def tBLXr_r9 : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br, 353201360Srdivacky "blx\t$func", 354201360Srdivacky [(ARMtcall GPR:$func)]>, 355201360Srdivacky Requires<[IsThumb, HasV5T, IsDarwin]>, 356201360Srdivacky T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24 357198090Srdivacky 358198090Srdivacky // ARMv4T 359201360Srdivacky def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?, 360204642Srdivacky (outs), (ins tGPR:$func, variable_ops), IIC_Br, 361201360Srdivacky "mov\tlr, pc\n\tbx\t$func", 362201360Srdivacky [(ARMcall_nolink tGPR:$func)]>, 363198090Srdivacky Requires<[IsThumb1Only, IsDarwin]>; 364198090Srdivacky} 365198090Srdivacky 366193323Sedlet isBranch = 1, isTerminator = 1 in { 367193323Sed let isBarrier = 1 in { 368193323Sed let isPredicable = 1 in 369198090Srdivacky def tB : T1I<(outs), (ins brtarget:$target), IIC_Br, 370201360Srdivacky "b\t$target", [(br bb:$target)]>, 371201360Srdivacky T1Encoding<{1,1,1,0,0,?}>; 372193323Sed 373193323Sed // Far jump 374198090Srdivacky let Defs = [LR] in 375204642Srdivacky def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br, 376198892Srdivacky "bl\t$target\t@ far jump",[]>; 377193323Sed 378195340Sed def tBR_JTr : T1JTI<(outs), 379195340Sed (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id), 380198892Srdivacky IIC_Br, "mov\tpc, $target\n\t.align\t2\n$jt", 381201360Srdivacky [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>, 382201360Srdivacky Encoding16 { 383201360Srdivacky let Inst{15-7} = 0b010001101; 384201360Srdivacky let Inst{2-0} = 0b111; 385193323Sed } 386201360Srdivacky } 387193323Sed} 388193323Sed 389193323Sed// FIXME: should be able to write a pattern for ARMBrcond, but can't use 390193323Sed// a two-value operand where a dag node expects two operands. :( 391193323Sedlet isBranch = 1, isTerminator = 1 in 392198090Srdivacky def tBcc : T1I<(outs), (ins brtarget:$target, pred:$cc), IIC_Br, 393198892Srdivacky "b$cc\t$target", 394201360Srdivacky [/*(ARMbrcond bb:$target, imm:$cc)*/]>, 395201360Srdivacky T1Encoding<{1,1,0,1,?,?}>; 396193323Sed 397198892Srdivacky// Compare and branch on zero / non-zero 398198892Srdivackylet isBranch = 1, isTerminator = 1 in { 399198892Srdivacky def tCBZ : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br, 400201360Srdivacky "cbz\t$cmp, $target", []>, 401201360Srdivacky T1Misc<{0,0,?,1,?,?,?}>; 402198892Srdivacky 403198892Srdivacky def tCBNZ : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br, 404201360Srdivacky "cbnz\t$cmp, $target", []>, 405201360Srdivacky T1Misc<{1,0,?,1,?,?,?}>; 406198892Srdivacky} 407198892Srdivacky 408204642Srdivacky// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only 409204642Srdivacky// A8.6.16 B: Encoding T1 410204642Srdivacky// If Inst{11-8} == 0b1111 then SEE SVC 411204642Srdivackylet isCall = 1 in { 412204642Srdivackydef tSVC : T1pI<(outs), (ins i32imm:$svc), IIC_Br, "svc", "\t$svc", []>, 413204642Srdivacky Encoding16 { 414204642Srdivacky let Inst{15-12} = 0b1101; 415204642Srdivacky let Inst{11-8} = 0b1111; 416204642Srdivacky} 417204642Srdivacky} 418204642Srdivacky 419204642Srdivacky// A8.6.16 B: Encoding T1 -- for disassembly only 420204642Srdivacky// If Inst{11-8} == 0b1110 then UNDEFINED 421204642Srdivackydef tTRAP : T1I<(outs), (ins), IIC_Br, "trap", []>, Encoding16 { 422204642Srdivacky let Inst{15-12} = 0b1101; 423204642Srdivacky let Inst{11-8} = 0b1110; 424204642Srdivacky} 425204642Srdivacky 426193323Sed//===----------------------------------------------------------------------===// 427193323Sed// Load Store Instructions. 428193323Sed// 429193323Sed 430204642Srdivackylet canFoldAsLoad = 1, isReMaterializable = 1 in 431204642Srdivackydef tLDR : T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr, 432198892Srdivacky "ldr", "\t$dst, $addr", 433201360Srdivacky [(set tGPR:$dst, (load t_addrmode_s4:$addr))]>, 434201360Srdivacky T1LdSt<0b100>; 435204642Srdivackydef tLDRi: T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr, 436202375Srdivacky "ldr", "\t$dst, $addr", 437202375Srdivacky []>, 438202375Srdivacky T1LdSt4Imm<{1,?,?}>; 439193323Sed 440198090Srdivackydef tLDRB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr, 441198892Srdivacky "ldrb", "\t$dst, $addr", 442201360Srdivacky [(set tGPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>, 443201360Srdivacky T1LdSt<0b110>; 444202375Srdivackydef tLDRBi: T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr, 445202375Srdivacky "ldrb", "\t$dst, $addr", 446202375Srdivacky []>, 447202375Srdivacky T1LdSt1Imm<{1,?,?}>; 448193323Sed 449198090Srdivackydef tLDRH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr, 450198892Srdivacky "ldrh", "\t$dst, $addr", 451201360Srdivacky [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>, 452201360Srdivacky T1LdSt<0b101>; 453202375Srdivackydef tLDRHi: T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr, 454202375Srdivacky "ldrh", "\t$dst, $addr", 455202375Srdivacky []>, 456202375Srdivacky T1LdSt2Imm<{1,?,?}>; 457193323Sed 458198090Srdivackylet AddedComplexity = 10 in 459198090Srdivackydef tLDRSB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr, 460198892Srdivacky "ldrsb", "\t$dst, $addr", 461201360Srdivacky [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>, 462201360Srdivacky T1LdSt<0b011>; 463193323Sed 464198090Srdivackylet AddedComplexity = 10 in 465198090Srdivackydef tLDRSH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr, 466198892Srdivacky "ldrsh", "\t$dst, $addr", 467201360Srdivacky [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>, 468201360Srdivacky T1LdSt<0b111>; 469193323Sed 470193323Sedlet canFoldAsLoad = 1 in 471198090Srdivackydef tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi, 472198892Srdivacky "ldr", "\t$dst, $addr", 473201360Srdivacky [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>, 474201360Srdivacky T1LdStSP<{1,?,?}>; 475193323Sed 476193323Sed// Special instruction for restore. It cannot clobber condition register 477193323Sed// when it's expanded by eliminateCallFramePseudoInstr(). 478193323Sedlet canFoldAsLoad = 1, mayLoad = 1 in 479198090Srdivackydef tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi, 480201360Srdivacky "ldr", "\t$dst, $addr", []>, 481201360Srdivacky T1LdStSP<{1,?,?}>; 482193323Sed 483193323Sed// Load tconstpool 484198892Srdivacky// FIXME: Use ldr.n to work around a Darwin assembler bug. 485204642Srdivackylet canFoldAsLoad = 1, isReMaterializable = 1 in 486198090Srdivackydef tLDRpci : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi, 487198892Srdivacky "ldr", ".n\t$dst, $addr", 488201360Srdivacky [(set tGPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>, 489201360Srdivacky T1Encoding<{0,1,0,0,1,?}>; // A6.2 & A8.6.59 490193323Sed 491193323Sed// Special LDR for loads from non-pc-relative constpools. 492204642Srdivackylet canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in 493198090Srdivackydef tLDRcp : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi, 494201360Srdivacky "ldr", "\t$dst, $addr", []>, 495201360Srdivacky T1LdStSP<{1,?,?}>; 496193323Sed 497198090Srdivackydef tSTR : T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer, 498198892Srdivacky "str", "\t$src, $addr", 499201360Srdivacky [(store tGPR:$src, t_addrmode_s4:$addr)]>, 500201360Srdivacky T1LdSt<0b000>; 501202375Srdivackydef tSTRi: T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer, 502202375Srdivacky "str", "\t$src, $addr", 503202375Srdivacky []>, 504202375Srdivacky T1LdSt4Imm<{0,?,?}>; 505193323Sed 506198090Srdivackydef tSTRB : T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer, 507198892Srdivacky "strb", "\t$src, $addr", 508201360Srdivacky [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>, 509201360Srdivacky T1LdSt<0b010>; 510202375Srdivackydef tSTRBi: T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer, 511202375Srdivacky "strb", "\t$src, $addr", 512202375Srdivacky []>, 513202375Srdivacky T1LdSt1Imm<{0,?,?}>; 514193323Sed 515198090Srdivackydef tSTRH : T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer, 516198892Srdivacky "strh", "\t$src, $addr", 517201360Srdivacky [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>, 518201360Srdivacky T1LdSt<0b001>; 519202375Srdivackydef tSTRHi: T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer, 520202375Srdivacky "strh", "\t$src, $addr", 521202375Srdivacky []>, 522202375Srdivacky T1LdSt2Imm<{0,?,?}>; 523193323Sed 524198090Srdivackydef tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei, 525198892Srdivacky "str", "\t$src, $addr", 526201360Srdivacky [(store tGPR:$src, t_addrmode_sp:$addr)]>, 527201360Srdivacky T1LdStSP<{0,?,?}>; 528193323Sed 529193323Sedlet mayStore = 1 in { 530193323Sed// Special instruction for spill. It cannot clobber condition register 531193323Sed// when it's expanded by eliminateCallFramePseudoInstr(). 532198090Srdivackydef tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei, 533201360Srdivacky "str", "\t$src, $addr", []>, 534201360Srdivacky T1LdStSP<{0,?,?}>; 535193323Sed} 536193323Sed 537193323Sed//===----------------------------------------------------------------------===// 538193323Sed// Load / store multiple Instructions. 539193323Sed// 540193323Sed 541198090Srdivacky// These requires base address to be written back or one of the loaded regs. 542198090Srdivackylet mayLoad = 1, hasExtraDefRegAllocReq = 1 in 543198090Srdivackydef tLDM : T1I<(outs), 544198090Srdivacky (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops), 545198090Srdivacky IIC_iLoadm, 546201360Srdivacky "ldm${addr:submode}${p}\t$addr, $wb", []>, 547201360Srdivacky T1Encoding<{1,1,0,0,1,?}>; // A6.2 & A8.6.53 548193323Sed 549198090Srdivackylet mayStore = 1, hasExtraSrcRegAllocReq = 1 in 550198090Srdivackydef tSTM : T1I<(outs), 551198090Srdivacky (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops), 552198090Srdivacky IIC_iStorem, 553201360Srdivacky "stm${addr:submode}${p}\t$addr, $wb", []>, 554201360Srdivacky T1Encoding<{1,1,0,0,0,?}>; // A6.2 & A8.6.189 555193323Sed 556198090Srdivackylet mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in 557198090Srdivackydef tPOP : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br, 558201360Srdivacky "pop${p}\t$wb", []>, 559201360Srdivacky T1Misc<{1,1,0,?,?,?,?}>; 560193323Sed 561198090Srdivackylet mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in 562198090Srdivackydef tPUSH : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br, 563201360Srdivacky "push${p}\t$wb", []>, 564201360Srdivacky T1Misc<{0,1,0,?,?,?,?}>; 565198090Srdivacky 566193323Sed//===----------------------------------------------------------------------===// 567193323Sed// Arithmetic Instructions. 568193323Sed// 569193323Sed 570195098Sed// Add with carry register 571198090Srdivackylet isCommutable = 1, Uses = [CPSR] in 572198090Srdivackydef tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 573198892Srdivacky "adc", "\t$dst, $rhs", 574201360Srdivacky [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>, 575201360Srdivacky T1DataProcessing<0b0101>; 576193323Sed 577195098Sed// Add immediate 578198090Srdivackydef tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi, 579198892Srdivacky "add", "\t$dst, $lhs, $rhs", 580201360Srdivacky [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>, 581201360Srdivacky T1General<0b01110>; 582193323Sed 583198090Srdivackydef tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi, 584198892Srdivacky "add", "\t$dst, $rhs", 585201360Srdivacky [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>, 586201360Srdivacky T1General<{1,1,0,?,?}>; 587193323Sed 588195098Sed// Add register 589198090Srdivackylet isCommutable = 1 in 590198090Srdivackydef tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 591198892Srdivacky "add", "\t$dst, $lhs, $rhs", 592201360Srdivacky [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>, 593201360Srdivacky T1General<0b01100>; 594193323Sed 595194178Sedlet neverHasSideEffects = 1 in 596198090Srdivackydef tADDhirr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr, 597201360Srdivacky "add", "\t$dst, $rhs", []>, 598201360Srdivacky T1Special<{0,0,?,?}>; 599193323Sed 600195098Sed// And register 601198090Srdivackylet isCommutable = 1 in 602198090Srdivackydef tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 603198892Srdivacky "and", "\t$dst, $rhs", 604201360Srdivacky [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>, 605201360Srdivacky T1DataProcessing<0b0000>; 606193323Sed 607195098Sed// ASR immediate 608198090Srdivackydef tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi, 609198892Srdivacky "asr", "\t$dst, $lhs, $rhs", 610201360Srdivacky [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>, 611201360Srdivacky T1General<{0,1,0,?,?}>; 612193323Sed 613195098Sed// ASR register 614198090Srdivackydef tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr, 615198892Srdivacky "asr", "\t$dst, $rhs", 616201360Srdivacky [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>, 617201360Srdivacky T1DataProcessing<0b0100>; 618193323Sed 619195098Sed// BIC register 620198090Srdivackydef tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 621198892Srdivacky "bic", "\t$dst, $rhs", 622201360Srdivacky [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>, 623201360Srdivacky T1DataProcessing<0b1110>; 624193323Sed 625195098Sed// CMN register 626195098Sedlet Defs = [CPSR] in { 627202878Srdivacky//FIXME: Disable CMN, as CCodes are backwards from compare expectations 628202878Srdivacky// Compare-to-zero still works out, just not the relationals 629202878Srdivacky//def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr, 630202878Srdivacky// "cmn", "\t$lhs, $rhs", 631202878Srdivacky// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>, 632202878Srdivacky// T1DataProcessing<0b1011>; 633201360Srdivackydef tCMNz : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr, 634198892Srdivacky "cmn", "\t$lhs, $rhs", 635201360Srdivacky [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>, 636201360Srdivacky T1DataProcessing<0b1011>; 637195098Sed} 638193323Sed 639195098Sed// CMP immediate 640195098Sedlet Defs = [CPSR] in { 641198090Srdivackydef tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi, 642198892Srdivacky "cmp", "\t$lhs, $rhs", 643201360Srdivacky [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>, 644201360Srdivacky T1General<{1,0,1,?,?}>; 645198090Srdivackydef tCMPzi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi, 646198892Srdivacky "cmp", "\t$lhs, $rhs", 647201360Srdivacky [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>, 648201360Srdivacky T1General<{1,0,1,?,?}>; 649195098Sed} 650195098Sed 651195098Sed// CMP register 652195098Sedlet Defs = [CPSR] in { 653198090Srdivackydef tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr, 654198892Srdivacky "cmp", "\t$lhs, $rhs", 655201360Srdivacky [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>, 656201360Srdivacky T1DataProcessing<0b1010>; 657198090Srdivackydef tCMPzr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr, 658198892Srdivacky "cmp", "\t$lhs, $rhs", 659201360Srdivacky [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>, 660201360Srdivacky T1DataProcessing<0b1010>; 661198090Srdivacky 662198090Srdivackydef tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr, 663201360Srdivacky "cmp", "\t$lhs, $rhs", []>, 664201360Srdivacky T1Special<{0,1,?,?}>; 665198090Srdivackydef tCMPzhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr, 666201360Srdivacky "cmp", "\t$lhs, $rhs", []>, 667201360Srdivacky T1Special<{0,1,?,?}>; 668195098Sed} 669193323Sed 670193323Sed 671195098Sed// XOR register 672198090Srdivackylet isCommutable = 1 in 673198090Srdivackydef tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 674198892Srdivacky "eor", "\t$dst, $rhs", 675201360Srdivacky [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>, 676201360Srdivacky T1DataProcessing<0b0001>; 677193323Sed 678195098Sed// LSL immediate 679198090Srdivackydef tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi, 680198892Srdivacky "lsl", "\t$dst, $lhs, $rhs", 681201360Srdivacky [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>, 682201360Srdivacky T1General<{0,0,0,?,?}>; 683193323Sed 684195098Sed// LSL register 685198090Srdivackydef tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr, 686198892Srdivacky "lsl", "\t$dst, $rhs", 687201360Srdivacky [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>, 688201360Srdivacky T1DataProcessing<0b0010>; 689193323Sed 690195098Sed// LSR immediate 691198090Srdivackydef tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi, 692198892Srdivacky "lsr", "\t$dst, $lhs, $rhs", 693201360Srdivacky [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>, 694201360Srdivacky T1General<{0,0,1,?,?}>; 695193323Sed 696195098Sed// LSR register 697198090Srdivackydef tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr, 698198892Srdivacky "lsr", "\t$dst, $rhs", 699201360Srdivacky [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>, 700201360Srdivacky T1DataProcessing<0b0011>; 701193323Sed 702195098Sed// move register 703198090Srdivackydef tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iMOVi, 704198892Srdivacky "mov", "\t$dst, $src", 705201360Srdivacky [(set tGPR:$dst, imm0_255:$src)]>, 706201360Srdivacky T1General<{1,0,0,?,?}>; 707193323Sed 708193323Sed// TODO: A7-73: MOV(2) - mov setting flag. 709193323Sed 710193323Sed 711194178Sedlet neverHasSideEffects = 1 in { 712198090Srdivacky// FIXME: Make this predicable. 713198090Srdivackydef tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr, 714201360Srdivacky "mov\t$dst, $src", []>, 715201360Srdivacky T1Special<0b1000>; 716198090Srdivackylet Defs = [CPSR] in 717198090Srdivackydef tMOVSr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr, 718201360Srdivacky "movs\t$dst, $src", []>, Encoding16 { 719201360Srdivacky let Inst{15-6} = 0b0000000000; 720201360Srdivacky} 721198090Srdivacky 722198090Srdivacky// FIXME: Make these predicable. 723198090Srdivackydef tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iMOVr, 724201360Srdivacky "mov\t$dst, $src", []>, 725202878Srdivacky T1Special<{1,0,0,?}>; 726198090Srdivackydef tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iMOVr, 727201360Srdivacky "mov\t$dst, $src", []>, 728202878Srdivacky T1Special<{1,0,?,0}>; 729198090Srdivackydef tMOVgpr2gpr : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr, 730201360Srdivacky "mov\t$dst, $src", []>, 731202878Srdivacky T1Special<{1,0,?,?}>; 732194178Sed} // neverHasSideEffects 733193323Sed 734195098Sed// multiply register 735198090Srdivackylet isCommutable = 1 in 736198090Srdivackydef tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMUL32, 737198892Srdivacky "mul", "\t$dst, $rhs", 738201360Srdivacky [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>, 739201360Srdivacky T1DataProcessing<0b1101>; 740193323Sed 741195098Sed// move inverse register 742198090Srdivackydef tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr, 743198892Srdivacky "mvn", "\t$dst, $src", 744201360Srdivacky [(set tGPR:$dst, (not tGPR:$src))]>, 745201360Srdivacky T1DataProcessing<0b1111>; 746193323Sed 747195098Sed// bitwise or register 748198090Srdivackylet isCommutable = 1 in 749198090Srdivackydef tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 750198892Srdivacky "orr", "\t$dst, $rhs", 751201360Srdivacky [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>, 752201360Srdivacky T1DataProcessing<0b1100>; 753193323Sed 754195098Sed// swaps 755198090Srdivackydef tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 756198892Srdivacky "rev", "\t$dst, $src", 757198090Srdivacky [(set tGPR:$dst, (bswap tGPR:$src))]>, 758201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 759201360Srdivacky T1Misc<{1,0,1,0,0,0,?}>; 760193323Sed 761198090Srdivackydef tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 762198892Srdivacky "rev16", "\t$dst, $src", 763198090Srdivacky [(set tGPR:$dst, 764198090Srdivacky (or (and (srl tGPR:$src, (i32 8)), 0xFF), 765198090Srdivacky (or (and (shl tGPR:$src, (i32 8)), 0xFF00), 766198090Srdivacky (or (and (srl tGPR:$src, (i32 8)), 0xFF0000), 767198090Srdivacky (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>, 768201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 769201360Srdivacky T1Misc<{1,0,1,0,0,1,?}>; 770193323Sed 771198090Srdivackydef tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 772198892Srdivacky "revsh", "\t$dst, $src", 773198090Srdivacky [(set tGPR:$dst, 774198090Srdivacky (sext_inreg 775198090Srdivacky (or (srl (and tGPR:$src, 0xFF00), (i32 8)), 776198090Srdivacky (shl tGPR:$src, (i32 8))), i16))]>, 777201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 778201360Srdivacky T1Misc<{1,0,1,0,1,1,?}>; 779193323Sed 780195098Sed// rotate right register 781198090Srdivackydef tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr, 782198892Srdivacky "ror", "\t$dst, $rhs", 783201360Srdivacky [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>, 784201360Srdivacky T1DataProcessing<0b0111>; 785193323Sed 786198090Srdivacky// negate register 787198090Srdivackydef tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALUi, 788198892Srdivacky "rsb", "\t$dst, $src, #0", 789201360Srdivacky [(set tGPR:$dst, (ineg tGPR:$src))]>, 790201360Srdivacky T1DataProcessing<0b1001>; 791198090Srdivacky 792195098Sed// Subtract with carry register 793198090Srdivackylet Uses = [CPSR] in 794198090Srdivackydef tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 795198892Srdivacky "sbc", "\t$dst, $rhs", 796201360Srdivacky [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>, 797201360Srdivacky T1DataProcessing<0b0110>; 798193323Sed 799195098Sed// Subtract immediate 800198090Srdivackydef tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi, 801198892Srdivacky "sub", "\t$dst, $lhs, $rhs", 802201360Srdivacky [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>, 803201360Srdivacky T1General<0b01111>; 804193323Sed 805198090Srdivackydef tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi, 806198892Srdivacky "sub", "\t$dst, $rhs", 807201360Srdivacky [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>, 808201360Srdivacky T1General<{1,1,1,?,?}>; 809193323Sed 810195098Sed// subtract register 811198090Srdivackydef tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr, 812198892Srdivacky "sub", "\t$dst, $lhs, $rhs", 813201360Srdivacky [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>, 814201360Srdivacky T1General<0b01101>; 815193323Sed 816195098Sed// TODO: A7-96: STMIA - store multiple. 817195098Sed 818195098Sed// sign-extend byte 819198090Srdivackydef tSXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 820198892Srdivacky "sxtb", "\t$dst, $src", 821198090Srdivacky [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>, 822201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 823201360Srdivacky T1Misc<{0,0,1,0,0,1,?}>; 824195098Sed 825195098Sed// sign-extend short 826198090Srdivackydef tSXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 827198892Srdivacky "sxth", "\t$dst, $src", 828198090Srdivacky [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>, 829201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 830201360Srdivacky T1Misc<{0,0,1,0,0,0,?}>; 831193323Sed 832195098Sed// test 833195098Sedlet isCommutable = 1, Defs = [CPSR] in 834198090Srdivackydef tTST : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr, 835198892Srdivacky "tst", "\t$lhs, $rhs", 836201360Srdivacky [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>, 837201360Srdivacky T1DataProcessing<0b1000>; 838193323Sed 839195098Sed// zero-extend byte 840198090Srdivackydef tUXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 841198892Srdivacky "uxtb", "\t$dst, $src", 842198090Srdivacky [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>, 843201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 844201360Srdivacky T1Misc<{0,0,1,0,1,1,?}>; 845195098Sed 846195098Sed// zero-extend short 847198090Srdivackydef tUXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr, 848198892Srdivacky "uxth", "\t$dst, $src", 849198090Srdivacky [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>, 850201360Srdivacky Requires<[IsThumb1Only, HasV6]>, 851201360Srdivacky T1Misc<{0,0,1,0,1,0,?}>; 852193323Sed 853193323Sed 854204642Srdivacky// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation. 855198892Srdivacky// Expanded after instruction selection into a branch sequence. 856198892Srdivackylet usesCustomInserter = 1 in // Expanded after instruction selection. 857198090Srdivacky def tMOVCCr_pseudo : 858193323Sed PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc), 859198090Srdivacky NoItinerary, "@ tMOVCCr $cc", 860198090Srdivacky [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>; 861193323Sed 862198090Srdivacky 863198090Srdivacky// 16-bit movcc in IT blocks for Thumb2. 864198090Srdivackydef tMOVCCr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iCMOVr, 865201360Srdivacky "mov", "\t$dst, $rhs", []>, 866202878Srdivacky T1Special<{1,0,?,?}>; 867198090Srdivacky 868203954Srdivackydef tMOVCCi : T1pIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMOVi, 869201360Srdivacky "mov", "\t$dst, $rhs", []>, 870201360Srdivacky T1General<{1,0,0,?,?}>; 871198090Srdivacky 872193323Sed// tLEApcrel - Load a pc-relative address into a register without offending the 873193323Sed// assembler. 874198090Srdivackydef tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi, 875201360Srdivacky "adr$p\t$dst, #$label", []>, 876201360Srdivacky T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10 877193323Sed 878198090Srdivackydef tLEApcrelJT : T1I<(outs tGPR:$dst), 879198090Srdivacky (ins i32imm:$label, nohash_imm:$id, pred:$p), 880201360Srdivacky IIC_iALUi, "adr$p\t$dst, #${label}_${id}", []>, 881201360Srdivacky T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10 882193323Sed 883193323Sed//===----------------------------------------------------------------------===// 884193323Sed// TLS Instructions 885193323Sed// 886193323Sed 887193323Sed// __aeabi_read_tp preserves the registers r1-r3. 888193323Sedlet isCall = 1, 889193323Sed Defs = [R0, LR] in { 890201360Srdivacky def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br, 891201360Srdivacky "bl\t__aeabi_read_tp", 892201360Srdivacky [(set R0, ARMthread_pointer)]>; 893193323Sed} 894193323Sed 895200581Srdivacky// SJLJ Exception handling intrinsics 896200581Srdivacky// eh_sjlj_setjmp() is an instruction sequence to store the return 897200581Srdivacky// address and save #0 in R0 for the non-longjmp case. 898200581Srdivacky// Since by its nature we may be coming from some other function to get 899200581Srdivacky// here, and we're using the stack frame for the containing function to 900200581Srdivacky// save/restore registers, we can't keep anything live in regs across 901200581Srdivacky// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon 902200581Srdivacky// when we get here from a longjmp(). We force everthing out of registers 903200581Srdivacky// except for our own input by listing the relevant registers in Defs. By 904200581Srdivacky// doing so, we also cause the prologue/epilogue code to actively preserve 905200581Srdivacky// all of the callee-saved resgisters, which is exactly what we want. 906203954Srdivacky// The current SP is passed in $val, and we reuse the reg as a scratch. 907200581Srdivackylet Defs = 908200581Srdivacky [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ] in { 909203954Srdivacky def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val), 910200581Srdivacky AddrModeNone, SizeSpecial, NoItinerary, 911203954Srdivacky "str\t$val, [$src, #8]\t@ begin eh.setjmp\n" 912203954Srdivacky "\tmov\t$val, pc\n" 913203954Srdivacky "\tadds\t$val, #9\n" 914203954Srdivacky "\tstr\t$val, [$src, #4]\n" 915200581Srdivacky "\tmovs\tr0, #0\n" 916200581Srdivacky "\tb\t1f\n" 917203954Srdivacky "\tmovs\tr0, #1\t@ end eh.setjmp\n" 918200581Srdivacky "1:", "", 919203954Srdivacky [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>; 920200581Srdivacky} 921193323Sed//===----------------------------------------------------------------------===// 922193323Sed// Non-Instruction Patterns 923193323Sed// 924193323Sed 925198090Srdivacky// Add with carry 926198090Srdivackydef : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs), 927198090Srdivacky (tADDi3 tGPR:$lhs, imm0_7:$rhs)>; 928198090Srdivackydef : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs), 929198090Srdivacky (tADDi8 tGPR:$lhs, imm8_255:$rhs)>; 930198090Srdivackydef : T1Pat<(addc tGPR:$lhs, tGPR:$rhs), 931198090Srdivacky (tADDrr tGPR:$lhs, tGPR:$rhs)>; 932198090Srdivacky 933198090Srdivacky// Subtract with carry 934198090Srdivackydef : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs), 935198090Srdivacky (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>; 936198090Srdivackydef : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs), 937198090Srdivacky (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>; 938198090Srdivackydef : T1Pat<(subc tGPR:$lhs, tGPR:$rhs), 939198090Srdivacky (tSUBrr tGPR:$lhs, tGPR:$rhs)>; 940198090Srdivacky 941193323Sed// ConstantPool, GlobalAddress 942198090Srdivackydef : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>; 943198090Srdivackydef : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>; 944193323Sed 945193323Sed// JumpTable 946198090Srdivackydef : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id), 947198090Srdivacky (tLEApcrelJT tjumptable:$dst, imm:$id)>; 948193323Sed 949193323Sed// Direct calls 950198090Srdivackydef : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>, 951198090Srdivacky Requires<[IsThumb, IsNotDarwin]>; 952198090Srdivackydef : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>, 953198090Srdivacky Requires<[IsThumb, IsDarwin]>; 954193323Sed 955198090Srdivackydef : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>, 956198090Srdivacky Requires<[IsThumb, HasV5T, IsNotDarwin]>; 957198090Srdivackydef : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>, 958198090Srdivacky Requires<[IsThumb, HasV5T, IsDarwin]>; 959198090Srdivacky 960193323Sed// Indirect calls to ARM routines 961198090Srdivackydef : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>, 962198090Srdivacky Requires<[IsThumb, HasV5T, IsNotDarwin]>; 963198090Srdivackydef : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>, 964198090Srdivacky Requires<[IsThumb, HasV5T, IsDarwin]>; 965193323Sed 966193323Sed// zextload i1 -> zextload i8 967195340Seddef : T1Pat<(zextloadi1 t_addrmode_s1:$addr), 968195340Sed (tLDRB t_addrmode_s1:$addr)>; 969193323Sed 970193323Sed// extload -> zextload 971195340Seddef : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>; 972195340Seddef : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>; 973195340Seddef : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>; 974193323Sed 975198090Srdivacky// If it's impossible to use [r,r] address mode for sextload, select to 976198090Srdivacky// ldr{b|h} + sxt{b|h} instead. 977198090Srdivackydef : T1Pat<(sextloadi8 t_addrmode_s1:$addr), 978198090Srdivacky (tSXTB (tLDRB t_addrmode_s1:$addr))>, 979198090Srdivacky Requires<[IsThumb1Only, HasV6]>; 980198090Srdivackydef : T1Pat<(sextloadi16 t_addrmode_s2:$addr), 981198090Srdivacky (tSXTH (tLDRH t_addrmode_s2:$addr))>, 982198090Srdivacky Requires<[IsThumb1Only, HasV6]>; 983198090Srdivacky 984198090Srdivackydef : T1Pat<(sextloadi8 t_addrmode_s1:$addr), 985198090Srdivacky (tASRri (tLSLri (tLDRB t_addrmode_s1:$addr), 24), 24)>; 986198090Srdivackydef : T1Pat<(sextloadi16 t_addrmode_s1:$addr), 987198090Srdivacky (tASRri (tLSLri (tLDRH t_addrmode_s1:$addr), 16), 16)>; 988198090Srdivacky 989193323Sed// Large immediate handling. 990193323Sed 991193323Sed// Two piece imms. 992195098Seddef : T1Pat<(i32 thumb_immshifted:$src), 993195098Sed (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)), 994195098Sed (thumb_immshifted_shamt imm:$src))>; 995193323Sed 996195098Seddef : T1Pat<(i32 imm0_255_comp:$src), 997195098Sed (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>; 998199481Srdivacky 999199481Srdivacky// Pseudo instruction that combines ldr from constpool and add pc. This should 1000199481Srdivacky// be expanded into two instructions late to allow if-conversion and 1001199481Srdivacky// scheduling. 1002199481Srdivackylet isReMaterializable = 1 in 1003199481Srdivackydef tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp), 1004199481Srdivacky NoItinerary, "@ ldr.n\t$dst, $addr\n$cp:\n\tadd\t$dst, pc", 1005199481Srdivacky [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)), 1006199481Srdivacky imm:$cp))]>, 1007199481Srdivacky Requires<[IsThumb1Only]>; 1008