xref: /freebsd/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
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
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
416*81ad6265SDimitry Andricmulticlass uimm8SRLXForm<SDNode opc> {
417*81ad6265SDimitry Andric  def _0: SDNodeXForm<opc,
418*81ad6265SDimitry Andric    [{return CurDAG->getTargetConstant((N->getZExtValue() >> 0) & 0xFF, SDLoc(N), MVT::i32);}]>;
419*81ad6265SDimitry Andric  def _8: SDNodeXForm<opc,
420*81ad6265SDimitry Andric    [{return CurDAG->getTargetConstant((N->getZExtValue() >> 8) & 0xFF, SDLoc(N), MVT::i32);}]>;
421*81ad6265SDimitry Andric  def _16: SDNodeXForm<opc,
422*81ad6265SDimitry Andric    [{return CurDAG->getTargetConstant((N->getZExtValue() >> 16) & 0xFF, SDLoc(N), MVT::i32);}]>;
423*81ad6265SDimitry Andric  def _24: SDNodeXForm<opc,
424*81ad6265SDimitry Andric    [{return CurDAG->getTargetConstant((N->getZExtValue() >> 24) & 0xFF, SDLoc(N), MVT::i32);}]>;
425*81ad6265SDimitry Andric}
426*81ad6265SDimitry Andric
427*81ad6265SDimitry Andricdefm uimm8SRL : uimm8SRLXForm<imm>;
428*81ad6265SDimitry Andric
429fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
430fe6060f1SDimitry Andric// Instruction Formats
431fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
432fe6060f1SDimitry Andric
433fe6060f1SDimitry Andricinclude "CSKYInstrFormats.td"
434e8d8bef9SDimitry Andric
435e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
436e8d8bef9SDimitry Andric// Instruction definitions.
437e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
438e8d8bef9SDimitry Andric
439e8d8bef9SDimitry Andricclass TriOpFrag<dag res> : PatFrag<(ops node: $LHS, node:$MHS, node:$RHS), res>;
440e8d8bef9SDimitry Andricclass BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
441e8d8bef9SDimitry Andricclass UnOpFrag<dag res> : PatFrag<(ops node:$Src), res>;
442e8d8bef9SDimitry Andric
443349cc55cSDimitry Andricdef eqToAdd : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs), [{
444349cc55cSDimitry Andric  return isOrEquivalentToAdd(N);
445349cc55cSDimitry Andric}]>;
446349cc55cSDimitry Andric
447349cc55cSDimitry Andricdef BaseAddr : ComplexPattern<iPTR, 1, "SelectBaseAddr">;
448349cc55cSDimitry Andric
449349cc55cSDimitry Andric
450349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
451349cc55cSDimitry Andric// CSKYPseudo
452349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
453349cc55cSDimitry Andric
454349cc55cSDimitry Andric// Pessimistically assume the stack pointer will be clobbered
455349cc55cSDimitry Andriclet Defs = [R14], Uses = [R14] in {
456349cc55cSDimitry Andricdef ADJCALLSTACKDOWN : CSKYPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
457349cc55cSDimitry Andric  "!ADJCALLSTACKDOWN $amt1, $amt2", [(callseq_start timm:$amt1, timm:$amt2)]>;
458349cc55cSDimitry Andricdef ADJCALLSTACKUP   : CSKYPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
459349cc55cSDimitry Andric  "!ADJCALLSTACKUP $amt1, $amt2", [(callseq_end timm:$amt1, timm:$amt2)]>;
460349cc55cSDimitry Andric} // Defs = [R14], Uses = [R14]
461fe6060f1SDimitry Andric
462fe6060f1SDimitry Andric
463fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
464fe6060f1SDimitry Andric// Basic ALU instructions.
465fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
466fe6060f1SDimitry Andric
467349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
468349cc55cSDimitry Andric  let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
469349cc55cSDimitry Andric  let isAdd = 1 in
470e8d8bef9SDimitry Andric  def ADDI32 : I_12<0x0, "addi32", add, oimm12>;
471e8d8bef9SDimitry Andric  def SUBI32 : I_12<0x1, "subi32", sub, oimm12>;
472fe6060f1SDimitry Andric  def ORI32 : I_16_ZX<"ori32", uimm16,
473fe6060f1SDimitry Andric  [(set GPR:$rz, (or GPR:$rx, uimm16:$imm16))]>;
474fe6060f1SDimitry Andric  def XORI32 : I_12<0x4, "xori32", xor, uimm12>;
475e8d8bef9SDimitry Andric  def ANDI32 : I_12<0x2, "andi32", and, uimm12>;
476e8d8bef9SDimitry Andric  def ANDNI32 : I_12<0x3, "andni32", and, nimm12>;
477e8d8bef9SDimitry Andric  def LSLI32 : I_5_XZ<0x12, 0x1, "lsli32",
478e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
479e8d8bef9SDimitry Andric    [(set GPR:$rz, (shl GPR:$rx, uimm5:$imm5))]>;
480e8d8bef9SDimitry Andric  def LSRI32 : I_5_XZ<0x12, 0x2, "lsri32",
481e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
482e8d8bef9SDimitry Andric    [(set GPR:$rz, (srl GPR:$rx, uimm5:$imm5))]>;
483e8d8bef9SDimitry Andric  def ASRI32 : I_5_XZ<0x12, 0x4, "asri32",
484e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
485e8d8bef9SDimitry Andric    [(set GPR:$rz, (sra GPR:$rx, uimm5:$imm5))]>;
486fe6060f1SDimitry Andric  def ROTLI32 : I_5_XZ<0x12, 0x8, "rotli32",
487fe6060f1SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5),
488fe6060f1SDimitry Andric    [(set GPR:$rz, (rotl GPR:$rx, uimm5:$imm5))]>;
489e8d8bef9SDimitry Andric
490349cc55cSDimitry Andric  def ROTRI32 : CSKYPseudo<(outs GPR:$rz), (ins GPR:$rx, oimm5:$imm5),
491349cc55cSDimitry Andric                            "rotri32 $rz, $rx, $imm5", []>;
492349cc55cSDimitry Andric  }
493349cc55cSDimitry Andric  let isAdd = 1 in
494e8d8bef9SDimitry Andric  def ADDU32 : R_YXZ_SP_F1<0x0, 0x1,
495e8d8bef9SDimitry Andric    BinOpFrag<(add node:$LHS, node:$RHS)>, "addu32", 1>;
496e8d8bef9SDimitry Andric  def SUBU32 : R_YXZ_SP_F1<0x0, 0x4,
497e8d8bef9SDimitry Andric    BinOpFrag<(sub node:$LHS, node:$RHS)>, "subu32">;
498349cc55cSDimitry Andric
499fe6060f1SDimitry Andric  def MULT32 : R_YXZ_SP_F1<0x21, 0x1,
500fe6060f1SDimitry Andric    BinOpFrag<(mul node:$LHS, node:$RHS)>, "mult32", 1>;
501e8d8bef9SDimitry Andric  def AND32 : R_YXZ_SP_F1<0x8, 0x1,
502e8d8bef9SDimitry Andric    BinOpFrag<(and node:$LHS, node:$RHS)>, "and32", 1>;
503e8d8bef9SDimitry Andric  def ANDN32 : R_YXZ_SP_F1<0x8, 0x2,
504e8d8bef9SDimitry Andric    BinOpFrag<(and node:$LHS, (not node:$RHS))>, "andn32">;
505e8d8bef9SDimitry Andric  def OR32: R_YXZ_SP_F1<0x9, 0x1,
506e8d8bef9SDimitry Andric    BinOpFrag<(or node:$LHS, node:$RHS)>, "or32", 1>;
507e8d8bef9SDimitry Andric  def XOR32 : R_YXZ_SP_F1<0x9, 0x2,
508e8d8bef9SDimitry Andric    BinOpFrag<(xor node:$LHS, node:$RHS)>, "xor32", 1>;
509e8d8bef9SDimitry Andric  def NOR32 : R_YXZ_SP_F1<0x9, 0x4,
510e8d8bef9SDimitry Andric    BinOpFrag<(not (or node:$LHS, node:$RHS))>, "nor32", 1>;
511349cc55cSDimitry Andric  let isCodeGenOnly = 1 in
512fe6060f1SDimitry Andric  def NOT32 : R_XXZ<0b001001, 0b00100, (outs GPR:$rz), (ins GPR:$rx),
513fe6060f1SDimitry Andric    "not32", [(set GPR:$rz, (not GPR:$rx))]>;
514349cc55cSDimitry Andric
515349cc55cSDimitry Andric  let Size = 8 in
516349cc55cSDimitry Andric  def NEG32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx), "neg32 $rd, $rx", []>;
517349cc55cSDimitry Andric
518349cc55cSDimitry Andric  let Size = 8 in
519349cc55cSDimitry Andric  def RSUBI32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx, uimm12:$imm12), "rsubi32 $rd, $rx, $imm12", []>;
520349cc55cSDimitry Andric
521e8d8bef9SDimitry Andric  def LSL32 : R_YXZ_SP_F1<0x10, 0x1,
522e8d8bef9SDimitry Andric    BinOpFrag<(shl node:$LHS, node:$RHS)>, "lsl32">;
523e8d8bef9SDimitry Andric  def LSR32 : R_YXZ_SP_F1<0x10, 0x2,
524e8d8bef9SDimitry Andric    BinOpFrag<(srl node:$LHS, node:$RHS)>, "lsr32">;
525e8d8bef9SDimitry Andric  def ASR32 : R_YXZ_SP_F1<0x10, 0x4,
526e8d8bef9SDimitry Andric    BinOpFrag<(sra node:$LHS, node:$RHS)>, "asr32">;
527fe6060f1SDimitry Andric  def ROTL32 : R_YXZ_SP_F1<0x10, 0x8,
528fe6060f1SDimitry Andric    BinOpFrag<(rotl node:$LHS, (and node:$RHS, 0x1f))>, "rotl32">;
529fe6060f1SDimitry Andric
530349cc55cSDimitry Andric  def BMASKI32 : I_5_Z<0b010100, 0x1, "bmaski32", oimm5, []>;
531349cc55cSDimitry Andric  def LSLC32 : I_5_XZ<0x13, 0x1, "lslc32",
532349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>;
533349cc55cSDimitry Andric  def LSRC32 : I_5_XZ<0x13, 0x2, "lsrc32",
534349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>;
535349cc55cSDimitry Andric  def ASRC32 : I_5_XZ<0x13, 0x4, "asrc32",
536349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5), []>;
537349cc55cSDimitry Andric  def XSR32 : I_5_XZ<0x13, 0x8, "xsr32",
538349cc55cSDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, oimm5:$imm5, CARRY:$cin), []>;
539fe6060f1SDimitry Andric
540fe6060f1SDimitry Andric  def IXH32 : R_YXZ_SP_F1<0x2, 0x1,
541fe6060f1SDimitry Andric    BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 1)))>, "ixh32">;
542fe6060f1SDimitry Andric  def IXW32 : R_YXZ_SP_F1<0x2, 0x2,
543fe6060f1SDimitry Andric    BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 2)))>, "ixw32">;
544349cc55cSDimitry Andric  let Predicates = [iHas2E3] in
545fe6060f1SDimitry Andric  def IXD32 : R_YXZ_SP_F1<0x2, 0x4,
546fe6060f1SDimitry Andric    BinOpFrag<(add node:$LHS, (shl node:$RHS, (i32 3)))>, "ixd32">;
547fe6060f1SDimitry Andric
548349cc55cSDimitry Andric  let isCommutable = 1, isAdd = 1 in
549fe6060f1SDimitry Andric  def ADDC32 : R_YXZ<0x31, 0x0, 0x2, (outs GPR:$rz, CARRY:$cout),
550fe6060f1SDimitry Andric    (ins GPR:$rx, GPR:$ry, CARRY:$cin), "addc32", []>;
551fe6060f1SDimitry Andric  def SUBC32 : R_YXZ<0x31, 0x0, 0x8, (outs GPR:$rz, CARRY:$cout),
552fe6060f1SDimitry Andric    (ins GPR:$rx, GPR:$ry, CARRY:$cin), "subc32", []>;
553fe6060f1SDimitry Andric
554349cc55cSDimitry Andric  def INCF32 : I_5_ZX<0x3, 0x1, "incf32", uimm5, []>;
555349cc55cSDimitry Andric  def INCT32 : I_5_ZX<0x3, 0x2, "inct32", uimm5, []>;
556349cc55cSDimitry Andric  def DECF32 : I_5_ZX<0x3, 0x4, "decf32", uimm5, []>;
557349cc55cSDimitry Andric  def DECT32 : I_5_ZX<0x3, 0x8, "dect32", uimm5, []>;
558349cc55cSDimitry Andric}
559349cc55cSDimitry Andric
560349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
561e8d8bef9SDimitry Andric  def DIVS32 : R_YXZ_SP_F1<0x20, 0x2,
562e8d8bef9SDimitry Andric    BinOpFrag<(sdiv node:$LHS, node:$RHS)>, "divs32">;
563e8d8bef9SDimitry Andric  def DIVU32 : R_YXZ_SP_F1<0x20, 0x1,
564e8d8bef9SDimitry Andric    BinOpFrag<(udiv node:$LHS, node:$RHS)>, "divu32">;
565e8d8bef9SDimitry Andric
566fe6060f1SDimitry Andric  def DECGT32 : I_5_XZ<0x4, 0x1, "decgt32",
567fe6060f1SDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>;
568fe6060f1SDimitry Andric  def DECLT32 : I_5_XZ<0x4, 0x2, "declt32",
569fe6060f1SDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>;
570fe6060f1SDimitry Andric  def DECNE32 : I_5_XZ<0x4, 0x4, "decne32",
571fe6060f1SDimitry Andric    (outs GPR:$rz, CARRY:$cout), (ins GPR:$rx, uimm5:$imm5), []>;
572fe6060f1SDimitry Andric
573349cc55cSDimitry Andric  def SEXT32 : I_5_XZ_U<0x16, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), "sext32", []>;
574349cc55cSDimitry Andric  let isCodeGenOnly = 1 in {
575349cc55cSDimitry Andric  def SEXTB32 : I_5_XZ_US<0x16, 0, 7, "sextb32", sext_inreg, i8>;
576349cc55cSDimitry Andric  def SEXTH32 : I_5_XZ_US<0x16, 0, 15, "sexth32", sext_inreg, i16>;
577349cc55cSDimitry Andric  def ZEXTB32 : I_5_XZ_UZ<0x15, 0, 7, "zextb32", 255>;
578349cc55cSDimitry Andric  def ZEXTH32 : I_5_XZ_UZ<0x15, 0, 15, "zexth32", 65535>;
579349cc55cSDimitry Andric  }
580349cc55cSDimitry Andric  def ZEXT32 : I_5_XZ_U<0x15, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), "zext32",[]>;
581349cc55cSDimitry Andric
582349cc55cSDimitry Andric  let Constraints = "$rZ = $rz" in
583349cc55cSDimitry Andric  def INS32 : I_5_XZ_INS<0b010111, (outs GPR:$rz), (ins GPR:$rZ, GPR:$rx, uimm5_msb_size:$msb, uimm5:$lsb), "ins32", []>;
584349cc55cSDimitry Andric}
585349cc55cSDimitry Andric
586349cc55cSDimitry Andriclet Predicates = [iHas3E3r1] in {
587349cc55cSDimitry Andricdef MULTS32 : R_YXZ<0x3e, 0x20, 0x10, (outs GPRPair:$rz),
588349cc55cSDimitry Andric    (ins GPR:$rx, GPR:$ry), "mul.s32", []>;
589349cc55cSDimitry Andricdef MULTU32 : R_YXZ<0x3e, 0x20, 0x00, (outs GPRPair:$rz),
590349cc55cSDimitry Andric    (ins GPR:$rx, GPR:$ry), "mul.u32", []>;
591349cc55cSDimitry Andric
592349cc55cSDimitry Andriclet Constraints = "$rZ = $rz" in {
593349cc55cSDimitry Andricdef MULATS32 : R_YXZ<0x3e, 0x20, 0x14, (outs GPRPair:$rZ),
594349cc55cSDimitry Andric    (ins GPRPair:$rz, GPR:$rx, GPR:$ry), "mula.s32", []>;
595349cc55cSDimitry Andricdef MULATU32 : R_YXZ<0x3e, 0x20, 0x04, (outs GPRPair:$rZ),
596349cc55cSDimitry Andric    (ins GPRPair:$rz, GPR:$rx, GPR:$ry), "mula.u32", []>;
597349cc55cSDimitry Andric}
598349cc55cSDimitry Andric}
599349cc55cSDimitry Andric
600349cc55cSDimitry Andricdef MULSH32 : R_YXZ<0x31, 0b100100, 0b00001, (outs GPR:$rz),
601349cc55cSDimitry Andric    (ins GPR:$rx, GPR:$ry), "mulsh32", []>;
602fe6060f1SDimitry Andric
603fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
604fe6060f1SDimitry Andric// Load & Store instructions.
605fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
606fe6060f1SDimitry Andric
607fe6060f1SDimitry Andricdef LD32B : I_LD<AddrMode32B, 0x0, "ld32.b", uimm12>;
608fe6060f1SDimitry Andricdef LD32H : I_LD<AddrMode32H, 0x1, "ld32.h", uimm12_1>;
609fe6060f1SDimitry Andricdef LD32W : I_LD<AddrMode32WD, 0x2, "ld32.w", uimm12_2>;
610fe6060f1SDimitry Andric
611349cc55cSDimitry Andriclet OutOperandList = (outs GPRPair:$rz) in
612349cc55cSDimitry Andricdef LD32D : I_LD<AddrMode32WD, 0x3, "ld32.d", uimm12_2>;
613fe6060f1SDimitry Andric
614349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
615fe6060f1SDimitry Andric  def LD32BS : I_LD<AddrMode32B, 0x4, "ld32.bs", uimm12>;
616fe6060f1SDimitry Andric  def LD32HS : I_LD<AddrMode32H, 0x5, "ld32.hs", uimm12_1>;
617fe6060f1SDimitry Andric
618349cc55cSDimitry Andric  def LDM32 : I_5_YX<0b110100, 0b000111,
619349cc55cSDimitry Andric    (outs), (ins GPR:$rx, regseq:$regs, variable_ops), "ldm32\t$regs, (${rx})", []>;
620349cc55cSDimitry Andric  def STM32 : I_5_YX<0b110101, 0b000111,
621349cc55cSDimitry Andric    (outs), (ins GPR:$rx, regseq:$regs, variable_ops), "stm32\t$regs, (${rx})", []>;
622fe6060f1SDimitry Andric
623349cc55cSDimitry Andric  let Size = 4, isCodeGenOnly = 0 in {
624349cc55cSDimitry Andric  def LDQ32 : CSKYPseudo<(outs), (ins GPR:$rx, regseq:$regs, variable_ops),
625349cc55cSDimitry Andric                             "ldq32\t$regs, (${rx})", []>;
626349cc55cSDimitry Andric  def STQ32 : CSKYPseudo<(outs), (ins GPR:$rx, regseq:$regs, variable_ops),
627349cc55cSDimitry Andric                             "stq32\t$regs, (${rx})", []>;
628349cc55cSDimitry Andric  }
629349cc55cSDimitry Andric
630349cc55cSDimitry Andric}
631fe6060f1SDimitry Andric
632fe6060f1SDimitry Andricdef ST32B : I_ST<AddrMode32B, 0x0, "st32.b", uimm12>;
633fe6060f1SDimitry Andricdef ST32H : I_ST<AddrMode32H, 0x1, "st32.h", uimm12_1>;
634fe6060f1SDimitry Andricdef ST32W : I_ST<AddrMode32WD, 0x2, "st32.w", uimm12_2>;
635fe6060f1SDimitry Andric
636349cc55cSDimitry Andriclet InOperandList = (ins GPRPair:$rz, GPR:$rx, uimm12_2:$imm12 ) in
637349cc55cSDimitry Andricdef ST32D : I_ST<AddrMode32WD, 0x3, "st32.d", uimm12_2>;
638fe6060f1SDimitry Andric
639349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
640fe6060f1SDimitry Andric  def LDR32B :  I_LDR<0x0, "ldr32.b">;
641fe6060f1SDimitry Andric  def LDR32BS :  I_LDR<0x4, "ldr32.bs">;
642fe6060f1SDimitry Andric  def LDR32H :  I_LDR<0x1, "ldr32.h">;
643fe6060f1SDimitry Andric  def LDR32HS :  I_LDR<0x5, "ldr32.hs">;
644fe6060f1SDimitry Andric  def LDR32W :  I_LDR<0x2, "ldr32.w">;
645fe6060f1SDimitry Andric  def STR32B :  I_STR<0x0, "str32.b">;
646fe6060f1SDimitry Andric  def STR32H :  I_STR<0x1, "str32.h">;
647fe6060f1SDimitry Andric  def STR32W :  I_STR<0x2, "str32.w">;
648349cc55cSDimitry Andric}
649fe6060f1SDimitry Andric
650349cc55cSDimitry Andric// Indicate that we're dumping the CR register, so we'll need to
651349cc55cSDimitry Andric// scavenge a register for it.
652349cc55cSDimitry Andriclet mayStore = 1 in {
653349cc55cSDimitry Andricdef SPILL_CARRY : CSKYPseudo<(outs), (ins CARRY:$cond, GPR:$rx, uimm12_2:$imm),
654349cc55cSDimitry Andric                             "!SPILL_CARRY $cond, $rx, $imm", []>;
655349cc55cSDimitry Andric}
656349cc55cSDimitry Andric
657349cc55cSDimitry Andric// Indicate that we're restoring the CR register (previously
658349cc55cSDimitry Andric// spilled), so we'll need to scavenge a register for it.
659349cc55cSDimitry Andriclet mayLoad = 1 in {
660349cc55cSDimitry Andricdef RESTORE_CARRY : CSKYPseudo<(outs CARRY:$cond), (ins GPR:$rx, uimm12_2:$imm),
661349cc55cSDimitry Andric                                "!RESTORE_CARRY $cond, $rx, $imm", []>;
662349cc55cSDimitry Andric}
663349cc55cSDimitry Andric
664349cc55cSDimitry Andriclet mayLoad = 1 in {
665349cc55cSDimitry Andricdef STORE_PAIR : CSKYPseudo<(outs), (ins GPRPair:$rz, GPR:$rx, uimm12_2:$imm),
666349cc55cSDimitry Andric                            "!STORE_PAIR $rz, $rx, $imm", []>;
667349cc55cSDimitry Andric}
668349cc55cSDimitry Andric
669349cc55cSDimitry Andriclet mayLoad = 1 in {
670349cc55cSDimitry Andricdef LOAD_PAIR : CSKYPseudo<(outs GPRPair:$rz), (ins GPR:$rx, uimm12_2:$imm),
671349cc55cSDimitry Andric                            "!LOAD_PAIR $rz, $rx, $imm", []>;
672349cc55cSDimitry Andric}
673fe6060f1SDimitry Andric
674fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
675fe6060f1SDimitry Andric// Compare instructions.
676fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
677349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
678fe6060f1SDimitry Andric  def CMPNEI32 : I_16_X<0x1A, "cmpnei32", uimm16>;
679fe6060f1SDimitry Andric  def CMPHSI32 : I_16_X<0x18, "cmphsi32", oimm16>;
680fe6060f1SDimitry Andric  def CMPLTI32 : I_16_X<0x19, "cmplti32", oimm16>;
681349cc55cSDimitry Andric  def CMPLEI32 : CSKYPseudo<(outs CARRY:$ca), (ins GPR:$rx, uimm16:$imm16),
682349cc55cSDimitry Andric    "cmplei32\t$rx, $imm16", []>;
683349cc55cSDimitry Andric}
684349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
685fe6060f1SDimitry Andric  def CMPNE32 : R_YX<0x1, 0x4, "cmpne32">;
686fe6060f1SDimitry Andric  def CMPHS32 : R_YX<0x1, 0x1, "cmphs32">;
687fe6060f1SDimitry Andric  def CMPLT32 : R_YX<0x1, 0x2, "cmplt32">;
688fe6060f1SDimitry Andric
689349cc55cSDimitry Andric  def SETC32 : CSKY32Inst<AddrModeNone, 0x31,
690349cc55cSDimitry Andric    (outs CARRY:$ca), (ins), "setc32", []> {
691349cc55cSDimitry Andric    let Inst{25 - 21} = 0; //rx
692349cc55cSDimitry Andric    let Inst{20 - 16} = 0; //ry
693349cc55cSDimitry Andric    let Inst{15 - 10} = 0x1;
694349cc55cSDimitry Andric    let Inst{9 - 5} = 0x1;
695349cc55cSDimitry Andric    let Inst{4 - 0} = 0;
696349cc55cSDimitry Andric    let isCompare = 1;
697349cc55cSDimitry Andric  }
698349cc55cSDimitry Andric  def CLRC32 : CSKY32Inst<AddrModeNone, 0x31,
699349cc55cSDimitry Andric    (outs CARRY:$ca), (ins), "clrc32", []> {
700349cc55cSDimitry Andric    let Inst{25 - 21} = 0; //rx
701349cc55cSDimitry Andric    let Inst{20 - 16} = 0; //ry
702349cc55cSDimitry Andric    let Inst{15 - 10} = 0x1;
703349cc55cSDimitry Andric    let Inst{9 - 5} = 0x4;
704349cc55cSDimitry Andric    let Inst{4 - 0} = 0;
705349cc55cSDimitry Andric    let isCompare = 1;
706349cc55cSDimitry Andric  }
707349cc55cSDimitry Andric
708349cc55cSDimitry Andric  def TST32 : R_YX<0x8, 0x4, "tst32">;
709349cc55cSDimitry Andric  def TSTNBZ32 : R_X<0x8, 0x8,
710349cc55cSDimitry Andric    (outs CARRY:$ca), (ins GPR:$rx), "tstnbz32", []>;
711349cc55cSDimitry Andric}
712fe6060f1SDimitry Andric
713fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
714fe6060f1SDimitry Andric// Data move instructions.
715fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
716fe6060f1SDimitry Andric
717349cc55cSDimitry Andriclet Predicates= [iHasE2] in {
718349cc55cSDimitry Andric  let isCodeGenOnly = 1 in {
719fe6060f1SDimitry Andric  def MOVT32 : R_ZX<0x3, 0x2, "movt32", []>;
720fe6060f1SDimitry Andric  def MOVF32 : R_ZX<0x3, 0x1, "movf32", []>;
721349cc55cSDimitry Andric  }
722fe6060f1SDimitry Andric  def MOVI32 : I_16_MOV<0x10, "movi32", uimm16>;
723349cc55cSDimitry Andric  let Size = 4, isCodeGenOnly = 0 in
724349cc55cSDimitry Andric  def BGENI : CSKYPseudo<(outs GPR:$dst), (ins uimm5:$imm), "bgeni\t$dst, $imm", []>;
725fe6060f1SDimitry Andric  def MOVIH32 : I_16_MOV<0x11, "movih32", uimm16_16_xform>;
726fe6060f1SDimitry Andric  def MVC32 : R_Z_1<0x1, 0x8, "mvc32">;
727349cc55cSDimitry Andric  let isCodeGenOnly = 1 in
728fe6060f1SDimitry Andric  def MOV32 : R_XZ<0x12, 0x1, "mov32">;
729fe6060f1SDimitry Andric
730349cc55cSDimitry Andric  let usesCustomInserter = 1 in
731349cc55cSDimitry Andric  def ISEL32 : CSKYPseudo<(outs GPR:$dst), (ins CARRY:$cond, GPR:$src1, GPR:$src2),
732349cc55cSDimitry Andric    "!isel32\t$dst, $src1, src2", [(set GPR:$dst, (select CARRY:$cond, GPR:$src1, GPR:$src2))]>;
733349cc55cSDimitry Andric}
734fe6060f1SDimitry Andric
735349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
736fe6060f1SDimitry Andric  def MVCV32 : R_Z_1<0x1, 0x10, "mvcv32">;
737*81ad6265SDimitry Andric  def CLRF32 : R_Z_2<0xB, 0x1, "clrf32">;
738*81ad6265SDimitry Andric  def CLRT32 : R_Z_2<0xB, 0x2, "clrt32">;
739349cc55cSDimitry Andric}
740fe6060f1SDimitry Andric
741fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
742fe6060f1SDimitry Andric// Branch and call instructions.
743fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
744fe6060f1SDimitry Andric
745fe6060f1SDimitry Andriclet isBranch = 1, isTerminator = 1 in {
746fe6060f1SDimitry Andric  let isBarrier = 1, isPredicable = 1 in
747fe6060f1SDimitry Andric    def BR32 : I_16_L<0x0, (outs), (ins br_symbol:$imm16), "br32\t$imm16",
748fe6060f1SDimitry Andric                     [(br bb:$imm16)]>;
749fe6060f1SDimitry Andric
750fe6060f1SDimitry Andric  def BT32 : I_16_L<0x3, (outs), (ins CARRY:$ca, br_symbol:$imm16),
751349cc55cSDimitry Andric    "bt32\t$imm16", [(brcond CARRY:$ca, bb:$imm16)]>, Requires<[iHasE2]>;
752fe6060f1SDimitry Andric  def BF32 : I_16_L<0x2, (outs), (ins CARRY:$ca, br_symbol:$imm16),
753349cc55cSDimitry Andric    "bf32\t$imm16", []>, Requires<[iHasE2]>;
754fe6060f1SDimitry Andric}
755fe6060f1SDimitry Andric
756349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
757fe6060f1SDimitry Andric  def BEZ32 : I_16_X_L<0x8, "bez32", br_symbol>;
758fe6060f1SDimitry Andric  def BNEZ32 : I_16_X_L<0x9, "bnez32", br_symbol>;
759fe6060f1SDimitry Andric  def BHZ32 : I_16_X_L<0xA, "bhz32", br_symbol>;
760fe6060f1SDimitry Andric  def BLSZ32 : I_16_X_L<0xB, "blsz32", br_symbol>;
761fe6060f1SDimitry Andric  def BLZ32 : I_16_X_L<0xC, "blz32", br_symbol>;
762fe6060f1SDimitry Andric  def BHSZ32 : I_16_X_L<0xD, "bhsz32", br_symbol>;
763fe6060f1SDimitry Andric
764fe6060f1SDimitry Andric  let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
765fe6060f1SDimitry Andric    def JMP32 : I_16_JX<0x6, "jmp32", [(brind GPR:$rx)]>; // jmp to register
766fe6060f1SDimitry Andric    def JMPI32 : I_16_L<0x16, (outs), (ins constpool_symbol:$imm16),
767fe6060f1SDimitry Andric                   "jmpi32\t$imm16", []>;
768fe6060f1SDimitry Andric  }
769fe6060f1SDimitry Andric
770fe6060f1SDimitry Andric  let isCall = 1, Defs = [ R15 ] in
771fe6060f1SDimitry Andric    def JSR32 : I_16_JX<0x7, "jsr32", []>;
772fe6060f1SDimitry Andric
773fe6060f1SDimitry Andric  let isCall = 1, Defs = [ R15 ] , mayLoad = 1 in
774fe6060f1SDimitry Andric    def JSRI32: I_16_L<0x17, (outs),
775fe6060f1SDimitry Andric      (ins constpool_symbol:$imm16), "jsri32\t$imm16", []>;
776349cc55cSDimitry Andric}
777fe6060f1SDimitry Andric
778349cc55cSDimitry Andricdef BNEZAD32 : CSKY32Inst<AddrModeNone, 0x3a,
779349cc55cSDimitry Andric  (outs GPR:$rx_u), (ins GPR:$rx, br_symbol:$imm16), "bnezad32\t$rx, $imm16", []> {
780349cc55cSDimitry Andric  bits<5> rx;
781349cc55cSDimitry Andric  bits<16> imm16;
782349cc55cSDimitry Andric  let Inst{25 - 21} = 0x1;
783349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
784349cc55cSDimitry Andric  let Inst{15 - 0} = imm16;
785349cc55cSDimitry Andric  let isBranch = 1;
786349cc55cSDimitry Andric  let isTerminator = 1;
787349cc55cSDimitry Andric  let Constraints = "$rx_u = $rx";
788349cc55cSDimitry Andric  let Predicates = [iHas2E3, iHas10E60];
789349cc55cSDimitry Andric}
790fe6060f1SDimitry Andric
791fe6060f1SDimitry Andricdef BSR32 : J<0x38, (outs), (ins call_symbol:$offset), "bsr32", []>;
792fe6060f1SDimitry Andric
793fe6060f1SDimitry Andricdef BSR32_BR : J<0x38, (outs), (ins call_symbol:$offset), "bsr32", []>{
794fe6060f1SDimitry Andric  let isCodeGenOnly = 1;
795fe6060f1SDimitry Andric  let isBranch = 1;
796fe6060f1SDimitry Andric  let isTerminator = 1;
797fe6060f1SDimitry Andric  let isBarrier = 1;
798fe6060f1SDimitry Andric  let isPredicable = 1;
799fe6060f1SDimitry Andric  let Defs = [ R15 ];
800fe6060f1SDimitry Andric}
801fe6060f1SDimitry Andric
802fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
803fe6060f1SDimitry Andric// Symbol address instructions.
804fe6060f1SDimitry Andric//===----------------------------------------------------------------------===//
805fe6060f1SDimitry Andric
806349cc55cSDimitry Andricdef data_symbol_b : data_symbol<"CSKY::fixup_csky_doffset_imm18", 0>;
807349cc55cSDimitry Andricdef data_symbol_h : data_symbol<"CSKY::fixup_csky_doffset_imm18_scale2", 1>;
808349cc55cSDimitry Andricdef data_symbol_w : data_symbol<"CSKY::fixup_csky_doffset_imm18_scale4", 2> {
809349cc55cSDimitry Andric  let ParserMatchClass = DataAsmClass;
810349cc55cSDimitry Andric}
811349cc55cSDimitry Andric
812349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
813349cc55cSDimitry Andric
814fe6060f1SDimitry Andricdef GRS32 : I_18_Z_L<0x3, "grs32\t$rz, $offset",
815fe6060f1SDimitry Andric                    (outs GPR:$rz), (ins bare_symbol:$offset), []>;
816349cc55cSDimitry Andric
817349cc55cSDimitry Andriclet Uses = [R28] in {
818349cc55cSDimitry Andricdef LRS32B : I_18_Z_L<0x0, "lrs32.b\t$rz, $offset",
819349cc55cSDimitry Andric                    (outs GPR:$rz), (ins data_symbol_b:$offset), []>;
820349cc55cSDimitry Andricdef LRS32H : I_18_Z_L<0x1, "lrs32.h\t$rz, $offset",
821349cc55cSDimitry Andric                    (outs GPR:$rz), (ins data_symbol_h:$offset), []>;
822349cc55cSDimitry Andricdef LRS32W : I_18_Z_L<0x2, "lrs32.w\t$rz, $offset",
823349cc55cSDimitry Andric                    (outs GPR:$rz), (ins data_symbol_w:$offset), []>;
824349cc55cSDimitry Andricdef SRS32B : I_18_Z_L<0x4, "srs32.b\t$rz, $offset",
825349cc55cSDimitry Andric                    (outs), (ins GPR:$rz, data_symbol_b:$offset), []>;
826349cc55cSDimitry Andricdef SRS32H : I_18_Z_L<0x5, "srs32.h\t$rz, $offset",
827349cc55cSDimitry Andric                    (outs), (ins GPR:$rz, data_symbol_h:$offset), []>;
828349cc55cSDimitry Andricdef SRS32W : I_18_Z_L<0x6, "srs32.w\t$rz, $offset",
829349cc55cSDimitry Andric                    (outs), (ins GPR:$rz, data_symbol_w:$offset), []>;
830349cc55cSDimitry Andric}
831349cc55cSDimitry Andric
832349cc55cSDimitry Andricdef PUSH32 : I_12_PP<0b11111, 0b00000, (outs), (ins reglist:$regs, variable_ops), "push32 $regs">;
833349cc55cSDimitry Andric
834349cc55cSDimitry Andriclet Uses = [R14, R15], isReturn = 1, isTerminator = 1, isBarrier = 1 in
835349cc55cSDimitry Andricdef POP32 : I_12_PP<0b11110, 0b00000, (outs), (ins reglist:$regs, variable_ops), "pop32 $regs">;
836349cc55cSDimitry Andric
837349cc55cSDimitry Andric}
838fe6060f1SDimitry Andric
839fe6060f1SDimitry Andriclet mayLoad = 1, mayStore = 0 in {
840fe6060f1SDimitry Andricdef LRW32 : I_16_Z_L<0x14, "lrw32", (ins constpool_symbol:$imm16), []>;
841fe6060f1SDimitry Andriclet isCodeGenOnly = 1 in
842349cc55cSDimitry Andricdef LRW32_Gen : I_16_Z_L<0x14, "lrw32", (ins bare_symbol:$src1, constpool_symbol:$imm16), []>;
843fe6060f1SDimitry Andric}
844fe6060f1SDimitry Andric
845349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
846349cc55cSDimitry Andric// Atomic and fence instructions.
847349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
848349cc55cSDimitry Andric
849349cc55cSDimitry Andriclet Predicates = [iHasMP1E2] in {
850349cc55cSDimitry Andric  def BRWARW : BAR<0b01111, "bar.brwarw", 0>;
851349cc55cSDimitry Andric  def BRWARWS : BAR<0b01111, "bar.brwarws", 1>;
852349cc55cSDimitry Andric  def BRARW : BAR<0b00111, "bar.brarw", 0>;
853349cc55cSDimitry Andric  def BRARWS : BAR<0b00111, "bar.brarws", 1>;
854349cc55cSDimitry Andric  def BRWAW : BAR<0b01110, "bar.brwaw", 0>;
855349cc55cSDimitry Andric  def BRWAWS : BAR<0b01110, "bar.brwaws", 1>;
856349cc55cSDimitry Andric  def BRAR : BAR<0b00101, "bar.brar", 0>;
857349cc55cSDimitry Andric  def BRARS : BAR<0b00101, "bar.brars", 1>;
858349cc55cSDimitry Andric  def BWAW : BAR<0b01010, "bar.bwaw", 0>;
859349cc55cSDimitry Andric  def BWAWS : BAR<0b01010, "bar.bwaws", 1>;
860349cc55cSDimitry Andric
861349cc55cSDimitry Andric  def LDEX32W : I_LD<AddrMode32WD, 0x7, "ldex32.w", uimm12_2>;
862349cc55cSDimitry Andric  let Constraints = "$rd = $rz" in
863349cc55cSDimitry Andric    def STEX32W : I_LDST<AddrMode32WD, 0x37, 7,
864349cc55cSDimitry Andric      (outs GPR:$rd), (ins GPR:$rz, GPR:$rx, uimm12_2:$imm12), "stex32.w", []>;
865349cc55cSDimitry Andric}
866349cc55cSDimitry Andric
867349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
868349cc55cSDimitry Andric// Other operation instructions.
869349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
870349cc55cSDimitry Andric
871349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
872349cc55cSDimitry Andric  def BREV32 : R_XZ<0x18, 0x10, "brev32">;
873349cc55cSDimitry Andric  def ABS32 : R_XZ<0x0, 0x10, "abs32">;
874349cc55cSDimitry Andric  def BGENR32 : R_XZ<0x14, 0x2, "bgenr32">;
875349cc55cSDimitry Andric}
876349cc55cSDimitry Andric
877349cc55cSDimitry Andriclet Predicates = [iHasE2] in {
878349cc55cSDimitry Andric  def REVB32 : R_XZ<0x18, 0x4, "revb32">;
879349cc55cSDimitry Andric  def REVH32 : R_XZ<0x18, 0x8, "revh32">;
880349cc55cSDimitry Andric  def FF0 : R_XZ<0x1F, 0x1, "ff0.32">;
881349cc55cSDimitry Andric  def FF1 : R_XZ<0x1F, 0x2, "ff1.32">;
882349cc55cSDimitry Andric  def XTRB0 : R_XZ<0x1C, 0x1, "xtrb0.32">;
883349cc55cSDimitry Andric  def XTRB1 : R_XZ<0x1C, 0x2, "xtrb1.32">;
884349cc55cSDimitry Andric  def XTRB2 : R_XZ<0x1C, 0x4, "xtrb2.32">;
885349cc55cSDimitry Andric  def XTRB3 : R_XZ<0x1C, 0x8, "xtrb3.32">;
886349cc55cSDimitry Andric  def BTSTI32 : I_5_X<0x0A, 0x4, "btsti32", uimm5, []>;
887349cc55cSDimitry Andric  def BCLRI32 : I_5_XZ<0xA, 0x1, "bclri32",
888349cc55cSDimitry Andric  (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
889349cc55cSDimitry Andric  def BSETI32 : I_5_XZ<0xA, 0x2, "bseti32",
890349cc55cSDimitry Andric  (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
891349cc55cSDimitry Andric}
892349cc55cSDimitry Andric
893349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
894349cc55cSDimitry Andric// Special instructions.
895349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
896349cc55cSDimitry Andric
897349cc55cSDimitry Andricdef MFFCR : CSKY32Inst<AddrModeNone, 0x30,
898349cc55cSDimitry Andric  (outs GPR:$rx), (ins), "mfcr\t$rx, fcr", []> {
899349cc55cSDimitry Andric  bits<5> rx;
900349cc55cSDimitry Andric
901349cc55cSDimitry Andric  let Inst{25 - 21} = 0b00010;
902349cc55cSDimitry Andric  let Inst{20 - 16} = 0b00001;
903349cc55cSDimitry Andric  let Inst{15 - 10} = 0b011000;
904349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
905349cc55cSDimitry Andric  let Inst{4 - 0} = rx;
906349cc55cSDimitry Andric  let hasSideEffects = 1;
907349cc55cSDimitry Andric  let isCodeGenOnly = 1;
908349cc55cSDimitry Andric}
909349cc55cSDimitry Andric
910349cc55cSDimitry Andricdef MTFCR : CSKY32Inst<AddrModeNone, 0x30,
911349cc55cSDimitry Andric  (outs), (ins GPR:$rx), "mtcr\t$rx, fcr", []> {
912349cc55cSDimitry Andric  bits<5> rx;
913349cc55cSDimitry Andric
914349cc55cSDimitry Andric  let Inst{25 - 21} = 0b00010;
915349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
916349cc55cSDimitry Andric  let Inst{15 - 10} = 0b011001;
917349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
918349cc55cSDimitry Andric  let Inst{4 - 0} = 0b00001;
919349cc55cSDimitry Andric  let hasSideEffects = 1;
920349cc55cSDimitry Andric  let isCodeGenOnly = 1;
921349cc55cSDimitry Andric}
922349cc55cSDimitry Andric
923349cc55cSDimitry Andricdef SYNC32 : I_5_IMM5<0x30, 0b000001, 0b00001, "sync32", uimm5, []>;
924349cc55cSDimitry Andric
925349cc55cSDimitry Andricdef SYNC0_32 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
926349cc55cSDimitry Andric                 "sync32", []> {
927349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
928349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
929349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
930349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
931349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
932349cc55cSDimitry Andric}
933349cc55cSDimitry Andric
934349cc55cSDimitry Andricdef SYNC_32_I : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
935349cc55cSDimitry Andric                 "sync32.i", []> {
936349cc55cSDimitry Andric  let Inst{25 - 21} = 1;
937349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
938349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
939349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
940349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
941349cc55cSDimitry Andric}
942349cc55cSDimitry Andric
943349cc55cSDimitry Andricdef SYNC_32_S : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
944349cc55cSDimitry Andric                 "sync32.s", []> {
945349cc55cSDimitry Andric  let Inst{25 - 21} = 0b10000;
946349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
947349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
948349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
949349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
950349cc55cSDimitry Andric}
951349cc55cSDimitry Andric
952349cc55cSDimitry Andricdef SYNC_32_IS : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins),
953349cc55cSDimitry Andric                 "sync32.is", []> {
954349cc55cSDimitry Andric  let Inst{25 - 21} = 0b10001;
955349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
956349cc55cSDimitry Andric  let Inst{15 - 10} = 0b000001;
957349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
958349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
959349cc55cSDimitry Andric}
960349cc55cSDimitry Andric
961349cc55cSDimitry Andriclet Predicates = [iHas2E3] in {
962349cc55cSDimitry Andric  def RFI32 : I_5_XZ_PRIVI<0x11, 0x1, "rfi32">;
963349cc55cSDimitry Andric  def SCE32 : I_5_IMM5<0x30, 0b000110, 0b00001, "sce32", uimm4, []>;
964349cc55cSDimitry Andric}
965349cc55cSDimitry Andriclet Predicates = [HasExtendLrw] in
966349cc55cSDimitry Andricdef IDLY32 : I_5_IMM5<0x30, 0b000111, 0b00001, "idly32", imm5_idly, []>;
967349cc55cSDimitry Andricdef STOP32 : I_5_XZ_PRIVI<0x12, 0x1, "stop32">;
968349cc55cSDimitry Andricdef WAIT32 : I_5_XZ_PRIVI<0x13, 0x1, "wait32">;
969349cc55cSDimitry Andricdef DOZE32 : I_5_XZ_PRIVI<0x14, 0x1, "doze32">;
970349cc55cSDimitry Andricdef WE32 : I_5_XZ_PRIVI<0b010101, 0x1, "we32">;
971349cc55cSDimitry Andricdef SE32 : I_5_XZ_PRIVI<0b010110, 0x1, "se32">;
972349cc55cSDimitry Andricdef WSC32 : I_5_XZ_PRIVI<0b001111, 0x1, "wsc32">;
973349cc55cSDimitry Andric
974349cc55cSDimitry Andricdef CPOP32 : I_CPOP<(outs), (ins uimm5:$cpid, uimm20:$usdef), "cpop32 <$cpid, ${usdef}>">;
975349cc55cSDimitry Andricdef CPRC32 : I_CP<0b0100, (outs CARRY:$ca), (ins uimm5:$cpid, uimm12:$usdef), "cprc32 <$cpid, ${usdef}>">;
976349cc55cSDimitry Andricdef CPRCR32 : I_CP_Z<0b0010, (outs GPR:$rz), (ins uimm5:$cpid, uimm12:$usdef), "cprcr32 $rz, <$cpid, ${usdef}>">;
977349cc55cSDimitry Andricdef CPRGR32 : I_CP_Z<0b0000, (outs GPR:$rz), (ins uimm5:$cpid, uimm12:$usdef), "cprgr32 $rz, <$cpid, ${usdef}>">;
978349cc55cSDimitry Andricdef CPWCR32 : I_CP_Z<0b0011, (outs), (ins GPR:$rz, uimm5:$cpid, uimm12:$usdef), "cpwcr32 $rz, <$cpid, ${usdef}>">;
979349cc55cSDimitry Andricdef CPWGR32 : I_CP_Z<0b0001, (outs), (ins GPR:$rz, uimm5:$cpid, uimm12:$usdef), "cpwgr32 $rz, <$cpid, ${usdef}>">;
980349cc55cSDimitry Andric
981349cc55cSDimitry Andriclet Predicates = [iHas3r2E3r3] in {
982349cc55cSDimitry Andricdef DCACHE_IALL32 : I_5_CACHE<0b100101, 0b01000, "dcache32.iall">;
983349cc55cSDimitry Andricdef DCACHE_CALL32 : I_5_CACHE<0b100101, 0b00100, "dcache32.call">;
984349cc55cSDimitry Andricdef DCACHE_CIALL32 : I_5_CACHE<0b100101, 0b01100, "dcache32.ciall">;
985349cc55cSDimitry Andricdef DCACHE_IVA32 : I_5_X_CACHE<0b100101, 0b01011, "dcache32.iva">;
986349cc55cSDimitry Andricdef DCACHE_ISW32: I_5_X_CACHE<0b100101, 0b01010, "dcache32.isw">;
987349cc55cSDimitry Andricdef DCACHE_CVA32 : I_5_X_CACHE<0b100101, 0b00111, "dcache32.cva">;
988349cc55cSDimitry Andricdef DCACHE_CVAL32 : I_5_X_CACHE<0b100101, 0b10111, "dcache32.cval1">;
989349cc55cSDimitry Andricdef DCACHE_CSW32 : I_5_X_CACHE<0b100101, 0b00110, "dcache32.csw">;
990349cc55cSDimitry Andricdef DCACHE_CIVA32 : I_5_X_CACHE<0b100101, 0b01111, "dcache32.civa">;
991349cc55cSDimitry Andricdef DCACHE_CISW32 : I_5_X_CACHE<0b100101, 0b01110, "dcache32.cisw">;
992349cc55cSDimitry Andric
993349cc55cSDimitry Andricdef ICACHE_IALL32 : I_5_CACHE<0b100100, 0b01000, "icache32.iall">;
994349cc55cSDimitry Andricdef ICACHE_IALLS32 : I_5_CACHE<0b100100, 0b11000, "icache32.ialls">;
995349cc55cSDimitry Andricdef ICACHE_IVA32 : I_5_X_CACHE<0b100100, 0b01011, "icache32.iva">;
996349cc55cSDimitry Andric
997349cc55cSDimitry Andricdef TLBI_VAA32 : I_5_X_CACHE<0b100010, 0b00010, "tlbi32.vaa">;
998349cc55cSDimitry Andricdef TLBI_VAAS32 : I_5_X_CACHE<0b100010, 0b10010, "tlbi32.vaas">;
999349cc55cSDimitry Andricdef TLBI_ASID32 : I_5_X_CACHE<0b100010, 0b00001, "tlbi32.asid">;
1000349cc55cSDimitry Andricdef TLBI_ASIDS32 : I_5_X_CACHE<0b100010, 0b10001, "tlbi32.asids">;
1001349cc55cSDimitry Andricdef TLBI_VA32 : I_5_X_CACHE<0b100010, 0b00011, "tlbi32.va">;
1002349cc55cSDimitry Andricdef TLBI_VAS32 : I_5_X_CACHE<0b100010, 0b10011, "tlbi32.vas">;
1003349cc55cSDimitry Andricdef TLBI_ALL32 : I_5_CACHE<0b100010, 0b00000, "tlbi32.all">;
1004349cc55cSDimitry Andricdef TLBI_ALLS32 : I_5_CACHE<0b100010, 0b10000, "tlbi32.alls">;
1005349cc55cSDimitry Andric
1006349cc55cSDimitry Andricdef L2CACHE_IALL : I_5_CACHE<0b100110, 0b01000, "l2cache.iall">;
1007349cc55cSDimitry Andricdef L2CACHE_CALL : I_5_CACHE<0b100110, 0b00100, "l2cache.call">;
1008349cc55cSDimitry Andricdef L2CACHE_CIALL : I_5_CACHE<0b100110, 0b01100, "l2cache.ciall">;
1009349cc55cSDimitry Andric}
1010349cc55cSDimitry Andric
1011349cc55cSDimitry Andricdef PLDR32 :I_PLDR<AddrMode32WD, 0x36, 0b0110, (outs), (ins GPR:$rx, uimm12_2:$imm12), "pldr32", []>;
1012349cc55cSDimitry Andricdef PLDW32 :I_PLDR<AddrMode32WD, 0x37, 0b0110, (outs), (ins GPR:$rx, uimm12_2:$imm12), "pldw32", []>;
1013349cc55cSDimitry Andric
1014349cc55cSDimitry Andricdef TRAP32 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins uimm2:$imm2), "trap32 ${imm2}", []> {
1015349cc55cSDimitry Andric  bits<2> imm2;
1016349cc55cSDimitry Andric
1017349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
1018349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
1019349cc55cSDimitry Andric  let Inst{15 - 12} = 0b0010;
1020349cc55cSDimitry Andric  let Inst{11 - 10} = imm2;
1021349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
1022349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
1023349cc55cSDimitry Andric
1024349cc55cSDimitry Andric}
1025349cc55cSDimitry Andric
10260eae32dcSDimitry Andric//===----------------------------------------------------------------------===//
10270eae32dcSDimitry Andric// Instruction Patterns.
10280eae32dcSDimitry Andric//===----------------------------------------------------------------------===//
10290eae32dcSDimitry Andric
10300eae32dcSDimitry Andric// Load & Store Patterns
10310eae32dcSDimitry Andricmulticlass LdPat<PatFrag LoadOp, ImmLeaf imm_type, Instruction Inst, ValueType Type> {
10320eae32dcSDimitry Andric  def : Pat<(Type (LoadOp GPR:$rs1)), (Inst GPR:$rs1, 0)>;
10330eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (i32 frameindex:$rs1))), (Inst (i32 (to_tframeindex tframeindex:$rs1)), 0)>;
10340eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, imm_type:$uimm))),
10350eae32dcSDimitry Andric            (Inst GPR:$rs1, imm_type:$uimm)>;
10360eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add frameindex:$rs1, imm_type:$uimm))),
10370eae32dcSDimitry Andric            (Inst (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm)>;
10380eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (eqToAdd frameindex:$rs1, imm_type:$uimm))),
10390eae32dcSDimitry Andric            (Inst (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm)>;
10400eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, tglobaladdr:$gd))),
10410eae32dcSDimitry Andric            (Inst GPR:$rs1, tglobaladdr:$gd)>;
10420eae32dcSDimitry Andric}
10430eae32dcSDimitry Andric
10440eae32dcSDimitry Andricdefm : LdPat<extloadi8, uimm12, LD32B, i32>;
10450eae32dcSDimitry Andricdefm : LdPat<zextloadi8, uimm12, LD32B, i32>;
10460eae32dcSDimitry Andriclet Predicates = [iHasE2] in {
10470eae32dcSDimitry Andric  defm : LdPat<sextloadi8, uimm12, LD32BS, i32>;
10480eae32dcSDimitry Andric}
10490eae32dcSDimitry Andricdefm : LdPat<extloadi16, uimm12_1, LD32H, i32>;
10500eae32dcSDimitry Andricdefm : LdPat<zextloadi16, uimm12_1, LD32H, i32>;
10510eae32dcSDimitry Andriclet Predicates = [iHasE2] in {
10520eae32dcSDimitry Andricdefm : LdPat<sextloadi16, uimm12_1, LD32HS, i32>;
10530eae32dcSDimitry Andric}
10540eae32dcSDimitry Andricdefm : LdPat<load, uimm12_2, LD32W, i32>;
10550eae32dcSDimitry Andric
10560eae32dcSDimitry Andricmulticlass LdrPat<PatFrag LoadOp, Instruction Inst, ValueType Type> {
10570eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, GPR:$rs2))), (Inst GPR:$rs1, GPR:$rs2, 0)>;
10580eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 1))))), (Inst GPR:$rs1, GPR:$rs2, 1)>;
10590eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 2))))), (Inst GPR:$rs1, GPR:$rs2, 2)>;
10600eae32dcSDimitry Andric  def : Pat<(Type (LoadOp (add GPR:$rs1, (shl GPR:$rs2, (i32 3))))), (Inst GPR:$rs1, GPR:$rs2, 3)>;
10610eae32dcSDimitry Andric}
10620eae32dcSDimitry Andric
10630eae32dcSDimitry Andriclet Predicates = [iHas2E3] in {
10640eae32dcSDimitry Andric  defm : LdrPat<zextloadi8, LDR32B, i32>;
10650eae32dcSDimitry Andric  defm : LdrPat<sextloadi8, LDR32BS, i32>;
10660eae32dcSDimitry Andric  defm : LdrPat<extloadi8, LDR32BS, i32>;
10670eae32dcSDimitry Andric  defm : LdrPat<zextloadi16, LDR32H, i32>;
10680eae32dcSDimitry Andric  defm : LdrPat<sextloadi16, LDR32HS, i32>;
10690eae32dcSDimitry Andric  defm : LdrPat<extloadi16, LDR32HS, i32>;
10700eae32dcSDimitry Andric  defm : LdrPat<load, LDR32W, i32>;
10710eae32dcSDimitry Andric}
10720eae32dcSDimitry Andric
10730eae32dcSDimitry Andricmulticlass StPat<PatFrag StoreOp, ValueType Type, ImmLeaf imm_type, Instruction Inst> {
10740eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, GPR:$rs1), (Inst Type:$rs2, GPR:$rs1, 0)>;
10750eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, frameindex:$rs1), (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), 0)>;
10760eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, (add GPR:$rs1, imm_type:$uimm12)),
10770eae32dcSDimitry Andric            (Inst Type:$rs2, GPR:$rs1, imm_type:$uimm12)>;
10780eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, (add frameindex:$rs1, imm_type:$uimm12)),
10790eae32dcSDimitry Andric            (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm12)>;
10800eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rs2, (eqToAdd frameindex:$rs1, imm_type:$uimm12)),
10810eae32dcSDimitry Andric            (Inst Type:$rs2, (i32 (to_tframeindex tframeindex:$rs1)), imm_type:$uimm12)>;
10820eae32dcSDimitry Andric}
10830eae32dcSDimitry Andric
10840eae32dcSDimitry Andricdefm : StPat<truncstorei8, i32, uimm12, ST32B>;
10850eae32dcSDimitry Andricdefm : StPat<truncstorei16, i32, uimm12_1, ST32H>;
10860eae32dcSDimitry Andricdefm : StPat<store, i32, uimm12_2, ST32W>;
10870eae32dcSDimitry Andric
10880eae32dcSDimitry Andricmulticlass StrPat<PatFrag StoreOp, ValueType Type, Instruction Inst> {
10890eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, GPR:$rs2)), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 0)>;
10900eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 1)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 1)>;
10910eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 2)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 2)>;
10920eae32dcSDimitry Andric  def : Pat<(StoreOp Type:$rz, (add GPR:$rs1, (shl GPR:$rs2, (i32 3)))), (Inst Type:$rz, GPR:$rs1, GPR:$rs2, 3)>;
10930eae32dcSDimitry Andric}
10940eae32dcSDimitry Andric
10950eae32dcSDimitry Andriclet Predicates = [iHas2E3] in {
10960eae32dcSDimitry Andric  defm : StrPat<truncstorei8, i32, STR32B>;
10970eae32dcSDimitry Andric  defm : StrPat<truncstorei16, i32, STR32H>;
10980eae32dcSDimitry Andric  defm : StrPat<store, i32, STR32W>;
10990eae32dcSDimitry Andric
11000eae32dcSDimitry Andric  // Sext & Zext Patterns
11010eae32dcSDimitry Andric  def : Pat<(sext_inreg GPR:$src, i1), (SEXT32 GPR:$src, 0, 0)>;
11020eae32dcSDimitry Andric  def : Pat<(and GPR:$src, 255), (ZEXT32 GPR:$src, 7, 0)>;
11030eae32dcSDimitry Andric  def : Pat<(and GPR:$src, 65535), (ZEXT32 GPR:$src, 15, 0)>;
110404eeddc0SDimitry Andric
110504eeddc0SDimitry Andric   // Call Patterns
110604eeddc0SDimitry Andric  def : Pat<(CSKY_CALL tglobaladdr, tconstpool:$src2), (JSRI32 tconstpool:$src2)>;
110704eeddc0SDimitry Andric  def : Pat<(CSKY_CALL texternalsym, tconstpool:$src2), (JSRI32 tconstpool:$src2)>;
110804eeddc0SDimitry Andric  def : Pat<(CSKY_TAIL tglobaladdr, tconstpool:$src2), (JMPI32 tconstpool:$src2)>;
110904eeddc0SDimitry Andric  def : Pat<(CSKY_TAIL texternalsym, tconstpool:$src2), (JMPI32 tconstpool:$src2)>;
111004eeddc0SDimitry Andric
111104eeddc0SDimitry Andric  def : Pat<(CSKY_CALLReg GPR:$src), (JSR32 GPR:$src)>;
111204eeddc0SDimitry Andric  def : Pat<(CSKY_TAILReg GPR:$src), (JMP32 GPR:$src)>;
111304eeddc0SDimitry Andric}
111404eeddc0SDimitry Andric
111504eeddc0SDimitry Andric// Symbol address Patterns
111604eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tglobaladdr, tconstpool:$src2), (LRW32 tconstpool:$src2)>;
111704eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tblockaddress, tconstpool:$src2), (LRW32 tconstpool:$src2)>;
111804eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR tjumptable:$src1, tconstpool:$src2), (LRW32_Gen tjumptable:$src1, tconstpool:$src2)>;
111904eeddc0SDimitry Andricdef : Pat<(CSKY_LOAD_ADDR texternalsym, tconstpool:$src2), (LRW32 tconstpool:$src2)>;
112004eeddc0SDimitry Andric
112104eeddc0SDimitry Andriclet Predicates = [iHas2E3] in
112204eeddc0SDimitry Andric  def : Pat<(i32 constpool:$src), (GRS32 (to_tconstpool tconstpool:$src))>;
112304eeddc0SDimitry Andric
112404eeddc0SDimitry Andriclet Predicates = [iHasE2] in
112504eeddc0SDimitry Andric  def : Pat<(i32 constpool:$src),
112604eeddc0SDimitry Andric    (ORI32 (MOVIH32 (to_tconstpool_hi16 tconstpool:$src)),
112704eeddc0SDimitry Andric           (to_tconstpool_lo16 tconstpool:$src))>;
112804eeddc0SDimitry Andric
112904eeddc0SDimitry Andricdef : Pat<(i32 (load constpool:$src)), (LRW32 (to_tconstpool tconstpool:$src))>;
113004eeddc0SDimitry Andric
113104eeddc0SDimitry Andric// Branch Patterns.
113204eeddc0SDimitry Andriclet Predicates = [iHasE2] in {
113304eeddc0SDimitry Andric  def : Pat<(brcond CARRY:$ca, bb:$imm16),
113404eeddc0SDimitry Andric          (BT32 CARRY:$ca, bb:$imm16)>;
113504eeddc0SDimitry Andric
113604eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setne GPR:$rs1, uimm16:$rs2)), bb:$imm16),
113704eeddc0SDimitry Andric          (BT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), bb:$imm16)>;
113804eeddc0SDimitry Andric  def : Pat<(brcond (i32 (seteq GPR:$rs1, uimm16:$rs2)), bb:$imm16),
113904eeddc0SDimitry Andric          (BF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), bb:$imm16)>;
114004eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setuge GPR:$rs1, oimm16:$rs2)), bb:$imm16),
114104eeddc0SDimitry Andric          (BT32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
114204eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setult GPR:$rs1, oimm16:$rs2)), bb:$imm16),
114304eeddc0SDimitry Andric          (BF32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
114404eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setlt GPR:$rs1, oimm16:$rs2)), bb:$imm16),
114504eeddc0SDimitry Andric          (BT32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
114604eeddc0SDimitry Andric  def : Pat<(brcond (i32 (setge GPR:$rs1, oimm16:$rs2)), bb:$imm16),
114704eeddc0SDimitry Andric          (BF32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
114804eeddc0SDimitry Andric
114904eeddc0SDimitry Andric}
115004eeddc0SDimitry Andric
115104eeddc0SDimitry Andriclet Predicates = [iHas2E3] in {
115204eeddc0SDimitry Andric
115304eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setne GPR:$rs1, GPR:$rs2)), bb:$imm16),
115404eeddc0SDimitry Andric          (BT32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
115504eeddc0SDimitry Andricdef : Pat<(brcond (i32 (seteq GPR:$rs1, GPR:$rs2)), bb:$imm16),
115604eeddc0SDimitry Andric          (BF32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
115704eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setuge GPR:$rs1, GPR:$rs2)), bb:$imm16),
115804eeddc0SDimitry Andric          (BT32 (CMPHS32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
115904eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setule GPR:$rs1, GPR:$rs2)), bb:$imm16),
116004eeddc0SDimitry Andric          (BT32 (CMPHS32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
116104eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setult GPR:$rs1, GPR:$rs2)), bb:$imm16),
116204eeddc0SDimitry Andric          (BF32 (CMPHS32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
116304eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setugt GPR:$rs1, GPR:$rs2)), bb:$imm16),
116404eeddc0SDimitry Andric          (BF32 (CMPHS32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
116504eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setlt GPR:$rs1, GPR:$rs2)), bb:$imm16),
116604eeddc0SDimitry Andric          (BT32 (CMPLT32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
116704eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setgt GPR:$rs1, GPR:$rs2)), bb:$imm16),
116804eeddc0SDimitry Andric          (BT32 (CMPLT32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
116904eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setge GPR:$rs1, GPR:$rs2)), bb:$imm16),
117004eeddc0SDimitry Andric          (BF32 (CMPLT32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
117104eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setle GPR:$rs1, GPR:$rs2)), bb:$imm16),
117204eeddc0SDimitry Andric          (BF32 (CMPLT32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
117304eeddc0SDimitry Andric
117404eeddc0SDimitry Andricdef : Pat<(brcond (i32 (seteq GPR:$rs1, (i32 0))), bb:$imm16),
117504eeddc0SDimitry Andric          (BEZ32 GPR:$rs1, bb:$imm16)>;
117604eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setne GPR:$rs1, (i32 0))), bb:$imm16),
117704eeddc0SDimitry Andric          (BNEZ32 GPR:$rs1, bb:$imm16)>;
117804eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setlt GPR:$rs1, (i32 0))), bb:$imm16),
117904eeddc0SDimitry Andric          (BLZ32 GPR:$rs1, bb:$imm16)>;
118004eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setge GPR:$rs1, (i32 0))), bb:$imm16),
118104eeddc0SDimitry Andric          (BHSZ32 GPR:$rs1, bb:$imm16)>;
118204eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setgt GPR:$rs1, (i32 0))), bb:$imm16),
118304eeddc0SDimitry Andric          (BHZ32 GPR:$rs1, bb:$imm16)>;
118404eeddc0SDimitry Andricdef : Pat<(brcond (i32 (setle GPR:$rs1, (i32 0))), bb:$imm16),
118504eeddc0SDimitry Andric          (BLSZ32 GPR:$rs1, bb:$imm16)>;
118604eeddc0SDimitry Andric}
118704eeddc0SDimitry Andric
118804eeddc0SDimitry Andric// Compare Patterns.
118904eeddc0SDimitry Andriclet Predicates = [iHas2E3] in {
119004eeddc0SDimitry Andric  def : Pat<(setne GPR:$rs1, GPR:$rs2),
119104eeddc0SDimitry Andric            (CMPNE32 GPR:$rs1, GPR:$rs2)>;
119204eeddc0SDimitry Andric  def : Pat<(i32 (seteq GPR:$rs1, GPR:$rs2)),
119304eeddc0SDimitry Andric            (MVCV32 (CMPNE32 GPR:$rs1, GPR:$rs2))>;
119404eeddc0SDimitry Andric  def : Pat<(setuge GPR:$rs1, GPR:$rs2),
119504eeddc0SDimitry Andric            (CMPHS32 GPR:$rs1, GPR:$rs2)>;
119604eeddc0SDimitry Andric  def : Pat<(setule GPR:$rs1, GPR:$rs2),
119704eeddc0SDimitry Andric            (CMPHS32 GPR:$rs2, GPR:$rs1)>;
119804eeddc0SDimitry Andric  def : Pat<(i32 (setult GPR:$rs1, GPR:$rs2)),
119904eeddc0SDimitry Andric            (MVCV32 (CMPHS32 GPR:$rs1, GPR:$rs2))>;
120004eeddc0SDimitry Andric  def : Pat<(i32 (setugt GPR:$rs1, GPR:$rs2)),
120104eeddc0SDimitry Andric            (MVCV32 (CMPHS32 GPR:$rs2, GPR:$rs1))>;
120204eeddc0SDimitry Andric  def : Pat<(setlt GPR:$rs1, GPR:$rs2),
120304eeddc0SDimitry Andric            (CMPLT32 GPR:$rs1, GPR:$rs2)>;
120404eeddc0SDimitry Andric  def : Pat<(setgt GPR:$rs1, GPR:$rs2),
120504eeddc0SDimitry Andric            (CMPLT32 GPR:$rs2, GPR:$rs1)>;
120604eeddc0SDimitry Andric  def : Pat<(i32 (setge GPR:$rs1, GPR:$rs2)),
120704eeddc0SDimitry Andric            (MVCV32 (CMPLT32 GPR:$rs1, GPR:$rs2))>;
120804eeddc0SDimitry Andric  def : Pat<(i32 (setle GPR:$rs1, GPR:$rs2)),
120904eeddc0SDimitry Andric            (MVCV32 (CMPLT32 GPR:$rs2, GPR:$rs1))>;
121004eeddc0SDimitry Andric}
121104eeddc0SDimitry Andric
121204eeddc0SDimitry Andriclet Predicates = [iHasE2] in {
121304eeddc0SDimitry Andric  def : Pat<(setne GPR:$rs1, uimm16:$rs2),
121404eeddc0SDimitry Andric            (CMPNEI32 GPR:$rs1, uimm16:$rs2)>;
121504eeddc0SDimitry Andric  let Predicates = [iHas2E3] in
121604eeddc0SDimitry Andric  def : Pat<(i32 (seteq GPR:$rs1, uimm16:$rs2)),
121704eeddc0SDimitry Andric            (MVCV32 (CMPNEI32 GPR:$rs1, uimm16:$rs2))>;
121804eeddc0SDimitry Andric  def : Pat<(setuge GPR:$rs1, oimm16:$rs2),
121904eeddc0SDimitry Andric            (CMPHSI32 GPR:$rs1, oimm16:$rs2)>;
122004eeddc0SDimitry Andric  let Predicates = [iHas2E3] in
122104eeddc0SDimitry Andric  def : Pat<(i32 (setult GPR:$rs1, oimm16:$rs2)),
122204eeddc0SDimitry Andric            (MVCV32 (CMPHSI32 GPR:$rs1, oimm16:$rs2))>;
122304eeddc0SDimitry Andric  def : Pat<(setlt GPR:$rs1, oimm16:$rs2),
122404eeddc0SDimitry Andric            (CMPLTI32 GPR:$rs1, oimm16:$rs2)>;
122504eeddc0SDimitry Andric  let Predicates = [iHas2E3] in
122604eeddc0SDimitry Andric  def : Pat<(i32 (setge GPR:$rs1, oimm16:$rs2)),
122704eeddc0SDimitry Andric            (MVCV32 (CMPLTI32 GPR:$rs1, oimm16:$rs2))>;
122804eeddc0SDimitry Andric}
122904eeddc0SDimitry Andric
123004eeddc0SDimitry Andric// Select Patterns.
123104eeddc0SDimitry Andriclet Predicates = [iHasE2] in {
123204eeddc0SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false),
123304eeddc0SDimitry Andric          (MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>;
123404eeddc0SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false),
123504eeddc0SDimitry Andric          (MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>;
123604eeddc0SDimitry Andric
123704eeddc0SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
123804eeddc0SDimitry Andric          (MOVT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
123904eeddc0SDimitry Andricdef : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), GPR:$rx, GPR:$false),
124004eeddc0SDimitry Andric          (MOVT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$rx, GPR:$false)>;
124104eeddc0SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
124204eeddc0SDimitry Andric          (MOVF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
124304eeddc0SDimitry Andricdef : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), GPR:$rx, GPR:$false),
124404eeddc0SDimitry Andric          (MOVF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$rx, GPR:$false)>;
124504eeddc0SDimitry Andric
124604eeddc0SDimitry Andricdef : Pat<(select (i32 (setuge GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
124704eeddc0SDimitry Andric          (MOVT32 (CMPHS32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
124804eeddc0SDimitry Andricdef : Pat<(select (i32 (setuge GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
124904eeddc0SDimitry Andric          (MOVT32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
125004eeddc0SDimitry Andricdef : Pat<(select (i32 (setule GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
125104eeddc0SDimitry Andric          (MOVT32 (CMPHS32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
125204eeddc0SDimitry Andricdef : Pat<(select (i32 (setult GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
125304eeddc0SDimitry Andric          (MOVF32 (CMPHS32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
125404eeddc0SDimitry Andricdef : Pat<(select (i32 (setult GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
125504eeddc0SDimitry Andric          (MOVF32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
125604eeddc0SDimitry Andricdef : Pat<(select (i32 (setugt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
125704eeddc0SDimitry Andric          (MOVF32 (CMPHS32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
125804eeddc0SDimitry Andric
125904eeddc0SDimitry Andricdef : Pat<(select (i32 (setlt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
126004eeddc0SDimitry Andric          (MOVT32 (CMPLT32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
126104eeddc0SDimitry Andricdef : Pat<(select (i32 (setlt GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
126204eeddc0SDimitry Andric          (MOVT32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
126304eeddc0SDimitry Andricdef : Pat<(select (i32 (setgt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
126404eeddc0SDimitry Andric          (MOVT32 (CMPLT32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
126504eeddc0SDimitry Andricdef : Pat<(select (i32 (setge GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
126604eeddc0SDimitry Andric          (MOVF32 (CMPLT32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
126704eeddc0SDimitry Andricdef : Pat<(select (i32 (setge GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
126804eeddc0SDimitry Andric          (MOVF32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
126904eeddc0SDimitry Andricdef : Pat<(select (i32 (setle GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
127004eeddc0SDimitry Andric          (MOVF32 (CMPLT32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
127104eeddc0SDimitry Andric
127204eeddc0SDimitry Andricdef : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false),
127304eeddc0SDimitry Andric          (ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>;
127404eeddc0SDimitry Andricdef : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false),
127504eeddc0SDimitry Andric          (ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>;
12760eae32dcSDimitry Andric}
12770eae32dcSDimitry Andric
12780eae32dcSDimitry Andric// Constant materialize patterns.
12790eae32dcSDimitry Andriclet Predicates = [iHasE2] in
12800eae32dcSDimitry Andric  def : Pat<(i32 imm:$imm),
12810eae32dcSDimitry Andric            (ORI32 (MOVIH32 (uimm32_hi16 imm:$imm)), (uimm32_lo16 imm:$imm))>;
12820eae32dcSDimitry Andric
12830eae32dcSDimitry Andric
12840eae32dcSDimitry Andric// Other operations.
12850eae32dcSDimitry Andriclet Predicates = [iHasE2] in {
12860eae32dcSDimitry Andric  def : Pat<(rotl GPR:$rs1, GPR:$rs2),
12870eae32dcSDimitry Andric            (ROTL32 GPR:$rs1, (ANDI32 GPR:$rs2, 0x1f))>;
12880eae32dcSDimitry Andric  let Predicates = [iHas2E3] in {
12890eae32dcSDimitry Andric    def : Pat<(bitreverse GPR:$rx), (BREV32 GPR:$rx)>;
12900eae32dcSDimitry Andric    def : Pat<(bswap GPR:$rx), (REVB32 GPR:$rx)>;
12910eae32dcSDimitry Andric  }
12920eae32dcSDimitry Andric  def : Pat<(i32 (ctlz GPR:$rx)), (FF1 GPR:$rx)>;
12930eae32dcSDimitry Andric}
1294349cc55cSDimitry Andric
1295349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
1296349cc55cSDimitry Andric// Pseudo for assembly
1297349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
1298349cc55cSDimitry Andric
1299349cc55cSDimitry Andriclet isCall = 1, Defs = [ R15 ], mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
1300349cc55cSDimitry Andricdef JBSR32 : CSKYPseudo<(outs), (ins call_symbol:$src1), "jbsr32\t$src1", []>;
1301349cc55cSDimitry Andric
1302349cc55cSDimitry Andricdef JBR32 : CSKYPseudo<(outs), (ins br_symbol:$src1), "jbr32\t$src1", []> {
1303349cc55cSDimitry Andric  let isBranch = 1;
1304349cc55cSDimitry Andric  let isTerminator = 1;
1305349cc55cSDimitry Andric  let isBarrier = 1;
1306349cc55cSDimitry Andric  let isIndirectBranch = 1;
1307349cc55cSDimitry Andric  let mayLoad = 1;
1308349cc55cSDimitry Andric  let Size = 4;
1309349cc55cSDimitry Andric}
1310349cc55cSDimitry Andric
1311349cc55cSDimitry Andricdef JBT32 : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "jbt32\t$src1", []> {
1312349cc55cSDimitry Andric  let isBranch = 1;
1313349cc55cSDimitry Andric  let isTerminator = 1;
1314349cc55cSDimitry Andric  let isIndirectBranch = 1;
1315349cc55cSDimitry Andric  let mayLoad = 1;
1316349cc55cSDimitry Andric  let Size = 4;
1317349cc55cSDimitry Andric}
1318349cc55cSDimitry Andric
1319349cc55cSDimitry Andricdef JBF32 : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "jbf32\t$src1", []> {
1320349cc55cSDimitry Andric  let isBranch = 1;
1321349cc55cSDimitry Andric  let isTerminator = 1;
1322349cc55cSDimitry Andric  let isIndirectBranch = 1;
1323349cc55cSDimitry Andric  let mayLoad = 1;
1324349cc55cSDimitry Andric  let Size = 4;
1325349cc55cSDimitry Andric}
1326349cc55cSDimitry Andric
1327349cc55cSDimitry Andricdef JBT_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbt_e\t$src1", []> {
1328349cc55cSDimitry Andric  let isBranch = 1;
1329349cc55cSDimitry Andric  let isTerminator = 1;
1330349cc55cSDimitry Andric  let isIndirectBranch = 1;
1331349cc55cSDimitry Andric  let mayLoad = 1;
1332349cc55cSDimitry Andric  let Size = 6;
1333349cc55cSDimitry Andric}
1334349cc55cSDimitry Andric
1335349cc55cSDimitry Andricdef JBF_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbf_e\t$src1", []> {
1336349cc55cSDimitry Andric  let isBranch = 1;
1337349cc55cSDimitry Andric  let isTerminator = 1;
1338349cc55cSDimitry Andric  let isIndirectBranch = 1;
1339349cc55cSDimitry Andric  let mayLoad = 1;
1340349cc55cSDimitry Andric  let Size = 6;
1341349cc55cSDimitry Andric}
1342349cc55cSDimitry Andric
1343349cc55cSDimitry Andriclet mayLoad = 1, Size = 2, isCodeGenOnly = 0 in
1344349cc55cSDimitry Andricdef PseudoLRW32 : CSKYPseudo<(outs GPR:$rz), (ins bare_symbol:$src), "lrw32 $rz, $src", []>;
1345349cc55cSDimitry Andric
1346349cc55cSDimitry Andric
1347*81ad6265SDimitry Andric
1348349cc55cSDimitry Andric
1349349cc55cSDimitry Andriclet mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
1350349cc55cSDimitry Andricdef PseudoJSRI32 : CSKYPseudo<(outs), (ins call_symbol:$src), "jsri32 $src", []>;
1351349cc55cSDimitry Andric
1352349cc55cSDimitry Andriclet mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
1353349cc55cSDimitry Andricdef PseudoJMPI32 : CSKYPseudo<(outs), (ins br_symbol:$src), "jmpi32 $src", []>;
1354349cc55cSDimitry Andric
1355349cc55cSDimitry Andriclet isNotDuplicable = 1, mayLoad = 1, mayStore = 0, Size = 8 in
1356349cc55cSDimitry Andricdef PseudoTLSLA32 : CSKYPseudo<(outs GPR:$dst1, GPR:$dst2),
1357349cc55cSDimitry Andric  (ins constpool_symbol:$src, i32imm:$label), "!tlslrw32\t$dst1, $dst2, $src, $label", []>;
1358349cc55cSDimitry Andric
1359349cc55cSDimitry Andriclet hasSideEffects = 0, isNotDuplicable = 1 in
1360349cc55cSDimitry Andricdef CONSTPOOL_ENTRY : CSKYPseudo<(outs),
1361349cc55cSDimitry Andric  (ins i32imm:$instid, i32imm:$cpidx, i32imm:$size), "", []>;
1362349cc55cSDimitry Andric
1363349cc55cSDimitry Andricinclude "CSKYInstrInfo16Instr.td"
136404eeddc0SDimitry Andricinclude "CSKYInstrInfoF1.td"
136504eeddc0SDimitry Andricinclude "CSKYInstrInfoF2.td"
1366*81ad6265SDimitry Andricinclude "CSKYInstrAlias.td"
1367