10b57cec5SDimitry Andric//===-- AVRInstrInfo.td - AVR Instruction defs -------------*- 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 AVR instructions in TableGen format. 100b57cec5SDimitry Andric// 110b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andricinclude "AVRInstrFormats.td" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 160b57cec5SDimitry Andric// AVR Type Profiles 170b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 180b57cec5SDimitry Andric 190b57cec5SDimitry Andricdef SDT_AVRCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>; 200b57cec5SDimitry Andricdef SDT_AVRCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>; 210b57cec5SDimitry Andricdef SDT_AVRCall : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>; 220b57cec5SDimitry Andricdef SDT_AVRWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>; 23349cc55cSDimitry Andricdef SDT_AVRBrcond 24349cc55cSDimitry Andric : SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i8>]>; 250b57cec5SDimitry Andricdef SDT_AVRCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>; 260b57cec5SDimitry Andricdef SDT_AVRTst : SDTypeProfile<0, 1, [SDTCisInt<0>]>; 27349cc55cSDimitry Andricdef SDT_AVRSelectCC 28349cc55cSDimitry Andric : SDTypeProfile<1, 3, 29349cc55cSDimitry Andric [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i8>]>; 300b57cec5SDimitry Andric 310b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 320b57cec5SDimitry Andric// AVR Specific Node Definitions 330b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 340b57cec5SDimitry Andric 3506c3fb27SDimitry Andricdef AVRretglue : SDNode<"AVRISD::RET_GLUE", SDTNone, 360b57cec5SDimitry Andric [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 3706c3fb27SDimitry Andricdef AVRretiglue : SDNode<"AVRISD::RETI_GLUE", SDTNone, 380b57cec5SDimitry Andric [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 390b57cec5SDimitry Andric 400b57cec5SDimitry Andricdef AVRcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_AVRCallSeqStart, 410b57cec5SDimitry Andric [SDNPHasChain, SDNPOutGlue]>; 420b57cec5SDimitry Andricdef AVRcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_AVRCallSeqEnd, 430b57cec5SDimitry Andric [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 440b57cec5SDimitry Andric 450b57cec5SDimitry Andricdef AVRcall : SDNode<"AVRISD::CALL", SDT_AVRCall, 460b57cec5SDimitry Andric [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andricdef AVRWrapper : SDNode<"AVRISD::WRAPPER", SDT_AVRWrapper>; 490b57cec5SDimitry Andric 50349cc55cSDimitry Andricdef AVRbrcond 51349cc55cSDimitry Andric : SDNode<"AVRISD::BRCOND", SDT_AVRBrcond, [SDNPHasChain, SDNPInGlue]>; 520b57cec5SDimitry Andricdef AVRcmp : SDNode<"AVRISD::CMP", SDT_AVRCmp, [SDNPOutGlue]>; 530b57cec5SDimitry Andricdef AVRcmpc : SDNode<"AVRISD::CMPC", SDT_AVRCmp, [SDNPInGlue, SDNPOutGlue]>; 540b57cec5SDimitry Andricdef AVRtst : SDNode<"AVRISD::TST", SDT_AVRTst, [SDNPOutGlue]>; 550b57cec5SDimitry Andricdef AVRselectcc : SDNode<"AVRISD::SELECT_CC", SDT_AVRSelectCC, [SDNPInGlue]>; 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric// Shift nodes. 580b57cec5SDimitry Andricdef AVRlsl : SDNode<"AVRISD::LSL", SDTIntUnaryOp>; 590b57cec5SDimitry Andricdef AVRlsr : SDNode<"AVRISD::LSR", SDTIntUnaryOp>; 600b57cec5SDimitry Andricdef AVRrol : SDNode<"AVRISD::ROL", SDTIntUnaryOp>; 610b57cec5SDimitry Andricdef AVRror : SDNode<"AVRISD::ROR", SDTIntUnaryOp>; 620b57cec5SDimitry Andricdef AVRasr : SDNode<"AVRISD::ASR", SDTIntUnaryOp>; 6304eeddc0SDimitry Andricdef AVRlslhi : SDNode<"AVRISD::LSLHI", SDTIntUnaryOp>; 6404eeddc0SDimitry Andricdef AVRlsrlo : SDNode<"AVRISD::LSRLO", SDTIntUnaryOp>; 6504eeddc0SDimitry Andricdef AVRasrlo : SDNode<"AVRISD::ASRLO", SDTIntUnaryOp>; 66fe6060f1SDimitry Andricdef AVRlslbn : SDNode<"AVRISD::LSLBN", SDTIntBinOp>; 67fe6060f1SDimitry Andricdef AVRlsrbn : SDNode<"AVRISD::LSRBN", SDTIntBinOp>; 68fe6060f1SDimitry Andricdef AVRasrbn : SDNode<"AVRISD::ASRBN", SDTIntBinOp>; 69fe6060f1SDimitry Andricdef AVRlslwn : SDNode<"AVRISD::LSLWN", SDTIntBinOp>; 70fe6060f1SDimitry Andricdef AVRlsrwn : SDNode<"AVRISD::LSRWN", SDTIntBinOp>; 71fe6060f1SDimitry Andricdef AVRasrwn : SDNode<"AVRISD::ASRWN", SDTIntBinOp>; 72bdd1243dSDimitry Andricdef AVRlslw : SDNode<"AVRISD::LSLW", SDTIntShiftDOp>; 73bdd1243dSDimitry Andricdef AVRlsrw : SDNode<"AVRISD::LSRW", SDTIntShiftDOp>; 74bdd1243dSDimitry Andricdef AVRasrw : SDNode<"AVRISD::ASRW", SDTIntShiftDOp>; 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric// Pseudo shift nodes for non-constant shift amounts. 770b57cec5SDimitry Andricdef AVRlslLoop : SDNode<"AVRISD::LSLLOOP", SDTIntShiftOp>; 780b57cec5SDimitry Andricdef AVRlsrLoop : SDNode<"AVRISD::LSRLOOP", SDTIntShiftOp>; 790b57cec5SDimitry Andricdef AVRrolLoop : SDNode<"AVRISD::ROLLOOP", SDTIntShiftOp>; 800b57cec5SDimitry Andricdef AVRrorLoop : SDNode<"AVRISD::RORLOOP", SDTIntShiftOp>; 810b57cec5SDimitry Andricdef AVRasrLoop : SDNode<"AVRISD::ASRLOOP", SDTIntShiftOp>; 820b57cec5SDimitry Andric 83e8d8bef9SDimitry Andric// SWAP node. 84e8d8bef9SDimitry Andricdef AVRSwap : SDNode<"AVRISD::SWAP", SDTIntUnaryOp>; 85e8d8bef9SDimitry Andric 860b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 870b57cec5SDimitry Andric// AVR Operands, Complex Patterns and Transformations Definitions. 880b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 890b57cec5SDimitry Andric 90349cc55cSDimitry Andricdef imm8_neg_XFORM : SDNodeXForm<imm, [{ 91*0fca6ea1SDimitry Andric return CurDAG->getTargetConstant(-N->getAPIntValue(), SDLoc(N), MVT::i8); 920b57cec5SDimitry Andric}]>; 930b57cec5SDimitry Andric 94*0fca6ea1SDimitry Andricdef imm16_neg_XFORM : SDNodeXForm<imm, [{ 95*0fca6ea1SDimitry Andric return CurDAG->getTargetConstant(-N->getAPIntValue(), SDLoc(N), MVT::i16); 960b57cec5SDimitry Andric}]>; 970b57cec5SDimitry Andric 98349cc55cSDimitry Andricdef imm0_63_neg : PatLeaf<(imm), [{ 990b57cec5SDimitry Andric int64_t val = -N->getSExtValue(); 1000b57cec5SDimitry Andric return val >= 0 && val < 64; 101*0fca6ea1SDimitry Andric}], imm16_neg_XFORM>; 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andricdef uimm6 : PatLeaf<(imm), [{ return isUInt<6>(N->getZExtValue()); }]>; 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andric// imm_com8_XFORM - Return the complement of a imm_com8 value 106*0fca6ea1SDimitry Andricdef imm_com8_XFORM : SDNodeXForm<imm, [{ 107349cc55cSDimitry Andric return CurDAG->getTargetConstant( 108349cc55cSDimitry Andric ~((uint8_t) N->getZExtValue()), SDLoc(N), MVT::i8); 1090b57cec5SDimitry Andric}]>; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric// imm_com8 - Match an immediate that is a complement 1120b57cec5SDimitry Andric// of a 8-bit immediate. 1130b57cec5SDimitry Andric// Note: this pattern doesn't require an encoder method and such, as it's 1140b57cec5SDimitry Andric// only used on aliases (Pat<> and InstAlias<>). The actual encoding 1150b57cec5SDimitry Andric// is handled by the destination instructions, which use imm_com8. 1160b57cec5SDimitry Andricdef imm_com8_asmoperand : AsmOperandClass { let Name = "ImmCom8"; } 117349cc55cSDimitry Andricdef imm_com8 : Operand<i8> { let ParserMatchClass = imm_com8_asmoperand; } 1180b57cec5SDimitry Andric 119*0fca6ea1SDimitry Andricdef ioaddr_XFORM : SDNodeXForm<imm, [{ 1205ffd83dbSDimitry Andric uint8_t offset = Subtarget->getIORegisterOffset(); 121349cc55cSDimitry Andric return CurDAG->getTargetConstant( 122349cc55cSDimitry Andric uint8_t(N->getZExtValue()) - offset, SDLoc(N), MVT::i8); 123349cc55cSDimitry Andric}]>; 124349cc55cSDimitry Andric 125*0fca6ea1SDimitry Andricdef iobitpos8_XFORM : SDNodeXForm<imm, [{ 126349cc55cSDimitry Andric return CurDAG->getTargetConstant( 127349cc55cSDimitry Andric Log2_32(uint8_t(N->getZExtValue())), SDLoc(N), MVT::i8); 128349cc55cSDimitry Andric}]>; 129349cc55cSDimitry Andric 130349cc55cSDimitry Andricdef iobitposn8_XFORM : SDNodeXForm<imm, [{ 131349cc55cSDimitry Andric return CurDAG->getTargetConstant( 132*0fca6ea1SDimitry Andric Log2_32(uint8_t(~N->getZExtValue())), SDLoc(N), MVT::i8); 1330b57cec5SDimitry Andric}]>; 1340b57cec5SDimitry Andric 135349cc55cSDimitry Andricdef ioaddr8 : PatLeaf<(imm), [{ 1365ffd83dbSDimitry Andric uint8_t offset = Subtarget->getIORegisterOffset(); 1375ffd83dbSDimitry Andric uint64_t val = N->getZExtValue() - offset; 1385ffd83dbSDimitry Andric return val < 0x40; 139*0fca6ea1SDimitry Andric}], ioaddr_XFORM>; 1400b57cec5SDimitry Andric 141349cc55cSDimitry Andricdef lowioaddr8 : PatLeaf<(imm), [{ 1425ffd83dbSDimitry Andric uint8_t offset = Subtarget->getIORegisterOffset(); 1435ffd83dbSDimitry Andric uint64_t val = N->getZExtValue() - offset; 1445ffd83dbSDimitry Andric return val < 0x20; 145*0fca6ea1SDimitry Andric}], ioaddr_XFORM>; 1460b57cec5SDimitry Andric 147349cc55cSDimitry Andricdef ioaddr16 : PatLeaf<(imm), [{ 1485ffd83dbSDimitry Andric uint8_t offset = Subtarget->getIORegisterOffset(); 1495ffd83dbSDimitry Andric uint64_t val = N->getZExtValue() - offset; 1505ffd83dbSDimitry Andric return val < 0x3f; 151*0fca6ea1SDimitry Andric}], ioaddr_XFORM>; 1520b57cec5SDimitry Andric 153*0fca6ea1SDimitry Andricdef iobitpos8 : PatLeaf<(imm), [{ 154*0fca6ea1SDimitry Andric return isPowerOf2_32(uint8_t(N->getZExtValue())); 155*0fca6ea1SDimitry Andric}], iobitpos8_XFORM>; 1560b57cec5SDimitry Andric 157*0fca6ea1SDimitry Andricdef iobitposn8 : PatLeaf<(imm), [{ 158*0fca6ea1SDimitry Andric return isPowerOf2_32(uint8_t(~N->getZExtValue())); 159*0fca6ea1SDimitry Andric}], iobitposn8_XFORM>; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andricdef MemriAsmOperand : AsmOperandClass { 1620b57cec5SDimitry Andric let Name = "Memri"; 1630b57cec5SDimitry Andric let ParserMethod = "parseMemriOperand"; 1640b57cec5SDimitry Andric} 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andric/// Address operand for `reg+imm` used by STD and LDD. 167349cc55cSDimitry Andricdef memri : Operand<iPTR> { 1680b57cec5SDimitry Andric let MIOperandInfo = (ops PTRDISPREGS, i16imm); 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andric let PrintMethod = "printMemri"; 1710b57cec5SDimitry Andric let EncoderMethod = "encodeMemri"; 17281ad6265SDimitry Andric let DecoderMethod = "decodeMemri"; 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andric let ParserMatchClass = MemriAsmOperand; 1750b57cec5SDimitry Andric} 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric// Address operand for `SP+imm` used by STD{W}SPQRr 17881ad6265SDimitry Andricdef memspi : Operand<iPTR> { 17981ad6265SDimitry Andric let MIOperandInfo = (ops GPRSP, i16imm); 18081ad6265SDimitry Andric let PrintMethod = "printMemspi"; 18181ad6265SDimitry Andric} 1820b57cec5SDimitry Andric 183349cc55cSDimitry Andricdef relbrtarget_7 : Operand<OtherVT> { 1840b57cec5SDimitry Andric let PrintMethod = "printPCRelImm"; 1850b57cec5SDimitry Andric let EncoderMethod = "encodeRelCondBrTarget<AVR::fixup_7_pcrel>"; 1860b57cec5SDimitry Andric} 1870b57cec5SDimitry Andric 188349cc55cSDimitry Andricdef brtarget_13 : Operand<OtherVT> { 1890b57cec5SDimitry Andric let PrintMethod = "printPCRelImm"; 1900b57cec5SDimitry Andric let EncoderMethod = "encodeRelCondBrTarget<AVR::fixup_13_pcrel>"; 1910b57cec5SDimitry Andric} 1920b57cec5SDimitry Andric 1932a66634dSDimitry Andricdef rcalltarget_13 : Operand<i16> { 1942a66634dSDimitry Andric let PrintMethod = "printPCRelImm"; 1952a66634dSDimitry Andric let EncoderMethod = "encodeRelCondBrTarget<AVR::fixup_13_pcrel>"; 1962a66634dSDimitry Andric} 1972a66634dSDimitry Andric 1980b57cec5SDimitry Andric// The target of a 22 or 16-bit call/jmp instruction. 199349cc55cSDimitry Andricdef call_target : Operand<iPTR> { 2000b57cec5SDimitry Andric let EncoderMethod = "encodeCallTarget"; 2015ffd83dbSDimitry Andric let DecoderMethod = "decodeCallTarget"; 2020b57cec5SDimitry Andric} 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric// A 16-bit address (which can lead to an R_AVR_16 relocation). 205349cc55cSDimitry Andricdef imm16 : Operand<i16> { let EncoderMethod = "encodeImm<AVR::fixup_16, 2>"; } 2060b57cec5SDimitry Andric 207bdd1243dSDimitry Andric// A 7-bit address (which can lead to an R_AVR_LDS_STS_16 relocation). 208bdd1243dSDimitry Andricdef imm7tiny : Operand<i16> { 209bdd1243dSDimitry Andric let EncoderMethod = "encodeImm<AVR::fixup_lds_sts_16, 0>"; 210bdd1243dSDimitry Andric} 211bdd1243dSDimitry Andric 2120b57cec5SDimitry Andric/// A 6-bit immediate used in the ADIW/SBIW instructions. 213349cc55cSDimitry Andricdef imm_arith6 : Operand<i16> { 2140b57cec5SDimitry Andric let EncoderMethod = "encodeImm<AVR::fixup_6_adiw, 0>"; 2150b57cec5SDimitry Andric} 2160b57cec5SDimitry Andric 2170b57cec5SDimitry Andric/// An 8-bit immediate inside an instruction with the same format 2180b57cec5SDimitry Andric/// as the `LDI` instruction (the `FRdK` format). 219349cc55cSDimitry Andricdef imm_ldi8 : Operand<i8> { 2200b57cec5SDimitry Andric let EncoderMethod = "encodeImm<AVR::fixup_ldi, 0>"; 2210b57cec5SDimitry Andric} 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric/// A 5-bit port number used in SBIC and friends (the `FIOBIT` format). 224349cc55cSDimitry Andricdef imm_port5 : Operand<i8> { 2250b57cec5SDimitry Andric let EncoderMethod = "encodeImm<AVR::fixup_port5, 0>"; 2260b57cec5SDimitry Andric} 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric/// A 6-bit port number used in the `IN` instruction and friends (the 2290b57cec5SDimitry Andric/// `FIORdA` format. 230349cc55cSDimitry Andricdef imm_port6 : Operand<i8> { 2310b57cec5SDimitry Andric let EncoderMethod = "encodeImm<AVR::fixup_port6, 0>"; 2320b57cec5SDimitry Andric} 2330b57cec5SDimitry Andric 2340b57cec5SDimitry Andric// Addressing mode pattern reg+imm6 2350b57cec5SDimitry Andricdef addr : ComplexPattern<iPTR, 2, "SelectAddr", [], [SDNPWantRoot]>; 2360b57cec5SDimitry Andric 2370b57cec5SDimitry Andric// AsmOperand class for a pointer register. 2380b57cec5SDimitry Andric// Used with the LD/ST family of instructions. 2390b57cec5SDimitry Andric// See FSTLD in AVRInstrFormats.td 240349cc55cSDimitry Andricdef PtrRegAsmOperand : AsmOperandClass { let Name = "Reg"; } 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andric// A special operand type for the LD/ST instructions. 2430b57cec5SDimitry Andric// It converts the pointer register number into a two-bit field used in the 2440b57cec5SDimitry Andric// instruction. 245349cc55cSDimitry Andricdef LDSTPtrReg : Operand<i16> { 2460b57cec5SDimitry Andric let MIOperandInfo = (ops PTRREGS); 2470b57cec5SDimitry Andric let EncoderMethod = "encodeLDSTPtrReg"; 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andric let ParserMatchClass = PtrRegAsmOperand; 2500b57cec5SDimitry Andric} 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andric// A special operand type for the LDD/STD instructions. 2530b57cec5SDimitry Andric// It behaves identically to the LD/ST version, except restricts 2540b57cec5SDimitry Andric// the pointer registers to Y and Z. 255349cc55cSDimitry Andricdef LDDSTDPtrReg : Operand<i16> { 2560b57cec5SDimitry Andric let MIOperandInfo = (ops PTRDISPREGS); 2570b57cec5SDimitry Andric let EncoderMethod = "encodeLDSTPtrReg"; 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric let ParserMatchClass = PtrRegAsmOperand; 2600b57cec5SDimitry Andric} 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2630b57cec5SDimitry Andric// AVR predicates for subtarget features 2640b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andricdef HasSRAM : Predicate<"Subtarget->hasSRAM()">, 2675ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureSRAM)>; 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andricdef HasJMPCALL : Predicate<"Subtarget->hasJMPCALL()">, 2705ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureJMPCALL)>; 2710b57cec5SDimitry Andric 2720b57cec5SDimitry Andricdef HasIJMPCALL : Predicate<"Subtarget->hasIJMPCALL()">, 2735ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureIJMPCALL)>; 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andricdef HasEIJMPCALL : Predicate<"Subtarget->hasEIJMPCALL()">, 2765ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureEIJMPCALL)>; 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andricdef HasADDSUBIW : Predicate<"Subtarget->hasADDSUBIW()">, 2795ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureADDSUBIW)>; 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andricdef HasSmallStack : Predicate<"Subtarget->HasSmallStack()">, 2825ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureSmallStack)>; 2830b57cec5SDimitry Andric 2840b57cec5SDimitry Andricdef HasMOVW : Predicate<"Subtarget->hasMOVW()">, 2855ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureMOVW)>; 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andricdef HasLPM : Predicate<"Subtarget->hasLPM()">, 2885ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureLPM)>; 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andricdef HasLPMX : Predicate<"Subtarget->hasLPMX()">, 2915ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureLPMX)>; 2920b57cec5SDimitry Andric 2930b57cec5SDimitry Andricdef HasELPM : Predicate<"Subtarget->hasELPM()">, 2945ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureELPM)>; 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andricdef HasELPMX : Predicate<"Subtarget->hasELPMX()">, 2975ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureELPMX)>; 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andricdef HasSPM : Predicate<"Subtarget->hasSPM()">, 3005ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureSPM)>; 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andricdef HasSPMX : Predicate<"Subtarget->hasSPMX()">, 3035ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureSPMX)>; 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andricdef HasDES : Predicate<"Subtarget->hasDES()">, 3065ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureDES)>; 3070b57cec5SDimitry Andric 3080b57cec5SDimitry Andricdef SupportsRMW : Predicate<"Subtarget->supportsRMW()">, 3095ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureRMW)>; 3100b57cec5SDimitry Andric 3110b57cec5SDimitry Andricdef SupportsMultiplication : Predicate<"Subtarget->supportsMultiplication()">, 3125ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureMultiplication)>; 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andricdef HasBREAK : Predicate<"Subtarget->hasBREAK()">, 3155ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureBREAK)>; 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andricdef HasTinyEncoding : Predicate<"Subtarget->hasTinyEncoding()">, 3185ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureTinyEncoding)>; 3190b57cec5SDimitry Andric 320bdd1243dSDimitry Andricdef HasNonTinyEncoding : Predicate<"!Subtarget->hasTinyEncoding()">, 321bdd1243dSDimitry Andric AssemblerPredicate<(any_of (not FeatureTinyEncoding))>; 322bdd1243dSDimitry Andric 3230b57cec5SDimitry Andric// AVR specific condition code. These correspond to AVR_*_COND in 3240b57cec5SDimitry Andric// AVRInstrInfo.td. They must be kept in synch. 3250b57cec5SDimitry Andricdef AVR_COND_EQ : PatLeaf<(i8 0)>; 3260b57cec5SDimitry Andricdef AVR_COND_NE : PatLeaf<(i8 1)>; 3270b57cec5SDimitry Andricdef AVR_COND_GE : PatLeaf<(i8 2)>; 3280b57cec5SDimitry Andricdef AVR_COND_LT : PatLeaf<(i8 3)>; 3290b57cec5SDimitry Andricdef AVR_COND_SH : PatLeaf<(i8 4)>; 3300b57cec5SDimitry Andricdef AVR_COND_LO : PatLeaf<(i8 5)>; 3310b57cec5SDimitry Andricdef AVR_COND_MI : PatLeaf<(i8 6)>; 3320b57cec5SDimitry Andricdef AVR_COND_PL : PatLeaf<(i8 7)>; 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3350b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3360b57cec5SDimitry Andric// AVR Instruction list 3370b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3380b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andric// ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into 3410b57cec5SDimitry Andric// a stack adjustment and the codegen must know that they may modify the stack 3420b57cec5SDimitry Andric// pointer before prolog-epilog rewriting occurs. 3430b57cec5SDimitry Andric// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become 3440b57cec5SDimitry Andric// sub / add which can clobber SREG. 345349cc55cSDimitry Andriclet Defs = [SP, SREG], Uses = [SP] in { 346*0fca6ea1SDimitry Andric def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i16imm:$amt, i16imm:$amt2), 347*0fca6ea1SDimitry Andric "#ADJCALLSTACKDOWN", 348*0fca6ea1SDimitry Andric [(AVRcallseq_start timm:$amt, timm:$amt2)]>; 3490b57cec5SDimitry Andric 350fe6060f1SDimitry Andric // R31R30 is used to update SP. It is normally free because it is a 351fe6060f1SDimitry Andric // call-clobbered register but it is necessary to set it as a def as the 352fe6060f1SDimitry Andric // register allocator might use it in rare cases (for rematerialization, it 353fe6060f1SDimitry Andric // seems). hasSideEffects needs to be set to true so this instruction isn't 354fe6060f1SDimitry Andric // considered dead. 355349cc55cSDimitry Andric let Defs = [R31R30], hasSideEffects = 1 in def ADJCALLSTACKUP 356*0fca6ea1SDimitry Andric : Pseudo<(outs), (ins i16imm:$amt1, i16imm:$amt2), 357*0fca6ea1SDimitry Andric "#ADJCALLSTACKUP", [(AVRcallseq_end timm:$amt1, timm:$amt2)]>; 3580b57cec5SDimitry Andric} 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3610b57cec5SDimitry Andric// Addition 3620b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 363349cc55cSDimitry Andriclet isCommutable = 1, Constraints = "$src = $rd", Defs = [SREG] in { 3640b57cec5SDimitry Andric // ADD Rd, Rr 3650b57cec5SDimitry Andric // Adds two 8-bit registers. 366*0fca6ea1SDimitry Andric def ADDRdRr : FRdRr<0b0000, 0b11, (outs GPR8:$rd),(ins GPR8:$src, GPR8:$rr), 3670b57cec5SDimitry Andric "add\t$rd, $rr", 368*0fca6ea1SDimitry Andric [(set i8:$rd, (add i8:$src, i8:$rr)), (implicit SREG)]>; 3690b57cec5SDimitry Andric 3700b57cec5SDimitry Andric // ADDW Rd+1:Rd, Rr+1:Rr 3710b57cec5SDimitry Andric // Pseudo instruction to add four 8-bit registers as two 16-bit values. 3720b57cec5SDimitry Andric // 3730b57cec5SDimitry Andric // Expands to: 3740b57cec5SDimitry Andric // add Rd, Rr 3750b57cec5SDimitry Andric // adc Rd+1, Rr+1 376*0fca6ea1SDimitry Andric def ADDWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$src, DREGS:$rr), 3770b57cec5SDimitry Andric "addw\t$rd, $rr", 378*0fca6ea1SDimitry Andric [(set i16:$rd, (add i16:$src, i16:$rr)), 3790b57cec5SDimitry Andric (implicit SREG)]>; 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andric // ADC Rd, Rr 3820b57cec5SDimitry Andric // Adds two 8-bit registers with carry. 383*0fca6ea1SDimitry Andric let Uses = [SREG] in 384*0fca6ea1SDimitry Andric def ADCRdRr : FRdRr<0b0001, 0b11, (outs GPR8:$rd), (ins GPR8:$src, GPR8:$rr), 3850b57cec5SDimitry Andric "adc\t$rd, $rr", 386*0fca6ea1SDimitry Andric [(set i8:$rd, (adde i8:$src, i8:$rr)), (implicit SREG)]>; 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andric // ADCW Rd+1:Rd, Rr+1:Rr 3890b57cec5SDimitry Andric // Pseudo instruction to add four 8-bit registers as two 16-bit values with 3900b57cec5SDimitry Andric // carry. 3910b57cec5SDimitry Andric // 3920b57cec5SDimitry Andric // Expands to: 3930b57cec5SDimitry Andric // adc Rd, Rr 3940b57cec5SDimitry Andric // adc Rd+1, Rr+1 395*0fca6ea1SDimitry Andric let Uses = [SREG] in 396*0fca6ea1SDimitry Andric def ADCWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$src, DREGS:$rr), 397*0fca6ea1SDimitry Andric "adcw\t$rd, $rr", 398*0fca6ea1SDimitry Andric [(set i16:$rd, (adde i16:$src, i16:$rr)), 399*0fca6ea1SDimitry Andric (implicit SREG)]>; 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andric // AIDW Rd, k 4020b57cec5SDimitry Andric // Adds an immediate 6-bit value K to Rd, placing the result in Rd. 403*0fca6ea1SDimitry Andric def ADIWRdK : FWRdK<0b0, (outs IWREGS:$rd), (ins IWREGS :$src, imm_arith6:$k), 4040b57cec5SDimitry Andric "adiw\t$rd, $k", 405*0fca6ea1SDimitry Andric [(set i16:$rd, (add i16:$src, uimm6:$k)), 4060b57cec5SDimitry Andric (implicit SREG)]>, 4070b57cec5SDimitry Andric Requires<[HasADDSUBIW]>; 4080b57cec5SDimitry Andric} 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4110b57cec5SDimitry Andric// Subtraction 4120b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 413*0fca6ea1SDimitry Andriclet Constraints = "$rs = $rd", Defs = [SREG] in { 4140b57cec5SDimitry Andric // SUB Rd, Rr 4150b57cec5SDimitry Andric // Subtracts the 8-bit value of Rr from Rd and places the value in Rd. 416*0fca6ea1SDimitry Andric def SUBRdRr : FRdRr<0b0001, 0b10, (outs GPR8:$rd), (ins GPR8:$rs, GPR8:$rr), 4170b57cec5SDimitry Andric "sub\t$rd, $rr", 418*0fca6ea1SDimitry Andric [(set i8:$rd, (sub i8:$rs, i8:$rr)), (implicit SREG)]>; 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric // SUBW Rd+1:Rd, Rr+1:Rr 4210b57cec5SDimitry Andric // Subtracts two 16-bit values and places the result into Rd. 4220b57cec5SDimitry Andric // 4230b57cec5SDimitry Andric // Expands to: 4240b57cec5SDimitry Andric // sub Rd, Rr 4250b57cec5SDimitry Andric // sbc Rd+1, Rr+1 426*0fca6ea1SDimitry Andric def SUBWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$rs, DREGS:$rr), 4270b57cec5SDimitry Andric "subw\t$rd, $rr", 428*0fca6ea1SDimitry Andric [(set i16:$rd, (sub i16:$rs, i16:$rr)), 4290b57cec5SDimitry Andric (implicit SREG)]>; 4300b57cec5SDimitry Andric 431*0fca6ea1SDimitry Andric def SUBIRdK : FRdK<0b0101, (outs LD8:$rd), (ins LD8:$rs, imm_ldi8:$k), 4320b57cec5SDimitry Andric "subi\t$rd, $k", 433*0fca6ea1SDimitry Andric [(set i8:$rd, (sub i8:$rs, imm:$k)), (implicit SREG)]>; 4340b57cec5SDimitry Andric 4350b57cec5SDimitry Andric // SUBIW Rd+1:Rd, K+1:K 4360b57cec5SDimitry Andric // 4370b57cec5SDimitry Andric // Expands to: 4380b57cec5SDimitry Andric // subi Rd, K 4390b57cec5SDimitry Andric // sbci Rd+1, K+1 440*0fca6ea1SDimitry Andric def SUBIWRdK : Pseudo<(outs DLDREGS:$rd), (ins DLDREGS:$rs, i16imm:$rr), 4410b57cec5SDimitry Andric "subiw\t$rd, $rr", 442*0fca6ea1SDimitry Andric [(set i16:$rd, (sub i16:$rs, imm:$rr)), 4430b57cec5SDimitry Andric (implicit SREG)]>; 4440b57cec5SDimitry Andric 445*0fca6ea1SDimitry Andric def SBIWRdK : FWRdK<0b1, (outs IWREGS:$rd), (ins IWREGS:$rs, imm_arith6:$k), 4460b57cec5SDimitry Andric "sbiw\t$rd, $k", 447*0fca6ea1SDimitry Andric [(set i16:$rd, (sub i16:$rs, uimm6:$k)), 4480b57cec5SDimitry Andric (implicit SREG)]>, 4490b57cec5SDimitry Andric Requires<[HasADDSUBIW]>; 4500b57cec5SDimitry Andric 4510b57cec5SDimitry Andric // Subtract with carry operations which must read the carry flag in SREG. 452349cc55cSDimitry Andric let Uses = [SREG] in { 453*0fca6ea1SDimitry Andric def SBCRdRr : FRdRr<0b0000, 0b10, (outs GPR8:$rd), (ins GPR8:$rs, GPR8:$rr), 4540b57cec5SDimitry Andric "sbc\t$rd, $rr", 455*0fca6ea1SDimitry Andric [(set i8:$rd, (sube i8:$rs, i8:$rr)), (implicit SREG)]>; 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andric // SBCW Rd+1:Rd, Rr+1:Rr 4580b57cec5SDimitry Andric // 4590b57cec5SDimitry Andric // Expands to: 4600b57cec5SDimitry Andric // sbc Rd, Rr 4610b57cec5SDimitry Andric // sbc Rd+1, Rr+1 462*0fca6ea1SDimitry Andric def SBCWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$rs, DREGS:$rr), 463*0fca6ea1SDimitry Andric "sbcw\t$rd, $rr", 464*0fca6ea1SDimitry Andric [(set i16:$rd, (sube i16:$rs, i16:$rr)), 4650b57cec5SDimitry Andric (implicit SREG)]>; 4660b57cec5SDimitry Andric 467*0fca6ea1SDimitry Andric def SBCIRdK : FRdK<0b0100, (outs LD8:$rd), (ins LD8:$rs, imm_ldi8:$k), 468*0fca6ea1SDimitry Andric "sbci\t$rd, $k", 469*0fca6ea1SDimitry Andric [(set i8:$rd, (sube i8:$rs, imm:$k)), (implicit SREG)]>; 470*0fca6ea1SDimitry Andric 4710b57cec5SDimitry Andric // SBCIW Rd+1:Rd, K+1:K 4720b57cec5SDimitry Andric // sbci Rd, K 4730b57cec5SDimitry Andric // sbci Rd+1, K+1 474*0fca6ea1SDimitry Andric def SBCIWRdK : Pseudo<(outs DLDREGS:$rd), (ins DLDREGS:$rs, i16imm:$rr), 475*0fca6ea1SDimitry Andric "sbciw\t$rd, $rr", 476*0fca6ea1SDimitry Andric [(set i16:$rd, (sube i16:$rs, imm:$rr)), 477*0fca6ea1SDimitry Andric (implicit SREG)]>; 4780b57cec5SDimitry Andric } 4790b57cec5SDimitry Andric} 4800b57cec5SDimitry Andric 4810b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4820b57cec5SDimitry Andric// Increment and Decrement 4830b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 484349cc55cSDimitry Andriclet Constraints = "$src = $rd", Defs = [SREG] in { 485*0fca6ea1SDimitry Andric def INCRd : FRd<0b1001, 0b0100011, (outs GPR8:$rd), (ins GPR8:$src), 486*0fca6ea1SDimitry Andric "inc\t$rd", 487*0fca6ea1SDimitry Andric [(set i8:$rd, (add i8:$src, 1)), (implicit SREG)]>; 4880b57cec5SDimitry Andric 489*0fca6ea1SDimitry Andric def DECRd : FRd<0b1001, 0b0101010, (outs GPR8:$rd), (ins GPR8:$src), 490*0fca6ea1SDimitry Andric "dec\t$rd", 491*0fca6ea1SDimitry Andric [(set i8:$rd, (add i8:$src, -1)), (implicit SREG)]>; 4920b57cec5SDimitry Andric} 4930b57cec5SDimitry Andric 4940b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4950b57cec5SDimitry Andric// Multiplication 4960b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4970b57cec5SDimitry Andric 498349cc55cSDimitry Andriclet isCommutable = 1, Defs = [R1, R0, SREG] in { 4990b57cec5SDimitry Andric // MUL Rd, Rr 5000b57cec5SDimitry Andric // Multiplies Rd by Rr and places the result into R1:R0. 5010b57cec5SDimitry Andric let usesCustomInserter = 1 in { 502*0fca6ea1SDimitry Andric def MULRdRr : FRdRr<0b1001, 0b11, (outs), (ins GPR8:$rd, GPR8:$rr), 503*0fca6ea1SDimitry Andric "mul\t$rd, $rr", []>, 5040b57cec5SDimitry Andric Requires<[SupportsMultiplication]>; 5050b57cec5SDimitry Andric 506*0fca6ea1SDimitry Andric def MULSRdRr : FMUL2RdRr<0, (outs), (ins LD8:$rd, LD8:$rr), 507bdd1243dSDimitry Andric "muls\t$rd, $rr", []>, 5080b57cec5SDimitry Andric Requires<[SupportsMultiplication]>; 5090b57cec5SDimitry Andric } 5100b57cec5SDimitry Andric 511*0fca6ea1SDimitry Andric def MULSURdRr : FMUL2RdRr<1, (outs), (ins LD8lo:$rd, LD8lo:$rr), 512bdd1243dSDimitry Andric "mulsu\t$rd, $rr", []>, 5130b57cec5SDimitry Andric Requires<[SupportsMultiplication]>; 5140b57cec5SDimitry Andric 515*0fca6ea1SDimitry Andric def FMUL : FFMULRdRr<0b01, (outs), (ins LD8lo:$rd, LD8lo:$rr), 516bdd1243dSDimitry Andric "fmul\t$rd, $rr", []>, 5170b57cec5SDimitry Andric Requires<[SupportsMultiplication]>; 5180b57cec5SDimitry Andric 519*0fca6ea1SDimitry Andric def FMULS : FFMULRdRr<0b10, (outs), (ins LD8lo:$rd, LD8lo:$rr), 520bdd1243dSDimitry Andric "fmuls\t$rd, $rr", []>, 5210b57cec5SDimitry Andric Requires<[SupportsMultiplication]>; 5220b57cec5SDimitry Andric 523*0fca6ea1SDimitry Andric def FMULSU : FFMULRdRr<0b11, (outs), (ins LD8lo:$rd, LD8lo:$rr), 524bdd1243dSDimitry Andric "fmulsu\t$rd, $rr", []>, 5250b57cec5SDimitry Andric Requires<[SupportsMultiplication]>; 5260b57cec5SDimitry Andric} 5270b57cec5SDimitry Andric 528349cc55cSDimitry Andriclet Defs = 529*0fca6ea1SDimitry Andric [R15, R14, R13, R12, R11, R10, R9, R8, R7, R6, R5, R4, R3, R2, R1, R0] in 530*0fca6ea1SDimitry Andricdef DESK : FDES<(outs), (ins i8imm:$k), "des\t$k", []>, Requires<[HasDES]>; 5310b57cec5SDimitry Andric 5320b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 5330b57cec5SDimitry Andric// Logic 5340b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 535349cc55cSDimitry Andriclet Constraints = "$src = $rd", Defs = [SREG] in { 5360b57cec5SDimitry Andric // Register-Register logic instructions (which have the 5370b57cec5SDimitry Andric // property of commutativity). 538349cc55cSDimitry Andric let isCommutable = 1 in { 539*0fca6ea1SDimitry Andric def ANDRdRr : FRdRr<0b0010, 0b00, (outs GPR8:$rd), 540*0fca6ea1SDimitry Andric (ins GPR8:$src, GPR8:$rr), "and\t$rd, $rr", 541*0fca6ea1SDimitry Andric [(set i8:$rd, (and i8:$src, i8:$rr)), (implicit SREG)]>; 5420b57cec5SDimitry Andric 5430b57cec5SDimitry Andric // ANDW Rd+1:Rd, Rr+1:Rr 5440b57cec5SDimitry Andric // 5450b57cec5SDimitry Andric // Expands to: 5460b57cec5SDimitry Andric // and Rd, Rr 5470b57cec5SDimitry Andric // and Rd+1, Rr+1 548*0fca6ea1SDimitry Andric def ANDWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$src, DREGS:$rr), 549*0fca6ea1SDimitry Andric "andw\t$rd, $rr", 550*0fca6ea1SDimitry Andric [(set i16:$rd, (and i16:$src, i16:$rr)), 5510b57cec5SDimitry Andric (implicit SREG)]>; 5520b57cec5SDimitry Andric 553*0fca6ea1SDimitry Andric def ORRdRr : FRdRr<0b0010, 0b10, (outs GPR8:$rd), (ins GPR8:$src, GPR8:$rr), 554*0fca6ea1SDimitry Andric "or\t$rd, $rr", 555*0fca6ea1SDimitry Andric [(set i8:$rd, (or i8:$src, i8:$rr)), (implicit SREG)]>; 556*0fca6ea1SDimitry Andric 5570b57cec5SDimitry Andric // ORW Rd+1:Rd, Rr+1:Rr 5580b57cec5SDimitry Andric // 5590b57cec5SDimitry Andric // Expands to: 5600b57cec5SDimitry Andric // or Rd, Rr 5610b57cec5SDimitry Andric // or Rd+1, Rr+1 562*0fca6ea1SDimitry Andric def ORWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$src, DREGS:$rr), 563*0fca6ea1SDimitry Andric "orw\t$rd, $rr", 564*0fca6ea1SDimitry Andric [(set i16:$rd, (or i16:$src, i16:$rr)), 5650b57cec5SDimitry Andric (implicit SREG)]>; 5660b57cec5SDimitry Andric 567*0fca6ea1SDimitry Andric def EORRdRr : FRdRr<0b0010, 0b01, (outs GPR8:$rd), 568*0fca6ea1SDimitry Andric (ins GPR8:$src, GPR8:$rr), "eor\t$rd, $rr", 569*0fca6ea1SDimitry Andric [(set i8:$rd, (xor i8:$src, i8:$rr)), (implicit SREG)]>; 570*0fca6ea1SDimitry Andric 5710b57cec5SDimitry Andric // EORW Rd+1:Rd, Rr+1:Rr 5720b57cec5SDimitry Andric // 5730b57cec5SDimitry Andric // Expands to: 5740b57cec5SDimitry Andric // eor Rd, Rr 5750b57cec5SDimitry Andric // eor Rd+1, Rr+1 576*0fca6ea1SDimitry Andric def EORWRdRr : Pseudo<(outs DREGS:$rd), (ins DREGS:$src, DREGS:$rr), 577*0fca6ea1SDimitry Andric "eorw\t$rd, $rr", 578*0fca6ea1SDimitry Andric [(set i16:$rd, (xor i16:$src, i16:$rr)), 579*0fca6ea1SDimitry Andric (implicit SREG)]>; 5800b57cec5SDimitry Andric } 5810b57cec5SDimitry Andric 582*0fca6ea1SDimitry Andric def ANDIRdK : FRdK<0b0111, (outs LD8:$rd), (ins LD8:$src, imm_ldi8:$k), 5830b57cec5SDimitry Andric "andi\t$rd, $k", 584*0fca6ea1SDimitry Andric [(set i8:$rd, (and i8:$src, imm:$k)), (implicit SREG)]>; 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric // ANDI Rd+1:Rd, K+1:K 5870b57cec5SDimitry Andric // 5880b57cec5SDimitry Andric // Expands to: 5890b57cec5SDimitry Andric // andi Rd, K 5900b57cec5SDimitry Andric // andi Rd+1, K+1 591*0fca6ea1SDimitry Andric def ANDIWRdK : Pseudo<(outs DLDREGS:$rd), (ins DLDREGS:$src, i16imm:$k), 5920b57cec5SDimitry Andric "andiw\t$rd, $k", 593*0fca6ea1SDimitry Andric [(set i16:$rd, (and i16:$src, imm:$k)), 5940b57cec5SDimitry Andric (implicit SREG)]>; 5950b57cec5SDimitry Andric 596*0fca6ea1SDimitry Andric def ORIRdK : FRdK<0b0110, (outs LD8:$rd), (ins LD8:$src, imm_ldi8:$k), 5970b57cec5SDimitry Andric "ori\t$rd, $k", 598*0fca6ea1SDimitry Andric [(set i8:$rd, (or i8:$src, imm:$k)), (implicit SREG)]>; 5990b57cec5SDimitry Andric 6000b57cec5SDimitry Andric // ORIW Rd+1:Rd, K+1,K 6010b57cec5SDimitry Andric // 6020b57cec5SDimitry Andric // Expands to: 6030b57cec5SDimitry Andric // ori Rd, K 6040b57cec5SDimitry Andric // ori Rd+1, K+1 605*0fca6ea1SDimitry Andric def ORIWRdK : Pseudo<(outs DLDREGS:$rd), (ins DLDREGS:$src, i16imm:$rr), 6060b57cec5SDimitry Andric "oriw\t$rd, $rr", 607*0fca6ea1SDimitry Andric [(set i16:$rd, (or i16:$src, imm:$rr)), 6080b57cec5SDimitry Andric (implicit SREG)]>; 6090b57cec5SDimitry Andric} 6100b57cec5SDimitry Andric 6110b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6120b57cec5SDimitry Andric// One's/Two's Complement 6130b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 614349cc55cSDimitry Andriclet Constraints = "$src = $rd", Defs = [SREG] in { 615*0fca6ea1SDimitry Andric def COMRd : FRd<0b1001, 0b0100000, (outs GPR8:$rd), (ins GPR8:$src), 616*0fca6ea1SDimitry Andric "com\t$rd", [(set i8:$rd, (not i8:$src)), (implicit SREG)]>; 6170b57cec5SDimitry Andric 6180b57cec5SDimitry Andric // COMW Rd+1:Rd 6190b57cec5SDimitry Andric // 6200b57cec5SDimitry Andric // Expands to: 6210b57cec5SDimitry Andric // com Rd 6220b57cec5SDimitry Andric // com Rd+1 623*0fca6ea1SDimitry Andric def COMWRd : Pseudo<(outs DREGS:$rd), (ins DREGS:$src), "comw\t$rd", 624*0fca6ea1SDimitry Andric [(set i16:$rd, (not i16:$src)), (implicit SREG)]>; 6250b57cec5SDimitry Andric 626*0fca6ea1SDimitry Andric def NEGRd : FRd<0b1001, 0b0100001, (outs GPR8:$rd), (ins GPR8:$src), 627*0fca6ea1SDimitry Andric "neg\t$rd", [(set i8:$rd, (ineg i8:$src)), (implicit SREG)]>; 628e8d8bef9SDimitry Andric 629e8d8bef9SDimitry Andric // NEGW Rd+1:Rd 630e8d8bef9SDimitry Andric // 631e8d8bef9SDimitry Andric // Expands to: 632e8d8bef9SDimitry Andric // neg Rd+1 633e8d8bef9SDimitry Andric // neg Rd 634fe6060f1SDimitry Andric // sbc Rd+1, r1 635bdd1243dSDimitry Andric let hasSideEffects=0 in 636*0fca6ea1SDimitry Andric def NEGWRd : Pseudo<(outs DREGS:$rd), (ins DREGS:$src, GPR8:$zero), 637*0fca6ea1SDimitry Andric "negw\t$rd", []>; 6380b57cec5SDimitry Andric} 6390b57cec5SDimitry Andric 6400b57cec5SDimitry Andric// TST Rd 6410b57cec5SDimitry Andric// Test for zero of minus. 6420b57cec5SDimitry Andric// This operation is identical to a `Rd AND Rd`. 6430b57cec5SDimitry Andricdef : InstAlias<"tst\t$rd", (ANDRdRr GPR8:$rd, GPR8:$rd)>; 6440b57cec5SDimitry Andric 6450b57cec5SDimitry Andric// SBR Rd, K 6460b57cec5SDimitry Andric// 6470b57cec5SDimitry Andric// Mnemonic alias to 'ORI Rd, K'. Same bit pattern, same operands, 6480b57cec5SDimitry Andric// same everything. 649*0fca6ea1SDimitry Andricdef : InstAlias<"sbr\t$rd, $k", (ORIRdK LD8:$rd, imm_ldi8:$k), 6500b57cec5SDimitry Andric /* Disable display, so we don't override ORI */ 0>; 6510b57cec5SDimitry Andric 6520b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6530b57cec5SDimitry Andric// Jump instructions 6540b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 655349cc55cSDimitry Andriclet isBarrier = 1, isBranch = 1, isTerminator = 1 in { 656*0fca6ea1SDimitry Andric def RJMPk : FBRk<0, (outs), (ins brtarget_13:$k), "rjmp\t$k", [(br bb:$k)]>; 6570b57cec5SDimitry Andric 658*0fca6ea1SDimitry Andric let isIndirectBranch = 1, Uses = [R31R30] in 659*0fca6ea1SDimitry Andric def IJMP : F16<0b1001010000001001, (outs), (ins), "ijmp", []>, 6600b57cec5SDimitry Andric Requires<[HasIJMPCALL]>; 6610b57cec5SDimitry Andric 662*0fca6ea1SDimitry Andric let isIndirectBranch = 1, Uses = [R31R30] in 663*0fca6ea1SDimitry Andric def EIJMP : F16<0b1001010000011001, (outs), (ins), "eijmp", []>, 6640b57cec5SDimitry Andric Requires<[HasEIJMPCALL]>; 6650b57cec5SDimitry Andric 666*0fca6ea1SDimitry Andric def JMPk : F32BRk<0b110, (outs), (ins call_target:$k), "jmp\t$k", []>, 6670b57cec5SDimitry Andric Requires<[HasJMPCALL]>; 6680b57cec5SDimitry Andric} 6690b57cec5SDimitry Andric 6700b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 6710b57cec5SDimitry Andric// Call instructions 6720b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 673349cc55cSDimitry Andriclet isCall = 1 in { 6740b57cec5SDimitry Andric // SP is marked as a use to prevent stack-pointer assignments that appear 6750b57cec5SDimitry Andric // immediately before calls from potentially appearing dead. 676*0fca6ea1SDimitry Andric let Uses = [SP] in 677*0fca6ea1SDimitry Andric def RCALLk : FBRk<1, (outs), (ins rcalltarget_13:$k), "rcall\t$k", 678*0fca6ea1SDimitry Andric [(AVRcall imm:$k)]>; 6790b57cec5SDimitry Andric 6800b57cec5SDimitry Andric // SP is marked as a use to prevent stack-pointer assignments that appear 6810b57cec5SDimitry Andric // immediately before calls from potentially appearing dead. 682*0fca6ea1SDimitry Andric let Uses = [SP, R31R30] in 683*0fca6ea1SDimitry Andric def ICALL : F16<0b1001010100001001, (outs), (ins variable_ops), "icall", []>, 6840b57cec5SDimitry Andric Requires<[HasIJMPCALL]>; 6850b57cec5SDimitry Andric 6860b57cec5SDimitry Andric // SP is marked as a use to prevent stack-pointer assignments that appear 6870b57cec5SDimitry Andric // immediately before calls from potentially appearing dead. 688*0fca6ea1SDimitry Andric let Uses = [SP, R31R30] in 689*0fca6ea1SDimitry Andric def EICALL : F16<0b1001010100011001, (outs), (ins variable_ops), "eicall", 690*0fca6ea1SDimitry Andric []>, 6910b57cec5SDimitry Andric Requires<[HasEIJMPCALL]>; 6920b57cec5SDimitry Andric 6930b57cec5SDimitry Andric // SP is marked as a use to prevent stack-pointer assignments that appear 6940b57cec5SDimitry Andric // immediately before calls from potentially appearing dead. 6950b57cec5SDimitry Andric // 6962a66634dSDimitry Andric // TODO: the imm field can be either 16 or 22 bits in devices with more 6970b57cec5SDimitry Andric // than 64k of ROM, fix it once we support the largest devices. 698*0fca6ea1SDimitry Andric let Uses = [SP] in 699*0fca6ea1SDimitry Andric def CALLk : F32BRk<0b111, (outs), (ins call_target:$k), "call\t$k", 700*0fca6ea1SDimitry Andric [(AVRcall imm:$k)]>, 7010b57cec5SDimitry Andric Requires<[HasJMPCALL]>; 7020b57cec5SDimitry Andric} 7030b57cec5SDimitry Andric 7040b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7050b57cec5SDimitry Andric// Return instructions. 7060b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 707349cc55cSDimitry Andriclet isTerminator = 1, isReturn = 1, isBarrier = 1 in { 70806c3fb27SDimitry Andric def RET : F16<0b1001010100001000, (outs), (ins), "ret", [(AVRretglue)]>; 7090b57cec5SDimitry Andric 71006c3fb27SDimitry Andric def RETI : F16<0b1001010100011000, (outs), (ins), "reti", [(AVRretiglue)]>; 7110b57cec5SDimitry Andric} 7120b57cec5SDimitry Andric 7130b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7140b57cec5SDimitry Andric// Compare operations. 7150b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 716349cc55cSDimitry Andriclet Defs = [SREG] in { 7170b57cec5SDimitry Andric // CPSE Rd, Rr 7180b57cec5SDimitry Andric // Compare Rd and Rr, skipping the next instruction if they are equal. 719*0fca6ea1SDimitry Andric let isBarrier = 1, isBranch = 1, isTerminator = 1 in 720*0fca6ea1SDimitry Andric def CPSE : FRdRr<0b0001, 0b00, (outs), (ins GPR8:$rd, GPR8:$rr), 721349cc55cSDimitry Andric "cpse\t$rd, $rr", []>; 7220b57cec5SDimitry Andric 723*0fca6ea1SDimitry Andric def CPRdRr : FRdRr<0b0001, 0b01, (outs), (ins GPR8:$rd, GPR8:$rr), 724*0fca6ea1SDimitry Andric "cp\t$rd, $rr", 725*0fca6ea1SDimitry Andric [(AVRcmp i8:$rd, i8:$rr), (implicit SREG)]>; 7260b57cec5SDimitry Andric 7270b57cec5SDimitry Andric // CPW Rd+1:Rd, Rr+1:Rr 7280b57cec5SDimitry Andric // 7290b57cec5SDimitry Andric // Expands to: 7300b57cec5SDimitry Andric // cp Rd, Rr 7310b57cec5SDimitry Andric // cpc Rd+1, Rr+1 732*0fca6ea1SDimitry Andric def CPWRdRr : Pseudo<(outs), (ins DREGS:$src, DREGS:$src2), 7330b57cec5SDimitry Andric "cpw\t$src, $src2", 734*0fca6ea1SDimitry Andric [(AVRcmp i16:$src, i16:$src2), (implicit SREG)]>; 7350b57cec5SDimitry Andric 736*0fca6ea1SDimitry Andric let Uses = [SREG] in 737*0fca6ea1SDimitry Andric def CPCRdRr : FRdRr<0b0000, 0b01, (outs), (ins GPR8:$rd, GPR8:$rr), 738*0fca6ea1SDimitry Andric "cpc\t$rd, $rr", 739*0fca6ea1SDimitry Andric [(AVRcmpc i8:$rd, i8:$rr), (implicit SREG)]>; 7400b57cec5SDimitry Andric 7410b57cec5SDimitry Andric // CPCW Rd+1:Rd. Rr+1:Rr 7420b57cec5SDimitry Andric // 7430b57cec5SDimitry Andric // Expands to: 7440b57cec5SDimitry Andric // cpc Rd, Rr 7450b57cec5SDimitry Andric // cpc Rd+1, Rr+1 746*0fca6ea1SDimitry Andric let Uses = [SREG] in 747*0fca6ea1SDimitry Andric def CPCWRdRr : Pseudo<(outs), (ins DREGS:$src, DREGS:$src2), 7480b57cec5SDimitry Andric "cpcw\t$src, $src2", 749*0fca6ea1SDimitry Andric [(AVRcmpc i16:$src, i16:$src2), (implicit SREG)]>; 7500b57cec5SDimitry Andric 7510b57cec5SDimitry Andric // CPI Rd, K 7520b57cec5SDimitry Andric // Compares a register with an 8 bit immediate. 753*0fca6ea1SDimitry Andric def CPIRdK : FRdK<0b0011, (outs), (ins LD8:$rd, imm_ldi8:$k), "cpi\t$rd, $k", 754*0fca6ea1SDimitry Andric [(AVRcmp i8:$rd, imm:$k), (implicit SREG)]>; 7550b57cec5SDimitry Andric} 7560b57cec5SDimitry Andric 7570b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 7580b57cec5SDimitry Andric// Register conditional skipping/branching operations. 7590b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 760349cc55cSDimitry Andriclet isBranch = 1, isTerminator = 1 in { 7610b57cec5SDimitry Andric // Conditional skipping on GPR register bits, and 7620b57cec5SDimitry Andric // conditional skipping on IO register bits. 763349cc55cSDimitry Andric let isBarrier = 1 in { 764*0fca6ea1SDimitry Andric def SBRCRrB : FRdB<0b10, (outs), (ins GPR8:$rd, i8imm:$b), "sbrc\t$rd, $b", 765*0fca6ea1SDimitry Andric []>; 7660b57cec5SDimitry Andric 767*0fca6ea1SDimitry Andric def SBRSRrB : FRdB<0b11, (outs), (ins GPR8:$rd, i8imm:$b), "sbrs\t$rd, $b", 768*0fca6ea1SDimitry Andric []>; 7690b57cec5SDimitry Andric 770*0fca6ea1SDimitry Andric def SBICAb : FIOBIT<0b01, (outs), (ins imm_port5:$addr, i8imm:$b), 771bdd1243dSDimitry Andric "sbic\t$addr, $b", []>; 7720b57cec5SDimitry Andric 773*0fca6ea1SDimitry Andric def SBISAb : FIOBIT<0b11, (outs), (ins imm_port5:$addr, i8imm:$b), 774bdd1243dSDimitry Andric "sbis\t$addr, $b", []>; 7750b57cec5SDimitry Andric } 7760b57cec5SDimitry Andric 7770b57cec5SDimitry Andric // Relative branches on status flag bits. 778349cc55cSDimitry Andric let Uses = [SREG] in { 7790b57cec5SDimitry Andric // BRBS s, k 7800b57cec5SDimitry Andric // Branch if `s` flag in status register is set. 781*0fca6ea1SDimitry Andric def BRBSsk : FSK<0, (outs), (ins i8imm:$s, relbrtarget_7:$k), 782349cc55cSDimitry Andric "brbs\t$s, $k", []>; 7830b57cec5SDimitry Andric 7840b57cec5SDimitry Andric // BRBC s, k 7850b57cec5SDimitry Andric // Branch if `s` flag in status register is clear. 786*0fca6ea1SDimitry Andric def BRBCsk : FSK<1, (outs), (ins i8imm:$s, relbrtarget_7:$k), 787349cc55cSDimitry Andric "brbc\t$s, $k", []>; 7880b57cec5SDimitry Andric } 7890b57cec5SDimitry Andric} 7900b57cec5SDimitry Andric 7910b57cec5SDimitry Andric// BRCS k 7920b57cec5SDimitry Andric// Branch if carry flag is set 7930b57cec5SDimitry Andricdef : InstAlias<"brcs\t$k", (BRBSsk 0, relbrtarget_7 : $k)>; 7940b57cec5SDimitry Andric 7950b57cec5SDimitry Andric// BRCC k 7960b57cec5SDimitry Andric// Branch if carry flag is clear 7970b57cec5SDimitry Andricdef : InstAlias<"brcc\t$k", (BRBCsk 0, relbrtarget_7 : $k)>; 7980b57cec5SDimitry Andric 7990b57cec5SDimitry Andric// BRHS k 8000b57cec5SDimitry Andric// Branch if half carry flag is set 8010b57cec5SDimitry Andricdef : InstAlias<"brhs\t$k", (BRBSsk 5, relbrtarget_7 : $k)>; 8020b57cec5SDimitry Andric 8030b57cec5SDimitry Andric// BRHC k 8040b57cec5SDimitry Andric// Branch if half carry flag is clear 8050b57cec5SDimitry Andricdef : InstAlias<"brhc\t$k", (BRBCsk 5, relbrtarget_7 : $k)>; 8060b57cec5SDimitry Andric 8070b57cec5SDimitry Andric// BRTS k 8080b57cec5SDimitry Andric// Branch if the T flag is set 8090b57cec5SDimitry Andricdef : InstAlias<"brts\t$k", (BRBSsk 6, relbrtarget_7 : $k)>; 8100b57cec5SDimitry Andric 8110b57cec5SDimitry Andric// BRTC k 8120b57cec5SDimitry Andric// Branch if the T flag is clear 8130b57cec5SDimitry Andricdef : InstAlias<"brtc\t$k", (BRBCsk 6, relbrtarget_7 : $k)>; 8140b57cec5SDimitry Andric 8150b57cec5SDimitry Andric// BRVS k 8160b57cec5SDimitry Andric// Branch if the overflow flag is set 8170b57cec5SDimitry Andricdef : InstAlias<"brvs\t$k", (BRBSsk 3, relbrtarget_7 : $k)>; 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric// BRVC k 8200b57cec5SDimitry Andric// Branch if the overflow flag is clear 8210b57cec5SDimitry Andricdef : InstAlias<"brvc\t$k", (BRBCsk 3, relbrtarget_7 : $k)>; 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric// BRIE k 8240b57cec5SDimitry Andric// Branch if the global interrupt flag is enabled 8250b57cec5SDimitry Andricdef : InstAlias<"brie\t$k", (BRBSsk 7, relbrtarget_7 : $k)>; 8260b57cec5SDimitry Andric 8270b57cec5SDimitry Andric// BRID k 8280b57cec5SDimitry Andric// Branch if the global interrupt flag is disabled 8290b57cec5SDimitry Andricdef : InstAlias<"brid\t$k", (BRBCsk 7, relbrtarget_7 : $k)>; 8300b57cec5SDimitry Andric 8310b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8320b57cec5SDimitry Andric// PC-relative conditional branches 8330b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8340b57cec5SDimitry Andric// Based on status register. We cannot simplify these into instruction aliases 8350b57cec5SDimitry Andric// because we also need to be able to specify a pattern to match for ISel. 836349cc55cSDimitry Andriclet isBranch = 1, isTerminator = 1, Uses = [SREG] in { 837*0fca6ea1SDimitry Andric def BREQk : FBRsk<0, 0b001, (outs), (ins relbrtarget_7:$k), "breq\t$k", 838*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_EQ)]>; 8390b57cec5SDimitry Andric 840*0fca6ea1SDimitry Andric def BRNEk : FBRsk<1, 0b001, (outs), (ins relbrtarget_7:$k), "brne\t$k", 841*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_NE)]>; 8420b57cec5SDimitry Andric 843*0fca6ea1SDimitry Andric def BRSHk : FBRsk<1, 0b000, (outs), (ins relbrtarget_7:$k), "brsh\t$k", 844*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_SH)]>; 8450b57cec5SDimitry Andric 846*0fca6ea1SDimitry Andric def BRLOk : FBRsk<0, 0b000, (outs), (ins relbrtarget_7:$k), "brlo\t$k", 847*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_LO)]>; 8480b57cec5SDimitry Andric 849*0fca6ea1SDimitry Andric def BRMIk : FBRsk<0, 0b010, (outs), (ins relbrtarget_7:$k), "brmi\t$k", 850*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_MI)]>; 8510b57cec5SDimitry Andric 852*0fca6ea1SDimitry Andric def BRPLk : FBRsk<1, 0b010, (outs), (ins relbrtarget_7:$k), "brpl\t$k", 853*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_PL)]>; 8540b57cec5SDimitry Andric 855*0fca6ea1SDimitry Andric def BRGEk : FBRsk<1, 0b100, (outs), (ins relbrtarget_7:$k), "brge\t$k", 856*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_GE)]>; 8570b57cec5SDimitry Andric 858*0fca6ea1SDimitry Andric def BRLTk : FBRsk<0, 0b100, (outs), (ins relbrtarget_7:$k), "brlt\t$k", 859*0fca6ea1SDimitry Andric [(AVRbrcond bb:$k, AVR_COND_LT)]>; 8600b57cec5SDimitry Andric} 8610b57cec5SDimitry Andric 8620b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8630b57cec5SDimitry Andric// Data transfer instructions 8640b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8650b57cec5SDimitry Andric// 8 and 16-bit register move instructions. 866349cc55cSDimitry Andriclet hasSideEffects = 0 in { 867*0fca6ea1SDimitry Andric def MOVRdRr : FRdRr<0b0010, 0b11, (outs GPR8:$rd), (ins GPR8:$rr), 868349cc55cSDimitry Andric "mov\t$rd, $rr", []>; 8690b57cec5SDimitry Andric 870*0fca6ea1SDimitry Andric def MOVWRdRr : FMOVWRdRr<(outs DREGS:$rd), (ins DREGS:$rr), "movw\t$rd, $rr", 871*0fca6ea1SDimitry Andric []>, 8720b57cec5SDimitry Andric Requires<[HasMOVW]>; 8730b57cec5SDimitry Andric} 8740b57cec5SDimitry Andric 8750b57cec5SDimitry Andric// Load immediate values into registers. 876349cc55cSDimitry Andriclet isReMaterializable = 1 in { 877*0fca6ea1SDimitry Andric def LDIRdK : FRdK<0b1110, (outs LD8:$rd), (ins imm_ldi8:$k), "ldi\t$rd, $k", 878*0fca6ea1SDimitry Andric [(set i8:$rd, imm:$k)]>; 8790b57cec5SDimitry Andric 8800b57cec5SDimitry Andric // LDIW Rd+1:Rd, K+1:K 8810b57cec5SDimitry Andric // 8820b57cec5SDimitry Andric // Expands to: 8830b57cec5SDimitry Andric // ldi Rd, K 8840b57cec5SDimitry Andric // ldi Rd+1, K+1 885*0fca6ea1SDimitry Andric def LDIWRdK : Pseudo<(outs DLDREGS:$dst), (ins i16imm:$src), 886*0fca6ea1SDimitry Andric "ldiw\t$dst, $src", [(set i16:$dst, imm:$src)]>; 8870b57cec5SDimitry Andric} 8880b57cec5SDimitry Andric 8890b57cec5SDimitry Andric// Load from data space into register. 890349cc55cSDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1 in { 891*0fca6ea1SDimitry Andric def LDSRdK : F32DM<0b0, (outs GPR8:$rd), (ins imm16:$k), "lds\t$rd, $k", 892*0fca6ea1SDimitry Andric [(set i8:$rd, (load imm:$k))]>, 893bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 894bdd1243dSDimitry Andric 895bdd1243dSDimitry Andric // Load from data space into register, which is only available on AVRTiny. 896bdd1243dSDimitry Andric def LDSRdKTiny : FLDSSTSTINY<0b0, (outs LD8:$rd), (ins imm7tiny:$k), 897*0fca6ea1SDimitry Andric "lds\t$rd, $k", [(set i8:$rd, (load imm:$k))]>, 898bdd1243dSDimitry Andric Requires<[HasSRAM, HasTinyEncoding]>; 8990b57cec5SDimitry Andric 9000b57cec5SDimitry Andric // LDSW Rd+1:Rd, K+1:K 9010b57cec5SDimitry Andric // 9020b57cec5SDimitry Andric // Expands to: 9030b57cec5SDimitry Andric // lds Rd, (K+1:K) 9040b57cec5SDimitry Andric // lds Rd+1 (K+1:K) + 1 905*0fca6ea1SDimitry Andric def LDSWRdK : Pseudo<(outs DREGS:$dst), (ins i16imm:$src), "ldsw\t$dst, $src", 906*0fca6ea1SDimitry Andric [(set i16:$dst, (load imm:$src))]>, 907bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 9080b57cec5SDimitry Andric} 9090b57cec5SDimitry Andric 9100b57cec5SDimitry Andric// Indirect loads. 911349cc55cSDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1 in { 912*0fca6ea1SDimitry Andric def LDRdPtr : FSTLD<0, 0b00, (outs GPR8:$reg), (ins LDSTPtrReg:$ptrreg), 913*0fca6ea1SDimitry Andric "ld\t$reg, $ptrreg", 914*0fca6ea1SDimitry Andric [(set GPR8:$reg, (load i16:$ptrreg))]>, 9150b57cec5SDimitry Andric Requires<[HasSRAM]>; 9160b57cec5SDimitry Andric 9170b57cec5SDimitry Andric // LDW Rd+1:Rd, P 9180b57cec5SDimitry Andric // 9190b57cec5SDimitry Andric // Expands to: 9200b57cec5SDimitry Andric // ld Rd, P 9210b57cec5SDimitry Andric // ldd Rd+1, P+1 922bdd1243dSDimitry Andric // On reduced tiny cores, this instruction expands to: 923bdd1243dSDimitry Andric // ld Rd, P+ 924bdd1243dSDimitry Andric // ld Rd+1, P+ 925bdd1243dSDimitry Andric // subiw P, 2 926349cc55cSDimitry Andric let Constraints = "@earlyclobber $reg" in def LDWRdPtr 927*0fca6ea1SDimitry Andric : Pseudo<(outs DREGS:$reg), (ins PTRDISPREGS:$ptrreg), 928*0fca6ea1SDimitry Andric "ldw\t$reg, $ptrreg", [(set i16:$reg, (load i16:$ptrreg))]>, 9290b57cec5SDimitry Andric Requires<[HasSRAM]>; 9300b57cec5SDimitry Andric} 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andric// Indirect loads (with postincrement or predecrement). 933349cc55cSDimitry Andriclet mayLoad = 1, hasSideEffects = 0, 934349cc55cSDimitry Andric Constraints = "$ptrreg = $base_wb,@earlyclobber $reg" in { 935349cc55cSDimitry Andric def LDRdPtrPi : FSTLD<0, 0b01, 936349cc55cSDimitry Andric (outs GPR8 937349cc55cSDimitry Andric : $reg, PTRREGS 938349cc55cSDimitry Andric : $base_wb), 939349cc55cSDimitry Andric (ins LDSTPtrReg 940349cc55cSDimitry Andric : $ptrreg), 941349cc55cSDimitry Andric "ld\t$reg, $ptrreg+", []>, 9420b57cec5SDimitry Andric Requires<[HasSRAM]>; 9430b57cec5SDimitry Andric 9440b57cec5SDimitry Andric // LDW Rd+1:Rd, P+ 9450b57cec5SDimitry Andric // Expands to: 9460b57cec5SDimitry Andric // ld Rd, P+ 9470b57cec5SDimitry Andric // ld Rd+1, P+ 948*0fca6ea1SDimitry Andric def LDWRdPtrPi : Pseudo<(outs DREGS:$reg, PTRREGS:$base_wb), 949*0fca6ea1SDimitry Andric (ins PTRREGS:$ptrreg), "ldw\t$reg, $ptrreg+", []>, 9500b57cec5SDimitry Andric Requires<[HasSRAM]>; 9510b57cec5SDimitry Andric 952*0fca6ea1SDimitry Andric def LDRdPtrPd : FSTLD<0, 0b10, (outs GPR8:$reg, PTRREGS:$base_wb), 953*0fca6ea1SDimitry Andric (ins LDSTPtrReg:$ptrreg), "ld\t$reg, -$ptrreg", []>, 9540b57cec5SDimitry Andric Requires<[HasSRAM]>; 9550b57cec5SDimitry Andric 9560b57cec5SDimitry Andric // LDW Rd+1:Rd, -P 9570b57cec5SDimitry Andric // 9580b57cec5SDimitry Andric // Expands to: 9590b57cec5SDimitry Andric // ld Rd+1, -P 9600b57cec5SDimitry Andric // ld Rd, -P 961*0fca6ea1SDimitry Andric def LDWRdPtrPd : Pseudo<(outs DREGS:$reg, PTRREGS:$base_wb), 962*0fca6ea1SDimitry Andric (ins PTRREGS:$ptrreg), "ldw\t$reg, -$ptrreg", []>, 9630b57cec5SDimitry Andric Requires<[HasSRAM]>; 9640b57cec5SDimitry Andric} 9650b57cec5SDimitry Andric 9660b57cec5SDimitry Andric// Load indirect with displacement operations. 967349cc55cSDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1 in { 968*0fca6ea1SDimitry Andric def LDDRdPtrQ : FSTDLDD<0, (outs GPR8:$reg), (ins memri:$memri), 969*0fca6ea1SDimitry Andric "ldd\t$reg, $memri", 970*0fca6ea1SDimitry Andric [(set i8:$reg, (load addr:$memri))]>, 971bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 9720b57cec5SDimitry Andric 9730b57cec5SDimitry Andric // LDDW Rd+1:Rd, P+q 9740b57cec5SDimitry Andric // 9750b57cec5SDimitry Andric // Expands to: 9760b57cec5SDimitry Andric // ldd Rd, P+q 9770b57cec5SDimitry Andric // ldd Rd+1, P+q+1 978bdd1243dSDimitry Andric // On reduced tiny cores, this instruction expands to: 979bdd1243dSDimitry Andric // subiw P, -q 980bdd1243dSDimitry Andric // ld Rd, P+ 981bdd1243dSDimitry Andric // ld Rd+1, P+ 982bdd1243dSDimitry Andric // subiw P, q+2 983*0fca6ea1SDimitry Andric let Constraints = "@earlyclobber $dst" in 984*0fca6ea1SDimitry Andric def LDDWRdPtrQ : Pseudo<(outs DREGS:$dst), (ins memri:$memri), 985*0fca6ea1SDimitry Andric "lddw\t$dst, $memri", 986*0fca6ea1SDimitry Andric [(set i16:$dst, (load addr:$memri))]>, 9870b57cec5SDimitry Andric Requires<[HasSRAM]>; 9880b57cec5SDimitry Andric 9890b57cec5SDimitry Andric // An identical pseudo instruction to LDDWRdPtrQ, expect restricted to the Y 9900b57cec5SDimitry Andric // register and without the @earlyclobber flag. 9910b57cec5SDimitry Andric // 9920b57cec5SDimitry Andric // Used to work around a bug caused by the register allocator not 9930b57cec5SDimitry Andric // being able to handle the expansion of a COPY into an machine instruction 9940b57cec5SDimitry Andric // that has an earlyclobber flag. This is because the register allocator will 9950b57cec5SDimitry Andric // try expand a copy from a register slot into an earlyclobber instruction. 996349cc55cSDimitry Andric // Instructions that are earlyclobber need to be in a dedicated earlyclobber 997349cc55cSDimitry Andric // slot. 9980b57cec5SDimitry Andric // 9990b57cec5SDimitry Andric // This pseudo instruction can be used pre-AVR pseudo expansion in order to 10000b57cec5SDimitry Andric // get a frame index load without directly using earlyclobber instructions. 10010b57cec5SDimitry Andric // 10020b57cec5SDimitry Andric // The pseudo expansion pass trivially expands this into LDDWRdPtrQ. 10030b57cec5SDimitry Andric // 10040b57cec5SDimitry Andric // This instruction may be removed once PR13375 is fixed. 1005*0fca6ea1SDimitry Andric let mayLoad = 1, hasSideEffects = 0 in 1006*0fca6ea1SDimitry Andric def LDDWRdYQ : Pseudo<(outs DREGS:$dst), (ins memri:$memri), 1007349cc55cSDimitry Andric "lddw\t$dst, $memri", []>, 10080b57cec5SDimitry Andric Requires<[HasSRAM]>; 10090b57cec5SDimitry Andric} 10100b57cec5SDimitry Andric 1011349cc55cSDimitry Andricclass AtomicLoad<PatFrag Op, RegisterClass DRC, RegisterClass PTRRC> 1012*0fca6ea1SDimitry Andric : Pseudo<(outs DRC:$rd), (ins PTRRC:$rr), "atomic_op", 1013*0fca6ea1SDimitry Andric [(set DRC:$rd, (Op i16:$rr))]>; 10140b57cec5SDimitry Andric 1015349cc55cSDimitry Andricclass AtomicStore<PatFrag Op, RegisterClass DRC, RegisterClass PTRRC> 1016*0fca6ea1SDimitry Andric : Pseudo<(outs), (ins PTRRC:$rd, DRC:$rr), "atomic_op", 1017*0fca6ea1SDimitry Andric [(Op DRC:$rr, i16:$rd)]>; 10180b57cec5SDimitry Andric 101981ad6265SDimitry Andricclass AtomicLoadOp<PatFrag Op, RegisterClass DRC, RegisterClass PTRRC> 1020*0fca6ea1SDimitry Andric : Pseudo<(outs DRC:$rd), (ins PTRRC:$rr, DRC:$operand), "atomic_op", 1021*0fca6ea1SDimitry Andric [(set DRC:$rd, (Op i16:$rr, DRC:$operand))]>; 10220b57cec5SDimitry Andric 10230b57cec5SDimitry Andric// Atomic instructions 10240b57cec5SDimitry Andric// =================== 10250b57cec5SDimitry Andric// 10260b57cec5SDimitry Andric// 8-bit operations can use any pointer register because 10270b57cec5SDimitry Andric// they are expanded directly into an LD/ST instruction. 10280b57cec5SDimitry Andric// 10290b57cec5SDimitry Andric// 16-bit operations use 16-bit load/store postincrement instructions, 10300b57cec5SDimitry Andric// which require PTRDISPREGS. 10310b57cec5SDimitry Andric 10320b57cec5SDimitry Andricdef AtomicLoad8 : AtomicLoad<atomic_load_8, GPR8, PTRREGS>; 10330b57cec5SDimitry Andricdef AtomicLoad16 : AtomicLoad<atomic_load_16, DREGS, PTRDISPREGS>; 10340b57cec5SDimitry Andric 10350b57cec5SDimitry Andricdef AtomicStore8 : AtomicStore<atomic_store_8, GPR8, PTRREGS>; 10360b57cec5SDimitry Andricdef AtomicStore16 : AtomicStore<atomic_store_16, DREGS, PTRDISPREGS>; 10370b57cec5SDimitry Andric 10380b57cec5SDimitry Andricclass AtomicLoadOp8<PatFrag Op> : AtomicLoadOp<Op, GPR8, PTRREGS>; 10390b57cec5SDimitry Andricclass AtomicLoadOp16<PatFrag Op> : AtomicLoadOp<Op, DREGS, PTRDISPREGS>; 10400b57cec5SDimitry Andric 104181ad6265SDimitry Andriclet usesCustomInserter=1 in { 1042*0fca6ea1SDimitry Andric def AtomicLoadAdd8 : AtomicLoadOp8<atomic_load_add_i8>; 1043*0fca6ea1SDimitry Andric def AtomicLoadAdd16 : AtomicLoadOp16<atomic_load_add_i16>; 1044*0fca6ea1SDimitry Andric def AtomicLoadSub8 : AtomicLoadOp8<atomic_load_sub_i8>; 1045*0fca6ea1SDimitry Andric def AtomicLoadSub16 : AtomicLoadOp16<atomic_load_sub_i16>; 1046*0fca6ea1SDimitry Andric def AtomicLoadAnd8 : AtomicLoadOp8<atomic_load_and_i8>; 1047*0fca6ea1SDimitry Andric def AtomicLoadAnd16 : AtomicLoadOp16<atomic_load_and_i16>; 1048*0fca6ea1SDimitry Andric def AtomicLoadOr8 : AtomicLoadOp8<atomic_load_or_i8>; 1049*0fca6ea1SDimitry Andric def AtomicLoadOr16 : AtomicLoadOp16<atomic_load_or_i16>; 1050*0fca6ea1SDimitry Andric def AtomicLoadXor8 : AtomicLoadOp8<atomic_load_xor_i8>; 1051*0fca6ea1SDimitry Andric def AtomicLoadXor16 : AtomicLoadOp16<atomic_load_xor_i16>; 105281ad6265SDimitry Andric} 1053*0fca6ea1SDimitry Andric 1054349cc55cSDimitry Andricdef AtomicFence 1055349cc55cSDimitry Andric : Pseudo<(outs), (ins), "atomic_fence", [(atomic_fence timm, timm)]>; 10560b57cec5SDimitry Andric 10570b57cec5SDimitry Andric// Indirect store from register to data space. 1058*0fca6ea1SDimitry Andricdef STSKRr : F32DM<0b1, (outs), (ins imm16:$k, GPR8:$rd), "sts\t$k, $rd", 1059*0fca6ea1SDimitry Andric [(store i8:$rd, imm:$k)]>, 1060bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 1061bdd1243dSDimitry Andric 1062bdd1243dSDimitry Andric// Store from register to data space, which is only available on AVRTiny. 1063bdd1243dSDimitry Andricdef STSKRrTiny : FLDSSTSTINY<0b1, (outs), (ins imm7tiny:$k, LD8:$rd), 1064bdd1243dSDimitry Andric "sts\t$k, $rd", [(store i8:$rd, imm:$k)]>, 1065bdd1243dSDimitry Andric Requires<[HasSRAM, HasTinyEncoding]>; 10660b57cec5SDimitry Andric 10670b57cec5SDimitry Andric// STSW K+1:K, Rr+1:Rr 10680b57cec5SDimitry Andric// 10690b57cec5SDimitry Andric// Expands to: 10700b57cec5SDimitry Andric// sts Rr+1, (K+1:K) + 1 10710b57cec5SDimitry Andric// sts Rr, (K+1:K) 1072*0fca6ea1SDimitry Andricdef STSWKRr : Pseudo<(outs), (ins i16imm:$dst, DREGS:$src), 1073*0fca6ea1SDimitry Andric "stsw\t$dst, $src", [(store i16:$src, imm:$dst)]>, 1074bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 10750b57cec5SDimitry Andric 10760b57cec5SDimitry Andric// Indirect stores. 10770b57cec5SDimitry Andric// ST P, Rr 10780b57cec5SDimitry Andric// Stores the value of Rr into the location addressed by pointer P. 1079*0fca6ea1SDimitry Andricdef STPtrRr : FSTLD<1, 0b00, (outs), (ins LDSTPtrReg:$ptrreg, GPR8:$reg), 1080*0fca6ea1SDimitry Andric "st\t$ptrreg, $reg", [(store GPR8:$reg, i16:$ptrreg)]>, 10810b57cec5SDimitry Andric Requires<[HasSRAM]>; 10820b57cec5SDimitry Andric 10830b57cec5SDimitry Andric// STW P, Rr+1:Rr 10840b57cec5SDimitry Andric// Stores the value of Rr into the location addressed by pointer P. 10850b57cec5SDimitry Andric// 10860b57cec5SDimitry Andric// Expands to: 10870b57cec5SDimitry Andric// st P, Rr 10880b57cec5SDimitry Andric// std P+1, Rr+1 1089bdd1243dSDimitry Andric// On reduced tiny cores, this instruction expands to: 1090bdd1243dSDimitry Andric// st P+, Rr 1091bdd1243dSDimitry Andric// st P+, Rr+1 1092bdd1243dSDimitry Andric// subiw P, q+2 1093*0fca6ea1SDimitry Andricdef STWPtrRr : Pseudo<(outs), (ins PTRDISPREGS:$ptrreg, DREGS:$reg), 1094*0fca6ea1SDimitry Andric "stw\t$ptrreg, $reg", [(store i16:$reg, i16:$ptrreg)]>, 10950b57cec5SDimitry Andric Requires<[HasSRAM]>; 10960b57cec5SDimitry Andric 10970b57cec5SDimitry Andric// Indirect stores (with postincrement or predecrement). 1098349cc55cSDimitry Andriclet Constraints = "$ptrreg = $base_wb,@earlyclobber $base_wb" in { 10990b57cec5SDimitry Andric 11000b57cec5SDimitry Andric // ST P+, Rr 11010b57cec5SDimitry Andric // Stores the value of Rr into the location addressed by pointer P. 11020b57cec5SDimitry Andric // Post increments P. 1103*0fca6ea1SDimitry Andric def STPtrPiRr : FSTLD<1, 0b01, (outs LDSTPtrReg:$base_wb), 1104*0fca6ea1SDimitry Andric (ins LDSTPtrReg:$ptrreg, GPR8:$reg, i8imm:$offs), 1105*0fca6ea1SDimitry Andric "st\t$ptrreg+, $reg", 1106*0fca6ea1SDimitry Andric [(set i16:$base_wb, (post_store GPR8:$reg, i16:$ptrreg, 1107*0fca6ea1SDimitry Andric imm:$offs))]>, 11080b57cec5SDimitry Andric Requires<[HasSRAM]>; 11090b57cec5SDimitry Andric 11100b57cec5SDimitry Andric // STW P+, Rr+1:Rr 11110b57cec5SDimitry Andric // Stores the value of Rr into the location addressed by pointer P. 11120b57cec5SDimitry Andric // Post increments P. 11130b57cec5SDimitry Andric // 11140b57cec5SDimitry Andric // Expands to: 11150b57cec5SDimitry Andric // st P+, Rr 11160b57cec5SDimitry Andric // st P+, Rr+1 1117*0fca6ea1SDimitry Andric def STWPtrPiRr : Pseudo<(outs PTRREGS:$base_wb), 1118*0fca6ea1SDimitry Andric (ins PTRREGS:$ptrreg, DREGS:$trh, i8imm:$offs), 1119*0fca6ea1SDimitry Andric "stw\t$ptrreg+, $trh", 1120*0fca6ea1SDimitry Andric [(set PTRREGS:$base_wb, 1121*0fca6ea1SDimitry Andric (post_store DREGS:$trh, PTRREGS:$ptrreg, 1122*0fca6ea1SDimitry Andric imm:$offs))]>, 11230b57cec5SDimitry Andric Requires<[HasSRAM]>; 11240b57cec5SDimitry Andric 11250b57cec5SDimitry Andric // ST -P, Rr 11260b57cec5SDimitry Andric // Stores the value of Rr into the location addressed by pointer P. 11270b57cec5SDimitry Andric // Pre decrements P. 1128*0fca6ea1SDimitry Andric def STPtrPdRr : FSTLD<1, 0b10, (outs LDSTPtrReg:$base_wb), 1129*0fca6ea1SDimitry Andric (ins LDSTPtrReg:$ptrreg, GPR8:$reg, i8imm:$offs), 1130*0fca6ea1SDimitry Andric "st\t-$ptrreg, $reg", 1131*0fca6ea1SDimitry Andric [(set i16: $base_wb, 1132*0fca6ea1SDimitry Andric (pre_store GPR8:$reg, i16:$ptrreg, imm:$offs))]>, 11330b57cec5SDimitry Andric Requires<[HasSRAM]>; 11340b57cec5SDimitry Andric 11350b57cec5SDimitry Andric // STW -P, Rr+1:Rr 11360b57cec5SDimitry Andric // Stores the value of Rr into the location addressed by pointer P. 11370b57cec5SDimitry Andric // Pre decrements P. 11380b57cec5SDimitry Andric // 11390b57cec5SDimitry Andric // Expands to: 11400b57cec5SDimitry Andric // st -P, Rr+1 11410b57cec5SDimitry Andric // st -P, Rr 1142*0fca6ea1SDimitry Andric def STWPtrPdRr : Pseudo<(outs PTRREGS:$base_wb), 1143*0fca6ea1SDimitry Andric (ins PTRREGS:$ptrreg, DREGS:$reg, i8imm:$offs), 1144*0fca6ea1SDimitry Andric "stw\t-$ptrreg, $reg", 1145*0fca6ea1SDimitry Andric [(set PTRREGS:$base_wb, 1146*0fca6ea1SDimitry Andric (pre_store i16:$reg, i16:$ptrreg, imm:$offs))]>, 11470b57cec5SDimitry Andric Requires<[HasSRAM]>; 11480b57cec5SDimitry Andric} 11490b57cec5SDimitry Andric 11500b57cec5SDimitry Andric// Store indirect with displacement operations. 11510b57cec5SDimitry Andric// STD P+q, Rr 11520b57cec5SDimitry Andric// Stores the value of Rr into the location addressed by pointer P with a 11530b57cec5SDimitry Andric// displacement of q. Does not modify P. 1154*0fca6ea1SDimitry Andricdef STDPtrQRr : FSTDLDD<1, (outs), (ins memri:$memri, GPR8:$reg), 1155*0fca6ea1SDimitry Andric "std\t$memri, $reg", [(store i8:$reg, addr:$memri)]>, 1156bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 11570b57cec5SDimitry Andric 11580b57cec5SDimitry Andric// STDW P+q, Rr+1:Rr 11590b57cec5SDimitry Andric// Stores the value of Rr into the location addressed by pointer P with a 11600b57cec5SDimitry Andric// displacement of q. Does not modify P. 11610b57cec5SDimitry Andric// 11620b57cec5SDimitry Andric// Expands to: 11630b57cec5SDimitry Andric// std P+q, Rr 11640b57cec5SDimitry Andric// std P+q+1, Rr+1 1165bdd1243dSDimitry Andric// On reduced tiny cores, this instruction expands to: 1166bdd1243dSDimitry Andric// subiw P, -q 1167bdd1243dSDimitry Andric// st P+, Rr 1168bdd1243dSDimitry Andric// st P+, Rr+1 1169bdd1243dSDimitry Andric// subiw P, q+2 1170*0fca6ea1SDimitry Andricdef STDWPtrQRr : Pseudo<(outs), (ins memri:$memri, DREGS:$src), 1171*0fca6ea1SDimitry Andric "stdw\t$memri, $src", [(store i16:$src, addr:$memri)]>, 11720b57cec5SDimitry Andric Requires<[HasSRAM]>; 11730b57cec5SDimitry Andric 11740b57cec5SDimitry Andric// Load program memory operations. 1175349cc55cSDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1, mayLoad = 1, 1176349cc55cSDimitry Andric hasSideEffects = 0 in { 11770b57cec5SDimitry Andric let Defs = [R0], 1178349cc55cSDimitry Andric Uses = [R31R30] in def LPM 1179349cc55cSDimitry Andric : F16<0b1001010111001000, (outs), (ins), "lpm", []>, 11800b57cec5SDimitry Andric Requires<[HasLPM]>; 11810b57cec5SDimitry Andric 118206c3fb27SDimitry Andric // These pseudo instructions are combination of the OUT and LPM instructions. 118306c3fb27SDimitry Andric let Defs = [R0] in { 118406c3fb27SDimitry Andric def LPMBRdZ : Pseudo<(outs GPR8:$dst), (ins ZREG:$z), "lpmb\t$dst, $z", []>, 118506c3fb27SDimitry Andric Requires<[HasLPM]>; 118606c3fb27SDimitry Andric 118706c3fb27SDimitry Andric let Constraints = "@earlyclobber $dst" in 118806c3fb27SDimitry Andric def LPMWRdZ : Pseudo<(outs DREGS:$dst), (ins ZREG:$z), "lpmw\t$dst, $z", []>, 118906c3fb27SDimitry Andric Requires<[HasLPM]>; 119006c3fb27SDimitry Andric } 119106c3fb27SDimitry Andric 1192349cc55cSDimitry Andric def LPMRdZ : FLPMX<0, 0, 1193349cc55cSDimitry Andric (outs GPR8 1194bdd1243dSDimitry Andric : $rd), 1195349cc55cSDimitry Andric (ins ZREG 1196349cc55cSDimitry Andric : $z), 1197bdd1243dSDimitry Andric "lpm\t$rd, $z", []>, 11980b57cec5SDimitry Andric Requires<[HasLPMX]>; 11990b57cec5SDimitry Andric 12000b57cec5SDimitry Andric // Load program memory, while postincrementing the Z register. 1201349cc55cSDimitry Andric let Defs = [R31R30] in { 1202349cc55cSDimitry Andric def LPMRdZPi : FLPMX<0, 1, 1203349cc55cSDimitry Andric (outs GPR8 1204bdd1243dSDimitry Andric : $rd), 1205349cc55cSDimitry Andric (ins ZREG 1206349cc55cSDimitry Andric : $z), 1207bdd1243dSDimitry Andric "lpm\t$rd, $z+", []>, 12080b57cec5SDimitry Andric Requires<[HasLPMX]>; 12090b57cec5SDimitry Andric 1210349cc55cSDimitry Andric def LPMWRdZPi : Pseudo<(outs DREGS 1211349cc55cSDimitry Andric : $dst), 1212349cc55cSDimitry Andric (ins ZREG 1213349cc55cSDimitry Andric : $z), 1214349cc55cSDimitry Andric "lpmw\t$dst, $z+", []>, 12150b57cec5SDimitry Andric Requires<[HasLPMX]>; 12160b57cec5SDimitry Andric } 12170b57cec5SDimitry Andric} 12180b57cec5SDimitry Andric 12190b57cec5SDimitry Andric// Extended load program memory operations. 1220349cc55cSDimitry Andriclet mayLoad = 1, hasSideEffects = 0 in { 12210b57cec5SDimitry Andric let Defs = [R0], 1222349cc55cSDimitry Andric Uses = [R31R30] in def ELPM 1223349cc55cSDimitry Andric : F16<0b1001010111011000, (outs), (ins), "elpm", []>, 12240b57cec5SDimitry Andric Requires<[HasELPM]>; 12250b57cec5SDimitry Andric 1226bdd1243dSDimitry Andric def ELPMRdZ : FLPMX<1, 0, (outs GPR8:$rd), (ins ZREG:$z), 1227bdd1243dSDimitry Andric "elpm\t$rd, $z", []>, 12280b57cec5SDimitry Andric Requires<[HasELPMX]>; 12290b57cec5SDimitry Andric 123004eeddc0SDimitry Andric let Defs = [R31R30] in { 1231bdd1243dSDimitry Andric def ELPMRdZPi : FLPMX<1, 1, (outs GPR8:$rd), (ins ZREG:$z), 1232bdd1243dSDimitry Andric "elpm\t$rd, $z+", []>, 12330b57cec5SDimitry Andric Requires<[HasELPMX]>; 12340b57cec5SDimitry Andric } 12350b57cec5SDimitry Andric 123606c3fb27SDimitry Andric // These pseudo instructions are combination of the OUT and ELPM instructions. 123706c3fb27SDimitry Andric let Defs = [R0] in { 123804eeddc0SDimitry Andric def ELPMBRdZ : Pseudo<(outs GPR8:$dst), (ins ZREG:$z, LD8:$p), 123904eeddc0SDimitry Andric "elpmb\t$dst, $z, $p", []>, 124006c3fb27SDimitry Andric Requires<[HasELPM]>; 124104eeddc0SDimitry Andric 1242bdd1243dSDimitry Andric let Constraints = "@earlyclobber $dst" in 124304eeddc0SDimitry Andric def ELPMWRdZ : Pseudo<(outs DREGS:$dst), (ins ZREG:$z, LD8:$p), 124404eeddc0SDimitry Andric "elpmw\t$dst, $z, $p", []>, 124506c3fb27SDimitry Andric Requires<[HasELPM]>; 124606c3fb27SDimitry Andric } 124704eeddc0SDimitry Andric 124806c3fb27SDimitry Andric // These pseudos are combination of the OUT and ELPM instructions. 124906c3fb27SDimitry Andric let Defs = [R31R30], hasSideEffects = 1 in { 125004eeddc0SDimitry Andric def ELPMBRdZPi : Pseudo<(outs GPR8:$dst), (ins ZREG:$z, LD8:$p), 125104eeddc0SDimitry Andric "elpmb\t$dst, $z+, $p", []>, 125204eeddc0SDimitry Andric Requires<[HasELPMX]>; 125304eeddc0SDimitry Andric 125404eeddc0SDimitry Andric def ELPMWRdZPi : Pseudo<(outs DREGS:$dst), (ins ZREG:$z, LD8:$p), 125504eeddc0SDimitry Andric "elpmw\t$dst, $z+, $p", []>, 125604eeddc0SDimitry Andric Requires<[HasELPMX]>; 125704eeddc0SDimitry Andric } 125804eeddc0SDimitry Andric} 125904eeddc0SDimitry Andric 12600b57cec5SDimitry Andric// Store program memory operations. 1261349cc55cSDimitry Andriclet Uses = [R1, R0] in { 1262349cc55cSDimitry Andric let Uses = [R31R30, R1, R0] in def SPM 1263349cc55cSDimitry Andric : F16<0b1001010111101000, (outs), (ins), "spm", []>, 12640b57cec5SDimitry Andric Requires<[HasSPM]>; 12650b57cec5SDimitry Andric 1266349cc55cSDimitry Andric let Defs = [R31R30] in def SPMZPi : F16<0b1001010111111000, (outs), 1267349cc55cSDimitry Andric (ins ZREG 1268349cc55cSDimitry Andric : $z), 1269349cc55cSDimitry Andric "spm $z+", []>, 12700b57cec5SDimitry Andric Requires<[HasSPMX]>; 12710b57cec5SDimitry Andric} 12720b57cec5SDimitry Andric 12730b57cec5SDimitry Andric// Read data from IO location operations. 1274349cc55cSDimitry Andriclet canFoldAsLoad = 1, isReMaterializable = 1 in { 1275349cc55cSDimitry Andric def INRdA : FIORdA<(outs GPR8 1276bdd1243dSDimitry Andric : $rd), 1277349cc55cSDimitry Andric (ins imm_port6 1278bdd1243dSDimitry Andric : $A), 1279bdd1243dSDimitry Andric "in\t$rd, $A", [(set i8 1280bdd1243dSDimitry Andric : $rd, (load ioaddr8 1281bdd1243dSDimitry Andric : $A))]>; 12820b57cec5SDimitry Andric 1283349cc55cSDimitry Andric def INWRdA : Pseudo<(outs DREGS 1284349cc55cSDimitry Andric : $dst), 1285349cc55cSDimitry Andric (ins imm_port6 1286349cc55cSDimitry Andric : $src), 1287349cc55cSDimitry Andric "inw\t$dst, $src", [(set i16 1288349cc55cSDimitry Andric : $dst, (load ioaddr16 1289349cc55cSDimitry Andric : $src))]>; 12900b57cec5SDimitry Andric} 12910b57cec5SDimitry Andric 12920b57cec5SDimitry Andric// Write data to IO location operations. 12930b57cec5SDimitry Andricdef OUTARr : FIOARr<(outs), 1294349cc55cSDimitry Andric (ins imm_port6 1295bdd1243dSDimitry Andric : $A, GPR8 1296bdd1243dSDimitry Andric : $rr), 1297bdd1243dSDimitry Andric "out\t$A, $rr", [(store i8 1298bdd1243dSDimitry Andric : $rr, ioaddr8 1299bdd1243dSDimitry Andric : $A)]>; 13000b57cec5SDimitry Andric 13010b57cec5SDimitry Andricdef OUTWARr : Pseudo<(outs), 1302349cc55cSDimitry Andric (ins imm_port6 1303349cc55cSDimitry Andric : $dst, DREGS 1304349cc55cSDimitry Andric : $src), 1305349cc55cSDimitry Andric "outw\t$dst, $src", [(store i16 1306349cc55cSDimitry Andric : $src, ioaddr16 1307349cc55cSDimitry Andric : $dst)]>; 13080b57cec5SDimitry Andric 13090b57cec5SDimitry Andric// Stack push/pop operations. 1310349cc55cSDimitry Andriclet Defs = [SP], Uses = [SP], hasSideEffects = 0 in { 13110b57cec5SDimitry Andric // Stack push operations. 1312349cc55cSDimitry Andric let mayStore = 1 in { 1313349cc55cSDimitry Andric def PUSHRr : FRd<0b1001, 0b0011111, (outs), 1314349cc55cSDimitry Andric (ins GPR8 1315bdd1243dSDimitry Andric : $rd), 1316bdd1243dSDimitry Andric "push\t$rd", []>, 13170b57cec5SDimitry Andric Requires<[HasSRAM]>; 13180b57cec5SDimitry Andric 13190b57cec5SDimitry Andric def PUSHWRr : Pseudo<(outs), 1320349cc55cSDimitry Andric (ins DREGS 1321349cc55cSDimitry Andric : $reg), 1322349cc55cSDimitry Andric "pushw\t$reg", []>, 13230b57cec5SDimitry Andric Requires<[HasSRAM]>; 13240b57cec5SDimitry Andric } 13250b57cec5SDimitry Andric 13260b57cec5SDimitry Andric // Stack pop operations. 1327349cc55cSDimitry Andric let mayLoad = 1 in { 1328349cc55cSDimitry Andric def POPRd : FRd<0b1001, 0b0001111, 1329349cc55cSDimitry Andric (outs GPR8 1330bdd1243dSDimitry Andric : $rd), 1331bdd1243dSDimitry Andric (ins), "pop\t$rd", []>, 13320b57cec5SDimitry Andric Requires<[HasSRAM]>; 13330b57cec5SDimitry Andric 1334349cc55cSDimitry Andric def POPWRd : Pseudo<(outs DREGS 1335349cc55cSDimitry Andric : $reg), 1336349cc55cSDimitry Andric (ins), "popw\t$reg", []>, 13370b57cec5SDimitry Andric Requires<[HasSRAM]>; 13380b57cec5SDimitry Andric } 13390b57cec5SDimitry Andric} 13400b57cec5SDimitry Andric 13410b57cec5SDimitry Andric// Read-Write-Modify (RMW) instructions. 13420b57cec5SDimitry Andricdef XCHZRd : FZRd<0b100, 1343349cc55cSDimitry Andric (outs GPR8 1344349cc55cSDimitry Andric : $rd), 1345349cc55cSDimitry Andric (ins ZREG 1346349cc55cSDimitry Andric : $z), 1347349cc55cSDimitry Andric "xch\t$z, $rd", []>, 13480b57cec5SDimitry Andric Requires<[SupportsRMW]>; 13490b57cec5SDimitry Andric 13500b57cec5SDimitry Andricdef LASZRd : FZRd<0b101, 1351349cc55cSDimitry Andric (outs GPR8 1352349cc55cSDimitry Andric : $rd), 1353349cc55cSDimitry Andric (ins ZREG 1354349cc55cSDimitry Andric : $z), 1355349cc55cSDimitry Andric "las\t$z, $rd", []>, 13560b57cec5SDimitry Andric Requires<[SupportsRMW]>; 13570b57cec5SDimitry Andric 13580b57cec5SDimitry Andricdef LACZRd : FZRd<0b110, 1359349cc55cSDimitry Andric (outs GPR8 1360349cc55cSDimitry Andric : $rd), 1361349cc55cSDimitry Andric (ins ZREG 1362349cc55cSDimitry Andric : $z), 1363349cc55cSDimitry Andric "lac\t$z, $rd", []>, 13640b57cec5SDimitry Andric Requires<[SupportsRMW]>; 13650b57cec5SDimitry Andric 13660b57cec5SDimitry Andricdef LATZRd : FZRd<0b111, 1367349cc55cSDimitry Andric (outs GPR8 1368349cc55cSDimitry Andric : $rd), 1369349cc55cSDimitry Andric (ins ZREG 1370349cc55cSDimitry Andric : $z), 1371349cc55cSDimitry Andric "lat\t$z, $rd", []>, 13720b57cec5SDimitry Andric Requires<[SupportsRMW]>; 13730b57cec5SDimitry Andric 13740b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 13750b57cec5SDimitry Andric// Bit and bit-test instructions 13760b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 13770b57cec5SDimitry Andric 13780b57cec5SDimitry Andric// Bit shift/rotate operations. 1379349cc55cSDimitry Andriclet Constraints = "$src = $rd", Defs = [SREG] in { 13800b57cec5SDimitry Andric // 8-bit LSL is an alias of ADD Rd, Rd 13810b57cec5SDimitry Andric 1382349cc55cSDimitry Andric def LSLWRd : Pseudo<(outs DREGS 1383349cc55cSDimitry Andric : $rd), 1384349cc55cSDimitry Andric (ins DREGS 1385349cc55cSDimitry Andric : $src), 13860b57cec5SDimitry Andric "lslw\t$rd", 1387349cc55cSDimitry Andric [(set i16 1388349cc55cSDimitry Andric : $rd, (AVRlsl i16 1389349cc55cSDimitry Andric : $src)), 1390fe6060f1SDimitry Andric (implicit SREG)]>; 1391fe6060f1SDimitry Andric 139204eeddc0SDimitry Andric def LSLWHiRd : Pseudo<(outs DREGS:$rd), (ins DREGS:$src), "lslwhi\t$rd", 139304eeddc0SDimitry Andric [(set i16:$rd, (AVRlslhi i16:$src)), (implicit SREG)]>; 139404eeddc0SDimitry Andric 1395349cc55cSDimitry Andric def LSLWNRd : Pseudo<(outs DLDREGS 1396349cc55cSDimitry Andric : $rd), 1397349cc55cSDimitry Andric (ins DREGS 1398349cc55cSDimitry Andric : $src, imm16 1399349cc55cSDimitry Andric : $bits), 1400349cc55cSDimitry Andric "lslwn\t$rd, $bits", [ 1401349cc55cSDimitry Andric (set i16 1402349cc55cSDimitry Andric : $rd, (AVRlslwn i16 1403349cc55cSDimitry Andric : $src, imm 1404349cc55cSDimitry Andric : $bits)), 1405349cc55cSDimitry Andric (implicit SREG) 1406349cc55cSDimitry Andric ]>; 1407349cc55cSDimitry Andric 1408349cc55cSDimitry Andric def LSLBNRd : Pseudo<(outs LD8 1409349cc55cSDimitry Andric : $rd), 1410349cc55cSDimitry Andric (ins GPR8 1411349cc55cSDimitry Andric : $src, imm_ldi8 1412349cc55cSDimitry Andric : $bits), 1413349cc55cSDimitry Andric "lslbn\t$rd, $bits", [ 1414349cc55cSDimitry Andric (set i8 1415349cc55cSDimitry Andric : $rd, (AVRlslbn i8 1416349cc55cSDimitry Andric : $src, imm 1417349cc55cSDimitry Andric : $bits)), 1418349cc55cSDimitry Andric (implicit SREG) 1419349cc55cSDimitry Andric ]>; 1420349cc55cSDimitry Andric 1421349cc55cSDimitry Andric def LSRRd 1422349cc55cSDimitry Andric : FRd<0b1001, 0b0100110, 1423349cc55cSDimitry Andric (outs GPR8 1424349cc55cSDimitry Andric : $rd), 1425349cc55cSDimitry Andric (ins GPR8 1426349cc55cSDimitry Andric : $src), 1427349cc55cSDimitry Andric "lsr\t$rd", [(set i8 1428349cc55cSDimitry Andric : $rd, (AVRlsr i8 1429349cc55cSDimitry Andric : $src)), 1430fe6060f1SDimitry Andric (implicit SREG)]>; 1431e8d8bef9SDimitry Andric 1432349cc55cSDimitry Andric def LSRWRd : Pseudo<(outs DREGS 1433349cc55cSDimitry Andric : $rd), 1434349cc55cSDimitry Andric (ins DREGS 1435349cc55cSDimitry Andric : $src), 14360b57cec5SDimitry Andric "lsrw\t$rd", 1437349cc55cSDimitry Andric [(set i16 1438349cc55cSDimitry Andric : $rd, (AVRlsr i16 1439349cc55cSDimitry Andric : $src)), 1440fe6060f1SDimitry Andric (implicit SREG)]>; 1441fe6060f1SDimitry Andric 144204eeddc0SDimitry Andric def LSRWLoRd : Pseudo<(outs DREGS:$rd), (ins DREGS:$src), "lsrwlo\t$rd", 144304eeddc0SDimitry Andric [(set i16:$rd, (AVRlsrlo i16:$src)), (implicit SREG)]>; 144404eeddc0SDimitry Andric 1445349cc55cSDimitry Andric def LSRWNRd : Pseudo<(outs DLDREGS 1446349cc55cSDimitry Andric : $rd), 1447349cc55cSDimitry Andric (ins DREGS 1448349cc55cSDimitry Andric : $src, imm16 1449349cc55cSDimitry Andric : $bits), 1450349cc55cSDimitry Andric "lsrwn\t$rd, $bits", [ 1451349cc55cSDimitry Andric (set i16 1452349cc55cSDimitry Andric : $rd, (AVRlsrwn i16 1453349cc55cSDimitry Andric : $src, imm 1454349cc55cSDimitry Andric : $bits)), 1455349cc55cSDimitry Andric (implicit SREG) 1456349cc55cSDimitry Andric ]>; 1457349cc55cSDimitry Andric 1458349cc55cSDimitry Andric def LSRBNRd : Pseudo<(outs LD8 1459349cc55cSDimitry Andric : $rd), 1460349cc55cSDimitry Andric (ins GPR8 1461349cc55cSDimitry Andric : $src, imm_ldi8 1462349cc55cSDimitry Andric : $bits), 1463349cc55cSDimitry Andric "lsrbn\t$rd, $bits", [ 1464349cc55cSDimitry Andric (set i8 1465349cc55cSDimitry Andric : $rd, (AVRlsrbn i8 1466349cc55cSDimitry Andric : $src, imm 1467349cc55cSDimitry Andric : $bits)), 1468349cc55cSDimitry Andric (implicit SREG) 1469349cc55cSDimitry Andric ]>; 1470349cc55cSDimitry Andric 1471349cc55cSDimitry Andric def ASRRd 1472349cc55cSDimitry Andric : FRd<0b1001, 0b0100101, 1473349cc55cSDimitry Andric (outs GPR8 1474349cc55cSDimitry Andric : $rd), 1475349cc55cSDimitry Andric (ins GPR8 1476349cc55cSDimitry Andric : $src), 1477349cc55cSDimitry Andric "asr\t$rd", [(set i8 1478349cc55cSDimitry Andric : $rd, (AVRasr i8 1479349cc55cSDimitry Andric : $src)), 1480fe6060f1SDimitry Andric (implicit SREG)]>; 1481fe6060f1SDimitry Andric 148281ad6265SDimitry Andric def ASRWNRd : Pseudo<(outs DREGS 1483349cc55cSDimitry Andric : $rd), 1484349cc55cSDimitry Andric (ins DREGS 1485349cc55cSDimitry Andric : $src, imm16 1486349cc55cSDimitry Andric : $bits), 1487349cc55cSDimitry Andric "asrwn\t$rd, $bits", [ 1488349cc55cSDimitry Andric (set i16 1489349cc55cSDimitry Andric : $rd, (AVRasrwn i16 1490349cc55cSDimitry Andric : $src, imm 1491349cc55cSDimitry Andric : $bits)), 1492349cc55cSDimitry Andric (implicit SREG) 1493349cc55cSDimitry Andric ]>; 14940b57cec5SDimitry Andric 1495349cc55cSDimitry Andric def ASRBNRd : Pseudo<(outs LD8 1496349cc55cSDimitry Andric : $rd), 1497349cc55cSDimitry Andric (ins GPR8 1498349cc55cSDimitry Andric : $src, imm_ldi8 1499349cc55cSDimitry Andric : $bits), 1500349cc55cSDimitry Andric "asrbn\t$rd, $bits", [ 1501349cc55cSDimitry Andric (set i8 1502349cc55cSDimitry Andric : $rd, (AVRasrbn i8 1503349cc55cSDimitry Andric : $src, imm 1504349cc55cSDimitry Andric : $bits)), 1505349cc55cSDimitry Andric (implicit SREG) 1506349cc55cSDimitry Andric ]>; 1507fe6060f1SDimitry Andric 1508349cc55cSDimitry Andric def ASRWRd : Pseudo<(outs DREGS 1509349cc55cSDimitry Andric : $rd), 1510349cc55cSDimitry Andric (ins DREGS 1511349cc55cSDimitry Andric : $src), 15120b57cec5SDimitry Andric "asrw\t$rd", 1513349cc55cSDimitry Andric [(set i16 1514349cc55cSDimitry Andric : $rd, (AVRasr i16 1515349cc55cSDimitry Andric : $src)), 1516349cc55cSDimitry Andric (implicit SREG)]>; 15170b57cec5SDimitry Andric 151804eeddc0SDimitry Andric def ASRWLoRd : Pseudo<(outs DREGS:$rd), (ins DREGS:$src), "asrwlo\t$rd", 151904eeddc0SDimitry Andric [(set i16:$rd, (AVRasrlo i16:$src)), (implicit SREG)]>; 152006c3fb27SDimitry Andric let Uses = [R1] in 152106c3fb27SDimitry Andric def ROLBRdR1 : Pseudo<(outs GPR8:$rd), 152206c3fb27SDimitry Andric (ins GPR8:$src), 1523480093f4SDimitry Andric "rolb\t$rd", 152406c3fb27SDimitry Andric [(set i8:$rd, (AVRrol i8:$src)), 152506c3fb27SDimitry Andric (implicit SREG)]>, 152606c3fb27SDimitry Andric Requires<[HasNonTinyEncoding]>; 152706c3fb27SDimitry Andric 152806c3fb27SDimitry Andric let Uses = [R17] in 152906c3fb27SDimitry Andric def ROLBRdR17 : Pseudo<(outs GPR8:$rd), 153006c3fb27SDimitry Andric (ins GPR8:$src), 153106c3fb27SDimitry Andric "rolb\t$rd", 153206c3fb27SDimitry Andric [(set i8:$rd, (AVRrol i8:$src)), 153306c3fb27SDimitry Andric (implicit SREG)]>, 153406c3fb27SDimitry Andric Requires<[HasTinyEncoding]>; 1535480093f4SDimitry Andric 1536349cc55cSDimitry Andric def RORBRd : Pseudo<(outs GPR8 1537349cc55cSDimitry Andric : $rd), 1538349cc55cSDimitry Andric (ins GPR8 1539349cc55cSDimitry Andric : $src), 1540480093f4SDimitry Andric "rorb\t$rd", 1541349cc55cSDimitry Andric [(set i8 1542349cc55cSDimitry Andric : $rd, (AVRror i8 1543349cc55cSDimitry Andric : $src)), 1544349cc55cSDimitry Andric (implicit SREG)]>; 1545480093f4SDimitry Andric 1546fe6060f1SDimitry Andric // Bit rotate operations. 1547349cc55cSDimitry Andric let Uses = [SREG] in { 1548fe6060f1SDimitry Andric 1549349cc55cSDimitry Andric def ROLWRd 1550349cc55cSDimitry Andric : Pseudo<(outs DREGS 1551349cc55cSDimitry Andric : $rd), 1552349cc55cSDimitry Andric (ins DREGS 1553349cc55cSDimitry Andric : $src), 15540b57cec5SDimitry Andric "rolw\t$rd", 1555349cc55cSDimitry Andric [(set i16 1556349cc55cSDimitry Andric : $rd, (AVRrol i16 1557349cc55cSDimitry Andric : $src)), 1558349cc55cSDimitry Andric (implicit SREG)]>; 15590b57cec5SDimitry Andric 1560349cc55cSDimitry Andric def RORRd : FRd<0b1001, 0b0100111, 1561349cc55cSDimitry Andric (outs GPR8 1562349cc55cSDimitry Andric : $rd), 1563349cc55cSDimitry Andric (ins GPR8 1564349cc55cSDimitry Andric : $src), 1565349cc55cSDimitry Andric "ror\t$rd", []>; 15660b57cec5SDimitry Andric 1567349cc55cSDimitry Andric def RORWRd 1568349cc55cSDimitry Andric : Pseudo<(outs DREGS 1569349cc55cSDimitry Andric : $rd), 1570349cc55cSDimitry Andric (ins DREGS 1571349cc55cSDimitry Andric : $src), 15720b57cec5SDimitry Andric "rorw\t$rd", 1573349cc55cSDimitry Andric [(set i16 1574349cc55cSDimitry Andric : $rd, (AVRror i16 1575349cc55cSDimitry Andric : $src)), 1576349cc55cSDimitry Andric (implicit SREG)]>; 15770b57cec5SDimitry Andric } 15780b57cec5SDimitry Andric} 15790b57cec5SDimitry Andric 15800b57cec5SDimitry Andric// SWAP Rd 15810b57cec5SDimitry Andric// Swaps the high and low nibbles in a register. 1582349cc55cSDimitry Andriclet Constraints = 1583349cc55cSDimitry Andric "$src = $rd" in def SWAPRd : FRd<0b1001, 0b0100010, 1584349cc55cSDimitry Andric (outs GPR8 1585349cc55cSDimitry Andric : $rd), 1586349cc55cSDimitry Andric (ins GPR8 1587349cc55cSDimitry Andric : $src), 1588349cc55cSDimitry Andric "swap\t$rd", [(set i8 1589349cc55cSDimitry Andric : $rd, (AVRSwap i8 1590349cc55cSDimitry Andric : $src))]>; 15910b57cec5SDimitry Andric 15920b57cec5SDimitry Andric// IO register bit set/clear operations. 15930b57cec5SDimitry Andric//: TODO: add patterns when popcount(imm)==2 to be expanded with 2 sbi/cbi 15940b57cec5SDimitry Andric// instead of in+ori+out which requires one more instr. 1595349cc55cSDimitry Andricdef SBIAb : FIOBIT<0b10, (outs), 1596349cc55cSDimitry Andric (ins imm_port5 1597349cc55cSDimitry Andric : $addr, i8imm 1598bdd1243dSDimitry Andric : $b), 1599bdd1243dSDimitry Andric "sbi\t$addr, $b", [(store(or(i8(load lowioaddr8 1600349cc55cSDimitry Andric : $addr)), 1601349cc55cSDimitry Andric iobitpos8 1602bdd1243dSDimitry Andric : $b), 1603349cc55cSDimitry Andric lowioaddr8 1604349cc55cSDimitry Andric : $addr)]>; 16050b57cec5SDimitry Andric 1606349cc55cSDimitry Andricdef CBIAb : FIOBIT<0b00, (outs), 1607349cc55cSDimitry Andric (ins imm_port5 1608349cc55cSDimitry Andric : $addr, i8imm 1609bdd1243dSDimitry Andric : $b), 1610bdd1243dSDimitry Andric "cbi\t$addr, $b", [(store(and(i8(load lowioaddr8 1611349cc55cSDimitry Andric : $addr)), 1612349cc55cSDimitry Andric iobitposn8 1613bdd1243dSDimitry Andric : $b), 1614349cc55cSDimitry Andric lowioaddr8 1615349cc55cSDimitry Andric : $addr)]>; 16160b57cec5SDimitry Andric 16170b57cec5SDimitry Andric// Status register bit load/store operations. 1618349cc55cSDimitry Andriclet Defs = [SREG] in def BST : FRdB<0b01, (outs), 1619349cc55cSDimitry Andric (ins GPR8 1620349cc55cSDimitry Andric : $rd, i8imm 1621349cc55cSDimitry Andric : $b), 1622349cc55cSDimitry Andric "bst\t$rd, $b", []>; 16230b57cec5SDimitry Andric 1624fe6060f1SDimitry Andriclet Constraints = "$src = $rd", 1625349cc55cSDimitry Andric Uses = [SREG] in def BLD : FRdB<0b00, 1626349cc55cSDimitry Andric (outs GPR8 1627349cc55cSDimitry Andric : $rd), 1628349cc55cSDimitry Andric (ins GPR8 1629349cc55cSDimitry Andric : $src, i8imm 1630349cc55cSDimitry Andric : $b), 1631349cc55cSDimitry Andric "bld\t$rd, $b", []>; 16320b57cec5SDimitry Andric 16330b57cec5SDimitry Andricdef CBR : InstAlias<"cbr\t$rd, $k", (ANDIRdK LD8 : $rd, imm_com8 : $k), 0>; 16340b57cec5SDimitry Andric 16350b57cec5SDimitry Andric// CLR Rd 16360b57cec5SDimitry Andric// Alias for EOR Rd, Rd 16370b57cec5SDimitry Andric// ------------- 16380b57cec5SDimitry Andric// Clears all bits in a register. 16390b57cec5SDimitry Andricdef CLR : InstAlias<"clr\t$rd", (EORRdRr GPR8 : $rd, GPR8 : $rd)>; 16400b57cec5SDimitry Andric 16410b57cec5SDimitry Andric// LSL Rd 16420b57cec5SDimitry Andric// Alias for ADD Rd, Rd 16430b57cec5SDimitry Andric// -------------- 16440b57cec5SDimitry Andric// Logical shift left one bit. 16450b57cec5SDimitry Andricdef LSL : InstAlias<"lsl\t$rd", (ADDRdRr GPR8 : $rd, GPR8 : $rd)>; 16460b57cec5SDimitry Andric 16470b57cec5SDimitry Andricdef ROL : InstAlias<"rol\t$rd", (ADCRdRr GPR8 : $rd, GPR8 : $rd)>; 16480b57cec5SDimitry Andric 16490b57cec5SDimitry Andric// SER Rd 16500b57cec5SDimitry Andric// Alias for LDI Rd, 0xff 16510b57cec5SDimitry Andric// --------- 16520b57cec5SDimitry Andric// Sets all bits in a register. 16530b57cec5SDimitry Andricdef : InstAlias<"ser\t$rd", (LDIRdK LD8 : $rd, 0xff), 0>; 16540b57cec5SDimitry Andric 165581ad6265SDimitry Andriclet hasSideEffects=1 in { 165681ad6265SDimitry Andric let Defs = [SREG] in def BSETs : FS<0, 165781ad6265SDimitry Andric (outs), 165881ad6265SDimitry Andric (ins i8imm:$s), 1659349cc55cSDimitry Andric "bset\t$s", []>; 16600b57cec5SDimitry Andric 166181ad6265SDimitry Andric let Defs = [SREG] in def BCLRs : FS<1, 166281ad6265SDimitry Andric (outs), 166381ad6265SDimitry Andric (ins i8imm:$s), 1664349cc55cSDimitry Andric "bclr\t$s", []>; 166581ad6265SDimitry Andric} 16660b57cec5SDimitry Andric 16670b57cec5SDimitry Andric// Set/clear aliases for the carry (C) status flag (bit 0). 16680b57cec5SDimitry Andricdef : InstAlias<"sec", (BSETs 0)>; 16690b57cec5SDimitry Andricdef : InstAlias<"clc", (BCLRs 0)>; 16700b57cec5SDimitry Andric 16710b57cec5SDimitry Andric// Set/clear aliases for the zero (Z) status flag (bit 1). 16720b57cec5SDimitry Andricdef : InstAlias<"sez", (BSETs 1)>; 16730b57cec5SDimitry Andricdef : InstAlias<"clz", (BCLRs 1)>; 16740b57cec5SDimitry Andric 16750b57cec5SDimitry Andric// Set/clear aliases for the negative (N) status flag (bit 2). 16760b57cec5SDimitry Andricdef : InstAlias<"sen", (BSETs 2)>; 16770b57cec5SDimitry Andricdef : InstAlias<"cln", (BCLRs 2)>; 16780b57cec5SDimitry Andric 16790b57cec5SDimitry Andric// Set/clear aliases for the overflow (V) status flag (bit 3). 16800b57cec5SDimitry Andricdef : InstAlias<"sev", (BSETs 3)>; 16810b57cec5SDimitry Andricdef : InstAlias<"clv", (BCLRs 3)>; 16820b57cec5SDimitry Andric 16830b57cec5SDimitry Andric// Set/clear aliases for the signed (S) status flag (bit 4). 16840b57cec5SDimitry Andricdef : InstAlias<"ses", (BSETs 4)>; 16850b57cec5SDimitry Andricdef : InstAlias<"cls", (BCLRs 4)>; 16860b57cec5SDimitry Andric 16870b57cec5SDimitry Andric// Set/clear aliases for the half-carry (H) status flag (bit 5). 16880b57cec5SDimitry Andricdef : InstAlias<"seh", (BSETs 5)>; 16890b57cec5SDimitry Andricdef : InstAlias<"clh", (BCLRs 5)>; 16900b57cec5SDimitry Andric 16910b57cec5SDimitry Andric// Set/clear aliases for the T status flag (bit 6). 16920b57cec5SDimitry Andricdef : InstAlias<"set", (BSETs 6)>; 16930b57cec5SDimitry Andricdef : InstAlias<"clt", (BCLRs 6)>; 16940b57cec5SDimitry Andric 16950b57cec5SDimitry Andric// Set/clear aliases for the interrupt (I) status flag (bit 7). 16960b57cec5SDimitry Andricdef : InstAlias<"sei", (BSETs 7)>; 16970b57cec5SDimitry Andricdef : InstAlias<"cli", (BCLRs 7)>; 16980b57cec5SDimitry Andric 16990b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 17000b57cec5SDimitry Andric// Special/Control instructions 17010b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 17020b57cec5SDimitry Andric 17030b57cec5SDimitry Andric// BREAK 17040b57cec5SDimitry Andric// Breakpoint instruction 17050b57cec5SDimitry Andric// --------- 17060b57cec5SDimitry Andric// <|1001|0101|1001|1000> 1707349cc55cSDimitry Andricdef BREAK : F16<0b1001010110011000, (outs), (ins), "break", []>, 17080b57cec5SDimitry Andric Requires<[HasBREAK]>; 17090b57cec5SDimitry Andric 17100b57cec5SDimitry Andric// NOP 17110b57cec5SDimitry Andric// No-operation instruction 17120b57cec5SDimitry Andric// --------- 17130b57cec5SDimitry Andric// <|0000|0000|0000|0000> 1714349cc55cSDimitry Andricdef NOP : F16<0b0000000000000000, (outs), (ins), "nop", []>; 17150b57cec5SDimitry Andric 17160b57cec5SDimitry Andric// SLEEP 17170b57cec5SDimitry Andric// Sleep instruction 17180b57cec5SDimitry Andric// --------- 17190b57cec5SDimitry Andric// <|1001|0101|1000|1000> 1720349cc55cSDimitry Andricdef SLEEP : F16<0b1001010110001000, (outs), (ins), "sleep", []>; 17210b57cec5SDimitry Andric 17220b57cec5SDimitry Andric// WDR 17230b57cec5SDimitry Andric// Watchdog reset 17240b57cec5SDimitry Andric// --------- 17250b57cec5SDimitry Andric// <|1001|0101|1010|1000> 1726349cc55cSDimitry Andricdef WDR : F16<0b1001010110101000, (outs), (ins), "wdr", []>; 17270b57cec5SDimitry Andric 17280b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 17290b57cec5SDimitry Andric// Pseudo instructions for later expansion 17300b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 17310b57cec5SDimitry Andric 17320b57cec5SDimitry Andric//: TODO: Optimize this for wider types AND optimize the following code 17330b57cec5SDimitry Andric// compile int foo(char a, char b, char c, char d) {return d+b;} 17340b57cec5SDimitry Andric// looks like a missed sext_inreg opportunity. 1735349cc55cSDimitry Andricdef SEXT 1736349cc55cSDimitry Andric : ExtensionPseudo<(outs DREGS 1737349cc55cSDimitry Andric : $dst), 1738349cc55cSDimitry Andric (ins GPR8 1739349cc55cSDimitry Andric : $src), 17400b57cec5SDimitry Andric "sext\t$dst, $src", 1741349cc55cSDimitry Andric [(set i16 1742349cc55cSDimitry Andric : $dst, (sext i8 1743349cc55cSDimitry Andric : $src)), 1744349cc55cSDimitry Andric (implicit SREG)]>; 17450b57cec5SDimitry Andric 1746349cc55cSDimitry Andricdef ZEXT 1747349cc55cSDimitry Andric : ExtensionPseudo<(outs DREGS 1748349cc55cSDimitry Andric : $dst), 1749349cc55cSDimitry Andric (ins GPR8 1750349cc55cSDimitry Andric : $src), 17510b57cec5SDimitry Andric "zext\t$dst, $src", 1752349cc55cSDimitry Andric [(set i16 1753349cc55cSDimitry Andric : $dst, (zext i8 1754349cc55cSDimitry Andric : $src)), 1755349cc55cSDimitry Andric (implicit SREG)]>; 17560b57cec5SDimitry Andric 17570b57cec5SDimitry Andric// This pseudo gets expanded into a movw+adiw thus it clobbers SREG. 17580b57cec5SDimitry Andriclet Defs = [SREG], 1759349cc55cSDimitry Andric hasSideEffects = 0 in def FRMIDX : Pseudo<(outs DLDREGS 1760349cc55cSDimitry Andric : $dst), 1761349cc55cSDimitry Andric (ins DLDREGS 1762349cc55cSDimitry Andric : $src, i16imm 1763349cc55cSDimitry Andric : $src2), 1764349cc55cSDimitry Andric "frmidx\t$dst, $src, $src2", []>; 17650b57cec5SDimitry Andric 17660b57cec5SDimitry Andric// This pseudo is either converted to a regular store or a push which clobbers 17670b57cec5SDimitry Andric// SP. 1768349cc55cSDimitry Andricdef STDSPQRr : StorePseudo<(outs), 1769349cc55cSDimitry Andric (ins memspi 1770349cc55cSDimitry Andric : $dst, GPR8 1771349cc55cSDimitry Andric : $src), 1772349cc55cSDimitry Andric "stdstk\t$dst, $src", [(store i8 1773349cc55cSDimitry Andric : $src, addr 1774349cc55cSDimitry Andric : $dst)]>; 17750b57cec5SDimitry Andric 17760b57cec5SDimitry Andric// This pseudo is either converted to a regular store or a push which clobbers 17770b57cec5SDimitry Andric// SP. 1778349cc55cSDimitry Andricdef STDWSPQRr : StorePseudo<(outs), 1779349cc55cSDimitry Andric (ins memspi 1780349cc55cSDimitry Andric : $dst, DREGS 1781349cc55cSDimitry Andric : $src), 1782349cc55cSDimitry Andric "stdwstk\t$dst, $src", [(store i16 1783349cc55cSDimitry Andric : $src, addr 1784349cc55cSDimitry Andric : $dst)]>; 17850b57cec5SDimitry Andric 17860b57cec5SDimitry Andric// SP read/write pseudos. 1787349cc55cSDimitry Andriclet hasSideEffects = 0 in { 1788349cc55cSDimitry Andric let Uses = [SP] in def SPREAD : Pseudo<(outs DREGS 1789349cc55cSDimitry Andric : $dst), 1790349cc55cSDimitry Andric (ins GPRSP 1791349cc55cSDimitry Andric : $src), 1792349cc55cSDimitry Andric "spread\t$dst, $src", []>; 17930b57cec5SDimitry Andric 1794349cc55cSDimitry Andric let Defs = [SP] in def SPWRITE : Pseudo<(outs GPRSP 1795349cc55cSDimitry Andric : $dst), 1796349cc55cSDimitry Andric (ins DREGS 1797349cc55cSDimitry Andric : $src), 1798349cc55cSDimitry Andric "spwrite\t$dst, $src", []>; 17990b57cec5SDimitry Andric} 18000b57cec5SDimitry Andric 1801349cc55cSDimitry Andricdef Select8 : SelectPseudo<(outs GPR8 1802349cc55cSDimitry Andric : $dst), 1803349cc55cSDimitry Andric (ins GPR8 1804349cc55cSDimitry Andric : $src, GPR8 1805349cc55cSDimitry Andric : $src2, i8imm 1806349cc55cSDimitry Andric : $cc), 1807349cc55cSDimitry Andric "# Select8 PSEUDO", [(set i8 1808349cc55cSDimitry Andric : $dst, (AVRselectcc i8 1809349cc55cSDimitry Andric : $src, i8 1810349cc55cSDimitry Andric : $src2, imm 1811349cc55cSDimitry Andric : $cc))]>; 18120b57cec5SDimitry Andric 1813349cc55cSDimitry Andricdef Select16 : SelectPseudo<(outs DREGS 1814349cc55cSDimitry Andric : $dst), 1815349cc55cSDimitry Andric (ins DREGS 1816349cc55cSDimitry Andric : $src, DREGS 1817349cc55cSDimitry Andric : $src2, i8imm 1818349cc55cSDimitry Andric : $cc), 1819349cc55cSDimitry Andric "# Select16 PSEUDO", [(set i16 1820349cc55cSDimitry Andric : $dst, (AVRselectcc i16 1821349cc55cSDimitry Andric : $src, i16 1822349cc55cSDimitry Andric : $src2, imm 1823349cc55cSDimitry Andric : $cc))]>; 18240b57cec5SDimitry Andric 1825349cc55cSDimitry Andricdef Lsl8 : ShiftPseudo<(outs GPR8 1826349cc55cSDimitry Andric : $dst), 1827349cc55cSDimitry Andric (ins GPR8 1828349cc55cSDimitry Andric : $src, GPR8 1829349cc55cSDimitry Andric : $cnt), 1830349cc55cSDimitry Andric "# Lsl8 PSEUDO", [(set i8 1831349cc55cSDimitry Andric : $dst, (AVRlslLoop i8 1832349cc55cSDimitry Andric : $src, i8 1833349cc55cSDimitry Andric : $cnt))]>; 18340b57cec5SDimitry Andric 1835349cc55cSDimitry Andricdef Lsl16 : ShiftPseudo<(outs DREGS 1836349cc55cSDimitry Andric : $dst), 1837349cc55cSDimitry Andric (ins DREGS 1838349cc55cSDimitry Andric : $src, GPR8 1839349cc55cSDimitry Andric : $cnt), 1840349cc55cSDimitry Andric "# Lsl16 PSEUDO", [(set i16 1841349cc55cSDimitry Andric : $dst, (AVRlslLoop i16 1842349cc55cSDimitry Andric : $src, i8 1843349cc55cSDimitry Andric : $cnt))]>; 18440b57cec5SDimitry Andric 1845bdd1243dSDimitry Andricdef Lsl32 : ShiftPseudo<(outs DREGS:$dstlo, DREGS:$dsthi), 1846bdd1243dSDimitry Andric (ins DREGS:$srclo, DREGS:$srchi, i8imm:$cnt), 1847bdd1243dSDimitry Andric "# Lsl32 PSEUDO", 1848bdd1243dSDimitry Andric [(set i16:$dstlo, i16:$dsthi, (AVRlslw i16:$srclo, i16:$srchi, i8:$cnt))]>; 1849bdd1243dSDimitry Andric 1850349cc55cSDimitry Andricdef Lsr8 : ShiftPseudo<(outs GPR8 1851349cc55cSDimitry Andric : $dst), 1852349cc55cSDimitry Andric (ins GPR8 1853349cc55cSDimitry Andric : $src, GPR8 1854349cc55cSDimitry Andric : $cnt), 1855349cc55cSDimitry Andric "# Lsr8 PSEUDO", [(set i8 1856349cc55cSDimitry Andric : $dst, (AVRlsrLoop i8 1857349cc55cSDimitry Andric : $src, i8 1858349cc55cSDimitry Andric : $cnt))]>; 18590b57cec5SDimitry Andric 1860349cc55cSDimitry Andricdef Lsr16 : ShiftPseudo<(outs DREGS 1861349cc55cSDimitry Andric : $dst), 1862349cc55cSDimitry Andric (ins DREGS 1863349cc55cSDimitry Andric : $src, GPR8 1864349cc55cSDimitry Andric : $cnt), 1865349cc55cSDimitry Andric "# Lsr16 PSEUDO", [(set i16 1866349cc55cSDimitry Andric : $dst, (AVRlsrLoop i16 1867349cc55cSDimitry Andric : $src, i8 1868349cc55cSDimitry Andric : $cnt))]>; 18690b57cec5SDimitry Andric 1870bdd1243dSDimitry Andricdef Lsr32 : ShiftPseudo<(outs DREGS:$dstlo, DREGS:$dsthi), 1871bdd1243dSDimitry Andric (ins DREGS:$srclo, DREGS:$srchi, i8imm:$cnt), 1872bdd1243dSDimitry Andric "# Lsr32 PSEUDO", 1873bdd1243dSDimitry Andric [(set i16:$dstlo, i16:$dsthi, (AVRlsrw i16:$srclo, i16:$srchi, i8:$cnt))]>; 1874bdd1243dSDimitry Andric 1875349cc55cSDimitry Andricdef Rol8 : ShiftPseudo<(outs GPR8 1876349cc55cSDimitry Andric : $dst), 1877349cc55cSDimitry Andric (ins GPR8 1878349cc55cSDimitry Andric : $src, GPR8 1879349cc55cSDimitry Andric : $cnt), 1880349cc55cSDimitry Andric "# Rol8 PSEUDO", [(set i8 1881349cc55cSDimitry Andric : $dst, (AVRrolLoop i8 1882349cc55cSDimitry Andric : $src, i8 1883349cc55cSDimitry Andric : $cnt))]>; 18840b57cec5SDimitry Andric 1885349cc55cSDimitry Andricdef Rol16 : ShiftPseudo<(outs DREGS 1886349cc55cSDimitry Andric : $dst), 1887349cc55cSDimitry Andric (ins DREGS 1888349cc55cSDimitry Andric : $src, GPR8 1889349cc55cSDimitry Andric : $cnt), 1890349cc55cSDimitry Andric "# Rol16 PSEUDO", [(set i16 1891349cc55cSDimitry Andric : $dst, (AVRrolLoop i16 1892349cc55cSDimitry Andric : $src, i8 1893349cc55cSDimitry Andric : $cnt))]>; 18940b57cec5SDimitry Andric 1895349cc55cSDimitry Andricdef Ror8 : ShiftPseudo<(outs GPR8 1896349cc55cSDimitry Andric : $dst), 1897349cc55cSDimitry Andric (ins GPR8 1898349cc55cSDimitry Andric : $src, GPR8 1899349cc55cSDimitry Andric : $cnt), 1900349cc55cSDimitry Andric "# Ror8 PSEUDO", [(set i8 1901349cc55cSDimitry Andric : $dst, (AVRrorLoop i8 1902349cc55cSDimitry Andric : $src, i8 1903349cc55cSDimitry Andric : $cnt))]>; 19040b57cec5SDimitry Andric 1905349cc55cSDimitry Andricdef Ror16 : ShiftPseudo<(outs DREGS 1906349cc55cSDimitry Andric : $dst), 1907349cc55cSDimitry Andric (ins DREGS 1908349cc55cSDimitry Andric : $src, GPR8 1909349cc55cSDimitry Andric : $cnt), 1910349cc55cSDimitry Andric "# Ror16 PSEUDO", [(set i16 1911349cc55cSDimitry Andric : $dst, (AVRrorLoop i16 1912349cc55cSDimitry Andric : $src, i8 1913349cc55cSDimitry Andric : $cnt))]>; 19140b57cec5SDimitry Andric 1915349cc55cSDimitry Andricdef Asr8 : ShiftPseudo<(outs GPR8 1916349cc55cSDimitry Andric : $dst), 1917349cc55cSDimitry Andric (ins GPR8 1918349cc55cSDimitry Andric : $src, GPR8 1919349cc55cSDimitry Andric : $cnt), 1920349cc55cSDimitry Andric "# Asr8 PSEUDO", [(set i8 1921349cc55cSDimitry Andric : $dst, (AVRasrLoop i8 1922349cc55cSDimitry Andric : $src, i8 1923349cc55cSDimitry Andric : $cnt))]>; 19240b57cec5SDimitry Andric 1925349cc55cSDimitry Andricdef Asr16 : ShiftPseudo<(outs DREGS 1926349cc55cSDimitry Andric : $dst), 1927349cc55cSDimitry Andric (ins DREGS 1928349cc55cSDimitry Andric : $src, GPR8 1929349cc55cSDimitry Andric : $cnt), 1930349cc55cSDimitry Andric "# Asr16 PSEUDO", [(set i16 1931349cc55cSDimitry Andric : $dst, (AVRasrLoop i16 1932349cc55cSDimitry Andric : $src, i8 1933349cc55cSDimitry Andric : $cnt))]>; 19340b57cec5SDimitry Andric 1935bdd1243dSDimitry Andricdef Asr32 : ShiftPseudo<(outs DREGS:$dstlo, DREGS:$dsthi), 1936bdd1243dSDimitry Andric (ins DREGS:$srclo, DREGS:$srchi, i8imm:$cnt), 1937bdd1243dSDimitry Andric "# Asr32 PSEUDO", 1938bdd1243dSDimitry Andric [(set i16:$dstlo, i16:$dsthi, (AVRasrw i16:$srclo, i16:$srchi, i8:$cnt))]>; 1939bdd1243dSDimitry Andric 1940bdd1243dSDimitry Andric// lowered to a copy from the zero register. 194104eeddc0SDimitry Andriclet usesCustomInserter=1 in 1942bdd1243dSDimitry Andricdef CopyZero : Pseudo<(outs GPR8:$rd), (ins), "clrz\t$rd", [(set i8:$rd, 0)]>; 194304eeddc0SDimitry Andric 19440b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 19450b57cec5SDimitry Andric// Non-Instruction Patterns 19460b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 19470b57cec5SDimitry Andric 19480b57cec5SDimitry Andric//: TODO: look in x86InstrCompiler.td for odd encoding trick related to 19490b57cec5SDimitry Andric// add x, 128 -> sub x, -128. Clang is emitting an eor for this (ldi+eor) 19500b57cec5SDimitry Andric 19510b57cec5SDimitry Andric// the add instruction always writes the carry flag 1952349cc55cSDimitry Andricdef : Pat<(addc i8 : $src, i8 : $src2), (ADDRdRr i8 : $src, i8 : $src2)>; 1953349cc55cSDimitry Andricdef : Pat<(addc DREGS 1954349cc55cSDimitry Andric : $src, DREGS 1955349cc55cSDimitry Andric : $src2), 1956349cc55cSDimitry Andric (ADDWRdRr DREGS 1957349cc55cSDimitry Andric : $src, DREGS 1958349cc55cSDimitry Andric : $src2)>; 19590b57cec5SDimitry Andric 19600b57cec5SDimitry Andric// all sub instruction variants always writes the carry flag 1961349cc55cSDimitry Andricdef : Pat<(subc i8 : $src, i8 : $src2), (SUBRdRr i8 : $src, i8 : $src2)>; 1962349cc55cSDimitry Andricdef : Pat<(subc i16 : $src, i16 : $src2), (SUBWRdRr i16 : $src, i16 : $src2)>; 1963349cc55cSDimitry Andricdef : Pat<(subc i8 : $src, imm : $src2), (SUBIRdK i8 : $src, imm : $src2)>; 1964349cc55cSDimitry Andricdef : Pat<(subc i16 : $src, imm : $src2), (SUBIWRdK i16 : $src, imm : $src2)>; 19650b57cec5SDimitry Andric 19660b57cec5SDimitry Andric// These patterns convert add (x, -imm) to sub (x, imm) since we dont have 19670b57cec5SDimitry Andric// any add with imm instructions. Also take care of the adiw/sbiw instructions. 1968349cc55cSDimitry Andricdef : Pat<(add i16 1969349cc55cSDimitry Andric : $src1, imm0_63_neg 1970349cc55cSDimitry Andric : $src2), 1971349cc55cSDimitry Andric (SBIWRdK i16 1972349cc55cSDimitry Andric : $src1, (imm0_63_neg 1973bdd1243dSDimitry Andric : $src2))>, 1974bdd1243dSDimitry Andric Requires<[HasADDSUBIW]>; 1975349cc55cSDimitry Andricdef : Pat<(add i16 1976349cc55cSDimitry Andric : $src1, imm 1977349cc55cSDimitry Andric : $src2), 1978349cc55cSDimitry Andric (SUBIWRdK i16 1979349cc55cSDimitry Andric : $src1, (imm16_neg_XFORM imm 1980349cc55cSDimitry Andric : $src2))>; 1981349cc55cSDimitry Andricdef : Pat<(addc i16 1982349cc55cSDimitry Andric : $src1, imm 1983349cc55cSDimitry Andric : $src2), 1984349cc55cSDimitry Andric (SUBIWRdK i16 1985349cc55cSDimitry Andric : $src1, (imm16_neg_XFORM imm 1986349cc55cSDimitry Andric : $src2))>; 19870b57cec5SDimitry Andric 1988349cc55cSDimitry Andricdef : Pat<(add i8 1989349cc55cSDimitry Andric : $src1, imm 1990349cc55cSDimitry Andric : $src2), 1991349cc55cSDimitry Andric (SUBIRdK i8 1992349cc55cSDimitry Andric : $src1, (imm8_neg_XFORM imm 1993349cc55cSDimitry Andric : $src2))>; 1994349cc55cSDimitry Andricdef : Pat<(addc i8 1995349cc55cSDimitry Andric : $src1, imm 1996349cc55cSDimitry Andric : $src2), 1997349cc55cSDimitry Andric (SUBIRdK i8 1998349cc55cSDimitry Andric : $src1, (imm8_neg_XFORM imm 1999349cc55cSDimitry Andric : $src2))>; 2000349cc55cSDimitry Andricdef : Pat<(adde i8 2001349cc55cSDimitry Andric : $src1, imm 2002349cc55cSDimitry Andric : $src2), 2003349cc55cSDimitry Andric (SBCIRdK i8 2004349cc55cSDimitry Andric : $src1, (imm8_neg_XFORM imm 2005349cc55cSDimitry Andric : $src2))>; 20060b57cec5SDimitry Andric 2007bdd1243dSDimitry Andric// Emit NEGWRd with an extra zero register operand. 2008bdd1243dSDimitry Andricdef : Pat<(ineg i16:$src), 2009bdd1243dSDimitry Andric (NEGWRd i16:$src, (CopyZero))>; 2010bdd1243dSDimitry Andric 20110b57cec5SDimitry Andric// Calls. 20122a66634dSDimitry Andriclet Predicates = [HasJMPCALL] in { 2013349cc55cSDimitry Andric def : Pat<(AVRcall(i16 tglobaladdr:$dst)), (CALLk tglobaladdr:$dst)>; 2014349cc55cSDimitry Andric def : Pat<(AVRcall(i16 texternalsym:$dst)), (CALLk texternalsym:$dst)>; 20152a66634dSDimitry Andric} 20162a66634dSDimitry Andricdef : Pat<(AVRcall(i16 tglobaladdr:$dst)), (RCALLk tglobaladdr:$dst)>; 20172a66634dSDimitry Andricdef : Pat<(AVRcall(i16 texternalsym:$dst)), (RCALLk texternalsym:$dst)>; 20180b57cec5SDimitry Andric 20190b57cec5SDimitry Andric// `anyext` 2020349cc55cSDimitry Andricdef : Pat<(i16(anyext i8 2021349cc55cSDimitry Andric : $src)), 2022349cc55cSDimitry Andric (INSERT_SUBREG(i16(IMPLICIT_DEF)), i8 2023349cc55cSDimitry Andric : $src, sub_lo)>; 20240b57cec5SDimitry Andric 20250b57cec5SDimitry Andric// `trunc` 2026349cc55cSDimitry Andricdef : Pat<(i8(trunc i16 : $src)), (EXTRACT_SUBREG i16 : $src, sub_lo)>; 20270b57cec5SDimitry Andric 20280b57cec5SDimitry Andric// sext_inreg 2029349cc55cSDimitry Andricdef : Pat<(sext_inreg i16 2030349cc55cSDimitry Andric : $src, i8), 2031349cc55cSDimitry Andric (SEXT(i8(EXTRACT_SUBREG i16 2032349cc55cSDimitry Andric : $src, sub_lo)))>; 20330b57cec5SDimitry Andric 20340b57cec5SDimitry Andric// GlobalAddress 2035349cc55cSDimitry Andricdef : Pat<(i16(AVRWrapper tglobaladdr : $dst)), (LDIWRdK tglobaladdr : $dst)>; 2036349cc55cSDimitry Andricdef : Pat<(add i16 2037349cc55cSDimitry Andric : $src, (AVRWrapper tglobaladdr 2038349cc55cSDimitry Andric : $src2)), 2039349cc55cSDimitry Andric (SUBIWRdK i16 2040349cc55cSDimitry Andric : $src, tglobaladdr 2041349cc55cSDimitry Andric : $src2)>; 2042bdd1243dSDimitry Andricdef : Pat<(i8(load(AVRWrapper tglobaladdr:$dst))), 2043bdd1243dSDimitry Andric (LDSRdK tglobaladdr:$dst)>, 2044bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 2045bdd1243dSDimitry Andricdef : Pat<(i8(load(AVRWrapper tglobaladdr:$dst))), 2046bdd1243dSDimitry Andric (LDSRdKTiny tglobaladdr:$dst)>, 2047bdd1243dSDimitry Andric Requires<[HasSRAM, HasTinyEncoding]>; 2048bdd1243dSDimitry Andricdef : Pat<(i16(load(AVRWrapper tglobaladdr:$dst))), 2049bdd1243dSDimitry Andric (LDSWRdK tglobaladdr:$dst)>, 2050bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 2051bdd1243dSDimitry Andricdef : Pat<(store i8:$src, (i16(AVRWrapper tglobaladdr:$dst))), 2052bdd1243dSDimitry Andric (STSKRr tglobaladdr:$dst, i8:$src)>, 2053bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 2054bdd1243dSDimitry Andricdef : Pat<(store i8:$src, (i16(AVRWrapper tglobaladdr:$dst))), 2055bdd1243dSDimitry Andric (STSKRrTiny tglobaladdr:$dst, i8:$src)>, 2056bdd1243dSDimitry Andric Requires<[HasSRAM, HasTinyEncoding]>; 2057bdd1243dSDimitry Andricdef : Pat<(store i16:$src, (i16(AVRWrapper tglobaladdr:$dst))), 2058bdd1243dSDimitry Andric (STSWKRr tglobaladdr:$dst, i16:$src)>, 2059bdd1243dSDimitry Andric Requires<[HasSRAM, HasNonTinyEncoding]>; 20600b57cec5SDimitry Andric 20610b57cec5SDimitry Andric// BlockAddress 2062349cc55cSDimitry Andricdef : Pat<(i16(AVRWrapper tblockaddress 2063349cc55cSDimitry Andric : $dst)), 2064349cc55cSDimitry Andric (LDIWRdK tblockaddress 2065349cc55cSDimitry Andric : $dst)>; 20660b57cec5SDimitry Andric 2067349cc55cSDimitry Andricdef : Pat<(i8(trunc(AVRlsrwn DLDREGS 2068349cc55cSDimitry Andric : $src, (i16 8)))), 2069349cc55cSDimitry Andric (EXTRACT_SUBREG DREGS 2070349cc55cSDimitry Andric : $src, sub_hi)>; 20710b57cec5SDimitry Andric 20720b57cec5SDimitry Andric// :FIXME: DAGCombiner produces an shl node after legalization from these seq: 20730b57cec5SDimitry Andric// BR_JT -> (mul x, 2) -> (shl x, 1) 2074349cc55cSDimitry Andricdef : Pat<(shl i16 : $src1, (i8 1)), (LSLWRd i16 : $src1)>; 20750b57cec5SDimitry Andric 20760b57cec5SDimitry Andric// Lowering of 'tst' node to 'TST' instruction. 20770b57cec5SDimitry Andric// TST is an alias of AND Rd, Rd. 2078349cc55cSDimitry Andricdef : Pat<(AVRtst i8 : $rd), (ANDRdRr GPR8 : $rd, GPR8 : $rd)>; 20790b57cec5SDimitry Andric 20800b57cec5SDimitry Andric// Lowering of 'lsl' node to 'LSL' instruction. 20810b57cec5SDimitry Andric// LSL is an alias of 'ADD Rd, Rd' 2082349cc55cSDimitry Andricdef : Pat<(AVRlsl i8 : $rd), (ADDRdRr GPR8 : $rd, GPR8 : $rd)>; 2083