xref: /freebsd/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
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
18*04eeddc0SDimitry 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
25*04eeddc0SDimitry Andricdef SDT_CSKYCall : SDTypeProfile<0, 2, [SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
26*04eeddc0SDimitry Andric
27*04eeddc0SDimitry Andricdef SDT_CSKYCallReg : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
28*04eeddc0SDimitry Andric
29*04eeddc0SDimitry Andricdef SDT_CSKY_LOADADDR : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
30*04eeddc0SDimitry Andric                        SDTCisVT<1, iPTR>, SDTCisVT<2, iPTR>]>;
31*04eeddc0SDimitry 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
40*04eeddc0SDimitry Andricdef CSKY_CALL : SDNode<"CSKYISD::CALL", SDT_CSKYCall,
41*04eeddc0SDimitry Andric  [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
42*04eeddc0SDimitry Andric
43*04eeddc0SDimitry Andricdef CSKY_CALLReg : SDNode<"CSKYISD::CALLReg", SDT_CSKYCallReg,
44*04eeddc0SDimitry Andric  [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
45*04eeddc0SDimitry Andric
46*04eeddc0SDimitry Andricdef CSKY_TAIL : SDNode<"CSKYISD::TAIL", SDT_CSKYCall,
47*04eeddc0SDimitry Andric  [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
48*04eeddc0SDimitry Andric
49*04eeddc0SDimitry Andricdef CSKY_TAILReg : SDNode<"CSKYISD::TAILReg", SDT_CSKYCallReg,
50*04eeddc0SDimitry Andric  [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
51*04eeddc0SDimitry Andric
52*04eeddc0SDimitry Andricdef CSKY_LOAD_ADDR : SDNode<"CSKYISD::LOAD_ADDR", SDT_CSKY_LOADADDR>;
53*04eeddc0SDimitry 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
80*04eeddc0SDimitry Andricdef to_tconstpool : SDNodeXForm<constpool, [{
81*04eeddc0SDimitry Andric  auto CP = cast<ConstantPoolSDNode>(N);
82*04eeddc0SDimitry Andric  return CurDAG->getTargetConstantPool(CP->getConstVal(), TLI->getPointerTy(CurDAG->getDataLayout()),
83*04eeddc0SDimitry Andric                    CP->getAlign(), CP->getOffset(), CSKYII::MO_None);
84*04eeddc0SDimitry Andric}]>;
85*04eeddc0SDimitry Andric
86*04eeddc0SDimitry Andricdef to_tconstpool_hi16 : SDNodeXForm<constpool, [{
87*04eeddc0SDimitry Andric  auto CP = cast<ConstantPoolSDNode>(N);
88*04eeddc0SDimitry Andric  return CurDAG->getTargetConstantPool(CP->getConstVal(), TLI->getPointerTy(CurDAG->getDataLayout()),
89*04eeddc0SDimitry Andric                    CP->getAlign(), CP->getOffset(), CSKYII::MO_ADDR_HI16);
90*04eeddc0SDimitry Andric}]>;
91*04eeddc0SDimitry Andric
92*04eeddc0SDimitry Andricdef to_tconstpool_lo16 : SDNodeXForm<constpool, [{
93*04eeddc0SDimitry Andric  auto CP = cast<ConstantPoolSDNode>(N);
94*04eeddc0SDimitry Andric  return CurDAG->getTargetConstantPool(CP->getConstVal(), TLI->getPointerTy(CurDAG->getDataLayout()),
95*04eeddc0SDimitry Andric                    CP->getAlign(), CP->getOffset(), CSKYII::MO_ADDR_LO16);
96*04eeddc0SDimitry Andric}]>;
97*04eeddc0SDimitry 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
105e8d8bef9SDimitry Andricclass uimm<int num, int shift = 0> : Operand<i32>,
106e8d8bef9SDimitry Andric  ImmLeaf<i32, "return isShiftedUInt<"#num#", "#shift#">(Imm);"> {
107e8d8bef9SDimitry Andric  let EncoderMethod = "getImmOpValue<"#shift#">";
108fe6060f1SDimitry Andric  let ParserMatchClass =
109fe6060f1SDimitry Andric    !if(!ne(shift, 0),
110fe6060f1SDimitry Andric        UImmAsmOperand<num, "Shift"#shift>,
111fe6060f1SDimitry Andric        UImmAsmOperand<num>);
112349cc55cSDimitry Andric  let DecoderMethod = "decodeUImmOperand<"#num#", "#shift#">";
113e8d8bef9SDimitry Andric}
114e8d8bef9SDimitry Andric
115e8d8bef9SDimitry Andricclass simm<int num, int shift = 0> : Operand<i32>,
116e8d8bef9SDimitry Andric  ImmLeaf<i32, "return isShiftedInt<"#num#", "#shift#">(Imm);"> {
117e8d8bef9SDimitry Andric  let EncoderMethod = "getImmOpValue<"#shift#">";
118fe6060f1SDimitry Andric  let ParserMatchClass = SImmAsmOperand<num>;
119349cc55cSDimitry Andric  let DecoderMethod = "decodeSImmOperand<"#num#", "#shift#">";
120e8d8bef9SDimitry Andric}
121e8d8bef9SDimitry Andric
122e8d8bef9SDimitry Andricdef nimm_XFORM : SDNodeXForm<imm, [{
123e8d8bef9SDimitry Andric  return CurDAG->getTargetConstant(~N->getSExtValue(), SDLoc(N), MVT::i32);
124e8d8bef9SDimitry Andric}]>;
125e8d8bef9SDimitry Andricclass nimm<int num> : Operand<i32>,
126e8d8bef9SDimitry Andric  ImmLeaf<i32, "return isUInt<"#num#">(~Imm);", nimm_XFORM> {
127fe6060f1SDimitry Andric  let ParserMatchClass = UImmAsmOperand<num>;
128e8d8bef9SDimitry Andric}
129e8d8bef9SDimitry Andric
130fe6060f1SDimitry Andricdef uimm32_hi16 : SDNodeXForm<imm, [{
131fe6060f1SDimitry Andric  return CurDAG->getTargetConstant((N->getZExtValue() >> 16) & 0xFFFF,
132fe6060f1SDimitry Andric    SDLoc(N), MVT::i32);
133fe6060f1SDimitry Andric}]>;
134349cc55cSDimitry Andricdef uimm32_lo16 : SDNodeXForm<imm, [{
135349cc55cSDimitry Andric  return CurDAG->getTargetConstant(N->getZExtValue()& 0xFFFF, SDLoc(N), MVT::i32);
136349cc55cSDimitry Andric}]>;
137fe6060f1SDimitry Andricdef uimm16_16_xform : Operand<i32>,
138fe6060f1SDimitry Andric  ImmLeaf<i32, "return isShiftedUInt<16, 16>(Imm);", uimm32_hi16> {
139fe6060f1SDimitry Andric  let ParserMatchClass = UImmAsmOperand<16>;
140349cc55cSDimitry Andric  let EncoderMethod = "getImmOpValue";
141fe6060f1SDimitry Andric}
142fe6060f1SDimitry Andric
143fe6060f1SDimitry Andricdef uimm_shift : Operand<i32>, ImmLeaf<i32, "return isUInt<2>(Imm);"> {
144fe6060f1SDimitry Andric  let EncoderMethod = "getImmShiftOpValue";
145fe6060f1SDimitry Andric  let ParserMatchClass = UImmAsmOperand<2>;
146349cc55cSDimitry Andric  let DecoderMethod = "decodeImmShiftOpValue";
147fe6060f1SDimitry Andric}
148fe6060f1SDimitry Andric
149fe6060f1SDimitry Andricdef CSKYSymbol : AsmOperandClass {
150fe6060f1SDimitry Andric  let Name = "CSKYSymbol";
151fe6060f1SDimitry Andric  let RenderMethod = "addImmOperands";
152fe6060f1SDimitry Andric  let DiagnosticType = "InvalidCSKYSymbol";
153fe6060f1SDimitry Andric  let ParserMethod = "parseCSKYSymbol";
154fe6060f1SDimitry Andric}
155fe6060f1SDimitry Andric
156fe6060f1SDimitry Andricdef br_symbol : Operand<iPTR> {
157fe6060f1SDimitry Andric  let EncoderMethod =
158fe6060f1SDimitry Andric    "getBranchSymbolOpValue<CSKY::fixup_csky_pcrel_imm16_scale2>";
159fe6060f1SDimitry Andric  let ParserMatchClass = CSKYSymbol;
160349cc55cSDimitry Andric  let DecoderMethod = "decodeSImmOperand<16, 1>";
161349cc55cSDimitry Andric  let PrintMethod = "printCSKYSymbolOperand";
162349cc55cSDimitry Andric  let OperandType = "OPERAND_PCREL";
163fe6060f1SDimitry Andric}
164fe6060f1SDimitry Andric
165fe6060f1SDimitry Andricdef call_symbol : Operand<iPTR> {
166fe6060f1SDimitry Andric  let ParserMatchClass = CSKYSymbol;
167fe6060f1SDimitry Andric  let EncoderMethod = "getCallSymbolOpValue";
168349cc55cSDimitry Andric  let DecoderMethod = "decodeSImmOperand<26, 1>";
169349cc55cSDimitry Andric  let PrintMethod = "printCSKYSymbolOperand";
170349cc55cSDimitry Andric  let OperandType = "OPERAND_PCREL";
171fe6060f1SDimitry Andric}
172fe6060f1SDimitry Andric
173fe6060f1SDimitry Andricdef Constpool : AsmOperandClass {
174349cc55cSDimitry Andric  let Name = "Constpool";
175349cc55cSDimitry Andric  let RenderMethod = "addConstpoolOperands";
176fe6060f1SDimitry Andric  let DiagnosticType = "InvalidConstpool";
177fe6060f1SDimitry Andric  let ParserMethod = "parseConstpoolSymbol";
178fe6060f1SDimitry Andric}
179fe6060f1SDimitry Andric
180fe6060f1SDimitry Andricdef constpool_symbol : Operand<iPTR> {
181fe6060f1SDimitry Andric  let ParserMatchClass = Constpool;
182fe6060f1SDimitry Andric  let EncoderMethod =
183fe6060f1SDimitry Andric    "getConstpoolSymbolOpValue<CSKY::fixup_csky_pcrel_uimm16_scale4>";
184349cc55cSDimitry Andric  let DecoderMethod = "decodeUImmOperand<16, 2>";
185349cc55cSDimitry Andric  let PrintMethod = "printConstpool";
186349cc55cSDimitry Andric  let OperandType = "OPERAND_PCREL";
187349cc55cSDimitry Andric}
188349cc55cSDimitry Andric
189349cc55cSDimitry Andricdef DataAsmClass : AsmOperandClass {
190349cc55cSDimitry Andric  let Name = "DataSymbol";
191349cc55cSDimitry Andric  let RenderMethod = "addConstpoolOperands";
192349cc55cSDimitry Andric  let DiagnosticType = "InvalidConstpool";
193349cc55cSDimitry Andric  let ParserMethod = "parseDataSymbol";
194349cc55cSDimitry Andric}
195349cc55cSDimitry Andric
196349cc55cSDimitry Andricclass data_symbol<string reloc, int shift> : Operand<iPTR> {
197349cc55cSDimitry Andric  let ParserMatchClass = Constpool;
198349cc55cSDimitry Andric  let EncoderMethod =
199349cc55cSDimitry Andric    "getDataSymbolOpValue<"#reloc#">";
200349cc55cSDimitry Andric  let DecoderMethod = "decodeUImmOperand<18, "#shift#">";
201349cc55cSDimitry Andric  let PrintMethod = "printDataSymbol";
202fe6060f1SDimitry Andric}
203fe6060f1SDimitry Andric
204fe6060f1SDimitry Andricdef bare_symbol : Operand<iPTR> {
205fe6060f1SDimitry Andric  let ParserMatchClass = CSKYSymbol;
206fe6060f1SDimitry Andric  let EncoderMethod = "getBareSymbolOpValue";
207349cc55cSDimitry Andric  let PrintMethod = "printCSKYSymbolOperand";
208349cc55cSDimitry Andric  let DecoderMethod = "decodeSImmOperand<18, 1>";
209349cc55cSDimitry Andric  let OperandType = "OPERAND_PCREL";
210fe6060f1SDimitry Andric}
211e8d8bef9SDimitry Andric
2120eae32dcSDimitry Andricdef oimm3 : oimm<3> {
2130eae32dcSDimitry Andric  let MCOperandPredicate = [{
2140eae32dcSDimitry Andric    int64_t Imm;
2150eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2160eae32dcSDimitry Andric      return isUInt<3>(Imm - 1);
2170eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2180eae32dcSDimitry Andric  }];
2190eae32dcSDimitry Andric}
220349cc55cSDimitry Andricdef oimm4 : oimm<4>;
2210eae32dcSDimitry Andricdef oimm5 : oimm<5> {
2220eae32dcSDimitry Andric  let MCOperandPredicate = [{
2230eae32dcSDimitry Andric    int64_t Imm;
2240eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2250eae32dcSDimitry Andric      return isUInt<5>(Imm - 1);
2260eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2270eae32dcSDimitry Andric  }];
2280eae32dcSDimitry Andric}
229349cc55cSDimitry Andricdef oimm6 : oimm<6>;
230349cc55cSDimitry Andric
231349cc55cSDimitry Andricdef imm5_idly : Operand<i32>, ImmLeaf<i32,
232349cc55cSDimitry Andric  "return Imm <= 32 && Imm >= 0;"> {
233349cc55cSDimitry Andric  let EncoderMethod = "getImmOpValueIDLY";
234349cc55cSDimitry Andric  let DecoderMethod = "decodeOImmOperand<5>";
235349cc55cSDimitry Andric}
236349cc55cSDimitry Andric
2370eae32dcSDimitry Andricdef oimm8 : oimm<8> {
2380eae32dcSDimitry Andric  let MCOperandPredicate = [{
2390eae32dcSDimitry Andric    int64_t Imm;
2400eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2410eae32dcSDimitry Andric      return isUInt<8>(Imm - 1);
2420eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2430eae32dcSDimitry Andric  }];
2440eae32dcSDimitry Andric}
2450eae32dcSDimitry Andricdef oimm12 : oimm<12> {
2460eae32dcSDimitry Andric  let MCOperandPredicate = [{
2470eae32dcSDimitry Andric    int64_t Imm;
2480eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2490eae32dcSDimitry Andric      return isUInt<12>(Imm - 1);
2500eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2510eae32dcSDimitry Andric  }];
2520eae32dcSDimitry Andric}
2530eae32dcSDimitry Andricdef oimm16 : oimm<16> {
2540eae32dcSDimitry Andric  let MCOperandPredicate = [{
2550eae32dcSDimitry Andric    int64_t Imm;
2560eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2570eae32dcSDimitry Andric      return isUInt<16>(Imm - 1);
2580eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2590eae32dcSDimitry Andric  }];
2600eae32dcSDimitry Andric}
261e8d8bef9SDimitry Andric
262e8d8bef9SDimitry Andricdef nimm12 : nimm<12>;
263e8d8bef9SDimitry Andric
264349cc55cSDimitry Andricdef uimm1 : uimm<1>;
265349cc55cSDimitry Andricdef uimm2 : uimm<2>;
266349cc55cSDimitry Andric
267349cc55cSDimitry Andric
268349cc55cSDimitry Andricdef uimm2_jmpix : Operand<i32>,
269349cc55cSDimitry Andric  ImmLeaf<i32, "return Imm == 16 || Imm == 24 || Imm == 32 || Imm == 40;"> {
270349cc55cSDimitry Andric  let EncoderMethod = "getImmJMPIX";
271349cc55cSDimitry Andric  let DecoderMethod = "decodeJMPIXImmOperand";
272349cc55cSDimitry Andric}
273349cc55cSDimitry Andric
274349cc55cSDimitry Andricdef uimm3 : uimm<3>;
275349cc55cSDimitry Andricdef uimm4 : uimm<4>;
2760eae32dcSDimitry Andricdef uimm5 : uimm<5> {
2770eae32dcSDimitry Andric  let MCOperandPredicate = [{
2780eae32dcSDimitry Andric    int64_t Imm;
2790eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2800eae32dcSDimitry Andric      return isShiftedUInt<5, 0>(Imm);
2810eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2820eae32dcSDimitry Andric  }];
2830eae32dcSDimitry Andric}
284349cc55cSDimitry Andricdef uimm5_msb_size : uimm<5> {
285349cc55cSDimitry Andric  let EncoderMethod = "getImmOpValueMSBSize";
286349cc55cSDimitry Andric}
287349cc55cSDimitry Andric
2880eae32dcSDimitry Andricdef uimm5_1 : uimm<5, 1> {
2890eae32dcSDimitry Andric  let MCOperandPredicate = [{
2900eae32dcSDimitry Andric    int64_t Imm;
2910eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
2920eae32dcSDimitry Andric      return isShiftedUInt<5, 1>(Imm);
2930eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
2940eae32dcSDimitry Andric  }];
2950eae32dcSDimitry Andric}
2960eae32dcSDimitry Andricdef uimm5_2 : uimm<5, 2> {
2970eae32dcSDimitry Andric  let MCOperandPredicate = [{
2980eae32dcSDimitry Andric    int64_t Imm;
2990eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3000eae32dcSDimitry Andric      return isShiftedUInt<5, 2>(Imm);
3010eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3020eae32dcSDimitry Andric  }];
3030eae32dcSDimitry Andric}
304349cc55cSDimitry Andricdef uimm6 : uimm<6>;
305349cc55cSDimitry Andricdef uimm7 : uimm<7>;
306349cc55cSDimitry Andricdef uimm7_1 : uimm<7, 1>;
3070eae32dcSDimitry Andricdef uimm7_2 : uimm<7, 2>{
3080eae32dcSDimitry Andric  let MCOperandPredicate = [{
3090eae32dcSDimitry Andric    int64_t Imm;
3100eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3110eae32dcSDimitry Andric      return isShiftedUInt<7, 2>(Imm);
3120eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3130eae32dcSDimitry Andric  }];
3140eae32dcSDimitry Andric}
315349cc55cSDimitry Andricdef uimm7_3 : uimm<7, 3>;
3160eae32dcSDimitry Andricdef uimm8 : uimm<8> {
3170eae32dcSDimitry Andric  let MCOperandPredicate = [{
3180eae32dcSDimitry Andric    int64_t Imm;
3190eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3200eae32dcSDimitry Andric      return isShiftedUInt<8, 0>(Imm);
3210eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3220eae32dcSDimitry Andric  }];
3230eae32dcSDimitry Andric}
3240eae32dcSDimitry Andricdef uimm8_2 : uimm<8, 2> {
3250eae32dcSDimitry Andric  let MCOperandPredicate = [{
3260eae32dcSDimitry Andric    int64_t Imm;
3270eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3280eae32dcSDimitry Andric      return isShiftedUInt<8, 2>(Imm);
3290eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3300eae32dcSDimitry Andric  }];
3310eae32dcSDimitry Andric}
332349cc55cSDimitry Andricdef uimm8_3 : uimm<8, 3>;
333349cc55cSDimitry Andricdef uimm8_8 : uimm<8, 8>;
334349cc55cSDimitry Andricdef uimm8_16 : uimm<8, 16>;
335349cc55cSDimitry Andricdef uimm8_24 : uimm<8, 24>;
3360eae32dcSDimitry Andricdef uimm12 : uimm<12>  {
3370eae32dcSDimitry Andric  let MCOperandPredicate = [{
3380eae32dcSDimitry Andric    int64_t Imm;
3390eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3400eae32dcSDimitry Andric      return isShiftedUInt<12, 0>(Imm);
3410eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3420eae32dcSDimitry Andric  }];
3430eae32dcSDimitry Andric}
3440eae32dcSDimitry Andricdef uimm12_1 : uimm<12, 1> {
3450eae32dcSDimitry Andric  let MCOperandPredicate = [{
3460eae32dcSDimitry Andric    int64_t Imm;
3470eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3480eae32dcSDimitry Andric      return isShiftedUInt<12, 1>(Imm);
3490eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3500eae32dcSDimitry Andric  }];
3510eae32dcSDimitry Andric}
3520eae32dcSDimitry Andricdef uimm12_2 : uimm<12, 2> {
3530eae32dcSDimitry Andric  let MCOperandPredicate = [{
3540eae32dcSDimitry Andric    int64_t Imm;
3550eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3560eae32dcSDimitry Andric      return isShiftedUInt<12, 2>(Imm);
3570eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3580eae32dcSDimitry Andric  }];
3590eae32dcSDimitry Andric}
3600eae32dcSDimitry Andricdef uimm16 : uimm<16> {
3610eae32dcSDimitry Andric  let MCOperandPredicate = [{
3620eae32dcSDimitry Andric    int64_t Imm;
3630eae32dcSDimitry Andric    if (MCOp.evaluateAsConstantImm(Imm))
3640eae32dcSDimitry Andric      return isShiftedUInt<16, 0>(Imm);
3650eae32dcSDimitry Andric    return MCOp.isBareSymbolRef();
3660eae32dcSDimitry Andric  }];
3670eae32dcSDimitry Andric}
368349cc55cSDimitry Andricdef uimm16_8 : uimm<16, 8>;
369349cc55cSDimitry Andricdef uimm16_16 : uimm<16, 16>;
370349cc55cSDimitry Andricdef uimm20 : uimm<20>;
371349cc55cSDimitry Andricdef uimm24 : uimm<24>;
372349cc55cSDimitry Andricdef uimm24_8 : uimm<24, 8>;
373fe6060f1SDimitry Andric
374349cc55cSDimitry Andricdef simm8_2 : simm<8, 2>;
375349cc55cSDimitry Andric
376349cc55cSDimitry Andricclass RegSeqAsmOperand<string Suffix = ""> : AsmOperandClass {
377349cc55cSDimitry Andric  let Name = "RegSeq"#Suffix;
378349cc55cSDimitry Andric  let RenderMethod = "addRegSeqOperands";
379349cc55cSDimitry Andric  let DiagnosticType = "InvalidRegSeq";
380349cc55cSDimitry Andric  let ParserMethod = "parseRegSeq";
381349cc55cSDimitry Andric}
382349cc55cSDimitry Andric
383349cc55cSDimitry Andricdef regseq : Operand<iPTR> {
384349cc55cSDimitry Andric  let EncoderMethod = "getRegisterSeqOpValue";
385349cc55cSDimitry Andric  let ParserMatchClass = RegSeqAsmOperand<"">;
386349cc55cSDimitry Andric  let PrintMethod = "printRegisterSeq";
387349cc55cSDimitry Andric  let DecoderMethod = "DecodeRegSeqOperand";
388349cc55cSDimitry Andric  let MIOperandInfo = (ops GPR, uimm5);
389349cc55cSDimitry Andric}
390349cc55cSDimitry Andric
391349cc55cSDimitry Andricdef RegListAsmOperand : AsmOperandClass {
392349cc55cSDimitry Andric  let Name = "RegList";
393349cc55cSDimitry Andric  let RenderMethod = "addRegListOperands";
394349cc55cSDimitry Andric  let DiagnosticType = "InvalidRegList";
395349cc55cSDimitry Andric  let ParserMethod = "parseRegList";
396349cc55cSDimitry Andric}
397349cc55cSDimitry Andric
398349cc55cSDimitry Andricdef reglist : Operand<iPTR> {
399349cc55cSDimitry Andric  let ParserMatchClass = RegListAsmOperand;
400349cc55cSDimitry Andric  let PrintMethod = "printRegisterList";
401349cc55cSDimitry Andric}
402349cc55cSDimitry Andric
403349cc55cSDimitry Andricdef PSRFlag : AsmOperandClass {
404349cc55cSDimitry Andric  let Name = "PSRFlag";
405349cc55cSDimitry Andric  let RenderMethod = "addImmOperands";
406349cc55cSDimitry Andric  let DiagnosticType = "InvalidPSRFlag";
407349cc55cSDimitry Andric  let ParserMethod = "parsePSRFlag";
408349cc55cSDimitry Andric}
409349cc55cSDimitry Andric
410349cc55cSDimitry Andricdef psrflag : Operand<i32>, ImmLeaf<i32, "return isShiftedUInt<5, 0>(Imm);"> {
411349cc55cSDimitry Andric  let EncoderMethod = "getImmOpValue";
412349cc55cSDimitry Andric  let ParserMatchClass = PSRFlag;
413349cc55cSDimitry Andric  let PrintMethod = "printPSRFlag";
414349cc55cSDimitry Andric}
415fe6060f1SDimitry Andric
416fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
417fe6060f1SDimitry Andric// Instruction Formats
418fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
419fe6060f1SDimitry Andric
420fe6060f1SDimitry Andricinclude "CSKYInstrFormats.td"
421e8d8bef9SDimitry Andric
422e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
423e8d8bef9SDimitry Andric// Instruction definitions.
424e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
425e8d8bef9SDimitry Andric
426e8d8bef9SDimitry Andricclass TriOpFrag<dag res> : PatFrag<(ops node: $LHS, node:$MHS, node:$RHS), res>;
427e8d8bef9SDimitry Andricclass BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
428e8d8bef9SDimitry Andricclass UnOpFrag<dag res> : PatFrag<(ops node:$Src), res>;
429e8d8bef9SDimitry Andric
430349cc55cSDimitry Andricdef eqToAdd : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs), [{
431349cc55cSDimitry Andric  return isOrEquivalentToAdd(N);
432349cc55cSDimitry Andric}]>;
433349cc55cSDimitry Andric
434349cc55cSDimitry Andricdef BaseAddr : ComplexPattern<iPTR, 1, "SelectBaseAddr">;
435349cc55cSDimitry Andric
436349cc55cSDimitry Andric
437349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
438349cc55cSDimitry Andric// CSKYPseudo
439349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
440349cc55cSDimitry Andric
441349cc55cSDimitry Andric// Pessimistically assume the stack pointer will be clobbered
442349cc55cSDimitry Andriclet Defs = [R14], Uses = [R14] in {
443349cc55cSDimitry Andricdef ADJCALLSTACKDOWN : CSKYPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
444349cc55cSDimitry Andric  "!ADJCALLSTACKDOWN $amt1, $amt2", [(callseq_start timm:$amt1, timm:$amt2)]>;
445349cc55cSDimitry Andricdef ADJCALLSTACKUP   : CSKYPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
446349cc55cSDimitry Andric  "!ADJCALLSTACKUP $amt1, $amt2", [(callseq_end timm:$amt1, timm:$amt2)]>;
447349cc55cSDimitry Andric} // Defs = [R14], Uses = [R14]
448fe6060f1SDimitry Andric
449fe6060f1SDimitry Andric
450fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
451fe6060f1SDimitry Andric// Basic ALU instructions.
452fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
453fe6060f1SDimitry Andric
454349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
455349cc55cSDimitry Andric  let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
456349cc55cSDimitry Andric  let isAdd = 1 in
457e8d8bef9SDimitry Andric  def ADDI32 : I_12<0x0, "addi32", add, oimm12>;
458e8d8bef9SDimitry Andric  def SUBI32 : I_12<0x1, "subi32", sub, oimm12>;
459fe6060f1SDimitry Andric  def ORI32 : I_16_ZX<"ori32", uimm16,
460fe6060f1SDimitry Andric  [(set GPR:$rz, (or GPR:$rx, uimm16:$imm16))]>;
461fe6060f1SDimitry Andric  def XORI32 : I_12<0x4, "xori32", xor, uimm12>;
462e8d8bef9SDimitry Andric  def ANDI32 : I_12<0x2, "andi32", and, uimm12>;
463e8d8bef9SDimitry Andric  def ANDNI32 : I_12<0x3, "andni32", and, nimm12>;
464e8d8bef9SDimitry Andric  def LSLI32 : I_5_XZ<0x12, 0x1, "lsli32",
465e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
466e8d8bef9SDimitry Andric    [(set GPR:$rz, (shl GPR:$rx, uimm5:$imm5))]>;
467e8d8bef9SDimitry Andric  def LSRI32 : I_5_XZ<0x12, 0x2, "lsri32",
468e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
469e8d8bef9SDimitry Andric    [(set GPR:$rz, (srl GPR:$rx, uimm5:$imm5))]>;
470e8d8bef9SDimitry Andric  def ASRI32 : I_5_XZ<0x12, 0x4, "asri32",
471e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
472e8d8bef9SDimitry Andric    [(set GPR:$rz, (sra GPR:$rx, uimm5:$imm5))]>;
473fe6060f1SDimitry Andric  def ROTLI32 : I_5_XZ<0x12, 0x8, "rotli32",
474fe6060f1SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
475fe6060f1SDimitry Andric    [(set GPR:$rz, (rotl GPR:$rx, uimm5:$imm5))]>;
476e8d8bef9SDimitry Andric
477349cc55cSDimitry Andric  def ROTRI32 : CSKYPseudo<(outs GPR:$rz), (ins GPR:$rx, oimm5:$imm5),
478349cc55cSDimitry Andric                            "rotri32 $rz, $rx, $imm5", []>;
479349cc55cSDimitry Andric  }
480349cc55cSDimitry Andric  let isAdd = 1 in
481e8d8bef9SDimitry Andric  def ADDU32 : R_YXZ_SP_F1<0x0, 0x1,
482e8d8bef9SDimitry Andric    BinOpFrag<(add node:$LHS, node:$RHS)>, "addu32", 1>;
483e8d8bef9SDimitry Andric  def SUBU32 : R_YXZ_SP_F1<0x0, 0x4,
484e8d8bef9SDimitry Andric    BinOpFrag<(sub node:$LHS, node:$RHS)>, "subu32">;
485349cc55cSDimitry Andric
486fe6060f1SDimitry Andric  def MULT32 : R_YXZ_SP_F1<0x21, 0x1,
487fe6060f1SDimitry Andric    BinOpFrag<(mul node:$LHS, node:$RHS)>, "mult32", 1>;
488e8d8bef9SDimitry Andric  def AND32 : R_YXZ_SP_F1<0x8, 0x1,
489e8d8bef9SDimitry Andric    BinOpFrag<(and node:$LHS, node:$RHS)>, "and32", 1>;
490e8d8bef9SDimitry Andric  def ANDN32 : R_YXZ_SP_F1<0x8, 0x2,
491e8d8bef9SDimitry Andric    BinOpFrag<(and node:$LHS, (not node:$RHS))>, "andn32">;
492e8d8bef9SDimitry Andric  def OR32: R_YXZ_SP_F1<0x9, 0x1,
493e8d8bef9SDimitry Andric    BinOpFrag<(or node:$LHS, node:$RHS)>, "or32", 1>;
494e8d8bef9SDimitry Andric  def XOR32 : R_YXZ_SP_F1<0x9, 0x2,
495e8d8bef9SDimitry Andric    BinOpFrag<(xor node:$LHS, node:$RHS)>, "xor32", 1>;
496e8d8bef9SDimitry Andric  def NOR32 : R_YXZ_SP_F1<0x9, 0x4,
497e8d8bef9SDimitry Andric    BinOpFrag<(not (or node:$LHS, node:$RHS))>, "nor32", 1>;
498349cc55cSDimitry Andric  let isCodeGenOnly = 1 in
499fe6060f1SDimitry Andric  def NOT32 : R_XXZ<0b001001, 0b00100, (outs GPR:$rz), (ins GPR:$rx),
500fe6060f1SDimitry Andric    "not32", [(set GPR:$rz, (not GPR:$rx))]>;
501349cc55cSDimitry Andric
502349cc55cSDimitry Andric  let Size = 8 in
503349cc55cSDimitry Andric  def NEG32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx), "neg32 $rd, $rx", []>;
504349cc55cSDimitry Andric
505349cc55cSDimitry Andric  let Size = 8 in
506349cc55cSDimitry Andric  def RSUBI32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx, uimm12:$imm12), "rsubi32 $rd, $rx, $imm12", []>;
507349cc55cSDimitry Andric
508e8d8bef9SDimitry Andric  def LSL32 : R_YXZ_SP_F1<0x10, 0x1,
509e8d8bef9SDimitry Andric    BinOpFrag<(shl node:$LHS, node:$RHS)>, "lsl32">;
510e8d8bef9SDimitry Andric  def LSR32 : R_YXZ_SP_F1<0x10, 0x2,
511e8d8bef9SDimitry Andric    BinOpFrag<(srl node:$LHS, node:$RHS)>, "lsr32">;
512e8d8bef9SDimitry Andric  def ASR32 : R_YXZ_SP_F1<0x10, 0x4,
513e8d8bef9SDimitry Andric    BinOpFrag<(sra node:$LHS, node:$RHS)>, "asr32">;
514fe6060f1SDimitry Andric  def ROTL32 : R_YXZ_SP_F1<0x10, 0x8,
515fe6060f1SDimitry Andric    BinOpFrag<(rotl node:$LHS, (and node:$RHS, 0x1f))>, "rotl32">;
516fe6060f1SDimitry Andric
517349cc55cSDimitry Andric  def BMASKI32 : I_5_Z<0b010100, 0x1, "bmaski32", oimm5, []>;
518349cc55cSDimitry Andric  def LSLC32 : I_5_XZ<0x13, 0x1, "lslc32",
519349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>;
520349cc55cSDimitry Andric  def LSRC32 : I_5_XZ<0x13, 0x2, "lsrc32",
521349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>;
522349cc55cSDimitry Andric  def ASRC32 : I_5_XZ<0x13, 0x4, "asrc32",
523349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>;
524349cc55cSDimitry Andric  def XSR32 : I_5_XZ<0x13, 0x8, "xsr32",
525349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5, CARRY:$cin), []>;
526fe6060f1SDimitry Andric
527fe6060f1SDimitry Andric  def IXH32 : R_YXZ_SP_F1<0x2, 0x1,
528fe6060f1SDimitry Andric    BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 1)))>, "ixh32">;
529fe6060f1SDimitry Andric  def IXW32 : R_YXZ_SP_F1<0x2, 0x2,
530fe6060f1SDimitry Andric    BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 2)))>, "ixw32">;
531349cc55cSDimitry Andric  let Predicates = [iHas2E3] in
532fe6060f1SDimitry Andric  def IXD32 : R_YXZ_SP_F1<0x2, 0x4,
533fe6060f1SDimitry Andric    BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 3)))>, "ixd32">;
534fe6060f1SDimitry Andric
535349cc55cSDimitry Andric  let isCommutable = 1, isAdd = 1 in
536fe6060f1SDimitry Andric  def ADDC32 : R_YXZ<0x31, 0x0, 0x2, (outs GPR:$rz, CARRY:$cout),
537fe6060f1SDimitry Andric    (ins GPR:$rx, GPR:$ry, CARRY:$cin), "addc32", []>;
538fe6060f1SDimitry Andric  def SUBC32 : R_YXZ<0x31, 0x0, 0x8, (outs GPR:$rz, CARRY:$cout),
539fe6060f1SDimitry Andric    (ins GPR:$rx, GPR:$ry, CARRY:$cin), "subc32", []>;
540fe6060f1SDimitry Andric
541349cc55cSDimitry Andric  def INCF32 : I_5_ZX<0x3, 0x1, "incf32", uimm5, []>;
542349cc55cSDimitry Andric  def INCT32 : I_5_ZX<0x3, 0x2, "inct32", uimm5, []>;
543349cc55cSDimitry Andric  def DECF32 : I_5_ZX<0x3, 0x4, "decf32", uimm5, []>;
544349cc55cSDimitry Andric  def DECT32 : I_5_ZX<0x3, 0x8, "dect32", uimm5, []>;
545349cc55cSDimitry Andric}
546349cc55cSDimitry Andric
547349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
548e8d8bef9SDimitry Andric  def DIVS32 : R_YXZ_SP_F1<0x20, 0x2,
549e8d8bef9SDimitry Andric    BinOpFrag<(sdiv node:$LHS, node:$RHS)>, "divs32">;
550e8d8bef9SDimitry Andric  def DIVU32 : R_YXZ_SP_F1<0x20, 0x1,
551e8d8bef9SDimitry Andric    BinOpFrag<(udiv node:$LHS, node:$RHS)>, "divu32">;
552e8d8bef9SDimitry Andric
553fe6060f1SDimitry Andric  def DECGT32 : I_5_XZ<0x4, 0x1, "decgt32",
554fe6060f1SDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>;
555fe6060f1SDimitry Andric  def DECLT32 : I_5_XZ<0x4, 0x2, "declt32",
556fe6060f1SDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>;
557fe6060f1SDimitry Andric  def DECNE32 : I_5_XZ<0x4, 0x4, "decne32",
558fe6060f1SDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>;
559fe6060f1SDimitry Andric
560349cc55cSDimitry Andric  def SEXT32 : I_5_XZ_U<0x16, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), "sext32", []>;
561349cc55cSDimitry Andric  let isCodeGenOnly = 1 in {
562349cc55cSDimitry Andric  def SEXTB32 : I_5_XZ_US<0x16, 0, 7, "sextb32", sext_inreg, i8>;
563349cc55cSDimitry Andric  def SEXTH32 : I_5_XZ_US<0x16, 0, 15, "sexth32", sext_inreg, i16>;
564349cc55cSDimitry Andric  def ZEXTB32 : I_5_XZ_UZ<0x15, 0, 7, "zextb32", 255>;
565349cc55cSDimitry Andric  def ZEXTH32 : I_5_XZ_UZ<0x15, 0, 15, "zexth32", 65535>;
566349cc55cSDimitry Andric  }
567349cc55cSDimitry Andric  def ZEXT32 : I_5_XZ_U<0x15, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), "zext32",[]>;
568349cc55cSDimitry Andric
569349cc55cSDimitry Andric  let Constraints = "$rZ = $rz" in
570349cc55cSDimitry Andric  def INS32 : I_5_XZ_INS<0b010111, (outs GPR:$rz), (ins GPR:$rZ, GPR:$rx, uimm5_msb_size:$msb, uimm5:$lsb), "ins32", []>;
571349cc55cSDimitry Andric}
572349cc55cSDimitry Andric
573349cc55cSDimitry Andriclet Predicates = [iHas3E3r1] in {
574349cc55cSDimitry Andricdef MULTS32 : R_YXZ<0x3e, 0x20, 0x10, (outs GPRPair:$rz),
575349cc55cSDimitry Andric    (ins GPR:$rx, GPR:$ry), "mul.s32", []>;
576349cc55cSDimitry Andricdef MULTU32 : R_YXZ<0x3e, 0x20, 0x00, (outs GPRPair:$rz),
577349cc55cSDimitry Andric    (ins GPR:$rx, GPR:$ry), "mul.u32", []>;
578349cc55cSDimitry Andric
579349cc55cSDimitry Andriclet Constraints = "$rZ = $rz" in {
580349cc55cSDimitry Andricdef MULATS32 : R_YXZ<0x3e, 0x20, 0x14, (outs GPRPair:$rZ),
581349cc55cSDimitry Andric    (ins GPRPair:$rz, GPR:$rx, GPR:$ry), "mula.s32", []>;
582349cc55cSDimitry Andricdef MULATU32 : R_YXZ<0x3e, 0x20, 0x04, (outs GPRPair:$rZ),
583349cc55cSDimitry Andric    (ins GPRPair:$rz, GPR:$rx, GPR:$ry), "mula.u32", []>;
584349cc55cSDimitry Andric}
585349cc55cSDimitry Andric}
586349cc55cSDimitry Andric
587349cc55cSDimitry Andricdef MULSH32 : R_YXZ<0x31, 0b100100, 0b00001, (outs GPR:$rz),
588349cc55cSDimitry Andric    (ins GPR:$rx, GPR:$ry), "mulsh32", []>;
589fe6060f1SDimitry Andric
590fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
591fe6060f1SDimitry Andric// Load & Store instructions.
592fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
593fe6060f1SDimitry Andric
594fe6060f1SDimitry Andricdef LD32B : I_LD<AddrMode32B, 0x0, "ld32.b", uimm12>;
595fe6060f1SDimitry Andricdef LD32H : I_LD<AddrMode32H, 0x1, "ld32.h", uimm12_1>;
596fe6060f1SDimitry Andricdef LD32W : I_LD<AddrMode32WD, 0x2, "ld32.w", uimm12_2>;
597fe6060f1SDimitry Andric
598349cc55cSDimitry Andriclet OutOperandList = (outs GPRPair:$rz) in
599349cc55cSDimitry Andricdef LD32D : I_LD<AddrMode32WD, 0x3, "ld32.d", uimm12_2>;
600fe6060f1SDimitry Andric
601349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
602fe6060f1SDimitry Andric  def LD32BS : I_LD<AddrMode32B, 0x4, "ld32.bs", uimm12>;
603fe6060f1SDimitry Andric  def LD32HS : I_LD<AddrMode32H, 0x5, "ld32.hs", uimm12_1>;
604fe6060f1SDimitry Andric
605349cc55cSDimitry Andric  def LDM32 : I_5_YX<0b110100, 0b000111,
606349cc55cSDimitry Andric    (outs), (ins GPR:$rx, regseq:$regs, variable_ops), "ldm32\t$regs, (${rx})", []>;
607349cc55cSDimitry Andric  def STM32 : I_5_YX<0b110101, 0b000111,
608349cc55cSDimitry Andric    (outs), (ins GPR:$rx, regseq:$regs, variable_ops), "stm32\t$regs, (${rx})", []>;
609fe6060f1SDimitry Andric
610349cc55cSDimitry Andric  let Size = 4, isCodeGenOnly = 0 in {
611349cc55cSDimitry Andric  def LDQ32 : CSKYPseudo<(outs), (ins GPR:$rx, regseq:$regs, variable_ops),
612349cc55cSDimitry Andric                             "ldq32\t$regs, (${rx})", []>;
613349cc55cSDimitry Andric  def STQ32 : CSKYPseudo<(outs), (ins GPR:$rx, regseq:$regs, variable_ops),
614349cc55cSDimitry Andric                             "stq32\t$regs, (${rx})", []>;
615349cc55cSDimitry Andric  }
616349cc55cSDimitry Andric
617349cc55cSDimitry Andric}
618fe6060f1SDimitry Andric
619fe6060f1SDimitry Andricdef ST32B : I_ST<AddrMode32B, 0x0, "st32.b", uimm12>;
620fe6060f1SDimitry Andricdef ST32H : I_ST<AddrMode32H, 0x1, "st32.h", uimm12_1>;
621fe6060f1SDimitry Andricdef ST32W : I_ST<AddrMode32WD, 0x2, "st32.w", uimm12_2>;
622fe6060f1SDimitry Andric
623349cc55cSDimitry Andriclet InOperandList = (ins GPRPair:$rz, GPR:$rx, uimm12_2:$imm12 ) in
624349cc55cSDimitry Andricdef ST32D : I_ST<AddrMode32WD, 0x3, "st32.d", uimm12_2>;
625fe6060f1SDimitry Andric
626349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
627fe6060f1SDimitry Andric  def LDR32B :  I_LDR<0x0, "ldr32.b">;
628fe6060f1SDimitry Andric  def LDR32BS :  I_LDR<0x4, "ldr32.bs">;
629fe6060f1SDimitry Andric  def LDR32H :  I_LDR<0x1, "ldr32.h">;
630fe6060f1SDimitry Andric  def LDR32HS :  I_LDR<0x5, "ldr32.hs">;
631fe6060f1SDimitry Andric  def LDR32W :  I_LDR<0x2, "ldr32.w">;
632fe6060f1SDimitry Andric  def STR32B :  I_STR<0x0, "str32.b">;
633fe6060f1SDimitry Andric  def STR32H :  I_STR<0x1, "str32.h">;
634fe6060f1SDimitry Andric  def STR32W :  I_STR<0x2, "str32.w">;
635349cc55cSDimitry Andric}
636fe6060f1SDimitry Andric
637349cc55cSDimitry Andric// Indicate that we're dumping the CR register, so we'll need to
638349cc55cSDimitry Andric// scavenge a register for it.
639349cc55cSDimitry Andriclet mayStore = 1 in {
640349cc55cSDimitry Andricdef SPILL_CARRY : CSKYPseudo<(outs), (ins CARRY:$cond, GPR:$rx, uimm12_2:$imm),
641349cc55cSDimitry Andric                             "!SPILL_CARRY $cond, $rx, $imm", []>;
642349cc55cSDimitry Andric}
643349cc55cSDimitry Andric
644349cc55cSDimitry Andric// Indicate that we're restoring the CR register (previously
645349cc55cSDimitry Andric// spilled), so we'll need to scavenge a register for it.
646349cc55cSDimitry Andriclet mayLoad = 1 in {
647349cc55cSDimitry Andricdef RESTORE_CARRY : CSKYPseudo<(outs CARRY:$cond), (ins GPR:$rx, uimm12_2:$imm),
648349cc55cSDimitry Andric                                "!RESTORE_CARRY $cond, $rx, $imm", []>;
649349cc55cSDimitry Andric}
650349cc55cSDimitry Andric
651349cc55cSDimitry Andriclet mayLoad = 1 in {
652349cc55cSDimitry Andricdef STORE_PAIR : CSKYPseudo<(outs), (ins GPRPair:$rz, GPR:$rx, uimm12_2:$imm),
653349cc55cSDimitry Andric                            "!STORE_PAIR $rz, $rx, $imm", []>;
654349cc55cSDimitry Andric}
655349cc55cSDimitry Andric
656349cc55cSDimitry Andriclet mayLoad = 1 in {
657349cc55cSDimitry Andricdef LOAD_PAIR : CSKYPseudo<(outs GPRPair:$rz), (ins GPR:$rx, uimm12_2:$imm),
658349cc55cSDimitry Andric                            "!LOAD_PAIR $rz, $rx, $imm", []>;
659349cc55cSDimitry Andric}
660fe6060f1SDimitry Andric
661fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
662fe6060f1SDimitry Andric// Compare instructions.
663fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
664349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
665fe6060f1SDimitry Andric  def CMPNEI32 : I_16_X<0x1A, "cmpnei32", uimm16>;
666fe6060f1SDimitry Andric  def CMPHSI32 : I_16_X<0x18, "cmphsi32", oimm16>;
667fe6060f1SDimitry Andric  def CMPLTI32 : I_16_X<0x19, "cmplti32", oimm16>;
668349cc55cSDimitry Andric  def CMPLEI32 : CSKYPseudo<(outs CARRY:$ca), (ins GPR:$rx, uimm16:$imm16),
669349cc55cSDimitry Andric    "cmplei32\t$rx, $imm16", []>;
670349cc55cSDimitry Andric}
671349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
672fe6060f1SDimitry Andric  def CMPNE32 : R_YX<0x1, 0x4, "cmpne32">;
673fe6060f1SDimitry Andric  def CMPHS32 : R_YX<0x1, 0x1, "cmphs32">;
674fe6060f1SDimitry Andric  def CMPLT32 : R_YX<0x1, 0x2, "cmplt32">;
675fe6060f1SDimitry Andric
676349cc55cSDimitry Andric  def SETC32 : CSKY32Inst<AddrModeNone, 0x31,
677349cc55cSDimitry Andric    (outs CARRY:$ca), (ins), "setc32", []> {
678349cc55cSDimitry Andric    let Inst{25 - 21} = 0; //rx
679349cc55cSDimitry Andric    let Inst{20 - 16} = 0; //ry
680349cc55cSDimitry Andric    let Inst{15 - 10} = 0x1;
681349cc55cSDimitry Andric    let Inst{9 - 5} = 0x1;
682349cc55cSDimitry Andric    let Inst{4 - 0} = 0;
683349cc55cSDimitry Andric    let isCompare = 1;
684349cc55cSDimitry Andric  }
685349cc55cSDimitry Andric  def CLRC32 : CSKY32Inst<AddrModeNone, 0x31,
686349cc55cSDimitry Andric    (outs CARRY:$ca), (ins), "clrc32", []> {
687349cc55cSDimitry Andric    let Inst{25 - 21} = 0; //rx
688349cc55cSDimitry Andric    let Inst{20 - 16} = 0; //ry
689349cc55cSDimitry Andric    let Inst{15 - 10} = 0x1;
690349cc55cSDimitry Andric    let Inst{9 - 5} = 0x4;
691349cc55cSDimitry Andric    let Inst{4 - 0} = 0;
692349cc55cSDimitry Andric    let isCompare = 1;
693349cc55cSDimitry Andric  }
694349cc55cSDimitry Andric
695349cc55cSDimitry Andric  def TST32 : R_YX<0x8, 0x4, "tst32">;
696349cc55cSDimitry Andric  def TSTNBZ32 : R_X<0x8, 0x8,
697349cc55cSDimitry Andric    (outs CARRY:$ca), (ins GPR:$rx), "tstnbz32", []>;
698349cc55cSDimitry Andric}
699fe6060f1SDimitry Andric
700fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
701fe6060f1SDimitry Andric// Data move instructions.
702fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
703fe6060f1SDimitry Andric
704349cc55cSDimitry Andriclet Predicates= [iHasE2] in {
705349cc55cSDimitry Andric  let isCodeGenOnly = 1 in {
706fe6060f1SDimitry Andric  def MOVT32 : R_ZX<0x3, 0x2, "movt32", []>;
707fe6060f1SDimitry Andric  def MOVF32 : R_ZX<0x3, 0x1, "movf32", []>;
708349cc55cSDimitry Andric  }
709fe6060f1SDimitry Andric  def MOVI32 : I_16_MOV<0x10, "movi32", uimm16>;
710349cc55cSDimitry Andric  let Size = 4, isCodeGenOnly = 0 in
711349cc55cSDimitry Andric  def BGENI : CSKYPseudo<(outs GPR:$dst), (ins uimm5:$imm), "bgeni\t$dst, $imm", []>;
712349cc55cSDimitry Andric  def : InstAlias<"bgeni16 $dst, $imm", (BGENI GPR:$dst, uimm5:$imm)>;
713349cc55cSDimitry Andric  def : InstAlias<"bgeni32 $dst, $imm", (BGENI GPR:$dst, uimm5:$imm)>;
714fe6060f1SDimitry Andric  def MOVIH32 : I_16_MOV<0x11, "movih32", uimm16_16_xform>;
715fe6060f1SDimitry Andric  def MVC32 : R_Z_1<0x1, 0x8, "mvc32">;
716349cc55cSDimitry Andric  let isCodeGenOnly = 1 in
717fe6060f1SDimitry Andric  def MOV32 : R_XZ<0x12, 0x1, "mov32">;
718fe6060f1SDimitry Andric
719349cc55cSDimitry Andric  let usesCustomInserter = 1 in
720349cc55cSDimitry Andric  def ISEL32 : CSKYPseudo<(outs GPR:$dst), (ins CARRY:$cond, GPR:$src1, GPR:$src2),
721349cc55cSDimitry Andric    "!isel32\t$dst, $src1, src2", [(set GPR:$dst, (select CARRY:$cond, GPR:$src1, GPR:$src2))]>;
722349cc55cSDimitry Andric}
723fe6060f1SDimitry Andric
724349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
725fe6060f1SDimitry Andric  def MVCV32 : R_Z_1<0x1, 0x10, "mvcv32">;
726fe6060f1SDimitry Andric  def CLRF32 : R_Z_2<0xB, 0x1, "clrf32", []>;
727fe6060f1SDimitry Andric  def CLRT32 : R_Z_2<0xB, 0x2, "clrt32", []>;
728349cc55cSDimitry Andric}
729fe6060f1SDimitry Andric
730fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
731fe6060f1SDimitry Andric// Branch and call instructions.
732fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
733fe6060f1SDimitry Andric
734fe6060f1SDimitry Andriclet isBranch = 1, isTerminator = 1 in {
735fe6060f1SDimitry Andric  let isBarrier = 1, isPredicable = 1 in
736fe6060f1SDimitry Andric    def BR32 : I_16_L<0x0, (outs), (ins br_symbol:$imm16), "br32\t$imm16",
737fe6060f1SDimitry Andric                     [(br bb:$imm16)]>;
738fe6060f1SDimitry Andric
739fe6060f1SDimitry Andric  def BT32 : I_16_L<0x3, (outs), (ins CARRY:$ca, br_symbol:$imm16),
740349cc55cSDimitry Andric    "bt32\t$imm16", [(brcond CARRY:$ca, bb:$imm16)]>, Requires<[iHasE2]>;
741fe6060f1SDimitry Andric  def BF32 : I_16_L<0x2, (outs), (ins CARRY:$ca, br_symbol:$imm16),
742349cc55cSDimitry Andric    "bf32\t$imm16", []>, Requires<[iHasE2]>;
743fe6060f1SDimitry Andric}
744fe6060f1SDimitry Andric
745349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
746fe6060f1SDimitry Andric  def BEZ32 : I_16_X_L<0x8, "bez32", br_symbol>;
747fe6060f1SDimitry Andric  def BNEZ32 : I_16_X_L<0x9, "bnez32", br_symbol>;
748fe6060f1SDimitry Andric  def BHZ32 : I_16_X_L<0xA, "bhz32", br_symbol>;
749fe6060f1SDimitry Andric  def BLSZ32 : I_16_X_L<0xB, "blsz32", br_symbol>;
750fe6060f1SDimitry Andric  def BLZ32 : I_16_X_L<0xC, "blz32", br_symbol>;
751fe6060f1SDimitry Andric  def BHSZ32 : I_16_X_L<0xD, "bhsz32", br_symbol>;
752fe6060f1SDimitry Andric
753fe6060f1SDimitry Andric  let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
754fe6060f1SDimitry Andric    def JMP32 : I_16_JX<0x6, "jmp32", [(brind GPR:$rx)]>; // jmp to register
755fe6060f1SDimitry Andric    def JMPI32 : I_16_L<0x16, (outs), (ins constpool_symbol:$imm16),
756fe6060f1SDimitry Andric                   "jmpi32\t$imm16", []>;
757fe6060f1SDimitry Andric  }
758fe6060f1SDimitry Andric
759fe6060f1SDimitry Andric  let isCall = 1, Defs = [ R15 ] in
760fe6060f1SDimitry Andric    def JSR32 : I_16_JX<0x7, "jsr32", []>;
761fe6060f1SDimitry Andric
762fe6060f1SDimitry Andric  let isCall = 1, Defs = [ R15 ] , mayLoad = 1 in
763fe6060f1SDimitry Andric    def JSRI32: I_16_L<0x17, (outs),
764fe6060f1SDimitry Andric      (ins constpool_symbol:$imm16), "jsri32\t$imm16", []>;
765349cc55cSDimitry Andric}
766fe6060f1SDimitry Andric
767349cc55cSDimitry Andricdef BNEZAD32 : CSKY32Inst<AddrModeNone, 0x3a,
768349cc55cSDimitry Andric  (outs GPR:$rx_u), (ins GPR:$rx, br_symbol:$imm16), "bnezad32\t$rx, $imm16", []> {
769349cc55cSDimitry Andric  bits<5> rx;
770349cc55cSDimitry Andric  bits<16> imm16;
771349cc55cSDimitry Andric  let Inst{25 - 21} = 0x1;
772349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
773349cc55cSDimitry Andric  let Inst{15 - 0} = imm16;
774349cc55cSDimitry Andric  let isBranch = 1;
775349cc55cSDimitry Andric  let isTerminator = 1;
776349cc55cSDimitry Andric  let Constraints = "$rx_u = $rx";
777349cc55cSDimitry Andric  let Predicates = [iHas2E3, iHas10E60];
778349cc55cSDimitry Andric}
779fe6060f1SDimitry Andric
780fe6060f1SDimitry Andricdef BSR32 : J<0x38, (outs), (ins call_symbol:$offset), "bsr32", []>;
781fe6060f1SDimitry Andric
782349cc55cSDimitry Andricdef : InstAlias<"bsr $dst", (BSR32 call_symbol:$dst)>;
783349cc55cSDimitry Andric
784fe6060f1SDimitry Andricdef BSR32_BR : J<0x38, (outs), (ins call_symbol:$offset), "bsr32", []>{
785fe6060f1SDimitry Andric  let isCodeGenOnly = 1;
786fe6060f1SDimitry Andric  let isBranch = 1;
787fe6060f1SDimitry Andric  let isTerminator = 1;
788fe6060f1SDimitry Andric  let isBarrier = 1;
789fe6060f1SDimitry Andric  let isPredicable = 1;
790fe6060f1SDimitry Andric  let Defs = [ R15 ];
791fe6060f1SDimitry Andric}
792fe6060f1SDimitry Andric
793fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
794fe6060f1SDimitry Andric// Symbol address instructions.
795fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
796fe6060f1SDimitry Andric
797349cc55cSDimitry Andricdef data_symbol_b : data_symbol<"CSKY::fixup_csky_doffset_imm18", 0>;
798349cc55cSDimitry Andricdef data_symbol_h : data_symbol<"CSKY::fixup_csky_doffset_imm18_scale2", 1>;
799349cc55cSDimitry Andricdef data_symbol_w : data_symbol<"CSKY::fixup_csky_doffset_imm18_scale4", 2> {
800349cc55cSDimitry Andric  let ParserMatchClass = DataAsmClass;
801349cc55cSDimitry Andric}
802349cc55cSDimitry Andric
803349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
804349cc55cSDimitry Andric
805fe6060f1SDimitry Andricdef GRS32 : I_18_Z_L<0x3, "grs32\t$rz, $offset",
806fe6060f1SDimitry Andric                    (outs GPR:$rz), (ins bare_symbol:$offset), []>;
807349cc55cSDimitry Andricdef : InstAlias<"grs\t$rz, $offset", (GRS32 GPR:$rz, bare_symbol:$offset)>;
808349cc55cSDimitry Andric
809349cc55cSDimitry Andriclet Uses = [R28] in {
810349cc55cSDimitry Andricdef LRS32B : I_18_Z_L<0x0, "lrs32.b\t$rz, $offset",
811349cc55cSDimitry Andric                    (outs GPR:$rz), (ins data_symbol_b:$offset), []>;
812349cc55cSDimitry Andricdef LRS32H : I_18_Z_L<0x1, "lrs32.h\t$rz, $offset",
813349cc55cSDimitry Andric                    (outs GPR:$rz), (ins data_symbol_h:$offset), []>;
814349cc55cSDimitry Andricdef LRS32W : I_18_Z_L<0x2, "lrs32.w\t$rz, $offset",
815349cc55cSDimitry Andric                    (outs GPR:$rz), (ins data_symbol_w:$offset), []>;
816349cc55cSDimitry Andricdef SRS32B : I_18_Z_L<0x4, "srs32.b\t$rz, $offset",
817349cc55cSDimitry Andric                    (outs), (ins GPR:$rz, data_symbol_b:$offset), []>;
818349cc55cSDimitry Andricdef SRS32H : I_18_Z_L<0x5, "srs32.h\t$rz, $offset",
819349cc55cSDimitry Andric                    (outs), (ins GPR:$rz, data_symbol_h:$offset), []>;
820349cc55cSDimitry Andricdef SRS32W : I_18_Z_L<0x6, "srs32.w\t$rz, $offset",
821349cc55cSDimitry Andric                    (outs), (ins GPR:$rz, data_symbol_w:$offset), []>;
822349cc55cSDimitry Andric}
823349cc55cSDimitry Andric
824349cc55cSDimitry Andricdef PUSH32 : I_12_PP<0b11111, 0b00000, (outs), (ins reglist:$regs, variable_ops), "push32 $regs">;
825349cc55cSDimitry Andric
826349cc55cSDimitry Andriclet Uses = [R14, R15], isReturn = 1, isTerminator = 1, isBarrier = 1 in
827349cc55cSDimitry Andricdef POP32 : I_12_PP<0b11110, 0b00000, (outs), (ins reglist:$regs, variable_ops), "pop32 $regs">;
828349cc55cSDimitry Andric
829349cc55cSDimitry Andric}
830fe6060f1SDimitry Andric
831fe6060f1SDimitry Andriclet mayLoad = 1, mayStore = 0 in {
832fe6060f1SDimitry Andricdef LRW32 : I_16_Z_L<0x14, "lrw32", (ins constpool_symbol:$imm16), []>;
833fe6060f1SDimitry Andriclet isCodeGenOnly = 1 in
834349cc55cSDimitry Andricdef LRW32_Gen : I_16_Z_L<0x14, "lrw32", (ins bare_symbol:$src1, constpool_symbol:$imm16), []>;
835fe6060f1SDimitry Andric}
836fe6060f1SDimitry Andric
837349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
838349cc55cSDimitry Andric// Atomic and fence instructions.
839349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
840349cc55cSDimitry Andric
841349cc55cSDimitry Andriclet Predicates = [iHasMP1E2] in {
842349cc55cSDimitry Andric  def BRWARW : BAR<0b01111, "bar.brwarw", 0>;
843349cc55cSDimitry Andric  def BRWARWS : BAR<0b01111, "bar.brwarws", 1>;
844349cc55cSDimitry Andric  def BRARW : BAR<0b00111, "bar.brarw", 0>;
845349cc55cSDimitry Andric  def BRARWS : BAR<0b00111, "bar.brarws", 1>;
846349cc55cSDimitry Andric  def BRWAW : BAR<0b01110, "bar.brwaw", 0>;
847349cc55cSDimitry Andric  def BRWAWS : BAR<0b01110, "bar.brwaws", 1>;
848349cc55cSDimitry Andric  def BRAR : BAR<0b00101, "bar.brar", 0>;
849349cc55cSDimitry Andric  def BRARS : BAR<0b00101, "bar.brars", 1>;
850349cc55cSDimitry Andric  def BWAW : BAR<0b01010, "bar.bwaw", 0>;
851349cc55cSDimitry Andric  def BWAWS : BAR<0b01010, "bar.bwaws", 1>;
852349cc55cSDimitry Andric
853349cc55cSDimitry Andric  def LDEX32W : I_LD<AddrMode32WD, 0x7, "ldex32.w", uimm12_2>;
854349cc55cSDimitry Andric  let Constraints = "$rd = $rz" in
855349cc55cSDimitry Andric    def STEX32W : I_LDST<AddrMode32WD, 0x37, 7,
856349cc55cSDimitry Andric      (outs GPR:$rd), (ins GPR:$rz, GPR:$rx, uimm12_2:$imm12), "stex32.w", []>;
857349cc55cSDimitry Andric}
858349cc55cSDimitry Andric
859349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
860349cc55cSDimitry Andric// Other operation instructions.
861349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
862349cc55cSDimitry Andric
863349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
864349cc55cSDimitry Andric  def BREV32 : R_XZ<0x18, 0x10, "brev32">;
865349cc55cSDimitry Andric  def ABS32 : R_XZ<0x0, 0x10, "abs32">;
866349cc55cSDimitry Andric  def BGENR32 : R_XZ<0x14, 0x2, "bgenr32">;
867349cc55cSDimitry Andric}
868349cc55cSDimitry Andric
869349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
870349cc55cSDimitry Andric  def REVB32 : R_XZ<0x18, 0x4, "revb32">;
871349cc55cSDimitry Andric  def REVH32 : R_XZ<0x18, 0x8, "revh32">;
872349cc55cSDimitry Andric  def FF0 : R_XZ<0x1F, 0x1, "ff0.32">;
873349cc55cSDimitry Andric  def FF1 : R_XZ<0x1F, 0x2, "ff1.32">;
874349cc55cSDimitry Andric  def XTRB0 : R_XZ<0x1C, 0x1, "xtrb0.32">;
875349cc55cSDimitry Andric  def XTRB1 : R_XZ<0x1C, 0x2, "xtrb1.32">;
876349cc55cSDimitry Andric  def XTRB2 : R_XZ<0x1C, 0x4, "xtrb2.32">;
877349cc55cSDimitry Andric  def XTRB3 : R_XZ<0x1C, 0x8, "xtrb3.32">;
878349cc55cSDimitry Andric  def BTSTI32 : I_5_X<0x0A, 0x4, "btsti32", uimm5, []>;
879349cc55cSDimitry Andric  def BCLRI32 : I_5_XZ<0xA, 0x1, "bclri32",
880349cc55cSDimitry Andric  (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
881349cc55cSDimitry Andric  def BSETI32 : I_5_XZ<0xA, 0x2, "bseti32",
882349cc55cSDimitry Andric  (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
883349cc55cSDimitry Andric}
884349cc55cSDimitry Andric
885349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
886349cc55cSDimitry Andric// Special instructions.
887349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
888349cc55cSDimitry Andric
889349cc55cSDimitry Andricdef MFFCR : CSKY32Inst<AddrModeNone, 0x30,
890349cc55cSDimitry Andric  (outs GPR:$rx), (ins), "mfcr\t$rx, fcr", []> {
891349cc55cSDimitry Andric  bits<5> rx;
892349cc55cSDimitry Andric
893349cc55cSDimitry Andric  let Inst{25 - 21} = 0b00010;
894349cc55cSDimitry Andric  let Inst{20 - 16} = 0b00001;
895349cc55cSDimitry Andric  let Inst{15 - 10} = 0b011000;
896349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
897349cc55cSDimitry Andric  let Inst{4 - 0} = rx;
898349cc55cSDimitry Andric  let hasSideEffects = 1;
899349cc55cSDimitry Andric  let isCodeGenOnly = 1;
900349cc55cSDimitry Andric}
901349cc55cSDimitry Andric
902349cc55cSDimitry Andricdef MTFCR : CSKY32Inst<AddrModeNone, 0x30,
903349cc55cSDimitry Andric  (outs), (ins GPR:$rx), "mtcr\t$rx, fcr", []> {
904349cc55cSDimitry Andric  bits<5> rx;
905349cc55cSDimitry Andric
906349cc55cSDimitry Andric  let Inst{25 - 21} = 0b00010;
907349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
908349cc55cSDimitry Andric  let Inst{15 - 10} = 0b011001;
909349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
910349cc55cSDimitry Andric  let Inst{4 - 0} = 0b00001;
911349cc55cSDimitry Andric  let hasSideEffects = 1;
912349cc55cSDimitry Andric  let isCodeGenOnly = 1;
913349cc55cSDimitry Andric}
914349cc55cSDimitry Andric
915349cc55cSDimitry Andricdef SYNC32 : I_5_IMM5<0x30, 0b000001, 0b00001, "sync32", uimm5, []>;
916349cc55cSDimitry Andric
917349cc55cSDimitry Andricdef SYNC0_32 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
918349cc55cSDimitry Andric                 "sync32", []> {
919349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
920349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
921349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
922349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
923349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
924349cc55cSDimitry Andric}
925349cc55cSDimitry Andric
926349cc55cSDimitry Andricdef SYNC_32_I : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
927349cc55cSDimitry Andric                 "sync32.i", []> {
928349cc55cSDimitry Andric  let Inst{25 - 21} = 1;
929349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
930349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
931349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
932349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
933349cc55cSDimitry Andric}
934349cc55cSDimitry Andric
935349cc55cSDimitry Andricdef SYNC_32_S : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
936349cc55cSDimitry Andric                 "sync32.s", []> {
937349cc55cSDimitry Andric  let Inst{25 - 21} = 0b10000;
938349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
939349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
940349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
941349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
942349cc55cSDimitry Andric}
943349cc55cSDimitry Andric
944349cc55cSDimitry Andricdef SYNC_32_IS : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
945349cc55cSDimitry Andric                 "sync32.is", []> {
946349cc55cSDimitry Andric  let Inst{25 - 21} = 0b10001;
947349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
948349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
949349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
950349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
951349cc55cSDimitry Andric}
952349cc55cSDimitry Andric
953349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
954349cc55cSDimitry Andric  def RFI32 : I_5_XZ_PRIVI<0x11, 0x1, "rfi32">;
955349cc55cSDimitry Andric  def SCE32 : I_5_IMM5<0x30, 0b000110, 0b00001, "sce32", uimm4, []>;
956349cc55cSDimitry Andric}
957349cc55cSDimitry Andriclet Predicates = [HasExtendLrw] in
958349cc55cSDimitry Andricdef IDLY32 : I_5_IMM5<0x30, 0b000111, 0b00001, "idly32", imm5_idly, []>;
959349cc55cSDimitry Andricdef STOP32 : I_5_XZ_PRIVI<0x12, 0x1, "stop32">;
960349cc55cSDimitry Andricdef WAIT32 : I_5_XZ_PRIVI<0x13, 0x1, "wait32">;
961349cc55cSDimitry Andricdef DOZE32 : I_5_XZ_PRIVI<0x14, 0x1, "doze32">;
962349cc55cSDimitry Andricdef WE32 : I_5_XZ_PRIVI<0b010101, 0x1, "we32">;
963349cc55cSDimitry Andricdef SE32 : I_5_XZ_PRIVI<0b010110, 0x1, "se32">;
964349cc55cSDimitry Andricdef WSC32 : I_5_XZ_PRIVI<0b001111, 0x1, "wsc32">;
965349cc55cSDimitry Andric
966349cc55cSDimitry Andricdef CPOP32 : I_CPOP<(outs), (ins uimm5:$cpid, uimm20:$usdef), "cpop32 <$cpid, ${usdef}>">;
967349cc55cSDimitry Andricdef CPRC32 : I_CP<0b0100, (outs CARRY:$ca), (ins uimm5:$cpid, uimm12:$usdef), "cprc32 <$cpid, ${usdef}>">;
968349cc55cSDimitry Andricdef CPRCR32 : I_CP_Z<0b0010, (outs GPR:$rz), (ins uimm5:$cpid, uimm12:$usdef), "cprcr32 $rz, <$cpid, ${usdef}>">;
969349cc55cSDimitry Andricdef CPRGR32 : I_CP_Z<0b0000, (outs GPR:$rz), (ins uimm5:$cpid, uimm12:$usdef), "cprgr32 $rz, <$cpid, ${usdef}>">;
970349cc55cSDimitry Andricdef CPWCR32 : I_CP_Z<0b0011, (outs), (ins GPR:$rz, uimm5:$cpid, uimm12:$usdef), "cpwcr32 $rz, <$cpid, ${usdef}>">;
971349cc55cSDimitry Andricdef CPWGR32 : I_CP_Z<0b0001, (outs), (ins GPR:$rz, uimm5:$cpid, uimm12:$usdef), "cpwgr32 $rz, <$cpid, ${usdef}>">;
972349cc55cSDimitry Andric
973349cc55cSDimitry Andriclet Predicates = [iHas3r2E3r3] in {
974349cc55cSDimitry Andricdef DCACHE_IALL32 : I_5_CACHE<0b100101, 0b01000, "dcache32.iall">;
975349cc55cSDimitry Andricdef DCACHE_CALL32 : I_5_CACHE<0b100101, 0b00100, "dcache32.call">;
976349cc55cSDimitry Andricdef DCACHE_CIALL32 : I_5_CACHE<0b100101, 0b01100, "dcache32.ciall">;
977349cc55cSDimitry Andricdef DCACHE_IVA32 : I_5_X_CACHE<0b100101, 0b01011, "dcache32.iva">;
978349cc55cSDimitry Andricdef DCACHE_ISW32: I_5_X_CACHE<0b100101, 0b01010, "dcache32.isw">;
979349cc55cSDimitry Andricdef DCACHE_CVA32 : I_5_X_CACHE<0b100101, 0b00111, "dcache32.cva">;
980349cc55cSDimitry Andricdef DCACHE_CVAL32 : I_5_X_CACHE<0b100101, 0b10111, "dcache32.cval1">;
981349cc55cSDimitry Andricdef DCACHE_CSW32 : I_5_X_CACHE<0b100101, 0b00110, "dcache32.csw">;
982349cc55cSDimitry Andricdef DCACHE_CIVA32 : I_5_X_CACHE<0b100101, 0b01111, "dcache32.civa">;
983349cc55cSDimitry Andricdef DCACHE_CISW32 : I_5_X_CACHE<0b100101, 0b01110, "dcache32.cisw">;
984349cc55cSDimitry Andric
985349cc55cSDimitry Andricdef ICACHE_IALL32 : I_5_CACHE<0b100100, 0b01000, "icache32.iall">;
986349cc55cSDimitry Andricdef ICACHE_IALLS32 : I_5_CACHE<0b100100, 0b11000, "icache32.ialls">;
987349cc55cSDimitry Andricdef ICACHE_IVA32 : I_5_X_CACHE<0b100100, 0b01011, "icache32.iva">;
988349cc55cSDimitry Andric
989349cc55cSDimitry Andricdef TLBI_VAA32 : I_5_X_CACHE<0b100010, 0b00010, "tlbi32.vaa">;
990349cc55cSDimitry Andricdef TLBI_VAAS32 : I_5_X_CACHE<0b100010, 0b10010, "tlbi32.vaas">;
991349cc55cSDimitry Andricdef TLBI_ASID32 : I_5_X_CACHE<0b100010, 0b00001, "tlbi32.asid">;
992349cc55cSDimitry Andricdef TLBI_ASIDS32 : I_5_X_CACHE<0b100010, 0b10001, "tlbi32.asids">;
993349cc55cSDimitry Andricdef TLBI_VA32 : I_5_X_CACHE<0b100010, 0b00011, "tlbi32.va">;
994349cc55cSDimitry Andricdef TLBI_VAS32 : I_5_X_CACHE<0b100010, 0b10011, "tlbi32.vas">;
995349cc55cSDimitry Andricdef TLBI_ALL32 : I_5_CACHE<0b100010, 0b00000, "tlbi32.all">;
996349cc55cSDimitry Andricdef TLBI_ALLS32 : I_5_CACHE<0b100010, 0b10000, "tlbi32.alls">;
997349cc55cSDimitry Andric
998349cc55cSDimitry Andricdef L2CACHE_IALL : I_5_CACHE<0b100110, 0b01000, "l2cache.iall">;
999349cc55cSDimitry Andricdef L2CACHE_CALL : I_5_CACHE<0b100110, 0b00100, "l2cache.call">;
1000349cc55cSDimitry Andricdef L2CACHE_CIALL : I_5_CACHE<0b100110, 0b01100, "l2cache.ciall">;
1001349cc55cSDimitry Andric}
1002349cc55cSDimitry Andric
1003349cc55cSDimitry Andricdef PLDR32 :I_PLDR<AddrMode32WD, 0x36, 0b0110, (outs), (ins GPR:$rx, uimm12_2:$imm12), "pldr32", []>;
1004349cc55cSDimitry Andricdef PLDW32 :I_PLDR<AddrMode32WD, 0x37, 0b0110, (outs), (ins GPR:$rx, uimm12_2:$imm12), "pldw32", []>;
1005349cc55cSDimitry Andric
1006349cc55cSDimitry Andricdef TRAP32 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins uimm2:$imm2), "trap32 ${imm2}", []> {
1007349cc55cSDimitry Andric  bits<2> imm2;
1008349cc55cSDimitry Andric
1009349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
1010349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
1011349cc55cSDimitry Andric  let Inst{15 - 12} = 0b0010;
1012349cc55cSDimitry Andric  let Inst{11 - 10} = imm2;
1013349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
1014349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
1015349cc55cSDimitry Andric
1016349cc55cSDimitry Andric}
1017349cc55cSDimitry Andric
10180eae32dcSDimitry Andric//===----------------------------------------------------------------------===//
10190eae32dcSDimitry Andric// Instruction Patterns.
10200eae32dcSDimitry Andric//===----------------------------------------------------------------------===//
10210eae32dcSDimitry Andric
10220eae32dcSDimitry Andric// Load & Store Patterns
10230eae32dcSDimitry Andricmulticlass LdPat<PatFrag LoadOp, ImmLeaf imm_type, Instruction Inst, ValueType Type> {
10240eae32dcSDimitry Andric  def : Pat<(Type (LoadOp GPR:$rs1)), (Inst GPR:$rs1, 0)>;
10250eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (i32 frameindex:$rs1))), (Inst (i32 (to_tframeindex tframeindex:$rs1)), 0)>;
10260eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, imm_type:$uimm))),
10270eae32dcSDimitry Andric            (Inst GPR:$rs1, imm_type:$uimm)>;
10280eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add frameindex:$rs1, imm_type:$uimm))),
10290eae32dcSDimitry Andric            (Inst (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm)>;
10300eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (eqToAdd frameindex:$rs1, imm_type:$uimm))),
10310eae32dcSDimitry Andric            (Inst (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm)>;
10320eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, tglobaladdr:$gd))),
10330eae32dcSDimitry Andric            (Inst GPR:$rs1, tglobaladdr:$gd)>;
10340eae32dcSDimitry Andric}
10350eae32dcSDimitry Andric
10360eae32dcSDimitry Andricdefm : LdPat<extloadi8, uimm12, LD32B, i32>;
10370eae32dcSDimitry Andricdefm : LdPat<zextloadi8, uimm12, LD32B, i32>;
10380eae32dcSDimitry Andriclet Predicates = [iHasE2] in {
10390eae32dcSDimitry Andric  defm : LdPat<sextloadi8, uimm12, LD32BS, i32>;
10400eae32dcSDimitry Andric}
10410eae32dcSDimitry Andricdefm : LdPat<extloadi16, uimm12_1, LD32H, i32>;
10420eae32dcSDimitry Andricdefm : LdPat<zextloadi16, uimm12_1, LD32H, i32>;
10430eae32dcSDimitry Andriclet Predicates = [iHasE2] in {
10440eae32dcSDimitry Andricdefm : LdPat<sextloadi16, uimm12_1, LD32HS, i32>;
10450eae32dcSDimitry Andric}
10460eae32dcSDimitry Andricdefm : LdPat<load, uimm12_2, LD32W, i32>;
10470eae32dcSDimitry Andric
10480eae32dcSDimitry Andricmulticlass LdrPat<PatFrag LoadOp, Instruction Inst, ValueType Type> {
10490eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, GPR:$rs2))), (Inst GPR:$rs1, GPR:$rs2, 0)>;
10500eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 1))))), (Inst GPR:$rs1, GPR:$rs2, 1)>;
10510eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 2))))), (Inst GPR:$rs1, GPR:$rs2, 2)>;
10520eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 3))))), (Inst GPR:$rs1, GPR:$rs2, 3)>;
10530eae32dcSDimitry Andric}
10540eae32dcSDimitry Andric
10550eae32dcSDimitry Andriclet Predicates = [iHas2E3] in {
10560eae32dcSDimitry Andric  defm : LdrPat<zextloadi8, LDR32B, i32>;
10570eae32dcSDimitry Andric  defm : LdrPat<sextloadi8, LDR32BS, i32>;
10580eae32dcSDimitry Andric  defm : LdrPat<extloadi8, LDR32BS, i32>;
10590eae32dcSDimitry Andric  defm : LdrPat<zextloadi16, LDR32H, i32>;
10600eae32dcSDimitry Andric  defm : LdrPat<sextloadi16, LDR32HS, i32>;
10610eae32dcSDimitry Andric  defm : LdrPat<extloadi16, LDR32HS, i32>;
10620eae32dcSDimitry Andric  defm : LdrPat<load, LDR32W, i32>;
10630eae32dcSDimitry Andric}
10640eae32dcSDimitry Andric
10650eae32dcSDimitry Andricmulticlass StPat<PatFrag StoreOp, ValueType Type, ImmLeaf imm_type, Instruction Inst> {
10660eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, GPR:$rs1), (Inst Type:$rs2, GPR:$rs1, 0)>;
10670eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, frameindex:$rs1), (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), 0)>;
10680eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, (add GPR:$rs1, imm_type:$uimm12)),
10690eae32dcSDimitry Andric            (Inst Type:$rs2, GPR:$rs1, imm_type:$uimm12)>;
10700eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, (add frameindex:$rs1, imm_type:$uimm12)),
10710eae32dcSDimitry Andric            (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm12)>;
10720eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, (eqToAdd frameindex:$rs1, imm_type:$uimm12)),
10730eae32dcSDimitry Andric            (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm12)>;
10740eae32dcSDimitry Andric}
10750eae32dcSDimitry Andric
10760eae32dcSDimitry Andricdefm : StPat<truncstorei8, i32, uimm12, ST32B>;
10770eae32dcSDimitry Andricdefm : StPat<truncstorei16, i32, uimm12_1, ST32H>;
10780eae32dcSDimitry Andricdefm : StPat<store, i32, uimm12_2, ST32W>;
10790eae32dcSDimitry Andric
10800eae32dcSDimitry Andricmulticlass StrPat<PatFrag StoreOp, ValueType Type, Instruction Inst> {
10810eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, GPR:$rs2)), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 0)>;
10820eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 1)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 1)>;
10830eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 2)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 2)>;
10840eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 3)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 3)>;
10850eae32dcSDimitry Andric}
10860eae32dcSDimitry Andric
10870eae32dcSDimitry Andriclet Predicates = [iHas2E3] in {
10880eae32dcSDimitry Andric  defm : StrPat<truncstorei8, i32, STR32B>;
10890eae32dcSDimitry Andric  defm : StrPat<truncstorei16, i32, STR32H>;
10900eae32dcSDimitry Andric  defm : StrPat<store, i32, STR32W>;
10910eae32dcSDimitry Andric
10920eae32dcSDimitry Andric  // Sext & Zext Patterns
10930eae32dcSDimitry Andric  def : Pat<(sext_inreg GPR:$src, i1), (SEXT32 GPR:$src, 0, 0)>;
10940eae32dcSDimitry Andric  def : Pat<(and GPR:$src, 255), (ZEXT32 GPR:$src, 7, 0)>;
10950eae32dcSDimitry Andric  def : Pat<(and GPR:$src, 65535), (ZEXT32 GPR:$src, 15, 0)>;
1096*04eeddc0SDimitry Andric
1097*04eeddc0SDimitry Andric   // Call Patterns
1098*04eeddc0SDimitry Andric  def : Pat<(CSKY_CALL tglobaladdr, tconstpool:$src2), (JSRI32 tconstpool:$src2)>;
1099*04eeddc0SDimitry Andric  def : Pat<(CSKY_CALL texternalsym, tconstpool:$src2), (JSRI32 tconstpool:$src2)>;
1100*04eeddc0SDimitry Andric  def : Pat<(CSKY_TAIL tglobaladdr, tconstpool:$src2), (JMPI32 tconstpool:$src2)>;
1101*04eeddc0SDimitry Andric  def : Pat<(CSKY_TAIL texternalsym, tconstpool:$src2), (JMPI32 tconstpool:$src2)>;
1102*04eeddc0SDimitry Andric
1103*04eeddc0SDimitry Andric  def : Pat<(CSKY_CALLReg GPR:$src), (JSR32 GPR:$src)>;
1104*04eeddc0SDimitry Andric  def : Pat<(CSKY_TAILReg GPR:$src), (JMP32 GPR:$src)>;
1105*04eeddc0SDimitry Andric}
1106*04eeddc0SDimitry Andric
1107*04eeddc0SDimitry Andric// Symbol address Patterns
1108*04eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tglobaladdr, tconstpool:$src2), (LRW32 tconstpool:$src2)>;
1109*04eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tblockaddress, tconstpool:$src2), (LRW32 tconstpool:$src2)>;
1110*04eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tjumptable:$src1, tconstpool:$src2), (LRW32_Gen tjumptable:$src1, tconstpool:$src2)>;
1111*04eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR texternalsym, tconstpool:$src2), (LRW32 tconstpool:$src2)>;
1112*04eeddc0SDimitry Andric
1113*04eeddc0SDimitry Andriclet Predicates = [iHas2E3] in
1114*04eeddc0SDimitry Andric  def : Pat<(i32 constpool:$src), (GRS32 (to_tconstpool tconstpool:$src))>;
1115*04eeddc0SDimitry Andric
1116*04eeddc0SDimitry Andriclet Predicates = [iHasE2] in
1117*04eeddc0SDimitry Andric  def : Pat<(i32 constpool:$src),
1118*04eeddc0SDimitry Andric    (ORI32 (MOVIH32 (to_tconstpool_hi16 tconstpool:$src)),
1119*04eeddc0SDimitry Andric           (to_tconstpool_lo16 tconstpool:$src))>;
1120*04eeddc0SDimitry Andric
1121*04eeddc0SDimitry Andricdef : Pat<(i32 (load constpool:$src)), (LRW32 (to_tconstpool tconstpool:$src))>;
1122*04eeddc0SDimitry Andric
1123*04eeddc0SDimitry Andric// Branch Patterns.
1124*04eeddc0SDimitry Andriclet Predicates = [iHasE2] in {
1125*04eeddc0SDimitry Andric  def : Pat<(brcond CARRY:$ca, bb:$imm16),
1126*04eeddc0SDimitry Andric          (BT32 CARRY:$ca, bb:$imm16)>;
1127*04eeddc0SDimitry Andric
1128*04eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setne GPR:$rs1, uimm16:$rs2)), bb:$imm16),
1129*04eeddc0SDimitry Andric          (BT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), bb:$imm16)>;
1130*04eeddc0SDimitry Andric  def : Pat<(brcond (i32 (seteq GPR:$rs1, uimm16:$rs2)), bb:$imm16),
1131*04eeddc0SDimitry Andric          (BF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), bb:$imm16)>;
1132*04eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setuge GPR:$rs1, oimm16:$rs2)), bb:$imm16),
1133*04eeddc0SDimitry Andric          (BT32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
1134*04eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setult GPR:$rs1, oimm16:$rs2)), bb:$imm16),
1135*04eeddc0SDimitry Andric          (BF32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
1136*04eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setlt GPR:$rs1, oimm16:$rs2)), bb:$imm16),
1137*04eeddc0SDimitry Andric          (BT32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
1138*04eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setge GPR:$rs1, oimm16:$rs2)), bb:$imm16),
1139*04eeddc0SDimitry Andric          (BF32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
1140*04eeddc0SDimitry Andric
1141*04eeddc0SDimitry Andric}
1142*04eeddc0SDimitry Andric
1143*04eeddc0SDimitry Andriclet Predicates = [iHas2E3] in {
1144*04eeddc0SDimitry Andric
1145*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setne GPR:$rs1, GPR:$rs2)), bb:$imm16),
1146*04eeddc0SDimitry Andric          (BT32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
1147*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (seteq GPR:$rs1, GPR:$rs2)), bb:$imm16),
1148*04eeddc0SDimitry Andric          (BF32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
1149*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setuge GPR:$rs1, GPR:$rs2)), bb:$imm16),
1150*04eeddc0SDimitry Andric          (BT32 (CMPHS32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
1151*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setule GPR:$rs1, GPR:$rs2)), bb:$imm16),
1152*04eeddc0SDimitry Andric          (BT32 (CMPHS32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
1153*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setult GPR:$rs1, GPR:$rs2)), bb:$imm16),
1154*04eeddc0SDimitry Andric          (BF32 (CMPHS32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
1155*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setugt GPR:$rs1, GPR:$rs2)), bb:$imm16),
1156*04eeddc0SDimitry Andric          (BF32 (CMPHS32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
1157*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setlt GPR:$rs1, GPR:$rs2)), bb:$imm16),
1158*04eeddc0SDimitry Andric          (BT32 (CMPLT32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
1159*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setgt GPR:$rs1, GPR:$rs2)), bb:$imm16),
1160*04eeddc0SDimitry Andric          (BT32 (CMPLT32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
1161*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setge GPR:$rs1, GPR:$rs2)), bb:$imm16),
1162*04eeddc0SDimitry Andric          (BF32 (CMPLT32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
1163*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setle GPR:$rs1, GPR:$rs2)), bb:$imm16),
1164*04eeddc0SDimitry Andric          (BF32 (CMPLT32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
1165*04eeddc0SDimitry Andric
1166*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (seteq GPR:$rs1, (i32 0))), bb:$imm16),
1167*04eeddc0SDimitry Andric          (BEZ32 GPR:$rs1, bb:$imm16)>;
1168*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setne GPR:$rs1, (i32 0))), bb:$imm16),
1169*04eeddc0SDimitry Andric          (BNEZ32 GPR:$rs1, bb:$imm16)>;
1170*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setlt GPR:$rs1, (i32 0))), bb:$imm16),
1171*04eeddc0SDimitry Andric          (BLZ32 GPR:$rs1, bb:$imm16)>;
1172*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setge GPR:$rs1, (i32 0))), bb:$imm16),
1173*04eeddc0SDimitry Andric          (BHSZ32 GPR:$rs1, bb:$imm16)>;
1174*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setgt GPR:$rs1, (i32 0))), bb:$imm16),
1175*04eeddc0SDimitry Andric          (BHZ32 GPR:$rs1, bb:$imm16)>;
1176*04eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setle GPR:$rs1, (i32 0))), bb:$imm16),
1177*04eeddc0SDimitry Andric          (BLSZ32 GPR:$rs1, bb:$imm16)>;
1178*04eeddc0SDimitry Andric}
1179*04eeddc0SDimitry Andric
1180*04eeddc0SDimitry Andric// Compare Patterns.
1181*04eeddc0SDimitry Andriclet Predicates = [iHas2E3] in {
1182*04eeddc0SDimitry Andric  def : Pat<(setne GPR:$rs1, GPR:$rs2),
1183*04eeddc0SDimitry Andric            (CMPNE32 GPR:$rs1, GPR:$rs2)>;
1184*04eeddc0SDimitry Andric  def : Pat<(i32 (seteq GPR:$rs1, GPR:$rs2)),
1185*04eeddc0SDimitry Andric            (MVCV32 (CMPNE32 GPR:$rs1, GPR:$rs2))>;
1186*04eeddc0SDimitry Andric  def : Pat<(setuge GPR:$rs1, GPR:$rs2),
1187*04eeddc0SDimitry Andric            (CMPHS32 GPR:$rs1, GPR:$rs2)>;
1188*04eeddc0SDimitry Andric  def : Pat<(setule GPR:$rs1, GPR:$rs2),
1189*04eeddc0SDimitry Andric            (CMPHS32 GPR:$rs2, GPR:$rs1)>;
1190*04eeddc0SDimitry Andric  def : Pat<(i32 (setult GPR:$rs1, GPR:$rs2)),
1191*04eeddc0SDimitry Andric            (MVCV32 (CMPHS32 GPR:$rs1, GPR:$rs2))>;
1192*04eeddc0SDimitry Andric  def : Pat<(i32 (setugt GPR:$rs1, GPR:$rs2)),
1193*04eeddc0SDimitry Andric            (MVCV32 (CMPHS32 GPR:$rs2, GPR:$rs1))>;
1194*04eeddc0SDimitry Andric  def : Pat<(setlt GPR:$rs1, GPR:$rs2),
1195*04eeddc0SDimitry Andric            (CMPLT32 GPR:$rs1, GPR:$rs2)>;
1196*04eeddc0SDimitry Andric  def : Pat<(setgt GPR:$rs1, GPR:$rs2),
1197*04eeddc0SDimitry Andric            (CMPLT32 GPR:$rs2, GPR:$rs1)>;
1198*04eeddc0SDimitry Andric  def : Pat<(i32 (setge GPR:$rs1, GPR:$rs2)),
1199*04eeddc0SDimitry Andric            (MVCV32 (CMPLT32 GPR:$rs1, GPR:$rs2))>;
1200*04eeddc0SDimitry Andric  def : Pat<(i32 (setle GPR:$rs1, GPR:$rs2)),
1201*04eeddc0SDimitry Andric            (MVCV32 (CMPLT32 GPR:$rs2, GPR:$rs1))>;
1202*04eeddc0SDimitry Andric}
1203*04eeddc0SDimitry Andric
1204*04eeddc0SDimitry Andriclet Predicates = [iHasE2] in {
1205*04eeddc0SDimitry Andric  def : Pat<(setne GPR:$rs1, uimm16:$rs2),
1206*04eeddc0SDimitry Andric            (CMPNEI32 GPR:$rs1, uimm16:$rs2)>;
1207*04eeddc0SDimitry Andric  let Predicates = [iHas2E3] in
1208*04eeddc0SDimitry Andric  def : Pat<(i32 (seteq GPR:$rs1, uimm16:$rs2)),
1209*04eeddc0SDimitry Andric            (MVCV32 (CMPNEI32 GPR:$rs1, uimm16:$rs2))>;
1210*04eeddc0SDimitry Andric  def : Pat<(setuge GPR:$rs1, oimm16:$rs2),
1211*04eeddc0SDimitry Andric            (CMPHSI32 GPR:$rs1, oimm16:$rs2)>;
1212*04eeddc0SDimitry Andric  let Predicates = [iHas2E3] in
1213*04eeddc0SDimitry Andric  def : Pat<(i32 (setult GPR:$rs1, oimm16:$rs2)),
1214*04eeddc0SDimitry Andric            (MVCV32 (CMPHSI32 GPR:$rs1, oimm16:$rs2))>;
1215*04eeddc0SDimitry Andric  def : Pat<(setlt GPR:$rs1, oimm16:$rs2),
1216*04eeddc0SDimitry Andric            (CMPLTI32 GPR:$rs1, oimm16:$rs2)>;
1217*04eeddc0SDimitry Andric  let Predicates = [iHas2E3] in
1218*04eeddc0SDimitry Andric  def : Pat<(i32 (setge GPR:$rs1, oimm16:$rs2)),
1219*04eeddc0SDimitry Andric            (MVCV32 (CMPLTI32 GPR:$rs1, oimm16:$rs2))>;
1220*04eeddc0SDimitry Andric}
1221*04eeddc0SDimitry Andric
1222*04eeddc0SDimitry Andric// Select Patterns.
1223*04eeddc0SDimitry Andriclet Predicates = [iHasE2] in {
1224*04eeddc0SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false),
1225*04eeddc0SDimitry Andric          (MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>;
1226*04eeddc0SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false),
1227*04eeddc0SDimitry Andric          (MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>;
1228*04eeddc0SDimitry Andric
1229*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1230*04eeddc0SDimitry Andric          (MOVT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
1231*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), GPR:$rx, GPR:$false),
1232*04eeddc0SDimitry Andric          (MOVT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$rx, GPR:$false)>;
1233*04eeddc0SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1234*04eeddc0SDimitry Andric          (MOVF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
1235*04eeddc0SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), GPR:$rx, GPR:$false),
1236*04eeddc0SDimitry Andric          (MOVF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$rx, GPR:$false)>;
1237*04eeddc0SDimitry Andric
1238*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setuge GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1239*04eeddc0SDimitry Andric          (MOVT32 (CMPHS32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
1240*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setuge GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
1241*04eeddc0SDimitry Andric          (MOVT32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
1242*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setule GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1243*04eeddc0SDimitry Andric          (MOVT32 (CMPHS32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
1244*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setult GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1245*04eeddc0SDimitry Andric          (MOVF32 (CMPHS32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
1246*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setult GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
1247*04eeddc0SDimitry Andric          (MOVF32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
1248*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setugt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1249*04eeddc0SDimitry Andric          (MOVF32 (CMPHS32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
1250*04eeddc0SDimitry Andric
1251*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setlt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1252*04eeddc0SDimitry Andric          (MOVT32 (CMPLT32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
1253*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setlt GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
1254*04eeddc0SDimitry Andric          (MOVT32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
1255*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setgt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1256*04eeddc0SDimitry Andric          (MOVT32 (CMPLT32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
1257*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setge GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1258*04eeddc0SDimitry Andric          (MOVF32 (CMPLT32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
1259*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setge GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
1260*04eeddc0SDimitry Andric          (MOVF32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
1261*04eeddc0SDimitry Andricdef : Pat<(select (i32 (setle GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
1262*04eeddc0SDimitry Andric          (MOVF32 (CMPLT32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
1263*04eeddc0SDimitry Andric
1264*04eeddc0SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false),
1265*04eeddc0SDimitry Andric          (ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>;
1266*04eeddc0SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false),
1267*04eeddc0SDimitry Andric          (ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>;
12680eae32dcSDimitry Andric}
12690eae32dcSDimitry Andric
12700eae32dcSDimitry Andric// Constant materialize patterns.
12710eae32dcSDimitry Andriclet Predicates = [iHasE2] in
12720eae32dcSDimitry Andric  def : Pat<(i32 imm:$imm),
12730eae32dcSDimitry Andric            (ORI32 (MOVIH32 (uimm32_hi16 imm:$imm)), (uimm32_lo16 imm:$imm))>;
12740eae32dcSDimitry Andric
12750eae32dcSDimitry Andric
12760eae32dcSDimitry Andric// Other operations.
12770eae32dcSDimitry Andriclet Predicates = [iHasE2] in {
12780eae32dcSDimitry Andric  def : Pat<(rotl GPR:$rs1, GPR:$rs2),
12790eae32dcSDimitry Andric            (ROTL32 GPR:$rs1, (ANDI32 GPR:$rs2, 0x1f))>;
12800eae32dcSDimitry Andric  let Predicates = [iHas2E3] in {
12810eae32dcSDimitry Andric    def : Pat<(bitreverse GPR:$rx), (BREV32 GPR:$rx)>;
12820eae32dcSDimitry Andric    def : Pat<(bswap GPR:$rx), (REVB32 GPR:$rx)>;
12830eae32dcSDimitry Andric  }
12840eae32dcSDimitry Andric  def : Pat<(i32 (ctlz GPR:$rx)), (FF1 GPR:$rx)>;
12850eae32dcSDimitry Andric}
1286349cc55cSDimitry Andric
1287349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
1288349cc55cSDimitry Andric// Pseudo for assembly
1289349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
1290349cc55cSDimitry Andric
1291349cc55cSDimitry Andriclet isCall = 1, Defs = [ R15 ], mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
1292349cc55cSDimitry Andricdef JBSR32 : CSKYPseudo<(outs), (ins call_symbol:$src1), "jbsr32\t$src1", []>;
1293349cc55cSDimitry Andric
1294349cc55cSDimitry Andricdef : InstAlias<"jbsr\t$src1", (JBSR32 call_symbol:$src1)>;
1295349cc55cSDimitry Andric
1296349cc55cSDimitry Andricdef JBR32 : CSKYPseudo<(outs), (ins br_symbol:$src1), "jbr32\t$src1", []> {
1297349cc55cSDimitry Andric  let isBranch = 1;
1298349cc55cSDimitry Andric  let isTerminator = 1;
1299349cc55cSDimitry Andric  let isBarrier = 1;
1300349cc55cSDimitry Andric  let isIndirectBranch = 1;
1301349cc55cSDimitry Andric  let mayLoad = 1;
1302349cc55cSDimitry Andric  let Size = 4;
1303349cc55cSDimitry Andric}
1304349cc55cSDimitry Andric
1305349cc55cSDimitry Andricdef JBT32 : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "jbt32\t$src1", []> {
1306349cc55cSDimitry Andric  let isBranch = 1;
1307349cc55cSDimitry Andric  let isTerminator = 1;
1308349cc55cSDimitry Andric  let isIndirectBranch = 1;
1309349cc55cSDimitry Andric  let mayLoad = 1;
1310349cc55cSDimitry Andric  let Size = 4;
1311349cc55cSDimitry Andric}
1312349cc55cSDimitry Andric
1313349cc55cSDimitry Andricdef JBF32 : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "jbf32\t$src1", []> {
1314349cc55cSDimitry Andric  let isBranch = 1;
1315349cc55cSDimitry Andric  let isTerminator = 1;
1316349cc55cSDimitry Andric  let isIndirectBranch = 1;
1317349cc55cSDimitry Andric  let mayLoad = 1;
1318349cc55cSDimitry Andric  let Size = 4;
1319349cc55cSDimitry Andric}
1320349cc55cSDimitry Andric
1321349cc55cSDimitry Andricdef JBT_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbt_e\t$src1", []> {
1322349cc55cSDimitry Andric  let isBranch = 1;
1323349cc55cSDimitry Andric  let isTerminator = 1;
1324349cc55cSDimitry Andric  let isIndirectBranch = 1;
1325349cc55cSDimitry Andric  let mayLoad = 1;
1326349cc55cSDimitry Andric  let Size = 6;
1327349cc55cSDimitry Andric}
1328349cc55cSDimitry Andric
1329349cc55cSDimitry Andricdef JBF_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbf_e\t$src1", []> {
1330349cc55cSDimitry Andric  let isBranch = 1;
1331349cc55cSDimitry Andric  let isTerminator = 1;
1332349cc55cSDimitry Andric  let isIndirectBranch = 1;
1333349cc55cSDimitry Andric  let mayLoad = 1;
1334349cc55cSDimitry Andric  let Size = 6;
1335349cc55cSDimitry Andric}
1336349cc55cSDimitry Andric
1337349cc55cSDimitry Andriclet mayLoad = 1, Size = 2, isCodeGenOnly = 0 in
1338349cc55cSDimitry Andricdef PseudoLRW32 : CSKYPseudo<(outs GPR:$rz), (ins bare_symbol:$src), "lrw32 $rz, $src", []>;
1339349cc55cSDimitry Andric
1340349cc55cSDimitry Andric
1341349cc55cSDimitry Andricdef : InstAlias<"lrw $rz, $src", (PseudoLRW32 GPR:$rz, bare_symbol:$src)>;
1342349cc55cSDimitry Andricdef : InstAlias<"lrw $rz, $src", (LRW32 GPR:$rz, constpool_symbol:$src)>;
1343349cc55cSDimitry Andric
1344349cc55cSDimitry Andriclet mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
1345349cc55cSDimitry Andricdef PseudoJSRI32 : CSKYPseudo<(outs), (ins call_symbol:$src), "jsri32 $src", []>;
1346349cc55cSDimitry Andricdef : InstAlias<"jsri $dst", (PseudoJSRI32 call_symbol:$dst)>;
1347349cc55cSDimitry Andricdef : InstAlias<"jsri $dst", (JSRI32 constpool_symbol:$dst)>;
1348349cc55cSDimitry Andric
1349349cc55cSDimitry Andriclet mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
1350349cc55cSDimitry Andricdef PseudoJMPI32 : CSKYPseudo<(outs), (ins br_symbol:$src), "jmpi32 $src", []>;
1351349cc55cSDimitry Andricdef : InstAlias<"jmpi $dst", (PseudoJMPI32 br_symbol:$dst)>;
1352349cc55cSDimitry Andricdef : InstAlias<"jmpi $dst", (JMPI32 constpool_symbol:$dst)>;
1353349cc55cSDimitry Andric
1354349cc55cSDimitry Andriclet isNotDuplicable = 1, mayLoad = 1, mayStore = 0, Size = 8 in
1355349cc55cSDimitry Andricdef PseudoTLSLA32 : CSKYPseudo<(outs GPR:$dst1, GPR:$dst2),
1356349cc55cSDimitry Andric  (ins constpool_symbol:$src, i32imm:$label), "!tlslrw32\t$dst1, $dst2, $src, $label", []>;
1357349cc55cSDimitry Andric
1358349cc55cSDimitry Andriclet hasSideEffects = 0, isNotDuplicable = 1 in
1359349cc55cSDimitry Andricdef CONSTPOOL_ENTRY : CSKYPseudo<(outs),
1360349cc55cSDimitry Andric  (ins i32imm:$instid, i32imm:$cpidx, i32imm:$size), "", []>;
1361349cc55cSDimitry Andric
1362349cc55cSDimitry Andricinclude "CSKYInstrInfo16Instr.td"
1363*04eeddc0SDimitry Andricinclude "CSKYInstrInfoF1.td"
1364*04eeddc0SDimitry Andricinclude "CSKYInstrInfoF2.td"
1365