1e8d8bef9SDimitry Andric//===-- CSKYInstrInfo.td - Target Description for CSKY -----*- tablegen -*-===// 2e8d8bef9SDimitry Andric// 3e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e8d8bef9SDimitry Andric// 7e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 8e8d8bef9SDimitry Andric// 9e8d8bef9SDimitry Andric// This file describes the CSKY instructions in TableGen format. 10e8d8bef9SDimitry Andric// 11e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 12e8d8bef9SDimitry Andric 13e8d8bef9SDimitry Andric 14e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 15e8d8bef9SDimitry Andric// CSKY specific DAG Nodes. 16e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 17e8d8bef9SDimitry Andric 1804eeddc0SDimitry Andric// Target-independent type requirements, but with target-specific formats. 19349cc55cSDimitry Andricdef SDT_CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>, 20349cc55cSDimitry Andric SDTCisVT<1, i32>]>; 21349cc55cSDimitry Andric 22349cc55cSDimitry Andricdef SDT_CallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, 23349cc55cSDimitry Andric SDTCisVT<1, i32>]>; 24349cc55cSDimitry Andric 2504eeddc0SDimitry Andricdef SDT_CSKYCall : SDTypeProfile<0, 2, [SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>; 2604eeddc0SDimitry Andric 2704eeddc0SDimitry Andricdef SDT_CSKYCallReg : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>; 2804eeddc0SDimitry Andric 2904eeddc0SDimitry Andricdef SDT_CSKY_LOADADDR : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, 3004eeddc0SDimitry Andric SDTCisVT<1, iPTR>, SDTCisVT<2, iPTR>]>; 3104eeddc0SDimitry Andric 32349cc55cSDimitry Andricdef callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_CallSeqStart, 33349cc55cSDimitry Andric [SDNPHasChain, SDNPOutGlue]>; 34349cc55cSDimitry Andricdef callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_CallSeqEnd, 35349cc55cSDimitry Andric [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 36349cc55cSDimitry Andric 37fe6060f1SDimitry Andricdef CSKY_RET : SDNode<"CSKYISD::RET", SDTNone, 38fe6060f1SDimitry Andric [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 39e8d8bef9SDimitry Andric 4004eeddc0SDimitry Andricdef CSKY_CALL : SDNode<"CSKYISD::CALL", SDT_CSKYCall, 4104eeddc0SDimitry Andric [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>; 4204eeddc0SDimitry Andric 4304eeddc0SDimitry Andricdef CSKY_CALLReg : SDNode<"CSKYISD::CALLReg", SDT_CSKYCallReg, 4404eeddc0SDimitry Andric [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>; 4504eeddc0SDimitry Andric 4604eeddc0SDimitry Andricdef CSKY_TAIL : SDNode<"CSKYISD::TAIL", SDT_CSKYCall, 4704eeddc0SDimitry Andric [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>; 4804eeddc0SDimitry Andric 4904eeddc0SDimitry Andricdef CSKY_TAILReg : SDNode<"CSKYISD::TAILReg", SDT_CSKYCallReg, 5004eeddc0SDimitry Andric [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>; 5104eeddc0SDimitry Andric 5204eeddc0SDimitry Andricdef CSKY_LOAD_ADDR : SDNode<"CSKYISD::LOAD_ADDR", SDT_CSKY_LOADADDR>; 5304eeddc0SDimitry Andric 54e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 55e8d8bef9SDimitry Andric// Operand and SDNode transformation definitions. 56e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 57fe6060f1SDimitry Andricclass ImmAsmOperand<string prefix, int width, string suffix> : AsmOperandClass { 58fe6060f1SDimitry Andric let Name = prefix # "Imm" # width # suffix; 59fe6060f1SDimitry Andric let RenderMethod = "addImmOperands"; 60fe6060f1SDimitry Andric let DiagnosticType = !strconcat("Invalid", Name); 61fe6060f1SDimitry Andric} 62fe6060f1SDimitry Andric 63fe6060f1SDimitry Andricclass SImmAsmOperand<int width, string suffix = ""> 64fe6060f1SDimitry Andric : ImmAsmOperand<"S", width, suffix> { 65fe6060f1SDimitry Andric} 66fe6060f1SDimitry Andric 67fe6060f1SDimitry Andricclass UImmAsmOperand<int width, string suffix = ""> 68fe6060f1SDimitry Andric : ImmAsmOperand<"U", width, suffix> { 69fe6060f1SDimitry Andric} 70fe6060f1SDimitry Andric 71fe6060f1SDimitry Andricclass OImmAsmOperand<int width, string suffix = ""> 72fe6060f1SDimitry Andric : ImmAsmOperand<"O", width, suffix> { 73fe6060f1SDimitry Andric} 74e8d8bef9SDimitry Andric 750eae32dcSDimitry Andricdef to_tframeindex : SDNodeXForm<frameindex, [{ 760eae32dcSDimitry Andric auto FI = cast<FrameIndexSDNode>(N); 770eae32dcSDimitry Andric return CurDAG->getTargetFrameIndex(FI->getIndex(), TLI->getPointerTy(CurDAG->getDataLayout())); 780eae32dcSDimitry Andric}]>; 790eae32dcSDimitry Andric 8004eeddc0SDimitry Andricdef to_tconstpool : SDNodeXForm<constpool, [{ 8104eeddc0SDimitry Andric auto CP = cast<ConstantPoolSDNode>(N); 8204eeddc0SDimitry Andric return CurDAG->getTargetConstantPool(CP->getConstVal(), TLI->getPointerTy(CurDAG->getDataLayout()), 8304eeddc0SDimitry Andric CP->getAlign(), CP->getOffset(), CSKYII::MO_None); 8404eeddc0SDimitry Andric}]>; 8504eeddc0SDimitry Andric 8604eeddc0SDimitry Andricdef to_tconstpool_hi16 : SDNodeXForm<constpool, [{ 8704eeddc0SDimitry Andric auto CP = cast<ConstantPoolSDNode>(N); 8804eeddc0SDimitry Andric return CurDAG->getTargetConstantPool(CP->getConstVal(), TLI->getPointerTy(CurDAG->getDataLayout()), 8904eeddc0SDimitry Andric CP->getAlign(), CP->getOffset(), CSKYII::MO_ADDR_HI16); 9004eeddc0SDimitry Andric}]>; 9104eeddc0SDimitry Andric 9204eeddc0SDimitry Andricdef to_tconstpool_lo16 : SDNodeXForm<constpool, [{ 9304eeddc0SDimitry Andric auto CP = cast<ConstantPoolSDNode>(N); 9404eeddc0SDimitry Andric return CurDAG->getTargetConstantPool(CP->getConstVal(), TLI->getPointerTy(CurDAG->getDataLayout()), 9504eeddc0SDimitry Andric CP->getAlign(), CP->getOffset(), CSKYII::MO_ADDR_LO16); 9604eeddc0SDimitry Andric}]>; 9704eeddc0SDimitry Andric 98e8d8bef9SDimitry Andricclass oimm<int num> : Operand<i32>, 99e8d8bef9SDimitry Andric ImmLeaf<i32, "return isUInt<"#num#">(Imm - 1);"> { 100e8d8bef9SDimitry Andric let EncoderMethod = "getOImmOpValue"; 101fe6060f1SDimitry Andric let ParserMatchClass = OImmAsmOperand<num>; 102349cc55cSDimitry Andric let DecoderMethod = "decodeOImmOperand<"#num#">"; 103e8d8bef9SDimitry Andric} 104e8d8bef9SDimitry Andric 105*06c3fb27SDimitry Andricdef imm_neg_XFORM : SDNodeXForm<imm, [{ 106*06c3fb27SDimitry Andric return CurDAG->getTargetConstant(-N->getSExtValue(), SDLoc(N), MVT::i32); 107*06c3fb27SDimitry Andric}]>; 108*06c3fb27SDimitry Andric 109*06c3fb27SDimitry Andricclass oimm_neg<int num> : Operand<i32>, 110*06c3fb27SDimitry Andric ImmLeaf<i32, "return isUInt<"#num#">(-Imm - 1);"> { 111*06c3fb27SDimitry Andric} 112*06c3fb27SDimitry Andric 113e8d8bef9SDimitry Andricclass uimm<int num, int shift = 0> : Operand<i32>, 114e8d8bef9SDimitry Andric ImmLeaf<i32, "return isShiftedUInt<"#num#", "#shift#">(Imm);"> { 115e8d8bef9SDimitry Andric let EncoderMethod = "getImmOpValue<"#shift#">"; 116fe6060f1SDimitry Andric let ParserMatchClass = 117fe6060f1SDimitry Andric !if(!ne(shift, 0), 118fe6060f1SDimitry Andric UImmAsmOperand<num, "Shift"#shift>, 119fe6060f1SDimitry Andric UImmAsmOperand<num>); 120349cc55cSDimitry Andric let DecoderMethod = "decodeUImmOperand<"#num#", "#shift#">"; 121e8d8bef9SDimitry Andric} 122e8d8bef9SDimitry Andric 123*06c3fb27SDimitry Andricclass uimm_neg<int num, int shift = 0> : Operand<i32>, 124*06c3fb27SDimitry Andric ImmLeaf<i32, "return isShiftedUInt<"#num#", "#shift#">(-Imm);"> { 125*06c3fb27SDimitry Andric} 126*06c3fb27SDimitry Andric 127e8d8bef9SDimitry Andricclass simm<int num, int shift = 0> : Operand<i32>, 128e8d8bef9SDimitry Andric ImmLeaf<i32, "return isShiftedInt<"#num#", "#shift#">(Imm);"> { 129e8d8bef9SDimitry Andric let EncoderMethod = "getImmOpValue<"#shift#">"; 130fe6060f1SDimitry Andric let ParserMatchClass = SImmAsmOperand<num>; 131349cc55cSDimitry Andric let DecoderMethod = "decodeSImmOperand<"#num#", "#shift#">"; 132e8d8bef9SDimitry Andric} 133e8d8bef9SDimitry Andric 134e8d8bef9SDimitry Andricdef nimm_XFORM : SDNodeXForm<imm, [{ 135e8d8bef9SDimitry Andric return CurDAG->getTargetConstant(~N->getSExtValue(), SDLoc(N), MVT::i32); 136e8d8bef9SDimitry Andric}]>; 137e8d8bef9SDimitry Andricclass nimm<int num> : Operand<i32>, 138e8d8bef9SDimitry Andric ImmLeaf<i32, "return isUInt<"#num#">(~Imm);", nimm_XFORM> { 139fe6060f1SDimitry Andric let ParserMatchClass = UImmAsmOperand<num>; 140e8d8bef9SDimitry Andric} 141e8d8bef9SDimitry Andric 142fe6060f1SDimitry Andricdef uimm32_hi16 : SDNodeXForm<imm, [{ 143fe6060f1SDimitry Andric return CurDAG->getTargetConstant((N->getZExtValue() >> 16) & 0xFFFF, 144fe6060f1SDimitry Andric SDLoc(N), MVT::i32); 145fe6060f1SDimitry Andric}]>; 146349cc55cSDimitry Andricdef uimm32_lo16 : SDNodeXForm<imm, [{ 147349cc55cSDimitry Andric return CurDAG->getTargetConstant(N->getZExtValue()& 0xFFFF, SDLoc(N), MVT::i32); 148349cc55cSDimitry Andric}]>; 149fe6060f1SDimitry Andricdef uimm16_16_xform : Operand<i32>, 150fe6060f1SDimitry Andric ImmLeaf<i32, "return isShiftedUInt<16, 16>(Imm);", uimm32_hi16> { 151fe6060f1SDimitry Andric let ParserMatchClass = UImmAsmOperand<16>; 152349cc55cSDimitry Andric let EncoderMethod = "getImmOpValue"; 153fe6060f1SDimitry Andric} 154fe6060f1SDimitry Andric 155fe6060f1SDimitry Andricdef uimm_shift : Operand<i32>, ImmLeaf<i32, "return isUInt<2>(Imm);"> { 156fe6060f1SDimitry Andric let EncoderMethod = "getImmShiftOpValue"; 157fe6060f1SDimitry Andric let ParserMatchClass = UImmAsmOperand<2>; 158349cc55cSDimitry Andric let DecoderMethod = "decodeImmShiftOpValue"; 159fe6060f1SDimitry Andric} 160fe6060f1SDimitry Andric 161fe6060f1SDimitry Andricdef CSKYSymbol : AsmOperandClass { 162fe6060f1SDimitry Andric let Name = "CSKYSymbol"; 163fe6060f1SDimitry Andric let RenderMethod = "addImmOperands"; 164fe6060f1SDimitry Andric let DiagnosticType = "InvalidCSKYSymbol"; 165fe6060f1SDimitry Andric let ParserMethod = "parseCSKYSymbol"; 166fe6060f1SDimitry Andric} 167fe6060f1SDimitry Andric 168753f127fSDimitry Andricdef br_symbol : Operand<OtherVT> { 169fe6060f1SDimitry Andric let EncoderMethod = 170fe6060f1SDimitry Andric "getBranchSymbolOpValue<CSKY::fixup_csky_pcrel_imm16_scale2>"; 171fe6060f1SDimitry Andric let ParserMatchClass = CSKYSymbol; 172349cc55cSDimitry Andric let DecoderMethod = "decodeSImmOperand<16, 1>"; 173349cc55cSDimitry Andric let PrintMethod = "printCSKYSymbolOperand"; 174349cc55cSDimitry Andric let OperandType = "OPERAND_PCREL"; 175fe6060f1SDimitry Andric} 176fe6060f1SDimitry Andric 177fe6060f1SDimitry Andricdef call_symbol : Operand<iPTR> { 178fe6060f1SDimitry Andric let ParserMatchClass = CSKYSymbol; 179fe6060f1SDimitry Andric let EncoderMethod = "getCallSymbolOpValue"; 180349cc55cSDimitry Andric let DecoderMethod = "decodeSImmOperand<26, 1>"; 181349cc55cSDimitry Andric let PrintMethod = "printCSKYSymbolOperand"; 182349cc55cSDimitry Andric let OperandType = "OPERAND_PCREL"; 183fe6060f1SDimitry Andric} 184fe6060f1SDimitry Andric 185fe6060f1SDimitry Andricdef Constpool : AsmOperandClass { 186349cc55cSDimitry Andric let Name = "Constpool"; 187349cc55cSDimitry Andric let RenderMethod = "addConstpoolOperands"; 188fe6060f1SDimitry Andric let DiagnosticType = "InvalidConstpool"; 189fe6060f1SDimitry Andric let ParserMethod = "parseConstpoolSymbol"; 190fe6060f1SDimitry Andric} 191fe6060f1SDimitry Andric 192fe6060f1SDimitry Andricdef constpool_symbol : Operand<iPTR> { 193fe6060f1SDimitry Andric let ParserMatchClass = Constpool; 194fe6060f1SDimitry Andric let EncoderMethod = 195fe6060f1SDimitry Andric "getConstpoolSymbolOpValue<CSKY::fixup_csky_pcrel_uimm16_scale4>"; 196349cc55cSDimitry Andric let DecoderMethod = "decodeUImmOperand<16, 2>"; 197349cc55cSDimitry Andric let PrintMethod = "printConstpool"; 198349cc55cSDimitry Andric let OperandType = "OPERAND_PCREL"; 199349cc55cSDimitry Andric} 200349cc55cSDimitry Andric 201349cc55cSDimitry Andricdef DataAsmClass : AsmOperandClass { 202349cc55cSDimitry Andric let Name = "DataSymbol"; 203349cc55cSDimitry Andric let RenderMethod = "addConstpoolOperands"; 204349cc55cSDimitry Andric let DiagnosticType = "InvalidConstpool"; 205349cc55cSDimitry Andric let ParserMethod = "parseDataSymbol"; 206349cc55cSDimitry Andric} 207349cc55cSDimitry Andric 208349cc55cSDimitry Andricclass data_symbol<string reloc, int shift> : Operand<iPTR> { 209349cc55cSDimitry Andric let ParserMatchClass = Constpool; 210349cc55cSDimitry Andric let EncoderMethod = 211349cc55cSDimitry Andric "getDataSymbolOpValue<"#reloc#">"; 212349cc55cSDimitry Andric let DecoderMethod = "decodeUImmOperand<18, "#shift#">"; 213349cc55cSDimitry Andric let PrintMethod = "printDataSymbol"; 214fe6060f1SDimitry Andric} 215fe6060f1SDimitry Andric 216fe6060f1SDimitry Andricdef bare_symbol : Operand<iPTR> { 217fe6060f1SDimitry Andric let ParserMatchClass = CSKYSymbol; 218fe6060f1SDimitry Andric let EncoderMethod = "getBareSymbolOpValue"; 219349cc55cSDimitry Andric let PrintMethod = "printCSKYSymbolOperand"; 220349cc55cSDimitry Andric let DecoderMethod = "decodeSImmOperand<18, 1>"; 221349cc55cSDimitry Andric let OperandType = "OPERAND_PCREL"; 222fe6060f1SDimitry Andric} 223e8d8bef9SDimitry Andric 2240eae32dcSDimitry Andricdef oimm3 : oimm<3> { 2250eae32dcSDimitry Andric let MCOperandPredicate = [{ 2260eae32dcSDimitry Andric int64_t Imm; 2270eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 2280eae32dcSDimitry Andric return isUInt<3>(Imm - 1); 2290eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 2300eae32dcSDimitry Andric }]; 2310eae32dcSDimitry Andric} 232349cc55cSDimitry Andricdef oimm4 : oimm<4>; 2330eae32dcSDimitry Andricdef oimm5 : oimm<5> { 2340eae32dcSDimitry Andric let MCOperandPredicate = [{ 2350eae32dcSDimitry Andric int64_t Imm; 2360eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 2370eae32dcSDimitry Andric return isUInt<5>(Imm - 1); 2380eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 2390eae32dcSDimitry Andric }]; 2400eae32dcSDimitry Andric} 241349cc55cSDimitry Andricdef oimm6 : oimm<6>; 242349cc55cSDimitry Andric 243349cc55cSDimitry Andricdef imm5_idly : Operand<i32>, ImmLeaf<i32, 244349cc55cSDimitry Andric "return Imm <= 32 && Imm >= 0;"> { 245349cc55cSDimitry Andric let EncoderMethod = "getImmOpValueIDLY"; 246349cc55cSDimitry Andric let DecoderMethod = "decodeOImmOperand<5>"; 247349cc55cSDimitry Andric} 248349cc55cSDimitry Andric 2490eae32dcSDimitry Andricdef oimm8 : oimm<8> { 2500eae32dcSDimitry Andric let MCOperandPredicate = [{ 2510eae32dcSDimitry Andric int64_t Imm; 2520eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 2530eae32dcSDimitry Andric return isUInt<8>(Imm - 1); 2540eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 2550eae32dcSDimitry Andric }]; 2560eae32dcSDimitry Andric} 2570eae32dcSDimitry Andricdef oimm12 : oimm<12> { 2580eae32dcSDimitry Andric let MCOperandPredicate = [{ 2590eae32dcSDimitry Andric int64_t Imm; 2600eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 2610eae32dcSDimitry Andric return isUInt<12>(Imm - 1); 2620eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 2630eae32dcSDimitry Andric }]; 2640eae32dcSDimitry Andric} 2650eae32dcSDimitry Andricdef oimm16 : oimm<16> { 2660eae32dcSDimitry Andric let MCOperandPredicate = [{ 2670eae32dcSDimitry Andric int64_t Imm; 2680eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 2690eae32dcSDimitry Andric return isUInt<16>(Imm - 1); 2700eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 2710eae32dcSDimitry Andric }]; 2720eae32dcSDimitry Andric} 273e8d8bef9SDimitry Andric 274*06c3fb27SDimitry Andricdef oimm8_neg : oimm_neg<8> { 275*06c3fb27SDimitry Andric let MCOperandPredicate = [{ 276*06c3fb27SDimitry Andric int64_t Imm; 277*06c3fb27SDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 278*06c3fb27SDimitry Andric return isUInt<8>(-Imm - 1); 279*06c3fb27SDimitry Andric return MCOp.isBareSymbolRef(); 280*06c3fb27SDimitry Andric }]; 281*06c3fb27SDimitry Andric} 282*06c3fb27SDimitry Andricdef oimm12_neg : oimm_neg<12> { 283*06c3fb27SDimitry Andric let MCOperandPredicate = [{ 284*06c3fb27SDimitry Andric int64_t Imm; 285*06c3fb27SDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 286*06c3fb27SDimitry Andric return isUInt<12>(-Imm - 1); 287*06c3fb27SDimitry Andric return MCOp.isBareSymbolRef(); 288*06c3fb27SDimitry Andric }]; 289*06c3fb27SDimitry Andric} 290*06c3fb27SDimitry Andric 291e8d8bef9SDimitry Andricdef nimm12 : nimm<12>; 292e8d8bef9SDimitry Andric 293349cc55cSDimitry Andricdef uimm1 : uimm<1>; 294349cc55cSDimitry Andricdef uimm2 : uimm<2>; 295349cc55cSDimitry Andric 296349cc55cSDimitry Andric 297349cc55cSDimitry Andricdef uimm2_jmpix : Operand<i32>, 298349cc55cSDimitry Andric ImmLeaf<i32, "return Imm == 16 || Imm == 24 || Imm == 32 || Imm == 40;"> { 299349cc55cSDimitry Andric let EncoderMethod = "getImmJMPIX"; 300349cc55cSDimitry Andric let DecoderMethod = "decodeJMPIXImmOperand"; 301349cc55cSDimitry Andric} 302349cc55cSDimitry Andric 303349cc55cSDimitry Andricdef uimm3 : uimm<3>; 304349cc55cSDimitry Andricdef uimm4 : uimm<4>; 3050eae32dcSDimitry Andricdef uimm5 : uimm<5> { 3060eae32dcSDimitry Andric let MCOperandPredicate = [{ 3070eae32dcSDimitry Andric int64_t Imm; 3080eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3090eae32dcSDimitry Andric return isShiftedUInt<5, 0>(Imm); 3100eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3110eae32dcSDimitry Andric }]; 3120eae32dcSDimitry Andric} 313349cc55cSDimitry Andricdef uimm5_msb_size : uimm<5> { 314349cc55cSDimitry Andric let EncoderMethod = "getImmOpValueMSBSize"; 315349cc55cSDimitry Andric} 316349cc55cSDimitry Andric 3170eae32dcSDimitry Andricdef uimm5_1 : uimm<5, 1> { 3180eae32dcSDimitry Andric let MCOperandPredicate = [{ 3190eae32dcSDimitry Andric int64_t Imm; 3200eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3210eae32dcSDimitry Andric return isShiftedUInt<5, 1>(Imm); 3220eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3230eae32dcSDimitry Andric }]; 3240eae32dcSDimitry Andric} 3250eae32dcSDimitry Andricdef uimm5_2 : uimm<5, 2> { 3260eae32dcSDimitry Andric let MCOperandPredicate = [{ 3270eae32dcSDimitry Andric int64_t Imm; 3280eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3290eae32dcSDimitry Andric return isShiftedUInt<5, 2>(Imm); 3300eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3310eae32dcSDimitry Andric }]; 3320eae32dcSDimitry Andric} 333349cc55cSDimitry Andricdef uimm6 : uimm<6>; 334349cc55cSDimitry Andricdef uimm7 : uimm<7>; 335349cc55cSDimitry Andricdef uimm7_1 : uimm<7, 1>; 3360eae32dcSDimitry Andricdef uimm7_2 : uimm<7, 2>{ 3370eae32dcSDimitry Andric let MCOperandPredicate = [{ 3380eae32dcSDimitry Andric int64_t Imm; 3390eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3400eae32dcSDimitry Andric return isShiftedUInt<7, 2>(Imm); 3410eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3420eae32dcSDimitry Andric }]; 3430eae32dcSDimitry Andric} 344349cc55cSDimitry Andricdef uimm7_3 : uimm<7, 3>; 3450eae32dcSDimitry Andricdef uimm8 : uimm<8> { 3460eae32dcSDimitry Andric let MCOperandPredicate = [{ 3470eae32dcSDimitry Andric int64_t Imm; 3480eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3490eae32dcSDimitry Andric return isShiftedUInt<8, 0>(Imm); 3500eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3510eae32dcSDimitry Andric }]; 3520eae32dcSDimitry Andric} 3530eae32dcSDimitry Andricdef uimm8_2 : uimm<8, 2> { 3540eae32dcSDimitry Andric let MCOperandPredicate = [{ 3550eae32dcSDimitry Andric int64_t Imm; 3560eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3570eae32dcSDimitry Andric return isShiftedUInt<8, 2>(Imm); 3580eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3590eae32dcSDimitry Andric }]; 3600eae32dcSDimitry Andric} 361349cc55cSDimitry Andricdef uimm8_3 : uimm<8, 3>; 362349cc55cSDimitry Andricdef uimm8_8 : uimm<8, 8>; 363349cc55cSDimitry Andricdef uimm8_16 : uimm<8, 16>; 364349cc55cSDimitry Andricdef uimm8_24 : uimm<8, 24>; 3650eae32dcSDimitry Andricdef uimm12 : uimm<12> { 3660eae32dcSDimitry Andric let MCOperandPredicate = [{ 3670eae32dcSDimitry Andric int64_t Imm; 3680eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3690eae32dcSDimitry Andric return isShiftedUInt<12, 0>(Imm); 3700eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3710eae32dcSDimitry Andric }]; 3720eae32dcSDimitry Andric} 3730eae32dcSDimitry Andricdef uimm12_1 : uimm<12, 1> { 3740eae32dcSDimitry Andric let MCOperandPredicate = [{ 3750eae32dcSDimitry Andric int64_t Imm; 3760eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3770eae32dcSDimitry Andric return isShiftedUInt<12, 1>(Imm); 3780eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3790eae32dcSDimitry Andric }]; 3800eae32dcSDimitry Andric} 3810eae32dcSDimitry Andricdef uimm12_2 : uimm<12, 2> { 3820eae32dcSDimitry Andric let MCOperandPredicate = [{ 3830eae32dcSDimitry Andric int64_t Imm; 3840eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3850eae32dcSDimitry Andric return isShiftedUInt<12, 2>(Imm); 3860eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3870eae32dcSDimitry Andric }]; 3880eae32dcSDimitry Andric} 3890eae32dcSDimitry Andricdef uimm16 : uimm<16> { 3900eae32dcSDimitry Andric let MCOperandPredicate = [{ 3910eae32dcSDimitry Andric int64_t Imm; 3920eae32dcSDimitry Andric if (MCOp.evaluateAsConstantImm(Imm)) 3930eae32dcSDimitry Andric return isShiftedUInt<16, 0>(Imm); 3940eae32dcSDimitry Andric return MCOp.isBareSymbolRef(); 3950eae32dcSDimitry Andric }]; 3960eae32dcSDimitry Andric} 397349cc55cSDimitry Andricdef uimm16_8 : uimm<16, 8>; 398349cc55cSDimitry Andricdef uimm16_16 : uimm<16, 16>; 399349cc55cSDimitry Andricdef uimm20 : uimm<20>; 400349cc55cSDimitry Andricdef uimm24 : uimm<24>; 401349cc55cSDimitry Andricdef uimm24_8 : uimm<24, 8>; 402fe6060f1SDimitry Andric 403*06c3fb27SDimitry Andricdef uimm5_neg : uimm_neg<5>; 404*06c3fb27SDimitry Andric 405349cc55cSDimitry Andricdef simm8_2 : simm<8, 2>; 406349cc55cSDimitry Andric 407349cc55cSDimitry Andricclass RegSeqAsmOperand<string Suffix = ""> : AsmOperandClass { 408349cc55cSDimitry Andric let Name = "RegSeq"#Suffix; 409349cc55cSDimitry Andric let RenderMethod = "addRegSeqOperands"; 410349cc55cSDimitry Andric let DiagnosticType = "InvalidRegSeq"; 411349cc55cSDimitry Andric let ParserMethod = "parseRegSeq"; 412349cc55cSDimitry Andric} 413349cc55cSDimitry Andric 414349cc55cSDimitry Andricdef regseq : Operand<iPTR> { 415349cc55cSDimitry Andric let EncoderMethod = "getRegisterSeqOpValue"; 416349cc55cSDimitry Andric let ParserMatchClass = RegSeqAsmOperand<"">; 417349cc55cSDimitry Andric let PrintMethod = "printRegisterSeq"; 418349cc55cSDimitry Andric let DecoderMethod = "DecodeRegSeqOperand"; 419349cc55cSDimitry Andric let MIOperandInfo = (ops GPR, uimm5); 420349cc55cSDimitry Andric} 421349cc55cSDimitry Andric 422349cc55cSDimitry Andricdef RegListAsmOperand : AsmOperandClass { 423349cc55cSDimitry Andric let Name = "RegList"; 424349cc55cSDimitry Andric let RenderMethod = "addRegListOperands"; 425349cc55cSDimitry Andric let DiagnosticType = "InvalidRegList"; 426349cc55cSDimitry Andric let ParserMethod = "parseRegList"; 427349cc55cSDimitry Andric} 428349cc55cSDimitry Andric 429349cc55cSDimitry Andricdef reglist : Operand<iPTR> { 430349cc55cSDimitry Andric let ParserMatchClass = RegListAsmOperand; 431349cc55cSDimitry Andric let PrintMethod = "printRegisterList"; 432349cc55cSDimitry Andric} 433349cc55cSDimitry Andric 434349cc55cSDimitry Andricdef PSRFlag : AsmOperandClass { 435349cc55cSDimitry Andric let Name = "PSRFlag"; 436349cc55cSDimitry Andric let RenderMethod = "addImmOperands"; 437349cc55cSDimitry Andric let DiagnosticType = "InvalidPSRFlag"; 438349cc55cSDimitry Andric let ParserMethod = "parsePSRFlag"; 439349cc55cSDimitry Andric} 440349cc55cSDimitry Andric 441349cc55cSDimitry Andricdef psrflag : Operand<i32>, ImmLeaf<i32, "return isShiftedUInt<5, 0>(Imm);"> { 442349cc55cSDimitry Andric let EncoderMethod = "getImmOpValue"; 443349cc55cSDimitry Andric let ParserMatchClass = PSRFlag; 444349cc55cSDimitry Andric let PrintMethod = "printPSRFlag"; 445349cc55cSDimitry Andric} 446fe6060f1SDimitry Andric 44781ad6265SDimitry Andricmulticlass uimm8SRLXForm<SDNode opc> { 44881ad6265SDimitry Andric def _0: SDNodeXForm<opc, 44981ad6265SDimitry Andric [{return CurDAG->getTargetConstant((N->getZExtValue() >> 0) & 0xFF, SDLoc(N), MVT::i32);}]>; 45081ad6265SDimitry Andric def _8: SDNodeXForm<opc, 45181ad6265SDimitry Andric [{return CurDAG->getTargetConstant((N->getZExtValue() >> 8) & 0xFF, SDLoc(N), MVT::i32);}]>; 45281ad6265SDimitry Andric def _16: SDNodeXForm<opc, 45381ad6265SDimitry Andric [{return CurDAG->getTargetConstant((N->getZExtValue() >> 16) & 0xFF, SDLoc(N), MVT::i32);}]>; 45481ad6265SDimitry Andric def _24: SDNodeXForm<opc, 45581ad6265SDimitry Andric [{return CurDAG->getTargetConstant((N->getZExtValue() >> 24) & 0xFF, SDLoc(N), MVT::i32);}]>; 45681ad6265SDimitry Andric} 45781ad6265SDimitry Andric 45881ad6265SDimitry Andricdefm uimm8SRL : uimm8SRLXForm<imm>; 45981ad6265SDimitry Andric 460fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 461fe6060f1SDimitry Andric// Instruction Formats 462fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 463fe6060f1SDimitry Andric 464fe6060f1SDimitry Andricinclude "CSKYInstrFormats.td" 465e8d8bef9SDimitry Andric 466e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 467e8d8bef9SDimitry Andric// Instruction definitions. 468e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 469e8d8bef9SDimitry Andric 470e8d8bef9SDimitry Andricclass TriOpFrag<dag res> : PatFrag<(ops node: $LHS, node:$MHS, node:$RHS), res>; 471e8d8bef9SDimitry Andricclass BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>; 472e8d8bef9SDimitry Andricclass UnOpFrag<dag res> : PatFrag<(ops node:$Src), res>; 473e8d8bef9SDimitry Andric 474349cc55cSDimitry Andricdef eqToAdd : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs), [{ 475349cc55cSDimitry Andric return isOrEquivalentToAdd(N); 476349cc55cSDimitry Andric}]>; 477349cc55cSDimitry Andric 478349cc55cSDimitry Andricdef BaseAddr : ComplexPattern<iPTR, 1, "SelectBaseAddr">; 479349cc55cSDimitry Andric 480349cc55cSDimitry Andric 481349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 482349cc55cSDimitry Andric// CSKYPseudo 483349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 484349cc55cSDimitry Andric 485349cc55cSDimitry Andric// Pessimistically assume the stack pointer will be clobbered 486349cc55cSDimitry Andriclet Defs = [R14], Uses = [R14] in { 487349cc55cSDimitry Andricdef ADJCALLSTACKDOWN : CSKYPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2), 488349cc55cSDimitry Andric "!ADJCALLSTACKDOWN $amt1, $amt2", [(callseq_start timm:$amt1, timm:$amt2)]>; 489349cc55cSDimitry Andricdef ADJCALLSTACKUP : CSKYPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2), 490349cc55cSDimitry Andric "!ADJCALLSTACKUP $amt1, $amt2", [(callseq_end timm:$amt1, timm:$amt2)]>; 491349cc55cSDimitry Andric} // Defs = [R14], Uses = [R14] 492fe6060f1SDimitry Andric 493fe6060f1SDimitry Andric 494fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 495fe6060f1SDimitry Andric// Basic ALU instructions. 496fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 497fe6060f1SDimitry Andric 498349cc55cSDimitry Andriclet Predicates = [iHasE2] in { 499349cc55cSDimitry Andric let isReMaterializable = 1, isAsCheapAsAMove = 1 in { 500349cc55cSDimitry Andric let isAdd = 1 in 501e8d8bef9SDimitry Andric def ADDI32 : I_12<0x0, "addi32", add, oimm12>; 502e8d8bef9SDimitry Andric def SUBI32 : I_12<0x1, "subi32", sub, oimm12>; 503fe6060f1SDimitry Andric def ORI32 : I_16_ZX<"ori32", uimm16, 504fe6060f1SDimitry Andric [(set GPR:$rz, (or GPR:$rx, uimm16:$imm16))]>; 505fe6060f1SDimitry Andric def XORI32 : I_12<0x4, "xori32", xor, uimm12>; 506e8d8bef9SDimitry Andric def ANDI32 : I_12<0x2, "andi32", and, uimm12>; 507e8d8bef9SDimitry Andric def ANDNI32 : I_12<0x3, "andni32", and, nimm12>; 508e8d8bef9SDimitry Andric def LSLI32 : I_5_XZ<0x12, 0x1, "lsli32", 509e8d8bef9SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 510e8d8bef9SDimitry Andric [(set GPR:$rz, (shl GPR:$rx, uimm5:$imm5))]>; 511e8d8bef9SDimitry Andric def LSRI32 : I_5_XZ<0x12, 0x2, "lsri32", 512e8d8bef9SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 513e8d8bef9SDimitry Andric [(set GPR:$rz, (srl GPR:$rx, uimm5:$imm5))]>; 514e8d8bef9SDimitry Andric def ASRI32 : I_5_XZ<0x12, 0x4, "asri32", 515e8d8bef9SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 516e8d8bef9SDimitry Andric [(set GPR:$rz, (sra GPR:$rx, uimm5:$imm5))]>; 517fe6060f1SDimitry Andric def ROTLI32 : I_5_XZ<0x12, 0x8, "rotli32", 518fe6060f1SDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), 519fe6060f1SDimitry Andric [(set GPR:$rz, (rotl GPR:$rx, uimm5:$imm5))]>; 520e8d8bef9SDimitry Andric 521349cc55cSDimitry Andric def ROTRI32 : CSKYPseudo<(outs GPR:$rz), (ins GPR:$rx, oimm5:$imm5), 522349cc55cSDimitry Andric "rotri32 $rz, $rx, $imm5", []>; 523349cc55cSDimitry Andric } 524349cc55cSDimitry Andric let isAdd = 1 in 525e8d8bef9SDimitry Andric def ADDU32 : R_YXZ_SP_F1<0x0, 0x1, 526e8d8bef9SDimitry Andric BinOpFrag<(add node:$LHS, node:$RHS)>, "addu32", 1>; 527e8d8bef9SDimitry Andric def SUBU32 : R_YXZ_SP_F1<0x0, 0x4, 528e8d8bef9SDimitry Andric BinOpFrag<(sub node:$LHS, node:$RHS)>, "subu32">; 529349cc55cSDimitry Andric 530fe6060f1SDimitry Andric def MULT32 : R_YXZ_SP_F1<0x21, 0x1, 531fe6060f1SDimitry Andric BinOpFrag<(mul node:$LHS, node:$RHS)>, "mult32", 1>; 532e8d8bef9SDimitry Andric def AND32 : R_YXZ_SP_F1<0x8, 0x1, 533e8d8bef9SDimitry Andric BinOpFrag<(and node:$LHS, node:$RHS)>, "and32", 1>; 534e8d8bef9SDimitry Andric def ANDN32 : R_YXZ_SP_F1<0x8, 0x2, 535e8d8bef9SDimitry Andric BinOpFrag<(and node:$LHS, (not node:$RHS))>, "andn32">; 536e8d8bef9SDimitry Andric def OR32: R_YXZ_SP_F1<0x9, 0x1, 537e8d8bef9SDimitry Andric BinOpFrag<(or node:$LHS, node:$RHS)>, "or32", 1>; 538e8d8bef9SDimitry Andric def XOR32 : R_YXZ_SP_F1<0x9, 0x2, 539e8d8bef9SDimitry Andric BinOpFrag<(xor node:$LHS, node:$RHS)>, "xor32", 1>; 540e8d8bef9SDimitry Andric def NOR32 : R_YXZ_SP_F1<0x9, 0x4, 541e8d8bef9SDimitry Andric BinOpFrag<(not (or node:$LHS, node:$RHS))>, "nor32", 1>; 542349cc55cSDimitry Andric let isCodeGenOnly = 1 in 543fe6060f1SDimitry Andric def NOT32 : R_XXZ<0b001001, 0b00100, (outs GPR:$rz), (ins GPR:$rx), 544fe6060f1SDimitry Andric "not32", [(set GPR:$rz, (not GPR:$rx))]>; 545349cc55cSDimitry Andric 546349cc55cSDimitry Andric let Size = 8 in 547349cc55cSDimitry Andric def NEG32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx), "neg32 $rd, $rx", []>; 548349cc55cSDimitry Andric 549349cc55cSDimitry Andric let Size = 8 in 550349cc55cSDimitry Andric def RSUBI32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx, uimm12:$imm12), "rsubi32 $rd, $rx, $imm12", []>; 551349cc55cSDimitry Andric 552*06c3fb27SDimitry Andric def : Pat<(add GPR:$rs1, (oimm12_neg:$im)), 553*06c3fb27SDimitry Andric (SUBI32 GPR:$rs1, (imm_neg_XFORM oimm12_neg:$im))>; 554*06c3fb27SDimitry Andric 555e8d8bef9SDimitry Andric def LSL32 : R_YXZ_SP_F1<0x10, 0x1, 556e8d8bef9SDimitry Andric BinOpFrag<(shl node:$LHS, node:$RHS)>, "lsl32">; 557e8d8bef9SDimitry Andric def LSR32 : R_YXZ_SP_F1<0x10, 0x2, 558e8d8bef9SDimitry Andric BinOpFrag<(srl node:$LHS, node:$RHS)>, "lsr32">; 559e8d8bef9SDimitry Andric def ASR32 : R_YXZ_SP_F1<0x10, 0x4, 560e8d8bef9SDimitry Andric BinOpFrag<(sra node:$LHS, node:$RHS)>, "asr32">; 561fe6060f1SDimitry Andric def ROTL32 : R_YXZ_SP_F1<0x10, 0x8, 562fe6060f1SDimitry Andric BinOpFrag<(rotl node:$LHS, (and node:$RHS, 0x1f))>, "rotl32">; 563fe6060f1SDimitry Andric 564349cc55cSDimitry Andric def BMASKI32 : I_5_Z<0b010100, 0x1, "bmaski32", oimm5, []>; 565349cc55cSDimitry Andric def LSLC32 : I_5_XZ<0x13, 0x1, "lslc32", 566349cc55cSDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>; 567349cc55cSDimitry Andric def LSRC32 : I_5_XZ<0x13, 0x2, "lsrc32", 568349cc55cSDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>; 569349cc55cSDimitry Andric def ASRC32 : I_5_XZ<0x13, 0x4, "asrc32", 570349cc55cSDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>; 571349cc55cSDimitry Andric def XSR32 : I_5_XZ<0x13, 0x8, "xsr32", 572349cc55cSDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5, CARRY:$cin), []>; 573fe6060f1SDimitry Andric 574fe6060f1SDimitry Andric def IXH32 : R_YXZ_SP_F1<0x2, 0x1, 575fe6060f1SDimitry Andric BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 1)))>, "ixh32">; 576fe6060f1SDimitry Andric def IXW32 : R_YXZ_SP_F1<0x2, 0x2, 577fe6060f1SDimitry Andric BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 2)))>, "ixw32">; 578349cc55cSDimitry Andric let Predicates = [iHas2E3] in 579fe6060f1SDimitry Andric def IXD32 : R_YXZ_SP_F1<0x2, 0x4, 580fe6060f1SDimitry Andric BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 3)))>, "ixd32">; 581fe6060f1SDimitry Andric 582349cc55cSDimitry Andric let isCommutable = 1, isAdd = 1 in 583fe6060f1SDimitry Andric def ADDC32 : R_YXZ<0x31, 0x0, 0x2, (outs GPR:$rz, CARRY:$cout), 584fe6060f1SDimitry Andric (ins GPR:$rx, GPR:$ry, CARRY:$cin), "addc32", []>; 585fe6060f1SDimitry Andric def SUBC32 : R_YXZ<0x31, 0x0, 0x8, (outs GPR:$rz, CARRY:$cout), 586fe6060f1SDimitry Andric (ins GPR:$rx, GPR:$ry, CARRY:$cin), "subc32", []>; 587fe6060f1SDimitry Andric 588349cc55cSDimitry Andric def INCF32 : I_5_ZX<0x3, 0x1, "incf32", uimm5, []>; 589349cc55cSDimitry Andric def INCT32 : I_5_ZX<0x3, 0x2, "inct32", uimm5, []>; 590349cc55cSDimitry Andric def DECF32 : I_5_ZX<0x3, 0x4, "decf32", uimm5, []>; 591349cc55cSDimitry Andric def DECT32 : I_5_ZX<0x3, 0x8, "dect32", uimm5, []>; 592349cc55cSDimitry Andric} 593349cc55cSDimitry Andric 594349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 595e8d8bef9SDimitry Andric def DIVS32 : R_YXZ_SP_F1<0x20, 0x2, 596e8d8bef9SDimitry Andric BinOpFrag<(sdiv node:$LHS, node:$RHS)>, "divs32">; 597e8d8bef9SDimitry Andric def DIVU32 : R_YXZ_SP_F1<0x20, 0x1, 598e8d8bef9SDimitry Andric BinOpFrag<(udiv node:$LHS, node:$RHS)>, "divu32">; 599e8d8bef9SDimitry Andric 600fe6060f1SDimitry Andric def DECGT32 : I_5_XZ<0x4, 0x1, "decgt32", 601fe6060f1SDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>; 602fe6060f1SDimitry Andric def DECLT32 : I_5_XZ<0x4, 0x2, "declt32", 603fe6060f1SDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>; 604fe6060f1SDimitry Andric def DECNE32 : I_5_XZ<0x4, 0x4, "decne32", 605fe6060f1SDimitry Andric (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>; 606fe6060f1SDimitry Andric 607349cc55cSDimitry Andric def SEXT32 : I_5_XZ_U<0x16, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), "sext32", []>; 608349cc55cSDimitry Andric let isCodeGenOnly = 1 in { 609349cc55cSDimitry Andric def SEXTB32 : I_5_XZ_US<0x16, 0, 7, "sextb32", sext_inreg, i8>; 610349cc55cSDimitry Andric def SEXTH32 : I_5_XZ_US<0x16, 0, 15, "sexth32", sext_inreg, i16>; 611349cc55cSDimitry Andric def ZEXTB32 : I_5_XZ_UZ<0x15, 0, 7, "zextb32", 255>; 612349cc55cSDimitry Andric def ZEXTH32 : I_5_XZ_UZ<0x15, 0, 15, "zexth32", 65535>; 613349cc55cSDimitry Andric } 614349cc55cSDimitry Andric def ZEXT32 : I_5_XZ_U<0x15, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), "zext32",[]>; 615349cc55cSDimitry Andric 616349cc55cSDimitry Andric let Constraints = "$rZ = $rz" in 617349cc55cSDimitry Andric def INS32 : I_5_XZ_INS<0b010111, (outs GPR:$rz), (ins GPR:$rZ, GPR:$rx, uimm5_msb_size:$msb, uimm5:$lsb), "ins32", []>; 618349cc55cSDimitry Andric} 619349cc55cSDimitry Andric 620349cc55cSDimitry Andriclet Predicates = [iHas3E3r1] in { 621349cc55cSDimitry Andricdef MULTS32 : R_YXZ<0x3e, 0x20, 0x10, (outs GPRPair:$rz), 622349cc55cSDimitry Andric (ins GPR:$rx, GPR:$ry), "mul.s32", []>; 623349cc55cSDimitry Andricdef MULTU32 : R_YXZ<0x3e, 0x20, 0x00, (outs GPRPair:$rz), 624349cc55cSDimitry Andric (ins GPR:$rx, GPR:$ry), "mul.u32", []>; 625349cc55cSDimitry Andric 626349cc55cSDimitry Andriclet Constraints = "$rZ = $rz" in { 627349cc55cSDimitry Andricdef MULATS32 : R_YXZ<0x3e, 0x20, 0x14, (outs GPRPair:$rZ), 628349cc55cSDimitry Andric (ins GPRPair:$rz, GPR:$rx, GPR:$ry), "mula.s32", []>; 629349cc55cSDimitry Andricdef MULATU32 : R_YXZ<0x3e, 0x20, 0x04, (outs GPRPair:$rZ), 630349cc55cSDimitry Andric (ins GPRPair:$rz, GPR:$rx, GPR:$ry), "mula.u32", []>; 631349cc55cSDimitry Andric} 632349cc55cSDimitry Andric} 633349cc55cSDimitry Andric 634349cc55cSDimitry Andricdef MULSH32 : R_YXZ<0x31, 0b100100, 0b00001, (outs GPR:$rz), 635349cc55cSDimitry Andric (ins GPR:$rx, GPR:$ry), "mulsh32", []>; 636fe6060f1SDimitry Andric 637fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 638fe6060f1SDimitry Andric// Load & Store instructions. 639fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 640fe6060f1SDimitry Andric 641fe6060f1SDimitry Andricdef LD32B : I_LD<AddrMode32B, 0x0, "ld32.b", uimm12>; 642fe6060f1SDimitry Andricdef LD32H : I_LD<AddrMode32H, 0x1, "ld32.h", uimm12_1>; 643fe6060f1SDimitry Andricdef LD32W : I_LD<AddrMode32WD, 0x2, "ld32.w", uimm12_2>; 644fe6060f1SDimitry Andric 645349cc55cSDimitry Andriclet OutOperandList = (outs GPRPair:$rz) in 646349cc55cSDimitry Andricdef LD32D : I_LD<AddrMode32WD, 0x3, "ld32.d", uimm12_2>; 647fe6060f1SDimitry Andric 648349cc55cSDimitry Andriclet Predicates = [iHasE2] in { 649fe6060f1SDimitry Andric def LD32BS : I_LD<AddrMode32B, 0x4, "ld32.bs", uimm12>; 650fe6060f1SDimitry Andric def LD32HS : I_LD<AddrMode32H, 0x5, "ld32.hs", uimm12_1>; 651fe6060f1SDimitry Andric 652349cc55cSDimitry Andric def LDM32 : I_5_YX<0b110100, 0b000111, 653349cc55cSDimitry Andric (outs), (ins GPR:$rx, regseq:$regs, variable_ops), "ldm32\t$regs, (${rx})", []>; 654349cc55cSDimitry Andric def STM32 : I_5_YX<0b110101, 0b000111, 655349cc55cSDimitry Andric (outs), (ins GPR:$rx, regseq:$regs, variable_ops), "stm32\t$regs, (${rx})", []>; 656fe6060f1SDimitry Andric 657349cc55cSDimitry Andric let Size = 4, isCodeGenOnly = 0 in { 658349cc55cSDimitry Andric def LDQ32 : CSKYPseudo<(outs), (ins GPR:$rx, regseq:$regs, variable_ops), 659349cc55cSDimitry Andric "ldq32\t$regs, (${rx})", []>; 660349cc55cSDimitry Andric def STQ32 : CSKYPseudo<(outs), (ins GPR:$rx, regseq:$regs, variable_ops), 661349cc55cSDimitry Andric "stq32\t$regs, (${rx})", []>; 662349cc55cSDimitry Andric } 663349cc55cSDimitry Andric 664349cc55cSDimitry Andric} 665fe6060f1SDimitry Andric 666fe6060f1SDimitry Andricdef ST32B : I_ST<AddrMode32B, 0x0, "st32.b", uimm12>; 667fe6060f1SDimitry Andricdef ST32H : I_ST<AddrMode32H, 0x1, "st32.h", uimm12_1>; 668fe6060f1SDimitry Andricdef ST32W : I_ST<AddrMode32WD, 0x2, "st32.w", uimm12_2>; 669fe6060f1SDimitry Andric 670349cc55cSDimitry Andriclet InOperandList = (ins GPRPair:$rz, GPR:$rx, uimm12_2:$imm12 ) in 671349cc55cSDimitry Andricdef ST32D : I_ST<AddrMode32WD, 0x3, "st32.d", uimm12_2>; 672fe6060f1SDimitry Andric 673349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 674fe6060f1SDimitry Andric def LDR32B : I_LDR<0x0, "ldr32.b">; 675fe6060f1SDimitry Andric def LDR32BS : I_LDR<0x4, "ldr32.bs">; 676fe6060f1SDimitry Andric def LDR32H : I_LDR<0x1, "ldr32.h">; 677fe6060f1SDimitry Andric def LDR32HS : I_LDR<0x5, "ldr32.hs">; 678fe6060f1SDimitry Andric def LDR32W : I_LDR<0x2, "ldr32.w">; 679fe6060f1SDimitry Andric def STR32B : I_STR<0x0, "str32.b">; 680fe6060f1SDimitry Andric def STR32H : I_STR<0x1, "str32.h">; 681fe6060f1SDimitry Andric def STR32W : I_STR<0x2, "str32.w">; 682349cc55cSDimitry Andric} 683fe6060f1SDimitry Andric 684349cc55cSDimitry Andric// Indicate that we're dumping the CR register, so we'll need to 685349cc55cSDimitry Andric// scavenge a register for it. 686349cc55cSDimitry Andriclet mayStore = 1 in { 687349cc55cSDimitry Andricdef SPILL_CARRY : CSKYPseudo<(outs), (ins CARRY:$cond, GPR:$rx, uimm12_2:$imm), 688349cc55cSDimitry Andric "!SPILL_CARRY $cond, $rx, $imm", []>; 689349cc55cSDimitry Andric} 690349cc55cSDimitry Andric 691349cc55cSDimitry Andric// Indicate that we're restoring the CR register (previously 692349cc55cSDimitry Andric// spilled), so we'll need to scavenge a register for it. 693349cc55cSDimitry Andriclet mayLoad = 1 in { 694349cc55cSDimitry Andricdef RESTORE_CARRY : CSKYPseudo<(outs CARRY:$cond), (ins GPR:$rx, uimm12_2:$imm), 695349cc55cSDimitry Andric "!RESTORE_CARRY $cond, $rx, $imm", []>; 696349cc55cSDimitry Andric} 697349cc55cSDimitry Andric 698349cc55cSDimitry Andriclet mayLoad = 1 in { 699349cc55cSDimitry Andricdef STORE_PAIR : CSKYPseudo<(outs), (ins GPRPair:$rz, GPR:$rx, uimm12_2:$imm), 700349cc55cSDimitry Andric "!STORE_PAIR $rz, $rx, $imm", []>; 701349cc55cSDimitry Andric} 702349cc55cSDimitry Andric 703349cc55cSDimitry Andriclet mayLoad = 1 in { 704349cc55cSDimitry Andricdef LOAD_PAIR : CSKYPseudo<(outs GPRPair:$rz), (ins GPR:$rx, uimm12_2:$imm), 705349cc55cSDimitry Andric "!LOAD_PAIR $rz, $rx, $imm", []>; 706349cc55cSDimitry Andric} 707fe6060f1SDimitry Andric 708fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 709fe6060f1SDimitry Andric// Compare instructions. 710fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 711349cc55cSDimitry Andriclet Predicates = [iHasE2] in { 712fe6060f1SDimitry Andric def CMPNEI32 : I_16_X<0x1A, "cmpnei32", uimm16>; 713fe6060f1SDimitry Andric def CMPHSI32 : I_16_X<0x18, "cmphsi32", oimm16>; 714fe6060f1SDimitry Andric def CMPLTI32 : I_16_X<0x19, "cmplti32", oimm16>; 715349cc55cSDimitry Andric def CMPLEI32 : CSKYPseudo<(outs CARRY:$ca), (ins GPR:$rx, uimm16:$imm16), 716349cc55cSDimitry Andric "cmplei32\t$rx, $imm16", []>; 717349cc55cSDimitry Andric} 718349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 719fe6060f1SDimitry Andric def CMPNE32 : R_YX<0x1, 0x4, "cmpne32">; 720fe6060f1SDimitry Andric def CMPHS32 : R_YX<0x1, 0x1, "cmphs32">; 721fe6060f1SDimitry Andric def CMPLT32 : R_YX<0x1, 0x2, "cmplt32">; 722fe6060f1SDimitry Andric 723349cc55cSDimitry Andric def SETC32 : CSKY32Inst<AddrModeNone, 0x31, 724349cc55cSDimitry Andric (outs CARRY:$ca), (ins), "setc32", []> { 725349cc55cSDimitry Andric let Inst{25 - 21} = 0; //rx 726349cc55cSDimitry Andric let Inst{20 - 16} = 0; //ry 727349cc55cSDimitry Andric let Inst{15 - 10} = 0x1; 728349cc55cSDimitry Andric let Inst{9 - 5} = 0x1; 729349cc55cSDimitry Andric let Inst{4 - 0} = 0; 730349cc55cSDimitry Andric let isCompare = 1; 731349cc55cSDimitry Andric } 732349cc55cSDimitry Andric def CLRC32 : CSKY32Inst<AddrModeNone, 0x31, 733349cc55cSDimitry Andric (outs CARRY:$ca), (ins), "clrc32", []> { 734349cc55cSDimitry Andric let Inst{25 - 21} = 0; //rx 735349cc55cSDimitry Andric let Inst{20 - 16} = 0; //ry 736349cc55cSDimitry Andric let Inst{15 - 10} = 0x1; 737349cc55cSDimitry Andric let Inst{9 - 5} = 0x4; 738349cc55cSDimitry Andric let Inst{4 - 0} = 0; 739349cc55cSDimitry Andric let isCompare = 1; 740349cc55cSDimitry Andric } 741349cc55cSDimitry Andric 742349cc55cSDimitry Andric def TST32 : R_YX<0x8, 0x4, "tst32">; 743349cc55cSDimitry Andric def TSTNBZ32 : R_X<0x8, 0x8, 744349cc55cSDimitry Andric (outs CARRY:$ca), (ins GPR:$rx), "tstnbz32", []>; 745349cc55cSDimitry Andric} 746fe6060f1SDimitry Andric 747fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 748fe6060f1SDimitry Andric// Data move instructions. 749fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 750fe6060f1SDimitry Andric 751349cc55cSDimitry Andriclet Predicates= [iHasE2] in { 752349cc55cSDimitry Andric let isCodeGenOnly = 1 in { 753fe6060f1SDimitry Andric def MOVT32 : R_ZX<0x3, 0x2, "movt32", []>; 754fe6060f1SDimitry Andric def MOVF32 : R_ZX<0x3, 0x1, "movf32", []>; 755349cc55cSDimitry Andric } 756fe6060f1SDimitry Andric def MOVI32 : I_16_MOV<0x10, "movi32", uimm16>; 757349cc55cSDimitry Andric let Size = 4, isCodeGenOnly = 0 in 758349cc55cSDimitry Andric def BGENI : CSKYPseudo<(outs GPR:$dst), (ins uimm5:$imm), "bgeni\t$dst, $imm", []>; 759fe6060f1SDimitry Andric def MOVIH32 : I_16_MOV<0x11, "movih32", uimm16_16_xform>; 760fe6060f1SDimitry Andric def MVC32 : R_Z_1<0x1, 0x8, "mvc32">; 761349cc55cSDimitry Andric let isCodeGenOnly = 1 in 762fe6060f1SDimitry Andric def MOV32 : R_XZ<0x12, 0x1, "mov32">; 763fe6060f1SDimitry Andric 764349cc55cSDimitry Andric let usesCustomInserter = 1 in 765349cc55cSDimitry Andric def ISEL32 : CSKYPseudo<(outs GPR:$dst), (ins CARRY:$cond, GPR:$src1, GPR:$src2), 766349cc55cSDimitry Andric "!isel32\t$dst, $src1, src2", [(set GPR:$dst, (select CARRY:$cond, GPR:$src1, GPR:$src2))]>; 767349cc55cSDimitry Andric} 768fe6060f1SDimitry Andric 769349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 770fe6060f1SDimitry Andric def MVCV32 : R_Z_1<0x1, 0x10, "mvcv32">; 77181ad6265SDimitry Andric def CLRF32 : R_Z_2<0xB, 0x1, "clrf32">; 77281ad6265SDimitry Andric def CLRT32 : R_Z_2<0xB, 0x2, "clrt32">; 773349cc55cSDimitry Andric} 774fe6060f1SDimitry Andric 775fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 776fe6060f1SDimitry Andric// Branch and call instructions. 777fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 778fe6060f1SDimitry Andric 779fe6060f1SDimitry Andriclet isBranch = 1, isTerminator = 1 in { 780fe6060f1SDimitry Andric let isBarrier = 1, isPredicable = 1 in 781fe6060f1SDimitry Andric def BR32 : I_16_L<0x0, (outs), (ins br_symbol:$imm16), "br32\t$imm16", 782fe6060f1SDimitry Andric [(br bb:$imm16)]>; 783fe6060f1SDimitry Andric 784fe6060f1SDimitry Andric def BT32 : I_16_L<0x3, (outs), (ins CARRY:$ca, br_symbol:$imm16), 785349cc55cSDimitry Andric "bt32\t$imm16", [(brcond CARRY:$ca, bb:$imm16)]>, Requires<[iHasE2]>; 786fe6060f1SDimitry Andric def BF32 : I_16_L<0x2, (outs), (ins CARRY:$ca, br_symbol:$imm16), 787349cc55cSDimitry Andric "bf32\t$imm16", []>, Requires<[iHasE2]>; 788fe6060f1SDimitry Andric} 789fe6060f1SDimitry Andric 790349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 791fe6060f1SDimitry Andric def BEZ32 : I_16_X_L<0x8, "bez32", br_symbol>; 792fe6060f1SDimitry Andric def BNEZ32 : I_16_X_L<0x9, "bnez32", br_symbol>; 793fe6060f1SDimitry Andric def BHZ32 : I_16_X_L<0xA, "bhz32", br_symbol>; 794fe6060f1SDimitry Andric def BLSZ32 : I_16_X_L<0xB, "blsz32", br_symbol>; 795fe6060f1SDimitry Andric def BLZ32 : I_16_X_L<0xC, "blz32", br_symbol>; 796fe6060f1SDimitry Andric def BHSZ32 : I_16_X_L<0xD, "bhsz32", br_symbol>; 797fe6060f1SDimitry Andric 798fe6060f1SDimitry Andric let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in { 799fe6060f1SDimitry Andric def JMP32 : I_16_JX<0x6, "jmp32", [(brind GPR:$rx)]>; // jmp to register 800fe6060f1SDimitry Andric def JMPI32 : I_16_L<0x16, (outs), (ins constpool_symbol:$imm16), 801fe6060f1SDimitry Andric "jmpi32\t$imm16", []>; 802fe6060f1SDimitry Andric } 803fe6060f1SDimitry Andric 804fe6060f1SDimitry Andric let isCall = 1, Defs = [ R15 ] in 805fe6060f1SDimitry Andric def JSR32 : I_16_JX<0x7, "jsr32", []>; 806fe6060f1SDimitry Andric 807fe6060f1SDimitry Andric let isCall = 1, Defs = [ R15 ] , mayLoad = 1 in 808fe6060f1SDimitry Andric def JSRI32: I_16_L<0x17, (outs), 809fe6060f1SDimitry Andric (ins constpool_symbol:$imm16), "jsri32\t$imm16", []>; 810349cc55cSDimitry Andric} 811fe6060f1SDimitry Andric 812349cc55cSDimitry Andricdef BNEZAD32 : CSKY32Inst<AddrModeNone, 0x3a, 813349cc55cSDimitry Andric (outs GPR:$rx_u), (ins GPR:$rx, br_symbol:$imm16), "bnezad32\t$rx, $imm16", []> { 814349cc55cSDimitry Andric bits<5> rx; 815349cc55cSDimitry Andric bits<16> imm16; 816349cc55cSDimitry Andric let Inst{25 - 21} = 0x1; 817349cc55cSDimitry Andric let Inst{20 - 16} = rx; 818349cc55cSDimitry Andric let Inst{15 - 0} = imm16; 819349cc55cSDimitry Andric let isBranch = 1; 820349cc55cSDimitry Andric let isTerminator = 1; 821349cc55cSDimitry Andric let Constraints = "$rx_u = $rx"; 822349cc55cSDimitry Andric let Predicates = [iHas2E3, iHas10E60]; 823349cc55cSDimitry Andric} 824fe6060f1SDimitry Andric 825fe6060f1SDimitry Andricdef BSR32 : J<0x38, (outs), (ins call_symbol:$offset), "bsr32", []>; 826fe6060f1SDimitry Andric 827fe6060f1SDimitry Andricdef BSR32_BR : J<0x38, (outs), (ins call_symbol:$offset), "bsr32", []>{ 828fe6060f1SDimitry Andric let isCodeGenOnly = 1; 829fe6060f1SDimitry Andric let isBranch = 1; 830fe6060f1SDimitry Andric let isTerminator = 1; 831fe6060f1SDimitry Andric let isBarrier = 1; 832fe6060f1SDimitry Andric let isPredicable = 1; 833fe6060f1SDimitry Andric let Defs = [ R15 ]; 834fe6060f1SDimitry Andric} 835fe6060f1SDimitry Andric 836fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 837fe6060f1SDimitry Andric// Symbol address instructions. 838fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 839fe6060f1SDimitry Andric 840349cc55cSDimitry Andricdef data_symbol_b : data_symbol<"CSKY::fixup_csky_doffset_imm18", 0>; 841349cc55cSDimitry Andricdef data_symbol_h : data_symbol<"CSKY::fixup_csky_doffset_imm18_scale2", 1>; 842349cc55cSDimitry Andricdef data_symbol_w : data_symbol<"CSKY::fixup_csky_doffset_imm18_scale4", 2> { 843349cc55cSDimitry Andric let ParserMatchClass = DataAsmClass; 844349cc55cSDimitry Andric} 845349cc55cSDimitry Andric 846349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 847349cc55cSDimitry Andric 848fe6060f1SDimitry Andricdef GRS32 : I_18_Z_L<0x3, "grs32\t$rz, $offset", 849fe6060f1SDimitry Andric (outs GPR:$rz), (ins bare_symbol:$offset), []>; 850349cc55cSDimitry Andric 851349cc55cSDimitry Andriclet Uses = [R28] in { 852349cc55cSDimitry Andricdef LRS32B : I_18_Z_L<0x0, "lrs32.b\t$rz, $offset", 853349cc55cSDimitry Andric (outs GPR:$rz), (ins data_symbol_b:$offset), []>; 854349cc55cSDimitry Andricdef LRS32H : I_18_Z_L<0x1, "lrs32.h\t$rz, $offset", 855349cc55cSDimitry Andric (outs GPR:$rz), (ins data_symbol_h:$offset), []>; 856349cc55cSDimitry Andricdef LRS32W : I_18_Z_L<0x2, "lrs32.w\t$rz, $offset", 857349cc55cSDimitry Andric (outs GPR:$rz), (ins data_symbol_w:$offset), []>; 858349cc55cSDimitry Andricdef SRS32B : I_18_Z_L<0x4, "srs32.b\t$rz, $offset", 859349cc55cSDimitry Andric (outs), (ins GPR:$rz, data_symbol_b:$offset), []>; 860349cc55cSDimitry Andricdef SRS32H : I_18_Z_L<0x5, "srs32.h\t$rz, $offset", 861349cc55cSDimitry Andric (outs), (ins GPR:$rz, data_symbol_h:$offset), []>; 862349cc55cSDimitry Andricdef SRS32W : I_18_Z_L<0x6, "srs32.w\t$rz, $offset", 863349cc55cSDimitry Andric (outs), (ins GPR:$rz, data_symbol_w:$offset), []>; 864349cc55cSDimitry Andric} 865349cc55cSDimitry Andric 866349cc55cSDimitry Andricdef PUSH32 : I_12_PP<0b11111, 0b00000, (outs), (ins reglist:$regs, variable_ops), "push32 $regs">; 867349cc55cSDimitry Andric 868349cc55cSDimitry Andriclet Uses = [R14, R15], isReturn = 1, isTerminator = 1, isBarrier = 1 in 869349cc55cSDimitry Andricdef POP32 : I_12_PP<0b11110, 0b00000, (outs), (ins reglist:$regs, variable_ops), "pop32 $regs">; 870349cc55cSDimitry Andric 871349cc55cSDimitry Andric} 872fe6060f1SDimitry Andric 873fe6060f1SDimitry Andriclet mayLoad = 1, mayStore = 0 in { 874fe6060f1SDimitry Andricdef LRW32 : I_16_Z_L<0x14, "lrw32", (ins constpool_symbol:$imm16), []>; 875fe6060f1SDimitry Andriclet isCodeGenOnly = 1 in 876349cc55cSDimitry Andricdef LRW32_Gen : I_16_Z_L<0x14, "lrw32", (ins bare_symbol:$src1, constpool_symbol:$imm16), []>; 877fe6060f1SDimitry Andric} 878fe6060f1SDimitry Andric 879349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 880349cc55cSDimitry Andric// Atomic and fence instructions. 881349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 882349cc55cSDimitry Andric 883349cc55cSDimitry Andriclet Predicates = [iHasMP1E2] in { 884349cc55cSDimitry Andric def BRWARW : BAR<0b01111, "bar.brwarw", 0>; 885349cc55cSDimitry Andric def BRWARWS : BAR<0b01111, "bar.brwarws", 1>; 886349cc55cSDimitry Andric def BRARW : BAR<0b00111, "bar.brarw", 0>; 887349cc55cSDimitry Andric def BRARWS : BAR<0b00111, "bar.brarws", 1>; 888349cc55cSDimitry Andric def BRWAW : BAR<0b01110, "bar.brwaw", 0>; 889349cc55cSDimitry Andric def BRWAWS : BAR<0b01110, "bar.brwaws", 1>; 890349cc55cSDimitry Andric def BRAR : BAR<0b00101, "bar.brar", 0>; 891349cc55cSDimitry Andric def BRARS : BAR<0b00101, "bar.brars", 1>; 892349cc55cSDimitry Andric def BWAW : BAR<0b01010, "bar.bwaw", 0>; 893349cc55cSDimitry Andric def BWAWS : BAR<0b01010, "bar.bwaws", 1>; 894349cc55cSDimitry Andric 895349cc55cSDimitry Andric def LDEX32W : I_LD<AddrMode32WD, 0x7, "ldex32.w", uimm12_2>; 896349cc55cSDimitry Andric let Constraints = "$rd = $rz" in 897349cc55cSDimitry Andric def STEX32W : I_LDST<AddrMode32WD, 0x37, 7, 898349cc55cSDimitry Andric (outs GPR:$rd), (ins GPR:$rz, GPR:$rx, uimm12_2:$imm12), "stex32.w", []>; 899349cc55cSDimitry Andric} 900349cc55cSDimitry Andric 901349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 902349cc55cSDimitry Andric// Other operation instructions. 903349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 904349cc55cSDimitry Andric 905349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 906349cc55cSDimitry Andric def BREV32 : R_XZ<0x18, 0x10, "brev32">; 907349cc55cSDimitry Andric def ABS32 : R_XZ<0x0, 0x10, "abs32">; 908349cc55cSDimitry Andric def BGENR32 : R_XZ<0x14, 0x2, "bgenr32">; 909bdd1243dSDimitry Andric def REVB32 : R_XZ<0x18, 0x4, "revb32">; 910bdd1243dSDimitry Andric def REVH32 : R_XZ<0x18, 0x8, "revh32">; 911349cc55cSDimitry Andric} 912349cc55cSDimitry Andric 913349cc55cSDimitry Andriclet Predicates = [iHasE2] in { 914349cc55cSDimitry Andric def FF0 : R_XZ<0x1F, 0x1, "ff0.32">; 915349cc55cSDimitry Andric def FF1 : R_XZ<0x1F, 0x2, "ff1.32">; 916349cc55cSDimitry Andric def XTRB0 : R_XZ<0x1C, 0x1, "xtrb0.32">; 917349cc55cSDimitry Andric def XTRB1 : R_XZ<0x1C, 0x2, "xtrb1.32">; 918349cc55cSDimitry Andric def XTRB2 : R_XZ<0x1C, 0x4, "xtrb2.32">; 919349cc55cSDimitry Andric def XTRB3 : R_XZ<0x1C, 0x8, "xtrb3.32">; 920349cc55cSDimitry Andric def BTSTI32 : I_5_X<0x0A, 0x4, "btsti32", uimm5, []>; 921349cc55cSDimitry Andric def BCLRI32 : I_5_XZ<0xA, 0x1, "bclri32", 922349cc55cSDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>; 923349cc55cSDimitry Andric def BSETI32 : I_5_XZ<0xA, 0x2, "bseti32", 924349cc55cSDimitry Andric (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>; 925349cc55cSDimitry Andric} 926349cc55cSDimitry Andric 927349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 928349cc55cSDimitry Andric// Special instructions. 929349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 930349cc55cSDimitry Andric 931349cc55cSDimitry Andricdef MFFCR : CSKY32Inst<AddrModeNone, 0x30, 932349cc55cSDimitry Andric (outs GPR:$rx), (ins), "mfcr\t$rx, fcr", []> { 933349cc55cSDimitry Andric bits<5> rx; 934349cc55cSDimitry Andric 935349cc55cSDimitry Andric let Inst{25 - 21} = 0b00010; 936349cc55cSDimitry Andric let Inst{20 - 16} = 0b00001; 937349cc55cSDimitry Andric let Inst{15 - 10} = 0b011000; 938349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 939349cc55cSDimitry Andric let Inst{4 - 0} = rx; 940349cc55cSDimitry Andric let hasSideEffects = 1; 941349cc55cSDimitry Andric let isCodeGenOnly = 1; 942349cc55cSDimitry Andric} 943349cc55cSDimitry Andric 944349cc55cSDimitry Andricdef MTFCR : CSKY32Inst<AddrModeNone, 0x30, 945349cc55cSDimitry Andric (outs), (ins GPR:$rx), "mtcr\t$rx, fcr", []> { 946349cc55cSDimitry Andric bits<5> rx; 947349cc55cSDimitry Andric 948349cc55cSDimitry Andric let Inst{25 - 21} = 0b00010; 949349cc55cSDimitry Andric let Inst{20 - 16} = rx; 950349cc55cSDimitry Andric let Inst{15 - 10} = 0b011001; 951349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 952349cc55cSDimitry Andric let Inst{4 - 0} = 0b00001; 953349cc55cSDimitry Andric let hasSideEffects = 1; 954349cc55cSDimitry Andric let isCodeGenOnly = 1; 955349cc55cSDimitry Andric} 956349cc55cSDimitry Andric 957349cc55cSDimitry Andricdef SYNC32 : I_5_IMM5<0x30, 0b000001, 0b00001, "sync32", uimm5, []>; 958349cc55cSDimitry Andric 959349cc55cSDimitry Andricdef SYNC0_32 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), 960349cc55cSDimitry Andric "sync32", []> { 961349cc55cSDimitry Andric let Inst{25 - 21} = 0; 962349cc55cSDimitry Andric let Inst{20 - 16} = 0; 963349cc55cSDimitry Andric let Inst{15 - 10} = 0b000001; 964349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 965349cc55cSDimitry Andric let Inst{4 - 0} = 0; 966349cc55cSDimitry Andric} 967349cc55cSDimitry Andric 968349cc55cSDimitry Andricdef SYNC_32_I : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), 969349cc55cSDimitry Andric "sync32.i", []> { 970349cc55cSDimitry Andric let Inst{25 - 21} = 1; 971349cc55cSDimitry Andric let Inst{20 - 16} = 0; 972349cc55cSDimitry Andric let Inst{15 - 10} = 0b000001; 973349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 974349cc55cSDimitry Andric let Inst{4 - 0} = 0; 975349cc55cSDimitry Andric} 976349cc55cSDimitry Andric 977349cc55cSDimitry Andricdef SYNC_32_S : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), 978349cc55cSDimitry Andric "sync32.s", []> { 979349cc55cSDimitry Andric let Inst{25 - 21} = 0b10000; 980349cc55cSDimitry Andric let Inst{20 - 16} = 0; 981349cc55cSDimitry Andric let Inst{15 - 10} = 0b000001; 982349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 983349cc55cSDimitry Andric let Inst{4 - 0} = 0; 984349cc55cSDimitry Andric} 985349cc55cSDimitry Andric 986349cc55cSDimitry Andricdef SYNC_32_IS : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), 987349cc55cSDimitry Andric "sync32.is", []> { 988349cc55cSDimitry Andric let Inst{25 - 21} = 0b10001; 989349cc55cSDimitry Andric let Inst{20 - 16} = 0; 990349cc55cSDimitry Andric let Inst{15 - 10} = 0b000001; 991349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 992349cc55cSDimitry Andric let Inst{4 - 0} = 0; 993349cc55cSDimitry Andric} 994349cc55cSDimitry Andric 995349cc55cSDimitry Andriclet Predicates = [iHas2E3] in { 996349cc55cSDimitry Andric def RFI32 : I_5_XZ_PRIVI<0x11, 0x1, "rfi32">; 997349cc55cSDimitry Andric def SCE32 : I_5_IMM5<0x30, 0b000110, 0b00001, "sce32", uimm4, []>; 998349cc55cSDimitry Andric} 999349cc55cSDimitry Andriclet Predicates = [HasExtendLrw] in 1000349cc55cSDimitry Andricdef IDLY32 : I_5_IMM5<0x30, 0b000111, 0b00001, "idly32", imm5_idly, []>; 1001349cc55cSDimitry Andricdef STOP32 : I_5_XZ_PRIVI<0x12, 0x1, "stop32">; 1002349cc55cSDimitry Andricdef WAIT32 : I_5_XZ_PRIVI<0x13, 0x1, "wait32">; 1003349cc55cSDimitry Andricdef DOZE32 : I_5_XZ_PRIVI<0x14, 0x1, "doze32">; 1004349cc55cSDimitry Andricdef WE32 : I_5_XZ_PRIVI<0b010101, 0x1, "we32">; 1005349cc55cSDimitry Andricdef SE32 : I_5_XZ_PRIVI<0b010110, 0x1, "se32">; 1006349cc55cSDimitry Andricdef WSC32 : I_5_XZ_PRIVI<0b001111, 0x1, "wsc32">; 1007349cc55cSDimitry Andric 1008349cc55cSDimitry Andricdef CPOP32 : I_CPOP<(outs), (ins uimm5:$cpid, uimm20:$usdef), "cpop32 <$cpid, ${usdef}>">; 1009349cc55cSDimitry Andricdef CPRC32 : I_CP<0b0100, (outs CARRY:$ca), (ins uimm5:$cpid, uimm12:$usdef), "cprc32 <$cpid, ${usdef}>">; 1010349cc55cSDimitry Andricdef CPRCR32 : I_CP_Z<0b0010, (outs GPR:$rz), (ins uimm5:$cpid, uimm12:$usdef), "cprcr32 $rz, <$cpid, ${usdef}>">; 1011349cc55cSDimitry Andricdef CPRGR32 : I_CP_Z<0b0000, (outs GPR:$rz), (ins uimm5:$cpid, uimm12:$usdef), "cprgr32 $rz, <$cpid, ${usdef}>">; 1012349cc55cSDimitry Andricdef CPWCR32 : I_CP_Z<0b0011, (outs), (ins GPR:$rz, uimm5:$cpid, uimm12:$usdef), "cpwcr32 $rz, <$cpid, ${usdef}>">; 1013349cc55cSDimitry Andricdef CPWGR32 : I_CP_Z<0b0001, (outs), (ins GPR:$rz, uimm5:$cpid, uimm12:$usdef), "cpwgr32 $rz, <$cpid, ${usdef}>">; 1014349cc55cSDimitry Andric 1015349cc55cSDimitry Andriclet Predicates = [iHas3r2E3r3] in { 1016349cc55cSDimitry Andricdef DCACHE_IALL32 : I_5_CACHE<0b100101, 0b01000, "dcache32.iall">; 1017349cc55cSDimitry Andricdef DCACHE_CALL32 : I_5_CACHE<0b100101, 0b00100, "dcache32.call">; 1018349cc55cSDimitry Andricdef DCACHE_CIALL32 : I_5_CACHE<0b100101, 0b01100, "dcache32.ciall">; 1019349cc55cSDimitry Andricdef DCACHE_IVA32 : I_5_X_CACHE<0b100101, 0b01011, "dcache32.iva">; 1020349cc55cSDimitry Andricdef DCACHE_ISW32: I_5_X_CACHE<0b100101, 0b01010, "dcache32.isw">; 1021349cc55cSDimitry Andricdef DCACHE_CVA32 : I_5_X_CACHE<0b100101, 0b00111, "dcache32.cva">; 1022349cc55cSDimitry Andricdef DCACHE_CVAL32 : I_5_X_CACHE<0b100101, 0b10111, "dcache32.cval1">; 1023349cc55cSDimitry Andricdef DCACHE_CSW32 : I_5_X_CACHE<0b100101, 0b00110, "dcache32.csw">; 1024349cc55cSDimitry Andricdef DCACHE_CIVA32 : I_5_X_CACHE<0b100101, 0b01111, "dcache32.civa">; 1025349cc55cSDimitry Andricdef DCACHE_CISW32 : I_5_X_CACHE<0b100101, 0b01110, "dcache32.cisw">; 1026349cc55cSDimitry Andric 1027349cc55cSDimitry Andricdef ICACHE_IALL32 : I_5_CACHE<0b100100, 0b01000, "icache32.iall">; 1028349cc55cSDimitry Andricdef ICACHE_IALLS32 : I_5_CACHE<0b100100, 0b11000, "icache32.ialls">; 1029349cc55cSDimitry Andricdef ICACHE_IVA32 : I_5_X_CACHE<0b100100, 0b01011, "icache32.iva">; 1030349cc55cSDimitry Andric 1031349cc55cSDimitry Andricdef TLBI_VAA32 : I_5_X_CACHE<0b100010, 0b00010, "tlbi32.vaa">; 1032349cc55cSDimitry Andricdef TLBI_VAAS32 : I_5_X_CACHE<0b100010, 0b10010, "tlbi32.vaas">; 1033349cc55cSDimitry Andricdef TLBI_ASID32 : I_5_X_CACHE<0b100010, 0b00001, "tlbi32.asid">; 1034349cc55cSDimitry Andricdef TLBI_ASIDS32 : I_5_X_CACHE<0b100010, 0b10001, "tlbi32.asids">; 1035349cc55cSDimitry Andricdef TLBI_VA32 : I_5_X_CACHE<0b100010, 0b00011, "tlbi32.va">; 1036349cc55cSDimitry Andricdef TLBI_VAS32 : I_5_X_CACHE<0b100010, 0b10011, "tlbi32.vas">; 1037349cc55cSDimitry Andricdef TLBI_ALL32 : I_5_CACHE<0b100010, 0b00000, "tlbi32.all">; 1038349cc55cSDimitry Andricdef TLBI_ALLS32 : I_5_CACHE<0b100010, 0b10000, "tlbi32.alls">; 1039349cc55cSDimitry Andric 1040349cc55cSDimitry Andricdef L2CACHE_IALL : I_5_CACHE<0b100110, 0b01000, "l2cache.iall">; 1041349cc55cSDimitry Andricdef L2CACHE_CALL : I_5_CACHE<0b100110, 0b00100, "l2cache.call">; 1042349cc55cSDimitry Andricdef L2CACHE_CIALL : I_5_CACHE<0b100110, 0b01100, "l2cache.ciall">; 1043349cc55cSDimitry Andric} 1044349cc55cSDimitry Andric 1045349cc55cSDimitry Andricdef PLDR32 :I_PLDR<AddrMode32WD, 0x36, 0b0110, (outs), (ins GPR:$rx, uimm12_2:$imm12), "pldr32", []>; 1046349cc55cSDimitry Andricdef PLDW32 :I_PLDR<AddrMode32WD, 0x37, 0b0110, (outs), (ins GPR:$rx, uimm12_2:$imm12), "pldw32", []>; 1047349cc55cSDimitry Andric 1048349cc55cSDimitry Andricdef TRAP32 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins uimm2:$imm2), "trap32 ${imm2}", []> { 1049349cc55cSDimitry Andric bits<2> imm2; 1050349cc55cSDimitry Andric 1051349cc55cSDimitry Andric let Inst{25 - 21} = 0; 1052349cc55cSDimitry Andric let Inst{20 - 16} = 0; 1053349cc55cSDimitry Andric let Inst{15 - 12} = 0b0010; 1054349cc55cSDimitry Andric let Inst{11 - 10} = imm2; 1055349cc55cSDimitry Andric let Inst{9 - 5} = 0b00001; 1056349cc55cSDimitry Andric let Inst{4 - 0} = 0; 1057349cc55cSDimitry Andric 1058349cc55cSDimitry Andric} 1059349cc55cSDimitry Andric 10600eae32dcSDimitry Andric//===----------------------------------------------------------------------===// 10610eae32dcSDimitry Andric// Instruction Patterns. 10620eae32dcSDimitry Andric//===----------------------------------------------------------------------===// 10630eae32dcSDimitry Andric 10640eae32dcSDimitry Andric// Load & Store Patterns 10650eae32dcSDimitry Andricmulticlass LdPat<PatFrag LoadOp, ImmLeaf imm_type, Instruction Inst, ValueType Type> { 10660eae32dcSDimitry Andric def : Pat<(Type (LoadOp GPR:$rs1)), (Inst GPR:$rs1, 0)>; 10670eae32dcSDimitry Andric def : Pat<(Type (LoadOp (i32 frameindex:$rs1))), (Inst (i32 (to_tframeindex tframeindex:$rs1)), 0)>; 10680eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add GPR:$rs1, imm_type:$uimm))), 10690eae32dcSDimitry Andric (Inst GPR:$rs1, imm_type:$uimm)>; 10700eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add frameindex:$rs1, imm_type:$uimm))), 10710eae32dcSDimitry Andric (Inst (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm)>; 10720eae32dcSDimitry Andric def : Pat<(Type (LoadOp (eqToAdd frameindex:$rs1, imm_type:$uimm))), 10730eae32dcSDimitry Andric (Inst (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm)>; 10740eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add GPR:$rs1, tglobaladdr:$gd))), 10750eae32dcSDimitry Andric (Inst GPR:$rs1, tglobaladdr:$gd)>; 10760eae32dcSDimitry Andric} 10770eae32dcSDimitry Andric 10780eae32dcSDimitry Andricdefm : LdPat<extloadi8, uimm12, LD32B, i32>; 10790eae32dcSDimitry Andricdefm : LdPat<zextloadi8, uimm12, LD32B, i32>; 10800eae32dcSDimitry Andriclet Predicates = [iHasE2] in { 10810eae32dcSDimitry Andric defm : LdPat<sextloadi8, uimm12, LD32BS, i32>; 10820eae32dcSDimitry Andric} 10830eae32dcSDimitry Andricdefm : LdPat<extloadi16, uimm12_1, LD32H, i32>; 10840eae32dcSDimitry Andricdefm : LdPat<zextloadi16, uimm12_1, LD32H, i32>; 10850eae32dcSDimitry Andriclet Predicates = [iHasE2] in { 10860eae32dcSDimitry Andricdefm : LdPat<sextloadi16, uimm12_1, LD32HS, i32>; 10870eae32dcSDimitry Andric} 10880eae32dcSDimitry Andricdefm : LdPat<load, uimm12_2, LD32W, i32>; 10890eae32dcSDimitry Andric 10900eae32dcSDimitry Andricmulticlass LdrPat<PatFrag LoadOp, Instruction Inst, ValueType Type> { 10910eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add GPR:$rs1, GPR:$rs2))), (Inst GPR:$rs1, GPR:$rs2, 0)>; 10920eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 1))))), (Inst GPR:$rs1, GPR:$rs2, 1)>; 10930eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 2))))), (Inst GPR:$rs1, GPR:$rs2, 2)>; 10940eae32dcSDimitry Andric def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 3))))), (Inst GPR:$rs1, GPR:$rs2, 3)>; 10950eae32dcSDimitry Andric} 10960eae32dcSDimitry Andric 10970eae32dcSDimitry Andriclet Predicates = [iHas2E3] in { 10980eae32dcSDimitry Andric defm : LdrPat<zextloadi8, LDR32B, i32>; 10990eae32dcSDimitry Andric defm : LdrPat<sextloadi8, LDR32BS, i32>; 11000eae32dcSDimitry Andric defm : LdrPat<extloadi8, LDR32BS, i32>; 11010eae32dcSDimitry Andric defm : LdrPat<zextloadi16, LDR32H, i32>; 11020eae32dcSDimitry Andric defm : LdrPat<sextloadi16, LDR32HS, i32>; 11030eae32dcSDimitry Andric defm : LdrPat<extloadi16, LDR32HS, i32>; 11040eae32dcSDimitry Andric defm : LdrPat<load, LDR32W, i32>; 11050eae32dcSDimitry Andric} 11060eae32dcSDimitry Andric 11070eae32dcSDimitry Andricmulticlass StPat<PatFrag StoreOp, ValueType Type, ImmLeaf imm_type, Instruction Inst> { 11080eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rs2, GPR:$rs1), (Inst Type:$rs2, GPR:$rs1, 0)>; 11090eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rs2, frameindex:$rs1), (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), 0)>; 11100eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rs2, (add GPR:$rs1, imm_type:$uimm12)), 11110eae32dcSDimitry Andric (Inst Type:$rs2, GPR:$rs1, imm_type:$uimm12)>; 11120eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rs2, (add frameindex:$rs1, imm_type:$uimm12)), 11130eae32dcSDimitry Andric (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm12)>; 11140eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rs2, (eqToAdd frameindex:$rs1, imm_type:$uimm12)), 11150eae32dcSDimitry Andric (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm12)>; 11160eae32dcSDimitry Andric} 11170eae32dcSDimitry Andric 11180eae32dcSDimitry Andricdefm : StPat<truncstorei8, i32, uimm12, ST32B>; 11190eae32dcSDimitry Andricdefm : StPat<truncstorei16, i32, uimm12_1, ST32H>; 11200eae32dcSDimitry Andricdefm : StPat<store, i32, uimm12_2, ST32W>; 11210eae32dcSDimitry Andric 11220eae32dcSDimitry Andricmulticlass StrPat<PatFrag StoreOp, ValueType Type, Instruction Inst> { 11230eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, GPR:$rs2)), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 0)>; 11240eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 1)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 1)>; 11250eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 2)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 2)>; 11260eae32dcSDimitry Andric def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 3)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 3)>; 11270eae32dcSDimitry Andric} 11280eae32dcSDimitry Andric 11290eae32dcSDimitry Andriclet Predicates = [iHas2E3] in { 11300eae32dcSDimitry Andric defm : StrPat<truncstorei8, i32, STR32B>; 11310eae32dcSDimitry Andric defm : StrPat<truncstorei16, i32, STR32H>; 11320eae32dcSDimitry Andric defm : StrPat<store, i32, STR32W>; 11330eae32dcSDimitry Andric 11340eae32dcSDimitry Andric // Sext & Zext Patterns 11350eae32dcSDimitry Andric def : Pat<(sext_inreg GPR:$src, i1), (SEXT32 GPR:$src, 0, 0)>; 11360eae32dcSDimitry Andric def : Pat<(and GPR:$src, 255), (ZEXT32 GPR:$src, 7, 0)>; 11370eae32dcSDimitry Andric def : Pat<(and GPR:$src, 65535), (ZEXT32 GPR:$src, 15, 0)>; 113804eeddc0SDimitry Andric 113904eeddc0SDimitry Andric // Call Patterns 114004eeddc0SDimitry Andric def : Pat<(CSKY_CALL tglobaladdr, tconstpool:$src2), (JSRI32 tconstpool:$src2)>; 114104eeddc0SDimitry Andric def : Pat<(CSKY_CALL texternalsym, tconstpool:$src2), (JSRI32 tconstpool:$src2)>; 114204eeddc0SDimitry Andric def : Pat<(CSKY_TAIL tglobaladdr, tconstpool:$src2), (JMPI32 tconstpool:$src2)>; 114304eeddc0SDimitry Andric def : Pat<(CSKY_TAIL texternalsym, tconstpool:$src2), (JMPI32 tconstpool:$src2)>; 114404eeddc0SDimitry Andric 114504eeddc0SDimitry Andric def : Pat<(CSKY_CALLReg GPR:$src), (JSR32 GPR:$src)>; 114604eeddc0SDimitry Andric def : Pat<(CSKY_TAILReg GPR:$src), (JMP32 GPR:$src)>; 114704eeddc0SDimitry Andric} 114804eeddc0SDimitry Andric 114904eeddc0SDimitry Andric// Symbol address Patterns 115004eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tglobaladdr, tconstpool:$src2), (LRW32 tconstpool:$src2)>; 115104eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tblockaddress, tconstpool:$src2), (LRW32 tconstpool:$src2)>; 115204eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tjumptable:$src1, tconstpool:$src2), (LRW32_Gen tjumptable:$src1, tconstpool:$src2)>; 115304eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR texternalsym, tconstpool:$src2), (LRW32 tconstpool:$src2)>; 1154bdd1243dSDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tconstpool:$src1, tconstpool:$src2), (LRW32_Gen tconstpool:$src1, tconstpool:$src2)>; 115504eeddc0SDimitry Andric 115604eeddc0SDimitry Andriclet Predicates = [iHas2E3] in 115704eeddc0SDimitry Andric def : Pat<(i32 constpool:$src), (GRS32 (to_tconstpool tconstpool:$src))>; 115804eeddc0SDimitry Andric 115904eeddc0SDimitry Andriclet Predicates = [iHasE2] in 116004eeddc0SDimitry Andric def : Pat<(i32 constpool:$src), 116104eeddc0SDimitry Andric (ORI32 (MOVIH32 (to_tconstpool_hi16 tconstpool:$src)), 116204eeddc0SDimitry Andric (to_tconstpool_lo16 tconstpool:$src))>; 116304eeddc0SDimitry Andric 116404eeddc0SDimitry Andricdef : Pat<(i32 (load constpool:$src)), (LRW32 (to_tconstpool tconstpool:$src))>; 116504eeddc0SDimitry Andric 116604eeddc0SDimitry Andric// Branch Patterns. 116704eeddc0SDimitry Andriclet Predicates = [iHasE2] in { 116804eeddc0SDimitry Andricdef : Pat<(brcond CARRY:$ca, bb:$imm16), 116904eeddc0SDimitry Andric (BT32 CARRY:$ca, bb:$imm16)>; 117004eeddc0SDimitry Andric 1171*06c3fb27SDimitry Andricmulticlass BTF32Pat0<PatFrag cond0, PatFrag cond1, ImmLeaf imm_ty, Instruction inst> { 1172*06c3fb27SDimitry Andric def : Pat<(brcond (i32 (cond0 GPR:$rs1, uimm16:$rs2)), bb:$imm16), 1173*06c3fb27SDimitry Andric (BT32 (inst GPR:$rs1, imm_ty:$rs2), bb:$imm16)>; 1174*06c3fb27SDimitry Andric def : Pat<(brcond (i32 (cond1 GPR:$rs1, uimm16:$rs2)), bb:$imm16), 1175*06c3fb27SDimitry Andric (BF32 (inst GPR:$rs1, imm_ty:$rs2), bb:$imm16)>; 1176*06c3fb27SDimitry Andric} 117704eeddc0SDimitry Andric 1178*06c3fb27SDimitry Andricdefm : BTF32Pat0<setne, seteq, uimm16, CMPNEI32>; 1179*06c3fb27SDimitry Andricdefm : BTF32Pat0<setuge, setult, oimm16, CMPHSI32>; 1180*06c3fb27SDimitry Andricdefm : BTF32Pat0<setlt, setge, oimm16, CMPLTI32>; 118104eeddc0SDimitry Andric} 118204eeddc0SDimitry Andric 118304eeddc0SDimitry Andriclet Predicates = [iHas2E3] in { 118404eeddc0SDimitry Andric 118504eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setne GPR:$rs1, GPR:$rs2)), bb:$imm16), 118604eeddc0SDimitry Andric (BT32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>; 118704eeddc0SDimitry Andricdef : Pat<(brcond (i32 (seteq GPR:$rs1, GPR:$rs2)), bb:$imm16), 118804eeddc0SDimitry Andric (BF32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>; 1189*06c3fb27SDimitry Andric 1190*06c3fb27SDimitry Andricmulticlass BTF32Pat1<PatFrag cond0, PatFrag cond1, Instruction cmp, 1191*06c3fb27SDimitry Andric Instruction br> { 1192*06c3fb27SDimitry Andric def : Pat<(brcond (i32 (cond0 GPR:$rs1, GPR:$rs2)), bb:$imm16), 1193*06c3fb27SDimitry Andric (br (cmp GPR:$rs1, GPR:$rs2), bb:$imm16)>; 1194*06c3fb27SDimitry Andric def : Pat<(brcond (i32 (cond1 GPR:$rs1, GPR:$rs2)), bb:$imm16), 1195*06c3fb27SDimitry Andric (br (cmp GPR:$rs2, GPR:$rs1), bb:$imm16)>; 1196*06c3fb27SDimitry Andric} 1197*06c3fb27SDimitry Andric 1198*06c3fb27SDimitry Andricdefm : BTF32Pat1<setuge, setule, CMPHS32, BT32>; 1199*06c3fb27SDimitry Andricdefm : BTF32Pat1<setult, setugt, CMPHS32, BF32>; 1200*06c3fb27SDimitry Andricdefm : BTF32Pat1<setlt, setgt, CMPLT32, BT32>; 1201*06c3fb27SDimitry Andricdefm : BTF32Pat1<setge, setle, CMPLT32, BF32>; 120204eeddc0SDimitry Andric 120304eeddc0SDimitry Andricdef : Pat<(brcond (i32 (seteq GPR:$rs1, (i32 0))), bb:$imm16), 120404eeddc0SDimitry Andric (BEZ32 GPR:$rs1, bb:$imm16)>; 120504eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setne GPR:$rs1, (i32 0))), bb:$imm16), 120604eeddc0SDimitry Andric (BNEZ32 GPR:$rs1, bb:$imm16)>; 120704eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setlt GPR:$rs1, (i32 0))), bb:$imm16), 120804eeddc0SDimitry Andric (BLZ32 GPR:$rs1, bb:$imm16)>; 1209*06c3fb27SDimitry Andricdef : Pat<(brcond (i32 (setlt GPR:$rs1, (i32 1))), bb:$imm16), 1210*06c3fb27SDimitry Andric (BLSZ32 GPR:$rs1, bb:$imm16)>; 121104eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setge GPR:$rs1, (i32 0))), bb:$imm16), 121204eeddc0SDimitry Andric (BHSZ32 GPR:$rs1, bb:$imm16)>; 1213*06c3fb27SDimitry Andricdef : Pat<(brcond (i32 (setge GPR:$rs1, (i32 1))), bb:$imm16), 1214*06c3fb27SDimitry Andric (BHZ32 GPR:$rs1, bb:$imm16)>; 121504eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setgt GPR:$rs1, (i32 0))), bb:$imm16), 121604eeddc0SDimitry Andric (BHZ32 GPR:$rs1, bb:$imm16)>; 1217*06c3fb27SDimitry Andricdef : Pat<(brcond (i32 (setgt GPR:$rs1, (i32 -1))), bb:$imm16), 1218*06c3fb27SDimitry Andric (BHSZ32 GPR:$rs1, bb:$imm16)>; 121904eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setle GPR:$rs1, (i32 0))), bb:$imm16), 122004eeddc0SDimitry Andric (BLSZ32 GPR:$rs1, bb:$imm16)>; 1221*06c3fb27SDimitry Andricdef : Pat<(brcond (i32 (setle GPR:$rs1, (i32 -1))), bb:$imm16), 1222*06c3fb27SDimitry Andric (BLZ32 GPR:$rs1, bb:$imm16)>; 122304eeddc0SDimitry Andric} 122404eeddc0SDimitry Andric 122504eeddc0SDimitry Andric// Compare Patterns. 122604eeddc0SDimitry Andriclet Predicates = [iHas2E3] in { 122704eeddc0SDimitry Andric def : Pat<(setne GPR:$rs1, GPR:$rs2), 122804eeddc0SDimitry Andric (CMPNE32 GPR:$rs1, GPR:$rs2)>; 122904eeddc0SDimitry Andric def : Pat<(i32 (seteq GPR:$rs1, GPR:$rs2)), 123004eeddc0SDimitry Andric (MVCV32 (CMPNE32 GPR:$rs1, GPR:$rs2))>; 123104eeddc0SDimitry Andric def : Pat<(setuge GPR:$rs1, GPR:$rs2), 123204eeddc0SDimitry Andric (CMPHS32 GPR:$rs1, GPR:$rs2)>; 123304eeddc0SDimitry Andric def : Pat<(setule GPR:$rs1, GPR:$rs2), 123404eeddc0SDimitry Andric (CMPHS32 GPR:$rs2, GPR:$rs1)>; 123504eeddc0SDimitry Andric def : Pat<(i32 (setult GPR:$rs1, GPR:$rs2)), 123604eeddc0SDimitry Andric (MVCV32 (CMPHS32 GPR:$rs1, GPR:$rs2))>; 123704eeddc0SDimitry Andric def : Pat<(i32 (setugt GPR:$rs1, GPR:$rs2)), 123804eeddc0SDimitry Andric (MVCV32 (CMPHS32 GPR:$rs2, GPR:$rs1))>; 123904eeddc0SDimitry Andric def : Pat<(setlt GPR:$rs1, GPR:$rs2), 124004eeddc0SDimitry Andric (CMPLT32 GPR:$rs1, GPR:$rs2)>; 124104eeddc0SDimitry Andric def : Pat<(setgt GPR:$rs1, GPR:$rs2), 124204eeddc0SDimitry Andric (CMPLT32 GPR:$rs2, GPR:$rs1)>; 124304eeddc0SDimitry Andric def : Pat<(i32 (setge GPR:$rs1, GPR:$rs2)), 124404eeddc0SDimitry Andric (MVCV32 (CMPLT32 GPR:$rs1, GPR:$rs2))>; 124504eeddc0SDimitry Andric def : Pat<(i32 (setle GPR:$rs1, GPR:$rs2)), 124604eeddc0SDimitry Andric (MVCV32 (CMPLT32 GPR:$rs2, GPR:$rs1))>; 124704eeddc0SDimitry Andric} 124804eeddc0SDimitry Andric 124904eeddc0SDimitry Andriclet Predicates = [iHasE2] in { 125004eeddc0SDimitry Andric def : Pat<(setne GPR:$rs1, uimm16:$rs2), 125104eeddc0SDimitry Andric (CMPNEI32 GPR:$rs1, uimm16:$rs2)>; 125204eeddc0SDimitry Andric let Predicates = [iHas2E3] in 125304eeddc0SDimitry Andric def : Pat<(i32 (seteq GPR:$rs1, uimm16:$rs2)), 125404eeddc0SDimitry Andric (MVCV32 (CMPNEI32 GPR:$rs1, uimm16:$rs2))>; 125504eeddc0SDimitry Andric def : Pat<(setuge GPR:$rs1, oimm16:$rs2), 125604eeddc0SDimitry Andric (CMPHSI32 GPR:$rs1, oimm16:$rs2)>; 125704eeddc0SDimitry Andric let Predicates = [iHas2E3] in 125804eeddc0SDimitry Andric def : Pat<(i32 (setult GPR:$rs1, oimm16:$rs2)), 125904eeddc0SDimitry Andric (MVCV32 (CMPHSI32 GPR:$rs1, oimm16:$rs2))>; 126004eeddc0SDimitry Andric def : Pat<(setlt GPR:$rs1, oimm16:$rs2), 126104eeddc0SDimitry Andric (CMPLTI32 GPR:$rs1, oimm16:$rs2)>; 126204eeddc0SDimitry Andric let Predicates = [iHas2E3] in 126304eeddc0SDimitry Andric def : Pat<(i32 (setge GPR:$rs1, oimm16:$rs2)), 126404eeddc0SDimitry Andric (MVCV32 (CMPLTI32 GPR:$rs1, oimm16:$rs2))>; 126504eeddc0SDimitry Andric} 126604eeddc0SDimitry Andric 126704eeddc0SDimitry Andric// Select Patterns. 126804eeddc0SDimitry Andriclet Predicates = [iHasE2] in { 1269bdd1243dSDimitry Andric 1270*06c3fb27SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false), 1271*06c3fb27SDimitry Andric (INCT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>; 1272*06c3fb27SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false), 1273*06c3fb27SDimitry Andric (INCF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>; 1274*06c3fb27SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false), 1275*06c3fb27SDimitry Andric (DECT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx, 1276*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1277*06c3fb27SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false), 1278*06c3fb27SDimitry Andric (DECF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx, 1279*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5:$imm))>; 1280*06c3fb27SDimitry Andric 1281*06c3fb27SDimitry Andricmulticlass INCDECPat<PatFrag cond0, PatFrag cond1, Instruction cmp> { 1282*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other), 1283*06c3fb27SDimitry Andric (INCT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>; 1284*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other), 1285*06c3fb27SDimitry Andric (INCF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>; 1286*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)), 1287*06c3fb27SDimitry Andric (INCF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>; 1288*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)), 1289*06c3fb27SDimitry Andric (INCT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>; 1290*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other), 1291*06c3fb27SDimitry Andric (DECT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, 1292*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1293*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other), 1294*06c3fb27SDimitry Andric (DECF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, 1295*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1296*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)), 1297*06c3fb27SDimitry Andric (DECF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, 1298*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1299*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)), 1300*06c3fb27SDimitry Andric (DECT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, 1301*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1302*06c3fb27SDimitry Andric} 1303*06c3fb27SDimitry Andric 1304*06c3fb27SDimitry Andricdefm : INCDECPat<setuge, setult, CMPHSI32>; 1305*06c3fb27SDimitry Andricdefm : INCDECPat<setlt, setge, CMPLTI32>; 1306*06c3fb27SDimitry Andric 1307*06c3fb27SDimitry Andricdef : Pat<(select CARRY:$ca, (add GPR:$rx, uimm5:$imm), GPR:$other), 1308*06c3fb27SDimitry Andric (INCT32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>; 1309*06c3fb27SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$other, (add GPR:$rx, uimm5:$imm)), 1310*06c3fb27SDimitry Andric (INCF32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>; 1311*06c3fb27SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), (add GPR:$rx, uimm5:$imm), GPR:$other), 1312*06c3fb27SDimitry Andric (INCT32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>; 1313*06c3fb27SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$other, (add GPR:$rx, uimm5:$imm)), 1314*06c3fb27SDimitry Andric (INCF32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>; 1315*06c3fb27SDimitry Andric 1316*06c3fb27SDimitry Andricdef : Pat<(select CARRY:$ca, (add GPR:$rx, uimm5_neg:$imm), GPR:$other), 1317*06c3fb27SDimitry Andric (DECT32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>; 1318*06c3fb27SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$other, (add GPR:$rx, uimm5_neg:$imm)), 1319*06c3fb27SDimitry Andric (DECF32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>; 1320*06c3fb27SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), (add GPR:$rx, uimm5_neg:$imm), GPR:$other), 1321*06c3fb27SDimitry Andric (DECT32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>; 1322*06c3fb27SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)), 1323*06c3fb27SDimitry Andric (DECF32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>; 1324*06c3fb27SDimitry Andric 132504eeddc0SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false), 132604eeddc0SDimitry Andric (MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>; 132704eeddc0SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false), 132804eeddc0SDimitry Andric (MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>; 132904eeddc0SDimitry Andric 1330*06c3fb27SDimitry Andricmulticlass MOVTF32Pat0<PatFrag cond0, PatFrag cond1, ImmLeaf imm_ty, Instruction inst> { 1331*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, imm_ty:$rs2)), GPR:$rx, GPR:$false), 1332*06c3fb27SDimitry Andric (MOVT32 (inst GPR:$rs1, imm_ty:$rs2), GPR:$rx, GPR:$false)>; 1333*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, imm_ty:$rs2)), GPR:$rx, GPR:$false), 1334*06c3fb27SDimitry Andric (MOVF32 (inst GPR:$rs1, imm_ty:$rs2), GPR:$rx, GPR:$false)>; 1335*06c3fb27SDimitry Andric} 133604eeddc0SDimitry Andric 1337*06c3fb27SDimitry Andricdefm : MOVTF32Pat0<setne, seteq, uimm16, CMPNEI32>; 1338*06c3fb27SDimitry Andricdefm : MOVTF32Pat0<setuge, setult, oimm16, CMPHSI32>; 1339*06c3fb27SDimitry Andricdefm : MOVTF32Pat0<setlt, setge, oimm16, CMPLTI32>; 1340bdd1243dSDimitry Andric 1341bdd1243dSDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false), 1342bdd1243dSDimitry Andric (ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>; 1343bdd1243dSDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false), 1344bdd1243dSDimitry Andric (ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>; 1345bdd1243dSDimitry Andric} 1346bdd1243dSDimitry Andric 1347bdd1243dSDimitry Andric 1348bdd1243dSDimitry Andriclet Predicates = [iHas2E3] in { 1349*06c3fb27SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false), 1350*06c3fb27SDimitry Andric (INCT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>; 1351*06c3fb27SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false), 1352*06c3fb27SDimitry Andric (INCF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>; 1353*06c3fb27SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false), 1354*06c3fb27SDimitry Andric (DECT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx, 1355*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1356*06c3fb27SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false), 1357*06c3fb27SDimitry Andric (DECF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx, 1358*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1359*06c3fb27SDimitry Andric 1360*06c3fb27SDimitry Andricmulticlass INCPat<PatFrag cond0, PatFrag cond1, Instruction cmp, Instruction inc0, Instruction inc1> { 1361*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other), 1362*06c3fb27SDimitry Andric (inc0 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>; 1363*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)), 1364*06c3fb27SDimitry Andric (inc1 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>; 1365*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other), 1366*06c3fb27SDimitry Andric (inc0 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx, uimm5:$imm)>; 1367*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)), 1368*06c3fb27SDimitry Andric (inc1 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx, uimm5:$imm)>; 1369*06c3fb27SDimitry Andric} 1370*06c3fb27SDimitry Andric 1371*06c3fb27SDimitry Andricdefm : INCPat<setuge, setule, CMPHS32, INCT32, INCF32>; 1372*06c3fb27SDimitry Andricdefm : INCPat<setult, setugt, CMPHS32, INCF32, INCT32>; 1373*06c3fb27SDimitry Andricdefm : INCPat<setlt, setgt, CMPLT32, INCT32, INCF32>; 1374*06c3fb27SDimitry Andricdefm : INCPat<setge, setle, CMPLT32, INCF32, INCT32>; 1375*06c3fb27SDimitry Andric 1376*06c3fb27SDimitry Andricmulticlass DECPat<PatFrag cond0, PatFrag cond1, Instruction cmp, Instruction dec0, Instruction dec1> { 1377*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other), 1378*06c3fb27SDimitry Andric (dec0 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx, 1379*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1380*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)), 1381*06c3fb27SDimitry Andric (dec1 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx, 1382*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1383*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other), 1384*06c3fb27SDimitry Andric (dec0 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx, 1385*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1386*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)), 1387*06c3fb27SDimitry Andric (dec1 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx, 1388*06c3fb27SDimitry Andric (imm_neg_XFORM uimm5_neg:$imm))>; 1389*06c3fb27SDimitry Andric} 1390*06c3fb27SDimitry Andric 1391*06c3fb27SDimitry Andricdefm : DECPat<setuge, setule, CMPHS32, DECT32, DECF32>; 1392*06c3fb27SDimitry Andricdefm : DECPat<setult, setugt, CMPHS32, DECF32, DECT32>; 1393*06c3fb27SDimitry Andricdefm : DECPat<setlt, setgt, CMPLT32, DECT32, DECF32>; 1394*06c3fb27SDimitry Andricdefm : DECPat<setge, setle, CMPLT32, DECF32, DECT32>; 1395bdd1243dSDimitry Andric 1396bdd1243dSDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false), 1397bdd1243dSDimitry Andric (MOVT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>; 1398bdd1243dSDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false), 1399bdd1243dSDimitry Andric (MOVF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>; 1400bdd1243dSDimitry Andric 1401*06c3fb27SDimitry Andricmulticlass MOVTF32Pat1<PatFrag cond0, PatFrag cond1, Instruction cmp_inst, 1402*06c3fb27SDimitry Andric Instruction mov_inst> { 1403*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false), 1404*06c3fb27SDimitry Andric (mov_inst (cmp_inst GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>; 1405*06c3fb27SDimitry Andric def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false), 1406*06c3fb27SDimitry Andric (mov_inst (cmp_inst GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>; 1407*06c3fb27SDimitry Andric} 140804eeddc0SDimitry Andric 1409*06c3fb27SDimitry Andricdefm : MOVTF32Pat1<setuge, setule, CMPHS32, MOVT32>; 1410*06c3fb27SDimitry Andricdefm : MOVTF32Pat1<setult, setugt, CMPHS32, MOVF32>; 1411*06c3fb27SDimitry Andricdefm : MOVTF32Pat1<setlt, setgt, CMPLT32, MOVT32>; 1412*06c3fb27SDimitry Andricdefm : MOVTF32Pat1<setge, setle, CMPLT32, MOVF32>; 141304eeddc0SDimitry Andric 1414*06c3fb27SDimitry Andricdef : Pat<(select CARRY:$ca, (i32 0), GPR:$other), 1415*06c3fb27SDimitry Andric (CLRT32 CARRY:$ca, GPR:$other)>; 1416*06c3fb27SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$other, (i32 0)), 1417*06c3fb27SDimitry Andric (CLRF32 CARRY:$ca, GPR:$other)>; 14180eae32dcSDimitry Andric} 14190eae32dcSDimitry Andric 14200eae32dcSDimitry Andric// Constant materialize patterns. 14210eae32dcSDimitry Andriclet Predicates = [iHasE2] in 14220eae32dcSDimitry Andric def : Pat<(i32 imm:$imm), 14230eae32dcSDimitry Andric (ORI32 (MOVIH32 (uimm32_hi16 imm:$imm)), (uimm32_lo16 imm:$imm))>; 14240eae32dcSDimitry Andric 14250eae32dcSDimitry Andric// Other operations. 14260eae32dcSDimitry Andriclet Predicates = [iHasE2] in { 14270eae32dcSDimitry Andric def : Pat<(rotl GPR:$rs1, GPR:$rs2), 14280eae32dcSDimitry Andric (ROTL32 GPR:$rs1, (ANDI32 GPR:$rs2, 0x1f))>; 14290eae32dcSDimitry Andric let Predicates = [iHas2E3] in { 14300eae32dcSDimitry Andric def : Pat<(bitreverse GPR:$rx), (BREV32 GPR:$rx)>; 14310eae32dcSDimitry Andric def : Pat<(bswap GPR:$rx), (REVB32 GPR:$rx)>; 14320eae32dcSDimitry Andric } 14330eae32dcSDimitry Andric def : Pat<(i32 (ctlz GPR:$rx)), (FF1 GPR:$rx)>; 14340eae32dcSDimitry Andric} 1435349cc55cSDimitry Andric 1436349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1437349cc55cSDimitry Andric// Pseudo for assembly 1438349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 1439349cc55cSDimitry Andric 1440349cc55cSDimitry Andriclet isCall = 1, Defs = [ R15 ], mayLoad = 1, Size = 4, isCodeGenOnly = 0 in 1441349cc55cSDimitry Andricdef JBSR32 : CSKYPseudo<(outs), (ins call_symbol:$src1), "jbsr32\t$src1", []>; 1442349cc55cSDimitry Andric 1443349cc55cSDimitry Andricdef JBR32 : CSKYPseudo<(outs), (ins br_symbol:$src1), "jbr32\t$src1", []> { 1444349cc55cSDimitry Andric let isBranch = 1; 1445349cc55cSDimitry Andric let isTerminator = 1; 1446349cc55cSDimitry Andric let isBarrier = 1; 1447349cc55cSDimitry Andric let isIndirectBranch = 1; 1448349cc55cSDimitry Andric let mayLoad = 1; 1449349cc55cSDimitry Andric let Size = 4; 1450349cc55cSDimitry Andric} 1451349cc55cSDimitry Andric 1452349cc55cSDimitry Andricdef JBT32 : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "jbt32\t$src1", []> { 1453349cc55cSDimitry Andric let isBranch = 1; 1454349cc55cSDimitry Andric let isTerminator = 1; 1455349cc55cSDimitry Andric let isIndirectBranch = 1; 1456349cc55cSDimitry Andric let mayLoad = 1; 1457349cc55cSDimitry Andric let Size = 4; 1458349cc55cSDimitry Andric} 1459349cc55cSDimitry Andric 1460349cc55cSDimitry Andricdef JBF32 : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "jbf32\t$src1", []> { 1461349cc55cSDimitry Andric let isBranch = 1; 1462349cc55cSDimitry Andric let isTerminator = 1; 1463349cc55cSDimitry Andric let isIndirectBranch = 1; 1464349cc55cSDimitry Andric let mayLoad = 1; 1465349cc55cSDimitry Andric let Size = 4; 1466349cc55cSDimitry Andric} 1467349cc55cSDimitry Andric 1468349cc55cSDimitry Andricdef JBT_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbt_e\t$src1", []> { 1469349cc55cSDimitry Andric let isBranch = 1; 1470349cc55cSDimitry Andric let isTerminator = 1; 1471349cc55cSDimitry Andric let isIndirectBranch = 1; 1472349cc55cSDimitry Andric let mayLoad = 1; 1473349cc55cSDimitry Andric let Size = 6; 1474349cc55cSDimitry Andric} 1475349cc55cSDimitry Andric 1476349cc55cSDimitry Andricdef JBF_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbf_e\t$src1", []> { 1477349cc55cSDimitry Andric let isBranch = 1; 1478349cc55cSDimitry Andric let isTerminator = 1; 1479349cc55cSDimitry Andric let isIndirectBranch = 1; 1480349cc55cSDimitry Andric let mayLoad = 1; 1481349cc55cSDimitry Andric let Size = 6; 1482349cc55cSDimitry Andric} 1483349cc55cSDimitry Andric 1484349cc55cSDimitry Andriclet mayLoad = 1, Size = 2, isCodeGenOnly = 0 in 1485349cc55cSDimitry Andricdef PseudoLRW32 : CSKYPseudo<(outs GPR:$rz), (ins bare_symbol:$src), "lrw32 $rz, $src", []>; 1486349cc55cSDimitry Andric 1487349cc55cSDimitry Andriclet mayLoad = 1, Size = 4, isCodeGenOnly = 0 in 1488349cc55cSDimitry Andricdef PseudoJSRI32 : CSKYPseudo<(outs), (ins call_symbol:$src), "jsri32 $src", []>; 1489349cc55cSDimitry Andric 1490349cc55cSDimitry Andriclet mayLoad = 1, Size = 4, isCodeGenOnly = 0 in 1491349cc55cSDimitry Andricdef PseudoJMPI32 : CSKYPseudo<(outs), (ins br_symbol:$src), "jmpi32 $src", []>; 1492349cc55cSDimitry Andric 1493349cc55cSDimitry Andriclet isNotDuplicable = 1, mayLoad = 1, mayStore = 0, Size = 8 in 1494349cc55cSDimitry Andricdef PseudoTLSLA32 : CSKYPseudo<(outs GPR:$dst1, GPR:$dst2), 1495349cc55cSDimitry Andric (ins constpool_symbol:$src, i32imm:$label), "!tlslrw32\t$dst1, $dst2, $src, $label", []>; 1496349cc55cSDimitry Andric 1497349cc55cSDimitry Andriclet hasSideEffects = 0, isNotDuplicable = 1 in 1498349cc55cSDimitry Andricdef CONSTPOOL_ENTRY : CSKYPseudo<(outs), 1499349cc55cSDimitry Andric (ins i32imm:$instid, i32imm:$cpidx, i32imm:$size), "", []>; 1500349cc55cSDimitry Andric 1501349cc55cSDimitry Andricinclude "CSKYInstrInfo16Instr.td" 150204eeddc0SDimitry Andricinclude "CSKYInstrInfoF1.td" 150304eeddc0SDimitry Andricinclude "CSKYInstrInfoF2.td" 150481ad6265SDimitry Andricinclude "CSKYInstrAlias.td" 1505