xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/ARM/ARMInstrThumb.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric//===-- ARMInstrThumb.td - Thumb support for ARM -----------*- tablegen -*-===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric//
90b57cec5SDimitry Andric// This file describes the Thumb instruction set.
100b57cec5SDimitry Andric//
110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric// Thumb specific DAG Nodes.
150b57cec5SDimitry Andric//
160b57cec5SDimitry Andric
175ffd83dbSDimitry Andricdef ARMtsecall : SDNode<"ARMISD::tSECALL", SDT_ARMcall,
185ffd83dbSDimitry Andric                        [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
195ffd83dbSDimitry Andric                         SDNPVariadic]>;
205ffd83dbSDimitry Andric
210b57cec5SDimitry Andricdef imm_sr_XFORM: SDNodeXForm<imm, [{
220b57cec5SDimitry Andric  unsigned Imm = N->getZExtValue();
230b57cec5SDimitry Andric  return CurDAG->getTargetConstant((Imm == 32 ? 0 : Imm), SDLoc(N), MVT::i32);
240b57cec5SDimitry Andric}]>;
250b57cec5SDimitry Andricdef ThumbSRImmAsmOperand: ImmAsmOperand<1,32> { let Name = "ImmThumbSR"; }
260b57cec5SDimitry Andricdef imm_sr : Operand<i32>, PatLeaf<(imm), [{
270b57cec5SDimitry Andric  uint64_t Imm = N->getZExtValue();
280b57cec5SDimitry Andric  return Imm > 0 && Imm <= 32;
290b57cec5SDimitry Andric}], imm_sr_XFORM> {
300b57cec5SDimitry Andric  let PrintMethod = "printThumbSRImm";
310b57cec5SDimitry Andric  let ParserMatchClass = ThumbSRImmAsmOperand;
320b57cec5SDimitry Andric}
330b57cec5SDimitry Andric
340b57cec5SDimitry Andricdef imm0_7_neg : PatLeaf<(i32 imm), [{
350b57cec5SDimitry Andric  return (uint32_t)-N->getZExtValue() < 8;
360b57cec5SDimitry Andric}], imm_neg_XFORM>;
370b57cec5SDimitry Andric
380b57cec5SDimitry Andricdef ThumbModImmNeg1_7AsmOperand : AsmOperandClass { let Name = "ThumbModImmNeg1_7"; }
390b57cec5SDimitry Andricdef mod_imm1_7_neg : Operand<i32>, PatLeaf<(imm), [{
400b57cec5SDimitry Andric    unsigned Value = -(unsigned)N->getZExtValue();
410b57cec5SDimitry Andric    return 0 < Value && Value < 8;
420b57cec5SDimitry Andric  }], imm_neg_XFORM> {
430b57cec5SDimitry Andric  let ParserMatchClass = ThumbModImmNeg1_7AsmOperand;
440b57cec5SDimitry Andric}
450b57cec5SDimitry Andric
460b57cec5SDimitry Andricdef ThumbModImmNeg8_255AsmOperand : AsmOperandClass { let Name = "ThumbModImmNeg8_255"; }
470b57cec5SDimitry Andricdef mod_imm8_255_neg : Operand<i32>, PatLeaf<(imm), [{
480b57cec5SDimitry Andric    unsigned Value = -(unsigned)N->getZExtValue();
490b57cec5SDimitry Andric    return 7 < Value && Value < 256;
500b57cec5SDimitry Andric  }], imm_neg_XFORM> {
510b57cec5SDimitry Andric  let ParserMatchClass = ThumbModImmNeg8_255AsmOperand;
520b57cec5SDimitry Andric}
530b57cec5SDimitry Andric
540b57cec5SDimitry Andric
550b57cec5SDimitry Andricdef imm0_255_comp : PatLeaf<(i32 imm), [{
560b57cec5SDimitry Andric  return ~((uint32_t)N->getZExtValue()) < 256;
570b57cec5SDimitry Andric}]>;
580b57cec5SDimitry Andric
590b57cec5SDimitry Andricdef imm8_255_neg : PatLeaf<(i32 imm), [{
600b57cec5SDimitry Andric  unsigned Val = -N->getZExtValue();
610b57cec5SDimitry Andric  return Val >= 8 && Val < 256;
620b57cec5SDimitry Andric}], imm_neg_XFORM>;
630b57cec5SDimitry Andric
640b57cec5SDimitry Andric// Break imm's up into two pieces: an immediate + a left shift. This uses
650b57cec5SDimitry Andric// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
660b57cec5SDimitry Andric// to get the val/shift pieces.
670b57cec5SDimitry Andricdef thumb_immshifted : PatLeaf<(imm), [{
680b57cec5SDimitry Andric  return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
690b57cec5SDimitry Andric}]>;
700b57cec5SDimitry Andric
710b57cec5SDimitry Andricdef thumb_immshifted_val : SDNodeXForm<imm, [{
720b57cec5SDimitry Andric  unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
730b57cec5SDimitry Andric  return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
740b57cec5SDimitry Andric}]>;
750b57cec5SDimitry Andric
760b57cec5SDimitry Andricdef thumb_immshifted_shamt : SDNodeXForm<imm, [{
770b57cec5SDimitry Andric  unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
780b57cec5SDimitry Andric  return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
790b57cec5SDimitry Andric}]>;
800b57cec5SDimitry Andric
810b57cec5SDimitry Andricdef imm256_510 : ImmLeaf<i32, [{
820b57cec5SDimitry Andric  return Imm >= 256 && Imm < 511;
830b57cec5SDimitry Andric}]>;
840b57cec5SDimitry Andric
850b57cec5SDimitry Andricdef thumb_imm256_510_addend : SDNodeXForm<imm, [{
860b57cec5SDimitry Andric  return CurDAG->getTargetConstant(N->getZExtValue() - 255, SDLoc(N), MVT::i32);
870b57cec5SDimitry Andric}]>;
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric// Scaled 4 immediate.
900b57cec5SDimitry Andricdef t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
910b57cec5SDimitry Andricdef t_imm0_1020s4 : Operand<i32> {
920b57cec5SDimitry Andric  let PrintMethod = "printThumbS4ImmOperand";
930b57cec5SDimitry Andric  let ParserMatchClass = t_imm0_1020s4_asmoperand;
940b57cec5SDimitry Andric  let OperandType = "OPERAND_IMMEDIATE";
950b57cec5SDimitry Andric}
960b57cec5SDimitry Andric
970b57cec5SDimitry Andricdef t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
980b57cec5SDimitry Andricdef t_imm0_508s4 : Operand<i32> {
990b57cec5SDimitry Andric  let PrintMethod = "printThumbS4ImmOperand";
1000b57cec5SDimitry Andric  let ParserMatchClass = t_imm0_508s4_asmoperand;
1010b57cec5SDimitry Andric  let OperandType = "OPERAND_IMMEDIATE";
1020b57cec5SDimitry Andric}
1030b57cec5SDimitry Andric// Alias use only, so no printer is necessary.
1040b57cec5SDimitry Andricdef t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
1050b57cec5SDimitry Andricdef t_imm0_508s4_neg : Operand<i32> {
1060b57cec5SDimitry Andric  let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
1070b57cec5SDimitry Andric  let OperandType = "OPERAND_IMMEDIATE";
1080b57cec5SDimitry Andric}
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andric// Define Thumb specific addressing modes.
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andric// unsigned 8-bit, 2-scaled memory offset
1130b57cec5SDimitry Andricclass OperandUnsignedOffset_b8s2 : AsmOperandClass {
1140b57cec5SDimitry Andric  let Name = "UnsignedOffset_b8s2";
1150b57cec5SDimitry Andric  let PredicateMethod = "isUnsignedOffset<8, 2>";
1160b57cec5SDimitry Andric}
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andricdef UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric// thumb style PC relative operand. signed, 8 bits magnitude,
1210b57cec5SDimitry Andric// two bits shift. can be represented as either [pc, #imm], #imm,
1220b57cec5SDimitry Andric// or relocatable expression...
1230b57cec5SDimitry Andricdef ThumbMemPC : AsmOperandClass {
1240b57cec5SDimitry Andric  let Name = "ThumbMemPC";
1250b57cec5SDimitry Andric}
1260b57cec5SDimitry Andric
1270b57cec5SDimitry Andriclet OperandType = "OPERAND_PCREL" in {
1280b57cec5SDimitry Andricdef t_brtarget : Operand<OtherVT> {
1290b57cec5SDimitry Andric  let EncoderMethod = "getThumbBRTargetOpValue";
1300b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbBROperand";
1310b57cec5SDimitry Andric}
1320b57cec5SDimitry Andric
1330b57cec5SDimitry Andric// ADR instruction labels.
1340b57cec5SDimitry Andricdef t_adrlabel : Operand<i32> {
1350b57cec5SDimitry Andric  let EncoderMethod = "getThumbAdrLabelOpValue";
1360b57cec5SDimitry Andric  let PrintMethod = "printAdrLabelOperand<2>";
1370b57cec5SDimitry Andric  let ParserMatchClass = UnsignedOffset_b8s2;
1380b57cec5SDimitry Andric}
1390b57cec5SDimitry Andric
1400b57cec5SDimitry Andric
1410b57cec5SDimitry Andricdef thumb_br_target : Operand<OtherVT> {
1420b57cec5SDimitry Andric  let ParserMatchClass = ThumbBranchTarget;
1430b57cec5SDimitry Andric  let EncoderMethod = "getThumbBranchTargetOpValue";
1440b57cec5SDimitry Andric  let OperandType = "OPERAND_PCREL";
1450b57cec5SDimitry Andric}
1460b57cec5SDimitry Andric
1470b57cec5SDimitry Andricdef thumb_bl_target : Operand<i32> {
1480b57cec5SDimitry Andric  let ParserMatchClass = ThumbBranchTarget;
1490b57cec5SDimitry Andric  let EncoderMethod = "getThumbBLTargetOpValue";
1500b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbBLTargetOperand";
1510b57cec5SDimitry Andric}
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric// Target for BLX *from* thumb mode.
1540b57cec5SDimitry Andricdef thumb_blx_target : Operand<i32> {
1550b57cec5SDimitry Andric  let ParserMatchClass = ARMBranchTarget;
1560b57cec5SDimitry Andric  let EncoderMethod = "getThumbBLXTargetOpValue";
1570b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbBLXOffset";
1580b57cec5SDimitry Andric}
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andricdef thumb_bcc_target : Operand<OtherVT> {
1610b57cec5SDimitry Andric  let ParserMatchClass = ThumbBranchTarget;
1620b57cec5SDimitry Andric  let EncoderMethod = "getThumbBCCTargetOpValue";
1630b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbBCCTargetOperand";
1640b57cec5SDimitry Andric}
1650b57cec5SDimitry Andric
1660b57cec5SDimitry Andricdef thumb_cb_target : Operand<OtherVT> {
1670b57cec5SDimitry Andric  let ParserMatchClass = ThumbBranchTarget;
1680b57cec5SDimitry Andric  let EncoderMethod = "getThumbCBTargetOpValue";
1690b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbCmpBROperand";
1700b57cec5SDimitry Andric}
171349cc55cSDimitry Andric} // OperandType = "OPERAND_PCREL"
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andric// t_addrmode_pc := <label> => pc + imm8 * 4
1740b57cec5SDimitry Andric//
1750b57cec5SDimitry Andricdef t_addrmode_pc : MemOperand {
1760b57cec5SDimitry Andric  let EncoderMethod = "getAddrModePCOpValue";
1770b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModePC";
1780b57cec5SDimitry Andric  let PrintMethod = "printThumbLdrLabelOperand";
1790b57cec5SDimitry Andric  let ParserMatchClass = ThumbMemPC;
1800b57cec5SDimitry Andric}
1810b57cec5SDimitry Andric
1820b57cec5SDimitry Andric// t_addrmode_rr := reg + reg
1830b57cec5SDimitry Andric//
1840b57cec5SDimitry Andricdef t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
1850b57cec5SDimitry Andricdef t_addrmode_rr : MemOperand,
1860b57cec5SDimitry Andric                    ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
1870b57cec5SDimitry Andric  let EncoderMethod = "getThumbAddrModeRegRegOpValue";
1880b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeRROperand";
1890b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeRR";
1900b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_rr_asm_operand;
1910b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
1920b57cec5SDimitry Andric}
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric// t_addrmode_rr_sext := reg + reg
1950b57cec5SDimitry Andric//
1960b57cec5SDimitry Andric// This is similar to t_addrmode_rr, but uses different heuristics for
1970b57cec5SDimitry Andric// ldrsb/ldrsh.
1980b57cec5SDimitry Andricdef t_addrmode_rr_sext : MemOperand,
1990b57cec5SDimitry Andric                    ComplexPattern<i32, 2, "SelectThumbAddrModeRRSext", []> {
2000b57cec5SDimitry Andric  let EncoderMethod = "getThumbAddrModeRegRegOpValue";
2010b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeRROperand";
2020b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeRR";
2030b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_rr_asm_operand;
2040b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
2050b57cec5SDimitry Andric}
2060b57cec5SDimitry Andric
2070b57cec5SDimitry Andric// t_addrmode_rrs := reg + reg
2080b57cec5SDimitry Andric//
2090b57cec5SDimitry Andric// We use separate scaled versions because the Select* functions need
2100b57cec5SDimitry Andric// to explicitly check for a matching constant and return false here so that
2110b57cec5SDimitry Andric// the reg+imm forms will match instead. This is a horrible way to do that,
2120b57cec5SDimitry Andric// as it forces tight coupling between the methods, but it's how selectiondag
2130b57cec5SDimitry Andric// currently works.
2140b57cec5SDimitry Andricdef t_addrmode_rrs1 : MemOperand,
2150b57cec5SDimitry Andric                      ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
2160b57cec5SDimitry Andric  let EncoderMethod = "getThumbAddrModeRegRegOpValue";
2170b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeRROperand";
2180b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeRR";
2190b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_rr_asm_operand;
2200b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
2210b57cec5SDimitry Andric}
2220b57cec5SDimitry Andricdef t_addrmode_rrs2 : MemOperand,
2230b57cec5SDimitry Andric                      ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
2240b57cec5SDimitry Andric  let EncoderMethod = "getThumbAddrModeRegRegOpValue";
2250b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeRR";
2260b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeRROperand";
2270b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_rr_asm_operand;
2280b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
2290b57cec5SDimitry Andric}
2300b57cec5SDimitry Andricdef t_addrmode_rrs4 : MemOperand,
2310b57cec5SDimitry Andric                      ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
2320b57cec5SDimitry Andric  let EncoderMethod = "getThumbAddrModeRegRegOpValue";
2330b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeRR";
2340b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeRROperand";
2350b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_rr_asm_operand;
2360b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
2370b57cec5SDimitry Andric}
2380b57cec5SDimitry Andric
2390b57cec5SDimitry Andric// t_addrmode_is4 := reg + imm5 * 4
2400b57cec5SDimitry Andric//
2410b57cec5SDimitry Andricdef t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
2420b57cec5SDimitry Andricdef t_addrmode_is4 : MemOperand,
2430b57cec5SDimitry Andric                     ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
2440b57cec5SDimitry Andric  let EncoderMethod = "getAddrModeISOpValue";
2450b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeIS";
2460b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeImm5S4Operand";
2470b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_is4_asm_operand;
2480b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
2490b57cec5SDimitry Andric}
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andric// t_addrmode_is2 := reg + imm5 * 2
2520b57cec5SDimitry Andric//
2530b57cec5SDimitry Andricdef t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
2540b57cec5SDimitry Andricdef t_addrmode_is2 : MemOperand,
2550b57cec5SDimitry Andric                     ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
2560b57cec5SDimitry Andric  let EncoderMethod = "getAddrModeISOpValue";
2570b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeIS";
2580b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeImm5S2Operand";
2590b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_is2_asm_operand;
2600b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
2610b57cec5SDimitry Andric}
2620b57cec5SDimitry Andric
2630b57cec5SDimitry Andric// t_addrmode_is1 := reg + imm5
2640b57cec5SDimitry Andric//
2650b57cec5SDimitry Andricdef t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
2660b57cec5SDimitry Andricdef t_addrmode_is1 : MemOperand,
2670b57cec5SDimitry Andric                     ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
2680b57cec5SDimitry Andric  let EncoderMethod = "getAddrModeISOpValue";
2690b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeIS";
2700b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeImm5S1Operand";
2710b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_is1_asm_operand;
2720b57cec5SDimitry Andric  let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
2730b57cec5SDimitry Andric}
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric// t_addrmode_sp := sp + imm8 * 4
2760b57cec5SDimitry Andric//
2770b57cec5SDimitry Andric// FIXME: This really shouldn't have an explicit SP operand at all. It should
2780b57cec5SDimitry Andric// be implicit, just like in the instruction encoding itself.
2790b57cec5SDimitry Andricdef t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
2800b57cec5SDimitry Andricdef t_addrmode_sp : MemOperand,
2810b57cec5SDimitry Andric                    ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
2820b57cec5SDimitry Andric  let EncoderMethod = "getAddrModeThumbSPOpValue";
2830b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddrModeSP";
2840b57cec5SDimitry Andric  let PrintMethod = "printThumbAddrModeSPOperand";
2850b57cec5SDimitry Andric  let ParserMatchClass = t_addrmode_sp_asm_operand;
2860b57cec5SDimitry Andric  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
2870b57cec5SDimitry Andric}
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric// Inspects parent to determine whether an or instruction can be implemented as
2900b57cec5SDimitry Andric// an add (i.e. whether we know overflow won't occur in the add).
2910b57cec5SDimitry Andricdef AddLikeOrOp : ComplexPattern<i32, 1, "SelectAddLikeOr", [],
2920b57cec5SDimitry Andric                                 [SDNPWantParent]>;
2930b57cec5SDimitry Andric
2940b57cec5SDimitry Andric// Pattern to exclude immediates from matching
2950b57cec5SDimitry Andricdef non_imm32 : PatLeaf<(i32 GPR), [{ return !isa<ConstantSDNode>(N); }]>;
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2980b57cec5SDimitry Andric//  Miscellaneous Instructions.
2990b57cec5SDimitry Andric//
3000b57cec5SDimitry Andric
3010b57cec5SDimitry Andric// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
3020b57cec5SDimitry Andric// from removing one half of the matched pairs. That breaks PEI, which assumes
3030b57cec5SDimitry Andric// these will always be in pairs, and asserts if it finds otherwise. Better way?
3040b57cec5SDimitry Andriclet Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
3050b57cec5SDimitry Andricdef tADJCALLSTACKUP :
3060b57cec5SDimitry Andric  PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
3070b57cec5SDimitry Andric             [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
3080b57cec5SDimitry Andric            Requires<[IsThumb, IsThumb1Only]>;
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andricdef tADJCALLSTACKDOWN :
3110b57cec5SDimitry Andric  PseudoInst<(outs), (ins i32imm:$amt, i32imm:$amt2), NoItinerary,
3120b57cec5SDimitry Andric             [(ARMcallseq_start imm:$amt, imm:$amt2)]>,
3130b57cec5SDimitry Andric            Requires<[IsThumb, IsThumb1Only]>;
3140b57cec5SDimitry Andric}
3150b57cec5SDimitry Andric
3160b57cec5SDimitry Andricclass T1SystemEncoding<bits<8> opc>
3170b57cec5SDimitry Andric  : T1Encoding<0b101111> {
3180b57cec5SDimitry Andric  let Inst{9-8} = 0b11;
3190b57cec5SDimitry Andric  let Inst{7-0} = opc;
3200b57cec5SDimitry Andric}
3210b57cec5SDimitry Andric
3220b57cec5SDimitry Andricdef tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
3230b57cec5SDimitry Andric                 [(int_arm_hint imm0_15:$imm)]>,
3240b57cec5SDimitry Andric            T1SystemEncoding<0x00>,
3250b57cec5SDimitry Andric            Requires<[IsThumb, HasV6M]> {
3260b57cec5SDimitry Andric  bits<4> imm;
3270b57cec5SDimitry Andric  let Inst{7-4} = imm;
3280b57cec5SDimitry Andric}
3290b57cec5SDimitry Andric
3300b57cec5SDimitry Andric// Note: When EmitPriority == 1, the alias will be used for printing
3310b57cec5SDimitry Andricclass tHintAlias<string Asm, dag Result, bit EmitPriority = 0> : tInstAlias<Asm, Result, EmitPriority> {
3320b57cec5SDimitry Andric  let Predicates = [IsThumb, HasV6M];
3330b57cec5SDimitry Andric}
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andricdef : tHintAlias<"nop$p", (tHINT 0, pred:$p), 1>; // A8.6.110
3360b57cec5SDimitry Andricdef : tHintAlias<"yield$p", (tHINT 1, pred:$p), 1>; // A8.6.410
3370b57cec5SDimitry Andricdef : tHintAlias<"wfe$p", (tHINT 2, pred:$p), 1>; // A8.6.408
3380b57cec5SDimitry Andricdef : tHintAlias<"wfi$p", (tHINT 3, pred:$p), 1>; // A8.6.409
3390b57cec5SDimitry Andricdef : tHintAlias<"sev$p", (tHINT 4, pred:$p), 1>; // A8.6.157
3400b57cec5SDimitry Andricdef : tInstAlias<"sevl$p", (tHINT 5, pred:$p), 1> {
3410b57cec5SDimitry Andric  let Predicates = [IsThumb2, HasV8];
3420b57cec5SDimitry Andric}
3430b57cec5SDimitry Andric
3440b57cec5SDimitry Andric// The imm operand $val can be used by a debugger to store more information
3450b57cec5SDimitry Andric// about the breakpoint.
3460b57cec5SDimitry Andricdef tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
3470b57cec5SDimitry Andric                []>,
3480b57cec5SDimitry Andric           T1Encoding<0b101111> {
3490b57cec5SDimitry Andric  let Inst{9-8} = 0b10;
3500b57cec5SDimitry Andric  // A8.6.22
3510b57cec5SDimitry Andric  bits<8> val;
3520b57cec5SDimitry Andric  let Inst{7-0} = val;
3530b57cec5SDimitry Andric}
3540b57cec5SDimitry Andric// default immediate for breakpoint mnemonic
3550b57cec5SDimitry Andricdef : InstAlias<"bkpt", (tBKPT 0), 0>, Requires<[IsThumb]>;
3560b57cec5SDimitry Andric
3570b57cec5SDimitry Andricdef tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
3580b57cec5SDimitry Andric                []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
3590b57cec5SDimitry Andric  let Inst{9-6} = 0b1010;
3600b57cec5SDimitry Andric  bits<6> val;
3610b57cec5SDimitry Andric  let Inst{5-0} = val;
3620b57cec5SDimitry Andric}
3630b57cec5SDimitry Andric
3640b57cec5SDimitry Andricdef tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
3650b57cec5SDimitry Andric                  []>, T1Encoding<0b101101>, Requires<[IsThumb, IsNotMClass]>, Deprecated<HasV8Ops> {
3660b57cec5SDimitry Andric  bits<1> end;
3670b57cec5SDimitry Andric  // A8.6.156
3680b57cec5SDimitry Andric  let Inst{9-5} = 0b10010;
3690b57cec5SDimitry Andric  let Inst{4}   = 1;
3700b57cec5SDimitry Andric  let Inst{3}   = end;
3710b57cec5SDimitry Andric  let Inst{2-0} = 0b000;
3720b57cec5SDimitry Andric}
3730b57cec5SDimitry Andric
3740b57cec5SDimitry Andric// Change Processor State is a system instruction -- for disassembly only.
3750b57cec5SDimitry Andricdef tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
3760b57cec5SDimitry Andric                NoItinerary, "cps$imod $iflags", []>,
3770b57cec5SDimitry Andric           T1Misc<0b0110011> {
3780b57cec5SDimitry Andric  // A8.6.38 & B6.1.1
3790b57cec5SDimitry Andric  bit imod;
3800b57cec5SDimitry Andric  bits<3> iflags;
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andric  let Inst{4}   = imod;
3830b57cec5SDimitry Andric  let Inst{3}   = 0;
3840b57cec5SDimitry Andric  let Inst{2-0} = iflags;
3850b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbCPS";
3860b57cec5SDimitry Andric}
3870b57cec5SDimitry Andric
3880b57cec5SDimitry Andric// For both thumb1 and thumb2.
3890b57cec5SDimitry Andriclet isNotDuplicable = 1, isCodeGenOnly = 1 in
3900b57cec5SDimitry Andricdef tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
3910b57cec5SDimitry Andric                  [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
3920b57cec5SDimitry Andric              T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
3930b57cec5SDimitry Andric  // A8.6.6
3940b57cec5SDimitry Andric  bits<3> dst;
3950b57cec5SDimitry Andric  let Inst{6-3} = 0b1111; // Rm = pc
3960b57cec5SDimitry Andric  let Inst{2-0} = dst;
3970b57cec5SDimitry Andric}
3980b57cec5SDimitry Andric
3990b57cec5SDimitry Andric// ADD <Rd>, sp, #<imm8>
4000b57cec5SDimitry Andric// FIXME: This should not be marked as having side effects, and it should be
4010b57cec5SDimitry Andric// rematerializable. Clearing the side effect bit causes miscompilations,
4020b57cec5SDimitry Andric// probably because the instruction can be moved around.
4030b57cec5SDimitry Andricdef tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
4040b57cec5SDimitry Andric                    IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
4050b57cec5SDimitry Andric               T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
4060b57cec5SDimitry Andric  // A6.2 & A8.6.8
4070b57cec5SDimitry Andric  bits<3> dst;
4080b57cec5SDimitry Andric  bits<8> imm;
4090b57cec5SDimitry Andric  let Inst{10-8} = dst;
4100b57cec5SDimitry Andric  let Inst{7-0}  = imm;
4110b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddSpecialReg";
4120b57cec5SDimitry Andric}
4130b57cec5SDimitry Andric
4140b57cec5SDimitry Andric// Thumb1 frame lowering is rather fragile, we hope to be able to use
4150b57cec5SDimitry Andric// tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
4160b57cec5SDimitry Andricdef tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
4170b57cec5SDimitry Andric                           NoItinerary, []>,
4180b57cec5SDimitry Andric                Requires<[IsThumb, IsThumb1Only]> {
4190b57cec5SDimitry Andric  let Defs = [CPSR];
4200b57cec5SDimitry Andric}
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andric// ADD sp, sp, #<imm7>
4230b57cec5SDimitry Andricdef tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
4240b57cec5SDimitry Andric                     IIC_iALUi, "add", "\t$Rdn, $imm", []>,
4250b57cec5SDimitry Andric              T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
4260b57cec5SDimitry Andric  // A6.2.5 & A8.6.8
4270b57cec5SDimitry Andric  bits<7> imm;
4280b57cec5SDimitry Andric  let Inst{6-0} = imm;
4290b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddSPImm";
4300b57cec5SDimitry Andric}
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andric// SUB sp, sp, #<imm7>
4330b57cec5SDimitry Andric// FIXME: The encoding and the ASM string don't match up.
4340b57cec5SDimitry Andricdef tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
4350b57cec5SDimitry Andric                    IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
4360b57cec5SDimitry Andric              T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
4370b57cec5SDimitry Andric  // A6.2.5 & A8.6.214
4380b57cec5SDimitry Andric  bits<7> imm;
4390b57cec5SDimitry Andric  let Inst{6-0} = imm;
4400b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddSPImm";
4410b57cec5SDimitry Andric}
4420b57cec5SDimitry Andric
4430b57cec5SDimitry Andricdef : tInstSubst<"add${p} sp, $imm",
4440b57cec5SDimitry Andric                 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
4450b57cec5SDimitry Andricdef : tInstSubst<"add${p} sp, sp, $imm",
4460b57cec5SDimitry Andric                 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andric// Can optionally specify SP as a three operand instruction.
4490b57cec5SDimitry Andricdef : tInstAlias<"add${p} sp, sp, $imm",
4500b57cec5SDimitry Andric                 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
4510b57cec5SDimitry Andricdef : tInstAlias<"sub${p} sp, sp, $imm",
4520b57cec5SDimitry Andric                 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
4530b57cec5SDimitry Andric
4540b57cec5SDimitry Andric// ADD <Rm>, sp
4550b57cec5SDimitry Andricdef tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
4560b57cec5SDimitry Andric                   "add", "\t$Rdn, $sp, $Rn", []>,
4570b57cec5SDimitry Andric              T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
4580b57cec5SDimitry Andric  // A8.6.9 Encoding T1
4590b57cec5SDimitry Andric  bits<4> Rdn;
4600b57cec5SDimitry Andric  let Inst{7}   = Rdn{3};
4610b57cec5SDimitry Andric  let Inst{6-3} = 0b1101;
4620b57cec5SDimitry Andric  let Inst{2-0} = Rdn{2-0};
4630b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddSPReg";
4640b57cec5SDimitry Andric}
4650b57cec5SDimitry Andric
4660b57cec5SDimitry Andric// ADD sp, <Rm>
4670b57cec5SDimitry Andricdef tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
4680b57cec5SDimitry Andric                  "add", "\t$Rdn, $Rm", []>,
4690b57cec5SDimitry Andric              T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
4700b57cec5SDimitry Andric  // A8.6.9 Encoding T2
4710b57cec5SDimitry Andric  bits<4> Rm;
4720b57cec5SDimitry Andric  let Inst{7} = 1;
4730b57cec5SDimitry Andric  let Inst{6-3} = Rm;
4740b57cec5SDimitry Andric  let Inst{2-0} = 0b101;
4750b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddSPReg";
4760b57cec5SDimitry Andric}
4770b57cec5SDimitry Andric
4780b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
4790b57cec5SDimitry Andric//  Control Flow Instructions.
4800b57cec5SDimitry Andric//
4810b57cec5SDimitry Andric
4820b57cec5SDimitry Andric// Indirect branches
4830b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
4840b57cec5SDimitry Andric  def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
4850b57cec5SDimitry Andric            T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
4860b57cec5SDimitry Andric    // A6.2.3 & A8.6.25
4870b57cec5SDimitry Andric    bits<4> Rm;
4880b57cec5SDimitry Andric    let Inst{6-3} = Rm;
4890b57cec5SDimitry Andric    let Inst{2-0} = 0b000;
4900b57cec5SDimitry Andric    let Unpredictable{2-0} = 0b111;
4910b57cec5SDimitry Andric  }
4920b57cec5SDimitry Andric  def tBXNS : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bxns${p}\t$Rm", []>,
4930b57cec5SDimitry Andric              Requires<[IsThumb, Has8MSecExt]>,
4940b57cec5SDimitry Andric              T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
4950b57cec5SDimitry Andric    bits<4> Rm;
4960b57cec5SDimitry Andric    let Inst{6-3} = Rm;
4970b57cec5SDimitry Andric    let Inst{2-0} = 0b100;
4980b57cec5SDimitry Andric    let Unpredictable{1-0} = 0b11;
4990b57cec5SDimitry Andric  }
5000b57cec5SDimitry Andric}
5010b57cec5SDimitry Andric
5020b57cec5SDimitry Andriclet isReturn = 1, isTerminator = 1, isBarrier = 1 in {
5030b57cec5SDimitry Andric  def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
50406c3fb27SDimitry Andric                   [(ARMretglue)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
5050b57cec5SDimitry Andric
5065ffd83dbSDimitry Andric  // alternative return for CMSE entry functions
5075ffd83dbSDimitry Andric  def tBXNS_RET : tPseudoInst<(outs), (ins), 2, IIC_Br,
50806c3fb27SDimitry Andric                  [(ARMseretglue)]>, Sched<[WriteBr]>;
5095ffd83dbSDimitry Andric
5100b57cec5SDimitry Andric  // Alternative return instruction used by vararg functions.
5110b57cec5SDimitry Andric  def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
5120b57cec5SDimitry Andric                   2, IIC_Br, [],
5130b57cec5SDimitry Andric                   (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
5140b57cec5SDimitry Andric}
5150b57cec5SDimitry Andric
5160b57cec5SDimitry Andric// All calls clobber the non-callee saved registers. SP is marked as a use to
5170b57cec5SDimitry Andric// prevent stack-pointer assignments that appear immediately before calls from
5180b57cec5SDimitry Andric// potentially appearing dead.
5190b57cec5SDimitry Andriclet isCall = 1,
5200b57cec5SDimitry Andric  Defs = [LR], Uses = [SP] in {
5210b57cec5SDimitry Andric  // Also used for Thumb2
5220b57cec5SDimitry Andric  def tBL  : TIx2<0b11110, 0b11, 1,
5230b57cec5SDimitry Andric                  (outs), (ins pred:$p, thumb_bl_target:$func), IIC_Br,
5240b57cec5SDimitry Andric                  "bl${p}\t$func",
5250b57cec5SDimitry Andric                  [(ARMcall tglobaladdr:$func)]>,
5260b57cec5SDimitry Andric             Requires<[IsThumb]>, Sched<[WriteBrL]> {
5270b57cec5SDimitry Andric    bits<24> func;
5280b57cec5SDimitry Andric    let Inst{26} = func{23};
5290b57cec5SDimitry Andric    let Inst{25-16} = func{20-11};
5300b57cec5SDimitry Andric    let Inst{13} = func{22};
5310b57cec5SDimitry Andric    let Inst{11} = func{21};
5320b57cec5SDimitry Andric    let Inst{10-0} = func{10-0};
5330b57cec5SDimitry Andric  }
5340b57cec5SDimitry Andric
5350b57cec5SDimitry Andric  // ARMv5T and above, also used for Thumb2
5360b57cec5SDimitry Andric  def tBLXi : TIx2<0b11110, 0b11, 0,
5370b57cec5SDimitry Andric                 (outs), (ins pred:$p, thumb_blx_target:$func), IIC_Br,
5380b57cec5SDimitry Andric                   "blx${p}\t$func", []>,
5390b57cec5SDimitry Andric              Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
5400b57cec5SDimitry Andric    bits<24> func;
5410b57cec5SDimitry Andric    let Inst{26} = func{23};
5420b57cec5SDimitry Andric    let Inst{25-16} = func{20-11};
5430b57cec5SDimitry Andric    let Inst{13} = func{22};
5440b57cec5SDimitry Andric    let Inst{11} = func{21};
5450b57cec5SDimitry Andric    let Inst{10-1} = func{10-1};
5460b57cec5SDimitry Andric    let Inst{0} = 0; // func{0} is assumed zero
5470b57cec5SDimitry Andric  }
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andric  // Also used for Thumb2
5500b57cec5SDimitry Andric  def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
551e8d8bef9SDimitry Andric                  "blx${p}\t$func", []>,
5520b57cec5SDimitry Andric              Requires<[IsThumb, HasV5T]>,
5530b57cec5SDimitry Andric              T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
5540b57cec5SDimitry Andric    bits<4> func;
5550b57cec5SDimitry Andric    let Inst{6-3} = func;
5560b57cec5SDimitry Andric    let Inst{2-0} = 0b000;
5570b57cec5SDimitry Andric  }
558e8d8bef9SDimitry Andric  def tBLXr_noip :  ARMPseudoExpand<(outs), (ins pred:$p, GPRnoip:$func),
559e8d8bef9SDimitry Andric                   2, IIC_Br, [], (tBLXr pred:$p, GPR:$func)>,
560e8d8bef9SDimitry Andric                   Requires<[IsThumb, HasV5T]>,
561e8d8bef9SDimitry Andric                   Sched<[WriteBrL]>;
562e8d8bef9SDimitry Andric
5630b57cec5SDimitry Andric
5640b57cec5SDimitry Andric  // ARMv8-M Security Extensions
5650b57cec5SDimitry Andric  def tBLXNSr : TI<(outs), (ins pred:$p, GPRnopc:$func), IIC_Br,
5660b57cec5SDimitry Andric                   "blxns${p}\t$func", []>,
5670b57cec5SDimitry Andric                Requires<[IsThumb, Has8MSecExt]>,
5680b57cec5SDimitry Andric                T1Special<{1,1,1,?}>, Sched<[WriteBrL]> {
5690b57cec5SDimitry Andric    bits<4> func;
5700b57cec5SDimitry Andric    let Inst{6-3} = func;
5710b57cec5SDimitry Andric    let Inst{2-0} = 0b100;
5720b57cec5SDimitry Andric    let Unpredictable{1-0} = 0b11;
5730b57cec5SDimitry Andric  }
5740b57cec5SDimitry Andric
5755ffd83dbSDimitry Andric  def tBLXNS_CALL : PseudoInst<(outs), (ins GPRnopc:$func), IIC_Br,
5765ffd83dbSDimitry Andric                    [(ARMtsecall GPRnopc:$func)]>,
5775ffd83dbSDimitry Andric                    Requires<[IsThumb, Has8MSecExt]>, Sched<[WriteBr]>;
5785ffd83dbSDimitry Andric
5790b57cec5SDimitry Andric  // ARMv4T
5800b57cec5SDimitry Andric  def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
5810b57cec5SDimitry Andric                  4, IIC_Br,
5820b57cec5SDimitry Andric                  [(ARMcall_nolink tGPR:$func)]>,
5830b57cec5SDimitry Andric            Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
5848bcb0991SDimitry Andric
5858bcb0991SDimitry Andric  // Also used for Thumb2
5868bcb0991SDimitry Andric  // push lr before the call
5878bcb0991SDimitry Andric  def tBL_PUSHLR : tPseudoInst<(outs), (ins GPRlr:$ra, pred:$p, thumb_bl_target:$func),
5888bcb0991SDimitry Andric                  4, IIC_Br,
5898bcb0991SDimitry Andric                  []>,
5908bcb0991SDimitry Andric             Requires<[IsThumb]>, Sched<[WriteBr]>;
5910b57cec5SDimitry Andric}
5920b57cec5SDimitry Andric
593e8d8bef9SDimitry Andricdef : ARMPat<(ARMcall GPR:$func), (tBLXr $func)>,
594e8d8bef9SDimitry Andric      Requires<[IsThumb, HasV5T, NoSLSBLRMitigation]>;
595e8d8bef9SDimitry Andricdef : ARMPat<(ARMcall GPRnoip:$func), (tBLXr_noip $func)>,
596e8d8bef9SDimitry Andric      Requires<[IsThumb, HasV5T, SLSBLRMitigation]>;
597e8d8bef9SDimitry Andric
5980b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, isBarrier = 1 in {
5990b57cec5SDimitry Andric  let isPredicable = 1 in
6000b57cec5SDimitry Andric  def tB   : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
6010b57cec5SDimitry Andric                 "b", "\t$target", [(br bb:$target)]>,
6020b57cec5SDimitry Andric             T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
6030b57cec5SDimitry Andric    bits<11> target;
6040b57cec5SDimitry Andric    let Inst{10-0} = target;
6050b57cec5SDimitry Andric    let AsmMatchConverter = "cvtThumbBranches";
6060b57cec5SDimitry Andric }
6070b57cec5SDimitry Andric
6080b57cec5SDimitry Andric  // Far jump
6090b57cec5SDimitry Andric  // Just a pseudo for a tBL instruction. Needed to let regalloc know about
6100b57cec5SDimitry Andric  // the clobber of LR.
6110b57cec5SDimitry Andric  let Defs = [LR] in
6120b57cec5SDimitry Andric  def tBfar : tPseudoExpand<(outs), (ins thumb_bl_target:$target, pred:$p),
6130b57cec5SDimitry Andric                          4, IIC_Br, [],
6140b57cec5SDimitry Andric                          (tBL pred:$p, thumb_bl_target:$target)>,
6150b57cec5SDimitry Andric                          Sched<[WriteBrTbl]>;
6160b57cec5SDimitry Andric
6170b57cec5SDimitry Andric  def tBR_JTr : tPseudoInst<(outs),
6180b57cec5SDimitry Andric                      (ins tGPR:$target, i32imm:$jt),
6190b57cec5SDimitry Andric                      0, IIC_Br,
6200b57cec5SDimitry Andric                      [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
6210b57cec5SDimitry Andric                      Sched<[WriteBrTbl]> {
6220b57cec5SDimitry Andric    let Size = 2;
6230b57cec5SDimitry Andric    let isNotDuplicable = 1;
6240b57cec5SDimitry Andric    list<Predicate> Predicates = [IsThumb, IsThumb1Only];
6250b57cec5SDimitry Andric  }
6260b57cec5SDimitry Andric}
6270b57cec5SDimitry Andric
6280b57cec5SDimitry Andric// FIXME: should be able to write a pattern for ARMBrcond, but can't use
6290b57cec5SDimitry Andric// a two-value operand where a dag node expects two operands. :(
6300b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1 in
6310b57cec5SDimitry Andric  def tBcc : T1I<(outs), (ins thumb_bcc_target:$target, pred:$p), IIC_Br,
6320b57cec5SDimitry Andric                 "b${p}\t$target",
6330b57cec5SDimitry Andric                 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
6340b57cec5SDimitry Andric             T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
6350b57cec5SDimitry Andric  bits<4> p;
6360b57cec5SDimitry Andric  bits<8> target;
6370b57cec5SDimitry Andric  let Inst{11-8} = p;
6380b57cec5SDimitry Andric  let Inst{7-0} = target;
6390b57cec5SDimitry Andric  let AsmMatchConverter = "cvtThumbBranches";
6400b57cec5SDimitry Andric}
6410b57cec5SDimitry Andric
6420b57cec5SDimitry Andric
6430b57cec5SDimitry Andric// Tail calls
6440b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
6450b57cec5SDimitry Andric  // IOS versions.
6460b57cec5SDimitry Andric  let Uses = [SP] in {
6470b57cec5SDimitry Andric    def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
6480b57cec5SDimitry Andric                     4, IIC_Br, [],
6490b57cec5SDimitry Andric                     (tBX GPR:$dst, (ops 14, zero_reg))>,
6500b57cec5SDimitry Andric                     Requires<[IsThumb]>, Sched<[WriteBr]>;
6510b57cec5SDimitry Andric  }
6520b57cec5SDimitry Andric  // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
6530b57cec5SDimitry Andric  // on MachO), so it's in ARMInstrThumb2.td.
6540b57cec5SDimitry Andric  // Non-MachO version:
6550b57cec5SDimitry Andric  let Uses = [SP] in {
6560b57cec5SDimitry Andric    def tTAILJMPdND : tPseudoExpand<(outs),
6570b57cec5SDimitry Andric                   (ins t_brtarget:$dst, pred:$p),
6580b57cec5SDimitry Andric                   4, IIC_Br, [],
6590b57cec5SDimitry Andric                   (tB t_brtarget:$dst, pred:$p)>,
6600b57cec5SDimitry Andric                 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
6610b57cec5SDimitry Andric  }
6620b57cec5SDimitry Andric}
6630b57cec5SDimitry Andric
6640b57cec5SDimitry Andric
6650b57cec5SDimitry Andric// A8.6.218 Supervisor Call (Software Interrupt)
6660b57cec5SDimitry Andric// A8.6.16 B: Encoding T1
6670b57cec5SDimitry Andric// If Inst{11-8} == 0b1111 then SEE SVC
6680b57cec5SDimitry Andriclet isCall = 1, Uses = [SP] in
6690b57cec5SDimitry Andricdef tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
6700b57cec5SDimitry Andric                "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
6710b57cec5SDimitry Andric  bits<8> imm;
6720b57cec5SDimitry Andric  let Inst{15-12} = 0b1101;
6730b57cec5SDimitry Andric  let Inst{11-8}  = 0b1111;
6740b57cec5SDimitry Andric  let Inst{7-0}   = imm;
6750b57cec5SDimitry Andric}
6760b57cec5SDimitry Andric
6770b57cec5SDimitry Andric// The assembler uses 0xDEFE for a trap instruction.
6780b57cec5SDimitry Andriclet isBarrier = 1, isTerminator = 1 in
6790b57cec5SDimitry Andricdef tTRAP : TI<(outs), (ins), IIC_Br,
6800b57cec5SDimitry Andric               "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
6810b57cec5SDimitry Andric  let Inst = 0xdefe;
6820b57cec5SDimitry Andric}
6830b57cec5SDimitry Andric
6840b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
6850b57cec5SDimitry Andric//  Load Store Instructions.
6860b57cec5SDimitry Andric//
6870b57cec5SDimitry Andric
6880b57cec5SDimitry Andric// PC-relative loads need to be matched first as constant pool accesses need to
6890b57cec5SDimitry Andric// always be PC-relative. We do this using AddedComplexity, as the pattern is
6900b57cec5SDimitry Andric// simpler than the patterns of the other load instructions.
6910b57cec5SDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 10 in
6920b57cec5SDimitry Andricdef tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
6930b57cec5SDimitry Andric                  "ldr", "\t$Rt, $addr",
6940b57cec5SDimitry Andric                  [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
6950b57cec5SDimitry Andric              T1Encoding<{0,1,0,0,1,?}>, Sched<[WriteLd]> {
6960b57cec5SDimitry Andric  // A6.2 & A8.6.59
6970b57cec5SDimitry Andric  bits<3> Rt;
6980b57cec5SDimitry Andric  bits<8> addr;
6990b57cec5SDimitry Andric  let Inst{10-8} = Rt;
7000b57cec5SDimitry Andric  let Inst{7-0}  = addr;
7010b57cec5SDimitry Andric}
7020b57cec5SDimitry Andric
7030b57cec5SDimitry Andric// SP-relative loads should be matched before standard immediate-offset loads as
7040b57cec5SDimitry Andric// it means we avoid having to move SP to another register.
7050b57cec5SDimitry Andriclet canFoldAsLoad = 1 in
7060b57cec5SDimitry Andricdef tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
7070b57cec5SDimitry Andric                    "ldr", "\t$Rt, $addr",
7080b57cec5SDimitry Andric                    [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
7090b57cec5SDimitry Andric              T1LdStSP<{1,?,?}>, Sched<[WriteLd]> {
7100b57cec5SDimitry Andric  bits<3> Rt;
7110b57cec5SDimitry Andric  bits<8> addr;
7120b57cec5SDimitry Andric  let Inst{10-8} = Rt;
7130b57cec5SDimitry Andric  let Inst{7-0} = addr;
7140b57cec5SDimitry Andric}
7150b57cec5SDimitry Andric
7160b57cec5SDimitry Andric// Loads: reg/reg and reg/imm5
7170b57cec5SDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1 in
7180b57cec5SDimitry Andricmulticlass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
7190b57cec5SDimitry Andric                              Operand AddrMode_r, Operand AddrMode_i,
7200b57cec5SDimitry Andric                              AddrMode am, InstrItinClass itin_r,
7210b57cec5SDimitry Andric                              InstrItinClass itin_i, string asm,
7220b57cec5SDimitry Andric                              PatFrag opnode> {
7230b57cec5SDimitry Andric  // Immediate-offset loads should be matched before register-offset loads as
7240b57cec5SDimitry Andric  // when the offset is a constant it's simpler to first check if it fits in the
7250b57cec5SDimitry Andric  // immediate offset field then fall back to register-offset if it doesn't.
7260b57cec5SDimitry Andric  def i : // reg/imm5
7270b57cec5SDimitry Andric    T1pILdStEncodeImm<imm_opc, 1 /* Load */,
7280b57cec5SDimitry Andric                      (outs tGPR:$Rt), (ins AddrMode_i:$addr),
7290b57cec5SDimitry Andric                      am, itin_i, asm, "\t$Rt, $addr",
7300b57cec5SDimitry Andric                      [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
7310b57cec5SDimitry Andric  // Register-offset loads are matched last.
7320b57cec5SDimitry Andric  def r : // reg/reg
7330b57cec5SDimitry Andric    T1pILdStEncode<reg_opc,
7340b57cec5SDimitry Andric                   (outs tGPR:$Rt), (ins AddrMode_r:$addr),
7350b57cec5SDimitry Andric                   am, itin_r, asm, "\t$Rt, $addr",
7360b57cec5SDimitry Andric                   [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
7370b57cec5SDimitry Andric}
7380b57cec5SDimitry Andric// Stores: reg/reg and reg/imm5
7390b57cec5SDimitry Andricmulticlass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
7400b57cec5SDimitry Andric                              Operand AddrMode_r, Operand AddrMode_i,
7410b57cec5SDimitry Andric                              AddrMode am, InstrItinClass itin_r,
7420b57cec5SDimitry Andric                              InstrItinClass itin_i, string asm,
7430b57cec5SDimitry Andric                              PatFrag opnode> {
7440b57cec5SDimitry Andric  def i : // reg/imm5
7450b57cec5SDimitry Andric    T1pILdStEncodeImm<imm_opc, 0 /* Store */,
7460b57cec5SDimitry Andric                      (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
7470b57cec5SDimitry Andric                      am, itin_i, asm, "\t$Rt, $addr",
7480b57cec5SDimitry Andric                      [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
7490b57cec5SDimitry Andric  def r : // reg/reg
7500b57cec5SDimitry Andric    T1pILdStEncode<reg_opc,
7510b57cec5SDimitry Andric                   (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
7520b57cec5SDimitry Andric                   am, itin_r, asm, "\t$Rt, $addr",
7530b57cec5SDimitry Andric                   [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
7540b57cec5SDimitry Andric}
7550b57cec5SDimitry Andric
7560b57cec5SDimitry Andric// A8.6.57 & A8.6.60
7570b57cec5SDimitry Andricdefm tLDR  : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rr,
7580b57cec5SDimitry Andric                                t_addrmode_is4, AddrModeT1_4,
7590b57cec5SDimitry Andric                                IIC_iLoad_r, IIC_iLoad_i, "ldr",
7600b57cec5SDimitry Andric                                load>, Sched<[WriteLd]>;
7610b57cec5SDimitry Andric
7620b57cec5SDimitry Andric// A8.6.64 & A8.6.61
7630b57cec5SDimitry Andricdefm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rr,
7640b57cec5SDimitry Andric                                t_addrmode_is1, AddrModeT1_1,
7650b57cec5SDimitry Andric                                IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
7660b57cec5SDimitry Andric                                zextloadi8>, Sched<[WriteLd]>;
7670b57cec5SDimitry Andric
7680b57cec5SDimitry Andric// A8.6.76 & A8.6.73
7690b57cec5SDimitry Andricdefm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rr,
7700b57cec5SDimitry Andric                                t_addrmode_is2, AddrModeT1_2,
7710b57cec5SDimitry Andric                                IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
7720b57cec5SDimitry Andric                                zextloadi16>, Sched<[WriteLd]>;
7730b57cec5SDimitry Andric
7740b57cec5SDimitry Andriclet AddedComplexity = 10 in
7750b57cec5SDimitry Andricdef tLDRSB :                    // A8.6.80
7760b57cec5SDimitry Andric  T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr_sext:$addr),
7770b57cec5SDimitry Andric                 AddrModeT1_1, IIC_iLoad_bh_r,
7780b57cec5SDimitry Andric                 "ldrsb", "\t$Rt, $addr",
7790b57cec5SDimitry Andric                 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr_sext:$addr))]>, Sched<[WriteLd]>;
7800b57cec5SDimitry Andric
7810b57cec5SDimitry Andriclet AddedComplexity = 10 in
7820b57cec5SDimitry Andricdef tLDRSH :                    // A8.6.84
7830b57cec5SDimitry Andric  T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr_sext:$addr),
7840b57cec5SDimitry Andric                 AddrModeT1_2, IIC_iLoad_bh_r,
7850b57cec5SDimitry Andric                 "ldrsh", "\t$Rt, $addr",
7860b57cec5SDimitry Andric                 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr_sext:$addr))]>, Sched<[WriteLd]>;
7870b57cec5SDimitry Andric
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andricdef tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
7900b57cec5SDimitry Andric                    "str", "\t$Rt, $addr",
7910b57cec5SDimitry Andric                    [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
7920b57cec5SDimitry Andric              T1LdStSP<{0,?,?}>, Sched<[WriteST]> {
7930b57cec5SDimitry Andric  bits<3> Rt;
7940b57cec5SDimitry Andric  bits<8> addr;
7950b57cec5SDimitry Andric  let Inst{10-8} = Rt;
7960b57cec5SDimitry Andric  let Inst{7-0} = addr;
7970b57cec5SDimitry Andric}
7980b57cec5SDimitry Andric
7990b57cec5SDimitry Andric// A8.6.194 & A8.6.192
8000b57cec5SDimitry Andricdefm tSTR  : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rr,
8010b57cec5SDimitry Andric                                t_addrmode_is4, AddrModeT1_4,
8020b57cec5SDimitry Andric                                IIC_iStore_r, IIC_iStore_i, "str",
8030b57cec5SDimitry Andric                                store>, Sched<[WriteST]>;
8040b57cec5SDimitry Andric
8050b57cec5SDimitry Andric// A8.6.197 & A8.6.195
8060b57cec5SDimitry Andricdefm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rr,
8070b57cec5SDimitry Andric                                t_addrmode_is1, AddrModeT1_1,
8080b57cec5SDimitry Andric                                IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
8090b57cec5SDimitry Andric                                truncstorei8>, Sched<[WriteST]>;
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andric// A8.6.207 & A8.6.205
8120b57cec5SDimitry Andricdefm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rr,
8130b57cec5SDimitry Andric                               t_addrmode_is2, AddrModeT1_2,
8140b57cec5SDimitry Andric                               IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
8150b57cec5SDimitry Andric                               truncstorei16>, Sched<[WriteST]>;
8160b57cec5SDimitry Andric
8170b57cec5SDimitry Andric
8180b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
8190b57cec5SDimitry Andric//  Load / store multiple Instructions.
8200b57cec5SDimitry Andric//
8210b57cec5SDimitry Andric
8220b57cec5SDimitry Andric// These require base address to be written back or one of the loaded regs.
8230b57cec5SDimitry Andriclet hasSideEffects = 0 in {
8240b57cec5SDimitry Andric
8250b57cec5SDimitry Andriclet mayLoad = 1, hasExtraDefRegAllocReq = 1, variadicOpsAreDefs = 1 in
8260b57cec5SDimitry Andricdef tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
8270b57cec5SDimitry Andric        IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
8280b57cec5SDimitry Andric  bits<3> Rn;
8290b57cec5SDimitry Andric  bits<8> regs;
8300b57cec5SDimitry Andric  let Inst{10-8} = Rn;
8310b57cec5SDimitry Andric  let Inst{7-0}  = regs;
8320b57cec5SDimitry Andric}
8330b57cec5SDimitry Andric
8340b57cec5SDimitry Andric// Writeback version is just a pseudo, as there's no encoding difference.
8350b57cec5SDimitry Andric// Writeback happens iff the base register is not in the destination register
8360b57cec5SDimitry Andric// list.
8370b57cec5SDimitry Andriclet mayLoad = 1, hasExtraDefRegAllocReq = 1 in
8380b57cec5SDimitry Andricdef tLDMIA_UPD :
8390b57cec5SDimitry Andric    InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
8400b57cec5SDimitry Andric                 "$Rn = $wb", IIC_iLoad_mu>,
8410b57cec5SDimitry Andric    PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
8420b57cec5SDimitry Andric  let Size = 2;
8430b57cec5SDimitry Andric  let OutOperandList = (outs tGPR:$wb);
8440b57cec5SDimitry Andric  let InOperandList = (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops);
8450b57cec5SDimitry Andric  let Pattern = [];
8460b57cec5SDimitry Andric  let isCodeGenOnly = 1;
8470b57cec5SDimitry Andric  let isPseudo = 1;
8480b57cec5SDimitry Andric  list<Predicate> Predicates = [IsThumb];
8490b57cec5SDimitry Andric}
8500b57cec5SDimitry Andric
8510b57cec5SDimitry Andric// There is no non-writeback version of STM for Thumb.
8520b57cec5SDimitry Andriclet mayStore = 1, hasExtraSrcRegAllocReq = 1 in
8530b57cec5SDimitry Andricdef tSTMIA_UPD : Thumb1I<(outs tGPR:$wb),
8540b57cec5SDimitry Andric                         (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
8550b57cec5SDimitry Andric                         AddrModeNone, 2, IIC_iStore_mu,
8560b57cec5SDimitry Andric                         "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
8570b57cec5SDimitry Andric                     T1Encoding<{1,1,0,0,0,?}> {
8580b57cec5SDimitry Andric  bits<3> Rn;
8590b57cec5SDimitry Andric  bits<8> regs;
8600b57cec5SDimitry Andric  let Inst{10-8} = Rn;
8610b57cec5SDimitry Andric  let Inst{7-0}  = regs;
8620b57cec5SDimitry Andric}
8630b57cec5SDimitry Andric
8640b57cec5SDimitry Andric} // hasSideEffects
8650b57cec5SDimitry Andric
8660b57cec5SDimitry Andricdef : InstAlias<"ldm${p} $Rn!, $regs",
8670b57cec5SDimitry Andric                (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs), 0>,
8680b57cec5SDimitry Andric        Requires<[IsThumb, IsThumb1Only]>;
8690b57cec5SDimitry Andric
8700b57cec5SDimitry Andriclet mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1,
8710b57cec5SDimitry Andric    variadicOpsAreDefs = 1 in
8720b57cec5SDimitry Andricdef tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
8730b57cec5SDimitry Andric               IIC_iPop,
8740b57cec5SDimitry Andric               "pop${p}\t$regs", []>,
8750b57cec5SDimitry Andric           T1Misc<{1,1,0,?,?,?,?}>, Sched<[WriteLd]> {
8760b57cec5SDimitry Andric  bits<16> regs;
8770b57cec5SDimitry Andric  let Inst{8}   = regs{15};
8780b57cec5SDimitry Andric  let Inst{7-0} = regs{7-0};
8790b57cec5SDimitry Andric}
8800b57cec5SDimitry Andric
8810b57cec5SDimitry Andriclet mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
8820b57cec5SDimitry Andricdef tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
8830b57cec5SDimitry Andric                IIC_iStore_m,
8840b57cec5SDimitry Andric                "push${p}\t$regs", []>,
8850b57cec5SDimitry Andric            T1Misc<{0,1,0,?,?,?,?}>, Sched<[WriteST]> {
8860b57cec5SDimitry Andric  bits<16> regs;
8870b57cec5SDimitry Andric  let Inst{8}   = regs{14};
8880b57cec5SDimitry Andric  let Inst{7-0} = regs{7-0};
8890b57cec5SDimitry Andric}
8900b57cec5SDimitry Andric
8910b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
8920b57cec5SDimitry Andric//  Arithmetic Instructions.
8930b57cec5SDimitry Andric//
8940b57cec5SDimitry Andric
8950b57cec5SDimitry Andric// Helper classes for encoding T1pI patterns:
8960b57cec5SDimitry Andricclass T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
8970b57cec5SDimitry Andric                   string opc, string asm, list<dag> pattern>
8980b57cec5SDimitry Andric    : T1pI<oops, iops, itin, opc, asm, pattern>,
8990b57cec5SDimitry Andric      T1DataProcessing<opA> {
9000b57cec5SDimitry Andric  bits<3> Rm;
9010b57cec5SDimitry Andric  bits<3> Rn;
9020b57cec5SDimitry Andric  let Inst{5-3} = Rm;
9030b57cec5SDimitry Andric  let Inst{2-0} = Rn;
9040b57cec5SDimitry Andric}
9050b57cec5SDimitry Andricclass T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
9060b57cec5SDimitry Andric                     string opc, string asm, list<dag> pattern>
9070b57cec5SDimitry Andric    : T1pI<oops, iops, itin, opc, asm, pattern>,
9080b57cec5SDimitry Andric      T1Misc<opA> {
9090b57cec5SDimitry Andric  bits<3> Rm;
9100b57cec5SDimitry Andric  bits<3> Rd;
9110b57cec5SDimitry Andric  let Inst{5-3} = Rm;
9120b57cec5SDimitry Andric  let Inst{2-0} = Rd;
9130b57cec5SDimitry Andric}
9140b57cec5SDimitry Andric
9150b57cec5SDimitry Andric// Helper classes for encoding T1sI patterns:
9160b57cec5SDimitry Andricclass T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
9170b57cec5SDimitry Andric                   string opc, string asm, list<dag> pattern>
9180b57cec5SDimitry Andric    : T1sI<oops, iops, itin, opc, asm, pattern>,
9190b57cec5SDimitry Andric      T1DataProcessing<opA> {
9200b57cec5SDimitry Andric  bits<3> Rd;
9210b57cec5SDimitry Andric  bits<3> Rn;
9220b57cec5SDimitry Andric  let Inst{5-3} = Rn;
9230b57cec5SDimitry Andric  let Inst{2-0} = Rd;
9240b57cec5SDimitry Andric}
9250b57cec5SDimitry Andricclass T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
9260b57cec5SDimitry Andric                    string opc, string asm, list<dag> pattern>
9270b57cec5SDimitry Andric    : T1sI<oops, iops, itin, opc, asm, pattern>,
9280b57cec5SDimitry Andric      T1General<opA> {
9290b57cec5SDimitry Andric  bits<3> Rm;
9300b57cec5SDimitry Andric  bits<3> Rn;
9310b57cec5SDimitry Andric  bits<3> Rd;
9320b57cec5SDimitry Andric  let Inst{8-6} = Rm;
9330b57cec5SDimitry Andric  let Inst{5-3} = Rn;
9340b57cec5SDimitry Andric  let Inst{2-0} = Rd;
9350b57cec5SDimitry Andric}
9360b57cec5SDimitry Andricclass T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
9370b57cec5SDimitry Andric                       string opc, string asm, list<dag> pattern>
9380b57cec5SDimitry Andric    : T1sI<oops, iops, itin, opc, asm, pattern>,
9390b57cec5SDimitry Andric      T1General<opA> {
9400b57cec5SDimitry Andric  bits<3> Rd;
9410b57cec5SDimitry Andric  bits<3> Rm;
9420b57cec5SDimitry Andric  let Inst{5-3} = Rm;
9430b57cec5SDimitry Andric  let Inst{2-0} = Rd;
9440b57cec5SDimitry Andric}
9450b57cec5SDimitry Andric
9460b57cec5SDimitry Andric// Helper classes for encoding T1sIt patterns:
9470b57cec5SDimitry Andricclass T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
9480b57cec5SDimitry Andric                    string opc, string asm, list<dag> pattern>
9490b57cec5SDimitry Andric    : T1sIt<oops, iops, itin, opc, asm, pattern>,
9500b57cec5SDimitry Andric      T1DataProcessing<opA> {
9510b57cec5SDimitry Andric  bits<3> Rdn;
9520b57cec5SDimitry Andric  bits<3> Rm;
9530b57cec5SDimitry Andric  let Inst{5-3} = Rm;
9540b57cec5SDimitry Andric  let Inst{2-0} = Rdn;
9550b57cec5SDimitry Andric}
9560b57cec5SDimitry Andricclass T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
9570b57cec5SDimitry Andric                        string opc, string asm, list<dag> pattern>
9580b57cec5SDimitry Andric    : T1sIt<oops, iops, itin, opc, asm, pattern>,
9590b57cec5SDimitry Andric      T1General<opA> {
9600b57cec5SDimitry Andric  bits<3> Rdn;
9610b57cec5SDimitry Andric  bits<8> imm8;
9620b57cec5SDimitry Andric  let Inst{10-8} = Rdn;
9630b57cec5SDimitry Andric  let Inst{7-0}  = imm8;
9640b57cec5SDimitry Andric}
9650b57cec5SDimitry Andric
9660b57cec5SDimitry Andriclet isAdd = 1 in {
9670b57cec5SDimitry Andric  // Add with carry register
9680b57cec5SDimitry Andric  let isCommutable = 1, Uses = [CPSR] in
9690b57cec5SDimitry Andric  def tADC :                      // A8.6.2
9700b57cec5SDimitry Andric    T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
9710b57cec5SDimitry Andric                  "adc", "\t$Rdn, $Rm",
9720b57cec5SDimitry Andric                  []>, Sched<[WriteALU]>;
9730b57cec5SDimitry Andric
9740b57cec5SDimitry Andric  // Add immediate
9750b57cec5SDimitry Andric  def tADDi3 :                    // A8.6.4 T1
9760b57cec5SDimitry Andric    T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
9770b57cec5SDimitry Andric                     IIC_iALUi,
9780b57cec5SDimitry Andric                     "add", "\t$Rd, $Rm, $imm3",
9790b57cec5SDimitry Andric                     [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
9800b57cec5SDimitry Andric                     Sched<[WriteALU]> {
9810b57cec5SDimitry Andric    bits<3> imm3;
9820b57cec5SDimitry Andric    let Inst{8-6} = imm3;
9830b57cec5SDimitry Andric  }
9840b57cec5SDimitry Andric
9850b57cec5SDimitry Andric  def tADDi8 :                    // A8.6.4 T2
9860b57cec5SDimitry Andric    T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
98706c3fb27SDimitry Andric                      (ins tGPR:$Rn, imm0_255_expr:$imm8), IIC_iALUi,
9880b57cec5SDimitry Andric                      "add", "\t$Rdn, $imm8",
98906c3fb27SDimitry Andric                      [(set tGPR:$Rdn, (add tGPR:$Rn, imm0_255_expr:$imm8))]>,
9900b57cec5SDimitry Andric                      Sched<[WriteALU]>;
9910b57cec5SDimitry Andric
9920b57cec5SDimitry Andric  // Add register
9930b57cec5SDimitry Andric  let isCommutable = 1 in
9940b57cec5SDimitry Andric  def tADDrr :                    // A8.6.6 T1
9950b57cec5SDimitry Andric    T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
9960b57cec5SDimitry Andric                  IIC_iALUr,
9970b57cec5SDimitry Andric                  "add", "\t$Rd, $Rn, $Rm",
99806c3fb27SDimitry Andric                  [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>,
99906c3fb27SDimitry Andric                  Sched<[WriteALU]>;
10000b57cec5SDimitry Andric
10010b57cec5SDimitry Andric  /// Similar to the above except these set the 's' bit so the
10020b57cec5SDimitry Andric  /// instruction modifies the CPSR register.
10030b57cec5SDimitry Andric  ///
10040b57cec5SDimitry Andric  /// These opcodes will be converted to the real non-S opcodes by
10050b57cec5SDimitry Andric  /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
10060b57cec5SDimitry Andric  let hasPostISelHook = 1, Defs = [CPSR] in {
10070b57cec5SDimitry Andric    let isCommutable = 1, Uses = [CPSR] in
10080b57cec5SDimitry Andric    def tADCS : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
10090b57cec5SDimitry Andric                            2, IIC_iALUr,
10100b57cec5SDimitry Andric                            [(set tGPR:$Rdn, CPSR, (ARMadde tGPR:$Rn, tGPR:$Rm,
10110b57cec5SDimitry Andric                                                            CPSR))]>,
10120b57cec5SDimitry Andric                Requires<[IsThumb1Only]>,
10130b57cec5SDimitry Andric                Sched<[WriteALU]>;
10140b57cec5SDimitry Andric
10150b57cec5SDimitry Andric    def tADDSi3 : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
10160b57cec5SDimitry Andric                              2, IIC_iALUi,
10170b57cec5SDimitry Andric                              [(set tGPR:$Rd, CPSR, (ARMaddc tGPR:$Rm,
10180b57cec5SDimitry Andric                                                             imm0_7:$imm3))]>,
10190b57cec5SDimitry Andric                  Requires<[IsThumb1Only]>,
10200b57cec5SDimitry Andric                  Sched<[WriteALU]>;
10210b57cec5SDimitry Andric
102206c3fb27SDimitry Andric    def tADDSi8 : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, imm0_255_expr:$imm8),
10230b57cec5SDimitry Andric                              2, IIC_iALUi,
10240b57cec5SDimitry Andric                              [(set tGPR:$Rdn, CPSR, (ARMaddc tGPR:$Rn,
102506c3fb27SDimitry Andric                                                      imm0_255_expr:$imm8))]>,
10260b57cec5SDimitry Andric                  Requires<[IsThumb1Only]>,
10270b57cec5SDimitry Andric                  Sched<[WriteALU]>;
10280b57cec5SDimitry Andric
10290b57cec5SDimitry Andric    let isCommutable = 1 in
10300b57cec5SDimitry Andric    def tADDSrr : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
10310b57cec5SDimitry Andric                              2, IIC_iALUr,
10320b57cec5SDimitry Andric                              [(set tGPR:$Rd, CPSR, (ARMaddc tGPR:$Rn,
10330b57cec5SDimitry Andric                                                             tGPR:$Rm))]>,
10340b57cec5SDimitry Andric                  Requires<[IsThumb1Only]>,
10350b57cec5SDimitry Andric                  Sched<[WriteALU]>;
10360b57cec5SDimitry Andric  }
10370b57cec5SDimitry Andric
10380b57cec5SDimitry Andric  let hasSideEffects = 0 in
10390b57cec5SDimitry Andric  def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
10400b57cec5SDimitry Andric                       "add", "\t$Rdn, $Rm", []>,
10410b57cec5SDimitry Andric                 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
10420b57cec5SDimitry Andric    // A8.6.6 T2
10430b57cec5SDimitry Andric    bits<4> Rdn;
10440b57cec5SDimitry Andric    bits<4> Rm;
10450b57cec5SDimitry Andric    let Inst{7}   = Rdn{3};
10460b57cec5SDimitry Andric    let Inst{6-3} = Rm;
10470b57cec5SDimitry Andric    let Inst{2-0} = Rdn{2-0};
10480b57cec5SDimitry Andric  }
10490b57cec5SDimitry Andric}
10500b57cec5SDimitry Andric
10510b57cec5SDimitry Andric// Thumb has more flexible short encodings for ADD than ORR, so use those where
10520b57cec5SDimitry Andric// possible.
10530b57cec5SDimitry Andricdef : T1Pat<(or AddLikeOrOp:$Rn, imm0_7:$imm), (tADDi3 $Rn, imm0_7:$imm)>;
10540b57cec5SDimitry Andric
10550b57cec5SDimitry Andricdef : T1Pat<(or AddLikeOrOp:$Rn, imm8_255:$imm), (tADDi8 $Rn, imm8_255:$imm)>;
10560b57cec5SDimitry Andric
10570b57cec5SDimitry Andricdef : T1Pat<(or AddLikeOrOp:$Rn, tGPR:$Rm), (tADDrr $Rn, $Rm)>;
10580b57cec5SDimitry Andric
10590b57cec5SDimitry Andric
10600b57cec5SDimitry Andricdef : tInstAlias <"add${s}${p} $Rdn, $Rm",
10610b57cec5SDimitry Andric                 (tADDrr tGPR:$Rdn,s_cc_out:$s, tGPR:$Rdn, tGPR:$Rm, pred:$p)>;
10620b57cec5SDimitry Andric
10630b57cec5SDimitry Andricdef : tInstSubst<"sub${s}${p} $rd, $rn, $imm",
10640b57cec5SDimitry Andric                 (tADDi3 tGPR:$rd, s_cc_out:$s, tGPR:$rn, mod_imm1_7_neg:$imm, pred:$p)>;
10650b57cec5SDimitry Andricdef : tInstSubst<"sub${s}${p} $rdn, $imm",
10660b57cec5SDimitry Andric                 (tADDi8 tGPR:$rdn, s_cc_out:$s, mod_imm8_255_neg:$imm, pred:$p)>;
10670b57cec5SDimitry Andric
10680b57cec5SDimitry Andric
10690b57cec5SDimitry Andric// AND register
10700b57cec5SDimitry Andriclet isCommutable = 1 in
10710b57cec5SDimitry Andricdef tAND :                      // A8.6.12
10720b57cec5SDimitry Andric  T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
10730b57cec5SDimitry Andric                IIC_iBITr,
10740b57cec5SDimitry Andric                "and", "\t$Rdn, $Rm",
10750b57cec5SDimitry Andric                [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
10760b57cec5SDimitry Andric
10770b57cec5SDimitry Andric// ASR immediate
10780b57cec5SDimitry Andricdef tASRri :                    // A8.6.14
10790b57cec5SDimitry Andric  T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
10800b57cec5SDimitry Andric                   IIC_iMOVsi,
10810b57cec5SDimitry Andric                   "asr", "\t$Rd, $Rm, $imm5",
10820b57cec5SDimitry Andric                   [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
10830b57cec5SDimitry Andric                   Sched<[WriteALU]> {
10840b57cec5SDimitry Andric  bits<5> imm5;
10850b57cec5SDimitry Andric  let Inst{10-6} = imm5;
10860b57cec5SDimitry Andric}
10870b57cec5SDimitry Andric
10880b57cec5SDimitry Andric// ASR register
10890b57cec5SDimitry Andricdef tASRrr :                    // A8.6.15
10900b57cec5SDimitry Andric  T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
10910b57cec5SDimitry Andric                IIC_iMOVsr,
10920b57cec5SDimitry Andric                "asr", "\t$Rdn, $Rm",
10930b57cec5SDimitry Andric                [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
10940b57cec5SDimitry Andric
10950b57cec5SDimitry Andric// BIC register
10960b57cec5SDimitry Andricdef tBIC :                      // A8.6.20
10970b57cec5SDimitry Andric  T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
10980b57cec5SDimitry Andric                IIC_iBITr,
10990b57cec5SDimitry Andric                "bic", "\t$Rdn, $Rm",
11000b57cec5SDimitry Andric                [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
11010b57cec5SDimitry Andric                Sched<[WriteALU]>;
11020b57cec5SDimitry Andric
11030b57cec5SDimitry Andric// CMN register
11040b57cec5SDimitry Andriclet isCompare = 1, Defs = [CPSR] in {
11050b57cec5SDimitry Andric//FIXME: Disable CMN, as CCodes are backwards from compare expectations
11060b57cec5SDimitry Andric//       Compare-to-zero still works out, just not the relationals
11070b57cec5SDimitry Andric//def tCMN :                     // A8.6.33
11080b57cec5SDimitry Andric//  T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
11090b57cec5SDimitry Andric//               IIC_iCMPr,
11100b57cec5SDimitry Andric//               "cmn", "\t$lhs, $rhs",
11110b57cec5SDimitry Andric//               [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
11120b57cec5SDimitry Andric
11130b57cec5SDimitry Andricdef tCMNz :                     // A8.6.33
11140b57cec5SDimitry Andric  T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
11150b57cec5SDimitry Andric               IIC_iCMPr,
11160b57cec5SDimitry Andric               "cmn", "\t$Rn, $Rm",
11170b57cec5SDimitry Andric               [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
11180b57cec5SDimitry Andric
11190b57cec5SDimitry Andric} // isCompare = 1, Defs = [CPSR]
11200b57cec5SDimitry Andric
11210b57cec5SDimitry Andric// CMP immediate
11220b57cec5SDimitry Andriclet isCompare = 1, Defs = [CPSR] in {
11230b57cec5SDimitry Andricdef tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
11240b57cec5SDimitry Andric                  "cmp", "\t$Rn, $imm8",
11250b57cec5SDimitry Andric                  [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
11260b57cec5SDimitry Andric             T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
11270b57cec5SDimitry Andric  // A8.6.35
11280b57cec5SDimitry Andric  bits<3> Rn;
11290b57cec5SDimitry Andric  bits<8> imm8;
11300b57cec5SDimitry Andric  let Inst{10-8} = Rn;
11310b57cec5SDimitry Andric  let Inst{7-0}  = imm8;
11320b57cec5SDimitry Andric}
11330b57cec5SDimitry Andric
11340b57cec5SDimitry Andric// CMP register
11350b57cec5SDimitry Andricdef tCMPr :                     // A8.6.36 T1
11360b57cec5SDimitry Andric  T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
11370b57cec5SDimitry Andric               IIC_iCMPr,
11380b57cec5SDimitry Andric               "cmp", "\t$Rn, $Rm",
11390b57cec5SDimitry Andric               [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
11400b57cec5SDimitry Andric
11410b57cec5SDimitry Andricdef tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
11420b57cec5SDimitry Andric                   "cmp", "\t$Rn, $Rm", []>,
11430b57cec5SDimitry Andric              T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
11440b57cec5SDimitry Andric  // A8.6.36 T2
11450b57cec5SDimitry Andric  bits<4> Rm;
11460b57cec5SDimitry Andric  bits<4> Rn;
11470b57cec5SDimitry Andric  let Inst{7}   = Rn{3};
11480b57cec5SDimitry Andric  let Inst{6-3} = Rm;
11490b57cec5SDimitry Andric  let Inst{2-0} = Rn{2-0};
11500b57cec5SDimitry Andric}
11510b57cec5SDimitry Andric} // isCompare = 1, Defs = [CPSR]
11520b57cec5SDimitry Andric
11530b57cec5SDimitry Andric
11540b57cec5SDimitry Andric// XOR register
11550b57cec5SDimitry Andriclet isCommutable = 1 in
11560b57cec5SDimitry Andricdef tEOR :                      // A8.6.45
11570b57cec5SDimitry Andric  T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
11580b57cec5SDimitry Andric                IIC_iBITr,
11590b57cec5SDimitry Andric                "eor", "\t$Rdn, $Rm",
11600b57cec5SDimitry Andric                [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
11610b57cec5SDimitry Andric
11620b57cec5SDimitry Andric// LSL immediate
11630b57cec5SDimitry Andricdef tLSLri :                    // A8.6.88
11640b57cec5SDimitry Andric  T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
11650b57cec5SDimitry Andric                   IIC_iMOVsi,
11660b57cec5SDimitry Andric                   "lsl", "\t$Rd, $Rm, $imm5",
11670b57cec5SDimitry Andric                   [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
11680b57cec5SDimitry Andric                   Sched<[WriteALU]> {
11690b57cec5SDimitry Andric  bits<5> imm5;
11700b57cec5SDimitry Andric  let Inst{10-6} = imm5;
11710b57cec5SDimitry Andric}
11720b57cec5SDimitry Andric
11730b57cec5SDimitry Andric// LSL register
11740b57cec5SDimitry Andricdef tLSLrr :                    // A8.6.89
11750b57cec5SDimitry Andric  T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
11760b57cec5SDimitry Andric                IIC_iMOVsr,
11770b57cec5SDimitry Andric                "lsl", "\t$Rdn, $Rm",
11780b57cec5SDimitry Andric                [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
11790b57cec5SDimitry Andric
11800b57cec5SDimitry Andric// LSR immediate
11810b57cec5SDimitry Andricdef tLSRri :                    // A8.6.90
11820b57cec5SDimitry Andric  T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
11830b57cec5SDimitry Andric                   IIC_iMOVsi,
11840b57cec5SDimitry Andric                   "lsr", "\t$Rd, $Rm, $imm5",
11850b57cec5SDimitry Andric                   [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
11860b57cec5SDimitry Andric                   Sched<[WriteALU]> {
11870b57cec5SDimitry Andric  bits<5> imm5;
11880b57cec5SDimitry Andric  let Inst{10-6} = imm5;
11890b57cec5SDimitry Andric}
11900b57cec5SDimitry Andric
11910b57cec5SDimitry Andric// LSR register
11920b57cec5SDimitry Andricdef tLSRrr :                    // A8.6.91
11930b57cec5SDimitry Andric  T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
11940b57cec5SDimitry Andric                IIC_iMOVsr,
11950b57cec5SDimitry Andric                "lsr", "\t$Rdn, $Rm",
11960b57cec5SDimitry Andric                [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
11970b57cec5SDimitry Andric
11980b57cec5SDimitry Andric// Move register
11990b57cec5SDimitry Andriclet isMoveImm = 1 in
120006c3fb27SDimitry Andricdef tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255_expr:$imm8), IIC_iMOVi,
12010b57cec5SDimitry Andric                  "mov", "\t$Rd, $imm8",
120206c3fb27SDimitry Andric                  [(set tGPR:$Rd, imm0_255_expr:$imm8)]>,
12030b57cec5SDimitry Andric             T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
12040b57cec5SDimitry Andric  // A8.6.96
12050b57cec5SDimitry Andric  bits<3> Rd;
12060b57cec5SDimitry Andric  bits<8> imm8;
12070b57cec5SDimitry Andric  let Inst{10-8} = Rd;
12080b57cec5SDimitry Andric  let Inst{7-0}  = imm8;
12090b57cec5SDimitry Andric}
12100b57cec5SDimitry Andric// Because we have an explicit tMOVSr below, we need an alias to handle
12110b57cec5SDimitry Andric// the immediate "movs" form here. Blech.
121206c3fb27SDimitry Andricdef : tInstAlias <"movs $Rdn, $imm8",
1213*0fca6ea1SDimitry Andric                 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255_expr:$imm8, 14, zero_reg)>;
12140b57cec5SDimitry Andric
12150b57cec5SDimitry Andric// A7-73: MOV(2) - mov setting flag.
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andriclet hasSideEffects = 0, isMoveReg = 1 in {
12180b57cec5SDimitry Andricdef tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
12190b57cec5SDimitry Andric                      2, IIC_iMOVr,
12200b57cec5SDimitry Andric                      "mov", "\t$Rd, $Rm", "", []>,
12210b57cec5SDimitry Andric                  T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
12220b57cec5SDimitry Andric  // A8.6.97
12230b57cec5SDimitry Andric  bits<4> Rd;
12240b57cec5SDimitry Andric  bits<4> Rm;
12250b57cec5SDimitry Andric  let Inst{7}   = Rd{3};
12260b57cec5SDimitry Andric  let Inst{6-3} = Rm;
12270b57cec5SDimitry Andric  let Inst{2-0} = Rd{2-0};
12280b57cec5SDimitry Andric}
12290b57cec5SDimitry Andriclet Defs = [CPSR] in
12300b57cec5SDimitry Andricdef tMOVSr      : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
12310b57cec5SDimitry Andric                      "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
12320b57cec5SDimitry Andric  // A8.6.97
12330b57cec5SDimitry Andric  bits<3> Rd;
12340b57cec5SDimitry Andric  bits<3> Rm;
12350b57cec5SDimitry Andric  let Inst{15-6} = 0b0000000000;
12360b57cec5SDimitry Andric  let Inst{5-3}  = Rm;
12370b57cec5SDimitry Andric  let Inst{2-0}  = Rd;
12380b57cec5SDimitry Andric}
12390b57cec5SDimitry Andric} // hasSideEffects
12400b57cec5SDimitry Andric
12410b57cec5SDimitry Andric// Multiply register
12420b57cec5SDimitry Andriclet isCommutable = 1 in
12430b57cec5SDimitry Andricdef tMUL :                      // A8.6.105 T1
12440b57cec5SDimitry Andric  Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
12450b57cec5SDimitry Andric           IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
12460b57cec5SDimitry Andric           [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
12470b57cec5SDimitry Andric      T1DataProcessing<0b1101>, Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
12480b57cec5SDimitry Andric  bits<3> Rd;
12490b57cec5SDimitry Andric  bits<3> Rn;
12500b57cec5SDimitry Andric  let Inst{5-3} = Rn;
12510b57cec5SDimitry Andric  let Inst{2-0} = Rd;
12520b57cec5SDimitry Andric  let AsmMatchConverter = "cvtThumbMultiply";
12530b57cec5SDimitry Andric}
12540b57cec5SDimitry Andric
12550b57cec5SDimitry Andricdef :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
12560b57cec5SDimitry Andric                                               pred:$p)>;
12570b57cec5SDimitry Andric
12580b57cec5SDimitry Andric// Move inverse register
12590b57cec5SDimitry Andricdef tMVN :                      // A8.6.107
12600b57cec5SDimitry Andric  T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
12610b57cec5SDimitry Andric               "mvn", "\t$Rd, $Rn",
12620b57cec5SDimitry Andric               [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
12630b57cec5SDimitry Andric
12640b57cec5SDimitry Andric// Bitwise or register
12650b57cec5SDimitry Andriclet isCommutable = 1 in
12660b57cec5SDimitry Andricdef tORR :                      // A8.6.114
12670b57cec5SDimitry Andric  T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
12680b57cec5SDimitry Andric                IIC_iBITr,
12690b57cec5SDimitry Andric                "orr", "\t$Rdn, $Rm",
12700b57cec5SDimitry Andric                [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
12710b57cec5SDimitry Andric
12720b57cec5SDimitry Andric// Swaps
12730b57cec5SDimitry Andricdef tREV :                      // A8.6.134
12740b57cec5SDimitry Andric  T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
12750b57cec5SDimitry Andric                 IIC_iUNAr,
12760b57cec5SDimitry Andric                 "rev", "\t$Rd, $Rm",
12770b57cec5SDimitry Andric                 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
12780b57cec5SDimitry Andric                 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
12790b57cec5SDimitry Andric
12800b57cec5SDimitry Andricdef tREV16 :                    // A8.6.135
12810b57cec5SDimitry Andric  T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
12820b57cec5SDimitry Andric                 IIC_iUNAr,
12830b57cec5SDimitry Andric                 "rev16", "\t$Rd, $Rm",
12840b57cec5SDimitry Andric             [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
12850b57cec5SDimitry Andric                Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
12860b57cec5SDimitry Andric
12870b57cec5SDimitry Andricdef tREVSH :                    // A8.6.136
12880b57cec5SDimitry Andric  T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
12890b57cec5SDimitry Andric                 IIC_iUNAr,
12900b57cec5SDimitry Andric                 "revsh", "\t$Rd, $Rm",
12910b57cec5SDimitry Andric                 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
12920b57cec5SDimitry Andric                 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
12930b57cec5SDimitry Andric
12940b57cec5SDimitry Andric// Rotate right register
12950b57cec5SDimitry Andricdef tROR :                      // A8.6.139
12960b57cec5SDimitry Andric  T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
12970b57cec5SDimitry Andric                IIC_iMOVsr,
12980b57cec5SDimitry Andric                "ror", "\t$Rdn, $Rm",
12990b57cec5SDimitry Andric                [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
13000b57cec5SDimitry Andric                Sched<[WriteALU]>;
13010b57cec5SDimitry Andric
13020b57cec5SDimitry Andric// Negate register
13030b57cec5SDimitry Andricdef tRSB :                      // A8.6.141
13040b57cec5SDimitry Andric  T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
13050b57cec5SDimitry Andric               IIC_iALUi,
13060b57cec5SDimitry Andric               "rsb", "\t$Rd, $Rn, #0",
13070b57cec5SDimitry Andric               [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
13080b57cec5SDimitry Andric
13090b57cec5SDimitry Andric// Subtract with carry register
13100b57cec5SDimitry Andriclet Uses = [CPSR] in
13110b57cec5SDimitry Andricdef tSBC :                      // A8.6.151
13120b57cec5SDimitry Andric  T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
13130b57cec5SDimitry Andric                IIC_iALUr,
13140b57cec5SDimitry Andric                "sbc", "\t$Rdn, $Rm",
13150b57cec5SDimitry Andric                []>,
13160b57cec5SDimitry Andric                Sched<[WriteALU]>;
13170b57cec5SDimitry Andric
13180b57cec5SDimitry Andric// Subtract immediate
13190b57cec5SDimitry Andricdef tSUBi3 :                    // A8.6.210 T1
13200b57cec5SDimitry Andric  T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
13210b57cec5SDimitry Andric                   IIC_iALUi,
13220b57cec5SDimitry Andric                   "sub", "\t$Rd, $Rm, $imm3",
13230b57cec5SDimitry Andric                   [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
13240b57cec5SDimitry Andric                   Sched<[WriteALU]> {
13250b57cec5SDimitry Andric  bits<3> imm3;
13260b57cec5SDimitry Andric  let Inst{8-6} = imm3;
13270b57cec5SDimitry Andric}
13280b57cec5SDimitry Andric
13290b57cec5SDimitry Andricdef tSUBi8 :                    // A8.6.210 T2
13300b57cec5SDimitry Andric  T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
13310b57cec5SDimitry Andric                    (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
13320b57cec5SDimitry Andric                    "sub", "\t$Rdn, $imm8",
13330b57cec5SDimitry Andric                    [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
13340b57cec5SDimitry Andric                    Sched<[WriteALU]>;
13350b57cec5SDimitry Andric
13360b57cec5SDimitry Andricdef : tInstSubst<"add${s}${p} $rd, $rn, $imm",
13370b57cec5SDimitry Andric                 (tSUBi3 tGPR:$rd, s_cc_out:$s, tGPR:$rn, mod_imm1_7_neg:$imm, pred:$p)>;
13380b57cec5SDimitry Andric
13390b57cec5SDimitry Andric
13400b57cec5SDimitry Andricdef : tInstSubst<"add${s}${p} $rdn, $imm",
13410b57cec5SDimitry Andric                 (tSUBi8 tGPR:$rdn, s_cc_out:$s, mod_imm8_255_neg:$imm, pred:$p)>;
13420b57cec5SDimitry Andric
13430b57cec5SDimitry Andric
13440b57cec5SDimitry Andric// Subtract register
13450b57cec5SDimitry Andricdef tSUBrr :                    // A8.6.212
13460b57cec5SDimitry Andric  T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
13470b57cec5SDimitry Andric                IIC_iALUr,
13480b57cec5SDimitry Andric                "sub", "\t$Rd, $Rn, $Rm",
13490b57cec5SDimitry Andric                [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
13500b57cec5SDimitry Andric                Sched<[WriteALU]>;
13510b57cec5SDimitry Andric
13520b57cec5SDimitry Andricdef : tInstAlias <"sub${s}${p} $Rdn, $Rm",
13530b57cec5SDimitry Andric                 (tSUBrr tGPR:$Rdn,s_cc_out:$s, tGPR:$Rdn, tGPR:$Rm, pred:$p)>;
13540b57cec5SDimitry Andric
13550b57cec5SDimitry Andric/// Similar to the above except these set the 's' bit so the
13560b57cec5SDimitry Andric/// instruction modifies the CPSR register.
13570b57cec5SDimitry Andric///
13580b57cec5SDimitry Andric/// These opcodes will be converted to the real non-S opcodes by
13590b57cec5SDimitry Andric/// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
13600b57cec5SDimitry Andriclet hasPostISelHook = 1, Defs = [CPSR] in {
13610b57cec5SDimitry Andric  let Uses = [CPSR] in
13620b57cec5SDimitry Andric  def tSBCS : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
13630b57cec5SDimitry Andric                          2, IIC_iALUr,
13640b57cec5SDimitry Andric                          [(set tGPR:$Rdn, CPSR, (ARMsube tGPR:$Rn, tGPR:$Rm,
13650b57cec5SDimitry Andric                                                          CPSR))]>,
13660b57cec5SDimitry Andric              Requires<[IsThumb1Only]>,
13670b57cec5SDimitry Andric              Sched<[WriteALU]>;
13680b57cec5SDimitry Andric
13690b57cec5SDimitry Andric  def tSUBSi3 : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
13700b57cec5SDimitry Andric                            2, IIC_iALUi,
13710b57cec5SDimitry Andric                            [(set tGPR:$Rd, CPSR, (ARMsubc tGPR:$Rm,
13720b57cec5SDimitry Andric                                                           imm0_7:$imm3))]>,
13730b57cec5SDimitry Andric                Requires<[IsThumb1Only]>,
13740b57cec5SDimitry Andric                Sched<[WriteALU]>;
13750b57cec5SDimitry Andric
13760b57cec5SDimitry Andric  def tSUBSi8 : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, imm0_255:$imm8),
13770b57cec5SDimitry Andric                            2, IIC_iALUi,
13780b57cec5SDimitry Andric                            [(set tGPR:$Rdn, CPSR, (ARMsubc tGPR:$Rn,
13790b57cec5SDimitry Andric                                                            imm8_255:$imm8))]>,
13800b57cec5SDimitry Andric                Requires<[IsThumb1Only]>,
13810b57cec5SDimitry Andric                Sched<[WriteALU]>;
13820b57cec5SDimitry Andric
13830b57cec5SDimitry Andric  def tSUBSrr : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
13840b57cec5SDimitry Andric                            2, IIC_iALUr,
13850b57cec5SDimitry Andric                            [(set tGPR:$Rd, CPSR, (ARMsubc tGPR:$Rn,
13860b57cec5SDimitry Andric                                                           tGPR:$Rm))]>,
13870b57cec5SDimitry Andric                Requires<[IsThumb1Only]>,
13880b57cec5SDimitry Andric                Sched<[WriteALU]>;
13890b57cec5SDimitry Andric
13900b57cec5SDimitry Andric  def tRSBS   : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rn),
13910b57cec5SDimitry Andric                            2, IIC_iALUr,
13920b57cec5SDimitry Andric                            [(set tGPR:$Rd, CPSR, (ARMsubc 0, tGPR:$Rn))]>,
13930b57cec5SDimitry Andric                Requires<[IsThumb1Only]>,
13940b57cec5SDimitry Andric                Sched<[WriteALU]>;
13958bcb0991SDimitry Andric
13968bcb0991SDimitry Andric  def tLSLSri : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rn, imm0_31:$imm5),
13978bcb0991SDimitry Andric                            2, IIC_iALUr,
13988bcb0991SDimitry Andric                            [(set tGPR:$Rd, CPSR, (ARMlsls tGPR:$Rn, imm0_31:$imm5))]>,
13998bcb0991SDimitry Andric                Requires<[IsThumb1Only]>,
14008bcb0991SDimitry Andric                Sched<[WriteALU]>;
14010b57cec5SDimitry Andric}
14020b57cec5SDimitry Andric
14030b57cec5SDimitry Andric// Sign-extend byte
14040b57cec5SDimitry Andricdef tSXTB :                     // A8.6.222
14050b57cec5SDimitry Andric  T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
14060b57cec5SDimitry Andric                 IIC_iUNAr,
14070b57cec5SDimitry Andric                 "sxtb", "\t$Rd, $Rm",
14080b57cec5SDimitry Andric                 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
14090b57cec5SDimitry Andric                 Requires<[IsThumb, IsThumb1Only, HasV6]>,
14100b57cec5SDimitry Andric                 Sched<[WriteALU]>;
14110b57cec5SDimitry Andric
14120b57cec5SDimitry Andric// Sign-extend short
14130b57cec5SDimitry Andricdef tSXTH :                     // A8.6.224
14140b57cec5SDimitry Andric  T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
14150b57cec5SDimitry Andric                 IIC_iUNAr,
14160b57cec5SDimitry Andric                 "sxth", "\t$Rd, $Rm",
14170b57cec5SDimitry Andric                 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
14180b57cec5SDimitry Andric                 Requires<[IsThumb, IsThumb1Only, HasV6]>,
14190b57cec5SDimitry Andric                 Sched<[WriteALU]>;
14200b57cec5SDimitry Andric
14210b57cec5SDimitry Andric// Test
14220b57cec5SDimitry Andriclet isCompare = 1, isCommutable = 1, Defs = [CPSR] in
14230b57cec5SDimitry Andricdef tTST :                      // A8.6.230
14240b57cec5SDimitry Andric  T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
14250b57cec5SDimitry Andric               "tst", "\t$Rn, $Rm",
14260b57cec5SDimitry Andric               [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
14270b57cec5SDimitry Andric               Sched<[WriteALU]>;
14280b57cec5SDimitry Andric
14290b57cec5SDimitry Andric// A8.8.247  UDF - Undefined (Encoding T1)
14300b57cec5SDimitry Andricdef tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
14310b57cec5SDimitry Andric              [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
14320b57cec5SDimitry Andric  bits<8> imm8;
14330b57cec5SDimitry Andric  let Inst{15-12} = 0b1101;
14340b57cec5SDimitry Andric  let Inst{11-8} = 0b1110;
14350b57cec5SDimitry Andric  let Inst{7-0} = imm8;
14360b57cec5SDimitry Andric}
14370b57cec5SDimitry Andric
14380b57cec5SDimitry Andricdef : Pat<(debugtrap), (tBKPT 0)>, Requires<[IsThumb, HasV5T]>;
14390b57cec5SDimitry Andricdef : Pat<(debugtrap), (tUDF 254)>, Requires<[IsThumb, NoV5T]>;
14400b57cec5SDimitry Andric
14410b57cec5SDimitry Andricdef t__brkdiv0 : TI<(outs), (ins), IIC_Br, "__brkdiv0",
14420b57cec5SDimitry Andric                    [(int_arm_undefined 249)]>, Encoding16,
14430b57cec5SDimitry Andric    Requires<[IsThumb, IsWindows]> {
14440b57cec5SDimitry Andric  let Inst = 0xdef9;
14450b57cec5SDimitry Andric  let isTerminator = 1;
14460b57cec5SDimitry Andric}
14470b57cec5SDimitry Andric
14480b57cec5SDimitry Andric// Zero-extend byte
14490b57cec5SDimitry Andricdef tUXTB :                     // A8.6.262
14500b57cec5SDimitry Andric  T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
14510b57cec5SDimitry Andric                 IIC_iUNAr,
14520b57cec5SDimitry Andric                 "uxtb", "\t$Rd, $Rm",
14530b57cec5SDimitry Andric                 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
14540b57cec5SDimitry Andric                 Requires<[IsThumb, IsThumb1Only, HasV6]>,
14550b57cec5SDimitry Andric                 Sched<[WriteALU]>;
14560b57cec5SDimitry Andric
14570b57cec5SDimitry Andric// Zero-extend short
14580b57cec5SDimitry Andricdef tUXTH :                     // A8.6.264
14590b57cec5SDimitry Andric  T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
14600b57cec5SDimitry Andric                 IIC_iUNAr,
14610b57cec5SDimitry Andric                 "uxth", "\t$Rd, $Rm",
14620b57cec5SDimitry Andric                 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
14630b57cec5SDimitry Andric                 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
14640b57cec5SDimitry Andric
14650b57cec5SDimitry Andric// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
14660b57cec5SDimitry Andric// Expanded after instruction selection into a branch sequence.
14670b57cec5SDimitry Andriclet usesCustomInserter = 1 in  // Expanded after instruction selection.
14680b57cec5SDimitry Andric  def tMOVCCr_pseudo :
14690b57cec5SDimitry Andric  PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
14700b57cec5SDimitry Andric             NoItinerary,
14710b57cec5SDimitry Andric             [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
14720b57cec5SDimitry Andric
14730b57cec5SDimitry Andric// tLEApcrel - Load a pc-relative address into a register without offending the
14740b57cec5SDimitry Andric// assembler.
14750b57cec5SDimitry Andric
14760b57cec5SDimitry Andricdef tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
14770b57cec5SDimitry Andric               IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
14780b57cec5SDimitry Andric               T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
14790b57cec5SDimitry Andric  bits<3> Rd;
14800b57cec5SDimitry Andric  bits<8> addr;
14810b57cec5SDimitry Andric  let Inst{10-8} = Rd;
14820b57cec5SDimitry Andric  let Inst{7-0} = addr;
14830b57cec5SDimitry Andric  let DecoderMethod = "DecodeThumbAddSpecialReg";
14840b57cec5SDimitry Andric}
14850b57cec5SDimitry Andric
14860b57cec5SDimitry Andriclet hasSideEffects = 0, isReMaterializable = 1 in
14870b57cec5SDimitry Andricdef tLEApcrel   : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
14880b57cec5SDimitry Andric                              2, IIC_iALUi, []>, Sched<[WriteALU]>;
14890b57cec5SDimitry Andric
14900b57cec5SDimitry Andriclet hasSideEffects = 1 in
14910b57cec5SDimitry Andricdef tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
14920b57cec5SDimitry Andric                              (ins i32imm:$label, pred:$p),
14930b57cec5SDimitry Andric                              2, IIC_iALUi, []>, Sched<[WriteALU]>;
14940b57cec5SDimitry Andric
14950b57cec5SDimitry Andric// Thumb-1 doesn't have the TBB or TBH instructions, but we can synthesize them
14960b57cec5SDimitry Andric// and make use of the same compressed jump table format as Thumb-2.
14970b57cec5SDimitry Andriclet Size = 2, isBranch = 1, isTerminator = 1, isBarrier = 1,
14980b57cec5SDimitry Andric    isIndirectBranch = 1, isNotDuplicable = 1 in {
14990b57cec5SDimitry Andricdef tTBB_JT : tPseudoInst<(outs),
15000b57cec5SDimitry Andric        (ins tGPRwithpc:$base, tGPR:$index, i32imm:$jt, i32imm:$pclbl), 0,
15010b57cec5SDimitry Andric         IIC_Br, []>, Sched<[WriteBr]>;
15020b57cec5SDimitry Andric
15030b57cec5SDimitry Andricdef tTBH_JT : tPseudoInst<(outs),
15040b57cec5SDimitry Andric        (ins tGPRwithpc:$base, tGPR:$index, i32imm:$jt, i32imm:$pclbl), 0,
15050b57cec5SDimitry Andric         IIC_Br, []>,  Sched<[WriteBr]>;
15060b57cec5SDimitry Andric}
15070b57cec5SDimitry Andric
15080b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
15090b57cec5SDimitry Andric// TLS Instructions
15100b57cec5SDimitry Andric//
15110b57cec5SDimitry Andric
15120b57cec5SDimitry Andric// __aeabi_read_tp preserves the registers r1-r3.
15130b57cec5SDimitry Andric// This is a pseudo inst so that we can get the encoding right,
15140b57cec5SDimitry Andric// complete with fixup for the aeabi_read_tp function.
15150b57cec5SDimitry Andriclet isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
15160b57cec5SDimitry Andricdef tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
15170b57cec5SDimitry Andric                          [(set R0, ARMthread_pointer)]>,
1518349cc55cSDimitry Andric                          Requires<[IsThumb, IsReadTPSoft]>,
15190b57cec5SDimitry Andric                          Sched<[WriteBr]>;
15200b57cec5SDimitry Andric
15210b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
15220b57cec5SDimitry Andric// SJLJ Exception handling intrinsics
15230b57cec5SDimitry Andric//
15240b57cec5SDimitry Andric
15250b57cec5SDimitry Andric// eh_sjlj_setjmp() is an instruction sequence to store the return address and
15260b57cec5SDimitry Andric// save #0 in R0 for the non-longjmp case.  Since by its nature we may be coming
15270b57cec5SDimitry Andric// from some other function to get here, and we're using the stack frame for the
15280b57cec5SDimitry Andric// containing function to save/restore registers, we can't keep anything live in
15290b57cec5SDimitry Andric// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
15300b57cec5SDimitry Andric// tromped upon when we get here from a longjmp(). We force everything out of
15310b57cec5SDimitry Andric// registers except for our own input by listing the relevant registers in
15320b57cec5SDimitry Andric// Defs. By doing so, we also cause the prologue/epilogue code to actively
15335ffd83dbSDimitry Andric// preserve all of the callee-saved registers, which is exactly what we want.
15340b57cec5SDimitry Andric// $val is a scratch register for our use.
15351fd87a68SDimitry Andric// This gets lowered to an instruction sequence of 12 bytes
15360b57cec5SDimitry Andriclet Defs = [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7, R12, CPSR ],
15371fd87a68SDimitry Andric    hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, Size = 12,
15380b57cec5SDimitry Andric    usesCustomInserter = 1 in
15390b57cec5SDimitry Andricdef tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
15400b57cec5SDimitry Andric                                  AddrModeNone, 0, NoItinerary, "","",
15410b57cec5SDimitry Andric                          [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
15420b57cec5SDimitry Andric
15431fd87a68SDimitry Andric// This gets lowered to an instruction sequence of 10 bytes
15440b57cec5SDimitry Andric// FIXME: Non-IOS version(s)
15450b57cec5SDimitry Andriclet isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
15461fd87a68SDimitry Andric    Size = 10, Defs = [ R7, LR, SP ] in
15470b57cec5SDimitry Andricdef tInt_eh_sjlj_longjmp : XI<(outs), (ins tGPR:$src, tGPR:$scratch),
15480b57cec5SDimitry Andric                              AddrModeNone, 0, IndexModeNone,
15490b57cec5SDimitry Andric                              Pseudo, NoItinerary, "", "",
15500b57cec5SDimitry Andric                              [(ARMeh_sjlj_longjmp tGPR:$src, tGPR:$scratch)]>,
15510b57cec5SDimitry Andric                             Requires<[IsThumb,IsNotWindows]>;
15520b57cec5SDimitry Andric
15531fd87a68SDimitry Andric// This gets lowered to an instruction sequence of 12 bytes
15540b57cec5SDimitry Andric// (Windows is Thumb2-only)
15550b57cec5SDimitry Andriclet isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
15561fd87a68SDimitry Andric    Size = 12, Defs = [ R11, LR, SP ] in
15570b57cec5SDimitry Andricdef tInt_WIN_eh_sjlj_longjmp
15580b57cec5SDimitry Andric  : XI<(outs), (ins GPR:$src, GPR:$scratch), AddrModeNone, 0, IndexModeNone,
15590b57cec5SDimitry Andric       Pseudo, NoItinerary, "", "", [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
15600b57cec5SDimitry Andric    Requires<[IsThumb,IsWindows]>;
15610b57cec5SDimitry Andric
15620b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
15630b57cec5SDimitry Andric// Non-Instruction Patterns
15640b57cec5SDimitry Andric//
15650b57cec5SDimitry Andric
15660b57cec5SDimitry Andric// Comparisons
15670b57cec5SDimitry Andricdef : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
15680b57cec5SDimitry Andric            (tCMPi8  tGPR:$Rn, imm0_255:$imm8)>;
15690b57cec5SDimitry Andricdef : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
15700b57cec5SDimitry Andric            (tCMPr   tGPR:$Rn, tGPR:$Rm)>;
15710b57cec5SDimitry Andric
15720b57cec5SDimitry Andric// Bswap 16 with load/store
15730b57cec5SDimitry Andricdef : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
15740b57cec5SDimitry Andric            (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
15750b57cec5SDimitry Andricdef : T1Pat<(srl (bswap (extloadi16 t_addrmode_rr:$addr)), (i32 16)),
15760b57cec5SDimitry Andric            (tREV16 (tLDRHr t_addrmode_rr:$addr))>;
15774824e7fdSDimitry Andricdef : T1Pat<(srl (bswap top16Zero:$Rn), (i32 16)),
15784824e7fdSDimitry Andric            (tREV16 tGPR:$Rn)>;
15790b57cec5SDimitry Andricdef : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
15800b57cec5SDimitry Andric                           t_addrmode_is2:$addr),
15810b57cec5SDimitry Andric            (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
15820b57cec5SDimitry Andricdef : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
15830b57cec5SDimitry Andric                           t_addrmode_rr:$addr),
15840b57cec5SDimitry Andric            (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rr:$addr)>;
15850b57cec5SDimitry Andric
15860b57cec5SDimitry Andric// ConstantPool
15870b57cec5SDimitry Andricdef : T1Pat<(ARMWrapper  tconstpool  :$dst), (tLEApcrel tconstpool  :$dst)>;
15880b57cec5SDimitry Andric
15890b57cec5SDimitry Andric// GlobalAddress
15900b57cec5SDimitry Andricdef tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
15910b57cec5SDimitry Andric                                  IIC_iLoadiALU,
15920b57cec5SDimitry Andric                                  [(set tGPR:$dst,
15930b57cec5SDimitry Andric                                        (ARMWrapperPIC tglobaladdr:$addr))]>,
15940b57cec5SDimitry Andric                       Requires<[IsThumb, DontUseMovtInPic]>;
15950b57cec5SDimitry Andric
15960b57cec5SDimitry Andricdef tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
15970b57cec5SDimitry Andric                                IIC_iLoad_i,
15980b57cec5SDimitry Andric                                [(set tGPR:$dst,
15990b57cec5SDimitry Andric                                      (ARMWrapper tglobaladdr:$src))]>,
160006c3fb27SDimitry Andric                     Requires<[IsThumb, DontUseMovt, DontGenExecuteOnly]>;
160106c3fb27SDimitry Andric
160206c3fb27SDimitry Andric// 32-bit immediate using mov/add with the 4 :lower0_7: to :upper8_15:
160306c3fb27SDimitry Andric// relocations.
160406c3fb27SDimitry Andric// This is a single pseudo instruction to make it re-materializable.
160506c3fb27SDimitry Andric// FIXME: Remove this when we can do generalized remat.
160606c3fb27SDimitry Andriclet Defs = [CPSR], isReMaterializable = 1, isMoveImm = 1, Size = 16, hasNoSchedulingInfo = 1 in
160706c3fb27SDimitry Andricdef tMOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), NoItinerary,
160806c3fb27SDimitry Andric                            [(set rGPR:$dst, (i32 imm:$src))]>,
160906c3fb27SDimitry Andric                            Requires<[IsThumb1Only, GenExecuteOnly, DontUseMovt]>;
161006c3fb27SDimitry Andric
161106c3fb27SDimitry Andricdef : ARMPat<(ARMWrapper  tglobaladdr :$dst), (tMOVi32imm tglobaladdr :$dst)>,
161206c3fb27SDimitry Andric            Requires<[GenT1ExecuteOnly]>;
161306c3fb27SDimitry Andricdef : ARMPat<(ARMWrapper texternalsym :$dst), (tMOVi32imm texternalsym :$dst)>,
161406c3fb27SDimitry Andric            Requires<[GenT1ExecuteOnly]>;
161506c3fb27SDimitry Andric
16160b57cec5SDimitry Andric
16170b57cec5SDimitry Andric// TLS globals
16180b57cec5SDimitry Andricdef : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
16190b57cec5SDimitry Andric          (tLDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
16200b57cec5SDimitry Andric      Requires<[IsThumb, DontUseMovtInPic]>;
16210b57cec5SDimitry Andricdef : Pat<(ARMWrapper tglobaltlsaddr:$addr),
16220b57cec5SDimitry Andric          (tLDRLIT_ga_abs tglobaltlsaddr:$addr)>,
16230b57cec5SDimitry Andric      Requires<[IsThumb, DontUseMovt]>;
16240b57cec5SDimitry Andric
16250b57cec5SDimitry Andric
16260b57cec5SDimitry Andric// JumpTable
16270b57cec5SDimitry Andricdef : T1Pat<(ARMWrapperJT tjumptable:$dst),
16280b57cec5SDimitry Andric            (tLEApcrelJT tjumptable:$dst)>;
16290b57cec5SDimitry Andric
16300b57cec5SDimitry Andric// Direct calls
16310b57cec5SDimitry Andricdef : T1Pat<(ARMcall texternalsym:$func), (tBL texternalsym:$func)>,
16320b57cec5SDimitry Andric      Requires<[IsThumb]>;
16330b57cec5SDimitry Andric
16340b57cec5SDimitry Andric// zextload i1 -> zextload i8
16350b57cec5SDimitry Andricdef : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
16360b57cec5SDimitry Andric            (tLDRBi t_addrmode_is1:$addr)>;
16370b57cec5SDimitry Andricdef : T1Pat<(zextloadi1 t_addrmode_rr:$addr),
16380b57cec5SDimitry Andric            (tLDRBr t_addrmode_rr:$addr)>;
16390b57cec5SDimitry Andric
16400b57cec5SDimitry Andric// extload from the stack -> word load from the stack, as it avoids having to
16410b57cec5SDimitry Andric// materialize the base in a separate register. This only works when a word
16420b57cec5SDimitry Andric// load puts the byte/halfword value in the same place in the register that the
16430b57cec5SDimitry Andric// byte/halfword load would, i.e. when little-endian.
16440b57cec5SDimitry Andricdef : T1Pat<(extloadi1  t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
16450b57cec5SDimitry Andric      Requires<[IsThumb, IsThumb1Only, IsLE]>;
16460b57cec5SDimitry Andricdef : T1Pat<(extloadi8  t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
16470b57cec5SDimitry Andric      Requires<[IsThumb, IsThumb1Only, IsLE]>;
16480b57cec5SDimitry Andricdef : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
16490b57cec5SDimitry Andric      Requires<[IsThumb, IsThumb1Only, IsLE]>;
16500b57cec5SDimitry Andric
16510b57cec5SDimitry Andric// extload -> zextload
16520b57cec5SDimitry Andricdef : T1Pat<(extloadi1  t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
16530b57cec5SDimitry Andricdef : T1Pat<(extloadi1  t_addrmode_rr:$addr),  (tLDRBr t_addrmode_rr:$addr)>;
16540b57cec5SDimitry Andricdef : T1Pat<(extloadi8  t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
16550b57cec5SDimitry Andricdef : T1Pat<(extloadi8  t_addrmode_rr:$addr),  (tLDRBr t_addrmode_rr:$addr)>;
16560b57cec5SDimitry Andricdef : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
16570b57cec5SDimitry Andricdef : T1Pat<(extloadi16 t_addrmode_rr:$addr),  (tLDRHr t_addrmode_rr:$addr)>;
16580b57cec5SDimitry Andric
16590b57cec5SDimitry Andric// post-inc loads and stores
16600b57cec5SDimitry Andric
16610b57cec5SDimitry Andric// post-inc LDR -> LDM r0!, {r1}. The way operands are layed out in LDMs is
16620b57cec5SDimitry Andric// different to how ISel expects them for a post-inc load, so use a pseudo
16630b57cec5SDimitry Andric// and expand it just after ISel.
16640b57cec5SDimitry Andriclet usesCustomInserter = 1, mayLoad =1,
16650b57cec5SDimitry Andric    Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in
16660b57cec5SDimitry Andric def tLDR_postidx: tPseudoInst<(outs tGPR:$Rt, tGPR:$Rn_wb),
16670b57cec5SDimitry Andric                               (ins tGPR:$Rn, pred:$p),
16680b57cec5SDimitry Andric                               4, IIC_iStore_ru,
16690b57cec5SDimitry Andric                               []>;
16700b57cec5SDimitry Andric
16710b57cec5SDimitry Andric// post-inc STR -> STM r0!, {r1}. The layout of this (because it doesn't def
16720b57cec5SDimitry Andric// multiple registers) is the same in ISel as MachineInstr, so there's no need
16730b57cec5SDimitry Andric// for a pseudo.
16740b57cec5SDimitry Andricdef : T1Pat<(post_store tGPR:$Rt, tGPR:$Rn, 4),
16750b57cec5SDimitry Andric            (tSTMIA_UPD tGPR:$Rn, tGPR:$Rt)>;
16760b57cec5SDimitry Andric
16770b57cec5SDimitry Andric// If it's impossible to use [r,r] address mode for sextload, select to
1678fe6060f1SDimitry Andric// ldsr{b|h} r, 0 instead, in a hope that the mov 0 will be more likely to be
1679fe6060f1SDimitry Andric// commoned out than a sxth.
1680fe6060f1SDimitry Andriclet AddedComplexity = 10 in {
1681fe6060f1SDimitry Andricdef : T1Pat<(sextloadi8 tGPR:$Rn),
1682fe6060f1SDimitry Andric            (tLDRSB tGPR:$Rn, (tMOVi8 0))>,
16830b57cec5SDimitry Andric      Requires<[IsThumb, IsThumb1Only, HasV6]>;
1684fe6060f1SDimitry Andricdef : T1Pat<(sextloadi16 tGPR:$Rn),
1685fe6060f1SDimitry Andric            (tLDRSH tGPR:$Rn, (tMOVi8 0))>,
16860b57cec5SDimitry Andric      Requires<[IsThumb, IsThumb1Only, HasV6]>;
1687fe6060f1SDimitry Andric}
16880b57cec5SDimitry Andric
16890b57cec5SDimitry Andricdef : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
16900b57cec5SDimitry Andric            (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
16910b57cec5SDimitry Andricdef : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
16920b57cec5SDimitry Andric            (tASRri (tLSLri (tLDRBr t_addrmode_rr:$addr), 24), 24)>;
16930b57cec5SDimitry Andricdef : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
16940b57cec5SDimitry Andric            (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
16950b57cec5SDimitry Andricdef : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
16960b57cec5SDimitry Andric            (tASRri (tLSLri (tLDRHr t_addrmode_rr:$addr), 16), 16)>;
16970b57cec5SDimitry Andric
16980b57cec5SDimitry Andricdef : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
16990b57cec5SDimitry Andric             (tLDRBi t_addrmode_is1:$src)>;
17000b57cec5SDimitry Andricdef : T1Pat<(atomic_load_8 t_addrmode_rr:$src),
17010b57cec5SDimitry Andric             (tLDRBr t_addrmode_rr:$src)>;
17020b57cec5SDimitry Andricdef : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
17030b57cec5SDimitry Andric             (tLDRHi t_addrmode_is2:$src)>;
17040b57cec5SDimitry Andricdef : T1Pat<(atomic_load_16 t_addrmode_rr:$src),
17050b57cec5SDimitry Andric             (tLDRHr t_addrmode_rr:$src)>;
17060b57cec5SDimitry Andricdef : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
17070b57cec5SDimitry Andric             (tLDRi t_addrmode_is4:$src)>;
17080b57cec5SDimitry Andricdef : T1Pat<(atomic_load_32 t_addrmode_rr:$src),
17090b57cec5SDimitry Andric             (tLDRr t_addrmode_rr:$src)>;
17105f757f3fSDimitry Andricdef : T1Pat<(atomic_store_8 tGPR:$val, t_addrmode_is1:$ptr),
17110b57cec5SDimitry Andric             (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
17125f757f3fSDimitry Andricdef : T1Pat<(atomic_store_8 tGPR:$val, t_addrmode_rr:$ptr),
17130b57cec5SDimitry Andric             (tSTRBr tGPR:$val, t_addrmode_rr:$ptr)>;
17145f757f3fSDimitry Andricdef : T1Pat<(atomic_store_16 tGPR:$val, t_addrmode_is2:$ptr),
17150b57cec5SDimitry Andric             (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
17165f757f3fSDimitry Andricdef : T1Pat<(atomic_store_16 tGPR:$val, t_addrmode_rr:$ptr),
17170b57cec5SDimitry Andric             (tSTRHr tGPR:$val, t_addrmode_rr:$ptr)>;
17185f757f3fSDimitry Andricdef : T1Pat<(atomic_store_32 tGPR:$val, t_addrmode_is4:$ptr),
17190b57cec5SDimitry Andric             (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
17205f757f3fSDimitry Andricdef : T1Pat<(atomic_store_32 tGPR:$val, t_addrmode_rr:$ptr),
17210b57cec5SDimitry Andric             (tSTRr tGPR:$val, t_addrmode_rr:$ptr)>;
17220b57cec5SDimitry Andric
17230b57cec5SDimitry Andric// Large immediate handling.
17240b57cec5SDimitry Andric
17250b57cec5SDimitry Andric// Two piece imms.
17260b57cec5SDimitry Andricdef : T1Pat<(i32 thumb_immshifted:$src),
17270b57cec5SDimitry Andric            (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
17280b57cec5SDimitry Andric                    (thumb_immshifted_shamt imm:$src))>;
17290b57cec5SDimitry Andric
17300b57cec5SDimitry Andricdef : T1Pat<(i32 imm0_255_comp:$src),
17310b57cec5SDimitry Andric            (tMVN (tMOVi8 (imm_not_XFORM imm:$src)))>;
17320b57cec5SDimitry Andric
17330b57cec5SDimitry Andricdef : T1Pat<(i32 imm256_510:$src),
17340b57cec5SDimitry Andric            (tADDi8 (tMOVi8 255),
17350b57cec5SDimitry Andric                    (thumb_imm256_510_addend imm:$src))>;
17360b57cec5SDimitry Andric
17370b57cec5SDimitry Andric// Pseudo instruction that combines ldr from constpool and add pc. This should
17380b57cec5SDimitry Andric// be expanded into two instructions late to allow if-conversion and
17390b57cec5SDimitry Andric// scheduling.
17400b57cec5SDimitry Andriclet isReMaterializable = 1 in
17410b57cec5SDimitry Andricdef tLDRpci_pic : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
17420b57cec5SDimitry Andric                             NoItinerary,
17430b57cec5SDimitry Andric               [(set tGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
17440b57cec5SDimitry Andric                                           imm:$cp))]>,
17450b57cec5SDimitry Andric               Requires<[IsThumb, IsThumb1Only]>;
17460b57cec5SDimitry Andric
17470b57cec5SDimitry Andric// Pseudo-instruction for merged POP and return.
17480b57cec5SDimitry Andric// FIXME: remove when we have a way to marking a MI with these properties.
17490b57cec5SDimitry Andriclet isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
17500b57cec5SDimitry Andric    hasExtraDefRegAllocReq = 1 in
17510b57cec5SDimitry Andricdef tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
17520b57cec5SDimitry Andric                           2, IIC_iPop_Br, [],
17530b57cec5SDimitry Andric                           (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
17540b57cec5SDimitry Andric
17550b57cec5SDimitry Andric// Indirect branch using "mov pc, $Rm"
17560b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
17570b57cec5SDimitry Andric  def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
17580b57cec5SDimitry Andric                  2, IIC_Br, [(brind GPR:$Rm)],
17590b57cec5SDimitry Andric                  (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
17600b57cec5SDimitry Andric}
17610b57cec5SDimitry Andric
17620b57cec5SDimitry Andric
17630b57cec5SDimitry Andric// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
17640b57cec5SDimitry Andric// encoding is available on ARMv6K, but we don't differentiate that finely.
1765*0fca6ea1SDimitry Andricdef : InstAlias<"nop", (tMOVr R8, R8, 14, zero_reg), 0>, Requires<[IsThumb, IsThumb1Only]>;
17660b57cec5SDimitry Andric
17670b57cec5SDimitry Andric
17680b57cec5SDimitry Andric// "neg" is and alias for "rsb rd, rn, #0"
17690b57cec5SDimitry Andricdef : tInstAlias<"neg${s}${p} $Rd, $Rm",
17700b57cec5SDimitry Andric                 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
17710b57cec5SDimitry Andric
17720b57cec5SDimitry Andric
17730b57cec5SDimitry Andric// Implied destination operand forms for shifts.
17740b57cec5SDimitry Andricdef : tInstAlias<"lsl${s}${p} $Rdm, $imm",
17750b57cec5SDimitry Andric             (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
17760b57cec5SDimitry Andricdef : tInstAlias<"lsr${s}${p} $Rdm, $imm",
17770b57cec5SDimitry Andric             (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
17780b57cec5SDimitry Andricdef : tInstAlias<"asr${s}${p} $Rdm, $imm",
17790b57cec5SDimitry Andric             (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
17800b57cec5SDimitry Andric
17810b57cec5SDimitry Andric// Pseudo instruction ldr Rt, =immediate
17820b57cec5SDimitry Andricdef tLDRConstPool
17830b57cec5SDimitry Andric  : tAsmPseudo<"ldr${p} $Rt, $immediate",
17840b57cec5SDimitry Andric               (ins tGPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
1785fe6060f1SDimitry Andric
1786fe6060f1SDimitry Andric//===----------------------------------
1787fe6060f1SDimitry Andric// Atomic cmpxchg for -O0
1788fe6060f1SDimitry Andric//===----------------------------------
1789fe6060f1SDimitry Andric
1790fe6060f1SDimitry Andric// See ARMInstrInfo.td. These two thumb specific pseudos are required to
1791fe6060f1SDimitry Andric// restrict the register class for the UXTB/UXTH ops used in the expansion.
1792fe6060f1SDimitry Andric
1793fe6060f1SDimitry Andriclet Constraints = "@earlyclobber $Rd,@earlyclobber $temp",
1794fe6060f1SDimitry Andric    mayLoad = 1, mayStore = 1 in {
1795fcaf7f86SDimitry Andricdef tCMP_SWAP_8 : PseudoInst<(outs GPR:$Rd, tGPR:$temp),
1796fe6060f1SDimitry Andric                             (ins GPR:$addr, tGPR:$desired, GPR:$new),
1797fe6060f1SDimitry Andric                             NoItinerary, []>, Sched<[]>;
1798fe6060f1SDimitry Andric
1799fcaf7f86SDimitry Andricdef tCMP_SWAP_16 : PseudoInst<(outs GPR:$Rd, tGPR:$temp),
1800fe6060f1SDimitry Andric                              (ins GPR:$addr, tGPR:$desired, GPR:$new),
1801fe6060f1SDimitry Andric                              NoItinerary, []>, Sched<[]>;
1802fcaf7f86SDimitry Andric
1803fcaf7f86SDimitry Andricdef tCMP_SWAP_32 : PseudoInst<(outs GPR:$Rd, tGPR:$temp),
1804fcaf7f86SDimitry Andric                              (ins GPR:$addr, GPR:$desired, GPR:$new),
1805fcaf7f86SDimitry Andric                              NoItinerary, []>, Sched<[]>;
1806fe6060f1SDimitry Andric}
1807