144d4fec24665da3efb9a714b0f3bd7ec873c1da
[oota-llvm.git] / lib / Target / XCore / XCoreInstrInfo.td
1 //===-- XCoreInstrInfo.td - Target Description for XCore ---*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the XCore instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 // Uses of CP, DP are not currently reflected in the patterns, since
15 // having a physical register as an operand prevents loop hoisting and
16 // since the value of these registers never changes during the life of the
17 // function.
18
19 //===----------------------------------------------------------------------===//
20 // Instruction format superclass.
21 //===----------------------------------------------------------------------===//
22
23 include "XCoreInstrFormats.td"
24
25 //===----------------------------------------------------------------------===//
26 // XCore specific DAG Nodes.
27 //
28
29 // Call
30 def SDT_XCoreBranchLink : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
31 def XCoreBranchLink     : SDNode<"XCoreISD::BL",SDT_XCoreBranchLink,
32                             [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
33                              SDNPVariadic]>;
34
35 def XCoreRetsp : SDNode<"XCoreISD::RETSP", SDTBrind,
36                       [SDNPHasChain, SDNPOptInGlue, SDNPMayLoad, SDNPVariadic]>;
37
38 def SDT_XCoreBR_JT    : SDTypeProfile<0, 2,
39                                       [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
40
41 def XCoreBR_JT : SDNode<"XCoreISD::BR_JT", SDT_XCoreBR_JT,
42                         [SDNPHasChain]>;
43
44 def XCoreBR_JT32 : SDNode<"XCoreISD::BR_JT32", SDT_XCoreBR_JT,
45                         [SDNPHasChain]>;
46
47 def SDT_XCoreAddress    : SDTypeProfile<1, 1,
48                             [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
49
50 def pcrelwrapper : SDNode<"XCoreISD::PCRelativeWrapper", SDT_XCoreAddress,
51                            []>;
52
53 def dprelwrapper : SDNode<"XCoreISD::DPRelativeWrapper", SDT_XCoreAddress,
54                            []>;
55
56 def cprelwrapper : SDNode<"XCoreISD::CPRelativeWrapper", SDT_XCoreAddress,
57                            []>;
58
59 def frametoargsoffset : SDNode<"XCoreISD::FRAME_TO_ARGS_OFFSET", SDTIntLeaf,
60                                []>;
61
62 def SDT_XCoreStwsp    : SDTypeProfile<0, 2, [SDTCisInt<1>]>;
63 def XCoreStwsp        : SDNode<"XCoreISD::STWSP", SDT_XCoreStwsp,
64                                [SDNPHasChain, SDNPMayStore]>;
65
66 // These are target-independent nodes, but have target-specific formats.
67 def SDT_XCoreCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
68 def SDT_XCoreCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
69                                         SDTCisVT<1, i32> ]>;
70
71 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_XCoreCallSeqStart,
72                            [SDNPHasChain, SDNPOutGlue]>;
73 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_XCoreCallSeqEnd,
74                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
75
76 def SDT_XCoreMEMBARRIER : SDTypeProfile<0, 0, []>;
77
78 def XCoreMemBarrier : SDNode<"XCoreISD::MEMBARRIER", SDT_XCoreMEMBARRIER,
79                              [SDNPHasChain]>;
80
81 //===----------------------------------------------------------------------===//
82 // Instruction Pattern Stuff
83 //===----------------------------------------------------------------------===//
84
85 def div4_xform : SDNodeXForm<imm, [{
86   // Transformation function: imm/4
87   assert(N->getZExtValue() % 4 == 0);
88   return getI32Imm(N->getZExtValue()/4);
89 }]>;
90
91 def msksize_xform : SDNodeXForm<imm, [{
92   // Transformation function: get the size of a mask
93   assert(isMask_32(N->getZExtValue()));
94   // look for the first non-zero bit
95   return getI32Imm(32 - countLeadingZeros((uint32_t)N->getZExtValue()));
96 }]>;
97
98 def neg_xform : SDNodeXForm<imm, [{
99   // Transformation function: -imm
100   uint32_t value = N->getZExtValue();
101   return getI32Imm(-value);
102 }]>;
103
104 def bpwsub_xform : SDNodeXForm<imm, [{
105   // Transformation function: 32-imm
106   uint32_t value = N->getZExtValue();
107   return getI32Imm(32-value);
108 }]>;
109
110 def div4neg_xform : SDNodeXForm<imm, [{
111   // Transformation function: -imm/4
112   uint32_t value = N->getZExtValue();
113   assert(-value % 4 == 0);
114   return getI32Imm(-value/4);
115 }]>;
116
117 def immUs4Neg : PatLeaf<(imm), [{
118   uint32_t value = (uint32_t)N->getZExtValue();
119   return (-value)%4 == 0 && (-value)/4 <= 11;
120 }]>;
121
122 def immUs4 : PatLeaf<(imm), [{
123   uint32_t value = (uint32_t)N->getZExtValue();
124   return value%4 == 0 && value/4 <= 11;
125 }]>;
126
127 def immUsNeg : PatLeaf<(imm), [{
128   return -((uint32_t)N->getZExtValue()) <= 11;
129 }]>;
130
131 def immUs : PatLeaf<(imm), [{
132   return (uint32_t)N->getZExtValue() <= 11;
133 }]>;
134
135 def immU6 : PatLeaf<(imm), [{
136   return (uint32_t)N->getZExtValue() < (1 << 6);
137 }]>;
138
139 def immU10 : PatLeaf<(imm), [{
140   return (uint32_t)N->getZExtValue() < (1 << 10);
141 }]>;
142
143 def immU16 : PatLeaf<(imm), [{
144   return (uint32_t)N->getZExtValue() < (1 << 16);
145 }]>;
146
147 def immU20 : PatLeaf<(imm), [{
148   return (uint32_t)N->getZExtValue() < (1 << 20);
149 }]>;
150
151 def immMskBitp : PatLeaf<(imm), [{ return immMskBitp(N); }]>;
152
153 def immBitp : PatLeaf<(imm), [{
154   uint32_t value = (uint32_t)N->getZExtValue();
155   return (value >= 1 && value <= 8)
156           || value == 16
157           || value == 24
158           || value == 32;
159 }]>;
160
161 def immBpwSubBitp : PatLeaf<(imm), [{
162   uint32_t value = (uint32_t)N->getZExtValue();
163   return (value >= 24 && value <= 31)
164           || value == 16
165           || value == 8
166           || value == 0;
167 }]>;
168
169 def lda16f : PatFrag<(ops node:$addr, node:$offset),
170                      (add node:$addr, (shl node:$offset, 1))>;
171 def lda16b : PatFrag<(ops node:$addr, node:$offset),
172                      (sub node:$addr, (shl node:$offset, 1))>;
173 def ldawf : PatFrag<(ops node:$addr, node:$offset),
174                      (add node:$addr, (shl node:$offset, 2))>;
175 def ldawb : PatFrag<(ops node:$addr, node:$offset),
176                      (sub node:$addr, (shl node:$offset, 2))>;
177
178 // Instruction operand types
179 def pcrel_imm  : Operand<i32>;
180 def pcrel_imm_neg  : Operand<i32> {
181   let DecoderMethod = "DecodeNegImmOperand";
182 }
183 def brtarget : Operand<OtherVT>;
184 def brtarget_neg : Operand<OtherVT> {
185   let DecoderMethod = "DecodeNegImmOperand";
186 }
187
188 // Addressing modes
189 def ADDRspii : ComplexPattern<i32, 2, "SelectADDRspii", [add, frameindex], []>;
190
191 // Address operands
192 def MEMii : Operand<i32> {
193   let MIOperandInfo = (ops i32imm, i32imm);
194 }
195
196 // Jump tables.
197 def InlineJT : Operand<i32> {
198   let PrintMethod = "printInlineJT";
199 }
200
201 def InlineJT32 : Operand<i32> {
202   let PrintMethod = "printInlineJT32";
203 }
204
205 //===----------------------------------------------------------------------===//
206 // Instruction Class Templates
207 //===----------------------------------------------------------------------===//
208
209 // Three operand short
210
211 multiclass F3R_2RUS<bits<5> opc1, bits<5> opc2, string OpcStr, SDNode OpNode> {
212   def _3r: _F3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
213                 !strconcat(OpcStr, " $dst, $b, $c"),
214                 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
215   def _2rus : _F2RUS<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
216                      !strconcat(OpcStr, " $dst, $b, $c"),
217                      [(set GRRegs:$dst, (OpNode GRRegs:$b, immUs:$c))]>;
218 }
219
220 multiclass F3R_2RUS_np<bits<5> opc1, bits<5> opc2, string OpcStr> {
221   def _3r: _F3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
222                 !strconcat(OpcStr, " $dst, $b, $c"), []>;
223   def _2rus : _F2RUS<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
224                      !strconcat(OpcStr, " $dst, $b, $c"), []>;
225 }
226
227 multiclass F3R_2RBITP<bits<5> opc1, bits<5> opc2, string OpcStr,
228                       SDNode OpNode> {
229   def _3r: _F3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
230                 !strconcat(OpcStr, " $dst, $b, $c"),
231                 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
232   def _2rus : _F2RUSBitp<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
233                          !strconcat(OpcStr, " $dst, $b, $c"),
234                          [(set GRRegs:$dst, (OpNode GRRegs:$b, immBitp:$c))]>;
235 }
236
237 class F3R<bits<5> opc, string OpcStr, SDNode OpNode> :
238   _F3R<opc, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
239        !strconcat(OpcStr, " $dst, $b, $c"),
240        [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
241
242 class F3R_np<bits<5> opc, string OpcStr> :
243   _F3R<opc, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
244        !strconcat(OpcStr, " $dst, $b, $c"), []>;
245 // Three operand long
246
247 /// FL3R_L2RUS multiclass - Define a normal FL3R/FL2RUS pattern in one shot.
248 multiclass FL3R_L2RUS<bits<9> opc1, bits<9> opc2, string OpcStr,
249                       SDNode OpNode> {
250   def _l3r: _FL3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
251                   !strconcat(OpcStr, " $dst, $b, $c"),
252                   [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
253   def _l2rus : _FL2RUS<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
254                        !strconcat(OpcStr, " $dst, $b, $c"),
255                        [(set GRRegs:$dst, (OpNode GRRegs:$b, immUs:$c))]>;
256 }
257
258 /// FL3R_L2RUS multiclass - Define a normal FL3R/FL2RUS pattern in one shot.
259 multiclass FL3R_L2RBITP<bits<9> opc1, bits<9> opc2, string OpcStr,
260                         SDNode OpNode> {
261   def _l3r: _FL3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
262                   !strconcat(OpcStr, " $dst, $b, $c"),
263                   [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
264   def _l2rus : _FL2RUSBitp<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
265                            !strconcat(OpcStr, " $dst, $b, $c"),
266                            [(set GRRegs:$dst, (OpNode GRRegs:$b, immBitp:$c))]>;
267 }
268
269 class FL3R<bits<9> opc, string OpcStr, SDNode OpNode> :
270   _FL3R<opc, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
271         !strconcat(OpcStr, " $dst, $b, $c"),
272         [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
273
274 // Register - U6
275 // Operand register - U6
276 multiclass FRU6_LRU6_branch<bits<6> opc, string OpcStr> {
277   def _ru6: _FRU6<opc, (outs), (ins GRRegs:$a, brtarget:$b),
278                   !strconcat(OpcStr, " $a, $b"), []>;
279   def _lru6: _FLRU6<opc, (outs), (ins GRRegs:$a, brtarget:$b),
280                     !strconcat(OpcStr, " $a, $b"), []>;
281 }
282
283 multiclass FRU6_LRU6_backwards_branch<bits<6> opc, string OpcStr> {
284   def _ru6: _FRU6<opc, (outs), (ins GRRegs:$a, brtarget_neg:$b),
285                   !strconcat(OpcStr, " $a, $b"), []>;
286   def _lru6: _FLRU6<opc, (outs), (ins GRRegs:$a, brtarget_neg:$b),
287                     !strconcat(OpcStr, " $a, $b"), []>;
288 }
289
290
291 // U6
292 multiclass FU6_LU6<bits<10> opc, string OpcStr, SDNode OpNode> {
293   def _u6: _FU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
294                 [(OpNode immU6:$a)]>;
295   def _lu6: _FLU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
296                   [(OpNode immU16:$a)]>;
297 }
298
299 multiclass FU6_LU6_int<bits<10> opc, string OpcStr, Intrinsic Int> {
300   def _u6: _FU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
301                 [(Int immU6:$a)]>;
302   def _lu6: _FLU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
303                   [(Int immU16:$a)]>;
304 }
305
306 multiclass FU6_LU6_np<bits<10> opc, string OpcStr> {
307   def _u6: _FU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"), []>;
308   def _lu6: _FLU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"), []>;
309 }
310
311 // Two operand short
312
313 class F2R_np<bits<6> opc, string OpcStr> :
314   _F2R<opc, (outs GRRegs:$dst), (ins GRRegs:$b),
315        !strconcat(OpcStr, " $dst, $b"), []>;
316
317 // Two operand long
318
319 //===----------------------------------------------------------------------===//
320 // Pseudo Instructions
321 //===----------------------------------------------------------------------===//
322
323 let Defs = [SP], Uses = [SP] in {
324 def ADJCALLSTACKDOWN : PseudoInstXCore<(outs), (ins i32imm:$amt),
325                                "# ADJCALLSTACKDOWN $amt",
326                                [(callseq_start timm:$amt)]>;
327 def ADJCALLSTACKUP : PseudoInstXCore<(outs), (ins i32imm:$amt1, i32imm:$amt2),
328                             "# ADJCALLSTACKUP $amt1",
329                             [(callseq_end timm:$amt1, timm:$amt2)]>;
330 }
331
332 let isReMaterializable = 1 in
333 def FRAME_TO_ARGS_OFFSET : PseudoInstXCore<(outs GRRegs:$dst), (ins),
334                                "# FRAME_TO_ARGS_OFFSET $dst",
335                                [(set GRRegs:$dst, (frametoargsoffset))]>;
336
337 def LDWFI : PseudoInstXCore<(outs GRRegs:$dst), (ins MEMii:$addr),
338                              "# LDWFI $dst, $addr",
339                              [(set GRRegs:$dst, (load ADDRspii:$addr))]>;
340
341 def LDAWFI : PseudoInstXCore<(outs GRRegs:$dst), (ins MEMii:$addr),
342                              "# LDAWFI $dst, $addr",
343                              [(set GRRegs:$dst, ADDRspii:$addr)]>;
344
345 def STWFI : PseudoInstXCore<(outs), (ins GRRegs:$src, MEMii:$addr),
346                             "# STWFI $src, $addr",
347                             [(store GRRegs:$src, ADDRspii:$addr)]>;
348
349 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
350 // instruction selection into a branch sequence.
351 let usesCustomInserter = 1 in {
352   def SELECT_CC : PseudoInstXCore<(outs GRRegs:$dst),
353                               (ins GRRegs:$cond, GRRegs:$T, GRRegs:$F),
354                               "# SELECT_CC PSEUDO!",
355                               [(set GRRegs:$dst,
356                                  (select GRRegs:$cond, GRRegs:$T, GRRegs:$F))]>;
357 }
358
359 let hasSideEffects = 1 in
360 def Int_MemBarrier : PseudoInstXCore<(outs), (ins), "#MEMBARRIER",
361                                      [(XCoreMemBarrier)]>;
362
363 //===----------------------------------------------------------------------===//
364 // Instructions
365 //===----------------------------------------------------------------------===//
366
367 // Three operand short
368 defm ADD : F3R_2RUS<0b00010, 0b10010, "add", add>;
369 defm SUB : F3R_2RUS<0b00011, 0b10011, "sub", sub>;
370 let neverHasSideEffects = 1 in {
371 defm EQ : F3R_2RUS_np<0b00110, 0b10110, "eq">;
372 def LSS_3r : F3R_np<0b11000, "lss">;
373 def LSU_3r : F3R_np<0b11001, "lsu">;
374 }
375 def AND_3r : F3R<0b00111, "and", and>;
376 def OR_3r : F3R<0b01000, "or", or>;
377
378 let mayLoad=1 in {
379 def LDW_3r : _F3R<0b01001, (outs GRRegs:$dst),
380                   (ins GRRegs:$addr, GRRegs:$offset),
381                   "ldw $dst, $addr[$offset]", []>;
382
383 def LDW_2rus : _F2RUS<0b00001, (outs GRRegs:$dst),
384                       (ins GRRegs:$addr, i32imm:$offset),
385                       "ldw $dst, $addr[$offset]", []>;
386
387 def LD16S_3r :  _F3R<0b10000, (outs GRRegs:$dst),
388                      (ins GRRegs:$addr, GRRegs:$offset),
389                      "ld16s $dst, $addr[$offset]", []>;
390
391 def LD8U_3r :  _F3R<0b10001, (outs GRRegs:$dst),
392                     (ins GRRegs:$addr, GRRegs:$offset),
393                     "ld8u $dst, $addr[$offset]", []>;
394 }
395
396 let mayStore=1 in {
397 def STW_l3r : _FL3R<0b000001100, (outs),
398                     (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
399                     "stw $val, $addr[$offset]", []>;
400
401 def STW_2rus : _F2RUS<0b0000, (outs),
402                       (ins GRRegs:$val, GRRegs:$addr, i32imm:$offset),
403                       "stw $val, $addr[$offset]", []>;
404 }
405
406 defm SHL : F3R_2RBITP<0b00100, 0b10100, "shl", shl>;
407 defm SHR : F3R_2RBITP<0b00101, 0b10101, "shr", srl>;
408
409 // The first operand is treated as an immediate since it refers to a register
410 // number in another thread.
411 def TSETR_3r : _F3RImm<0b10111, (outs), (ins i32imm:$a, GRRegs:$b, GRRegs:$c),
412                        "set t[$c]:r$a, $b", []>;
413
414 // Three operand long
415 def LDAWF_l3r : _FL3R<0b000111100, (outs GRRegs:$dst),
416                       (ins GRRegs:$addr, GRRegs:$offset),
417                       "ldaw $dst, $addr[$offset]",
418                       [(set GRRegs:$dst,
419                          (ldawf GRRegs:$addr, GRRegs:$offset))]>;
420
421 let neverHasSideEffects = 1 in
422 def LDAWF_l2rus : _FL2RUS<0b100111100, (outs GRRegs:$dst),
423                           (ins GRRegs:$addr, i32imm:$offset),
424                           "ldaw $dst, $addr[$offset]", []>;
425
426 def LDAWB_l3r : _FL3R<0b001001100, (outs GRRegs:$dst),
427                       (ins GRRegs:$addr, GRRegs:$offset),
428                       "ldaw $dst, $addr[-$offset]",
429                       [(set GRRegs:$dst,
430                          (ldawb GRRegs:$addr, GRRegs:$offset))]>;
431
432 let neverHasSideEffects = 1 in
433 def LDAWB_l2rus : _FL2RUS<0b101001100, (outs GRRegs:$dst),
434                          (ins GRRegs:$addr, i32imm:$offset),
435                          "ldaw $dst, $addr[-$offset]", []>;
436
437 def LDA16F_l3r : _FL3R<0b001011100, (outs GRRegs:$dst),
438                        (ins GRRegs:$addr, GRRegs:$offset),
439                        "lda16 $dst, $addr[$offset]",
440                        [(set GRRegs:$dst,
441                           (lda16f GRRegs:$addr, GRRegs:$offset))]>;
442
443 def LDA16B_l3r : _FL3R<0b001101100, (outs GRRegs:$dst),
444                        (ins GRRegs:$addr, GRRegs:$offset),
445                        "lda16 $dst, $addr[-$offset]",
446                        [(set GRRegs:$dst,
447                           (lda16b GRRegs:$addr, GRRegs:$offset))]>;
448
449 def MUL_l3r : FL3R<0b001111100, "mul", mul>;
450 // Instructions which may trap are marked as side effecting.
451 let hasSideEffects = 1 in {
452 def DIVS_l3r : FL3R<0b010001100, "divs", sdiv>;
453 def DIVU_l3r : FL3R<0b010011100, "divu", udiv>;
454 def REMS_l3r : FL3R<0b110001100, "rems", srem>;
455 def REMU_l3r : FL3R<0b110011100, "remu", urem>;
456 }
457 def XOR_l3r : FL3R<0b000011100, "xor", xor>;
458 defm ASHR : FL3R_L2RBITP<0b000101100, 0b100101100, "ashr", sra>;
459
460 let Constraints = "$src1 = $dst" in
461 def CRC_l3r : _FL3RSrcDst<0b101011100, (outs GRRegs:$dst),
462                           (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
463                           "crc32 $dst, $src2, $src3",
464                           [(set GRRegs:$dst,
465                              (int_xcore_crc32 GRRegs:$src1, GRRegs:$src2,
466                                               GRRegs:$src3))]>;
467
468 let mayStore=1 in {
469 def ST16_l3r : _FL3R<0b100001100, (outs),
470                      (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
471                      "st16 $val, $addr[$offset]", []>;
472
473 def ST8_l3r : _FL3R<0b100011100, (outs),
474                     (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
475                     "st8 $val, $addr[$offset]", []>;
476 }
477
478 def INPW_l2rus : _FL2RUSBitp<0b100101110, (outs GRRegs:$a),
479                              (ins GRRegs:$b, i32imm:$c), "inpw $a, res[$b], $c",
480                              []>;
481
482 def OUTPW_l2rus : _FL2RUSBitp<0b100101101, (outs),
483                               (ins GRRegs:$a, GRRegs:$b, i32imm:$c),
484                               "outpw res[$b], $a, $c", []>;
485
486 // Four operand long
487 let Constraints = "$e = $a,$f = $b" in {
488 def MACCU_l4r : _FL4RSrcDstSrcDst<
489   0b000001, (outs GRRegs:$a, GRRegs:$b),
490   (ins GRRegs:$e, GRRegs:$f, GRRegs:$c, GRRegs:$d), "maccu $a, $b, $c, $d", []>;
491
492 def MACCS_l4r : _FL4RSrcDstSrcDst<
493   0b000010, (outs GRRegs:$a, GRRegs:$b),
494   (ins GRRegs:$e, GRRegs:$f, GRRegs:$c, GRRegs:$d), "maccs $a, $b, $c, $d", []>;
495 }
496
497 let Constraints = "$e = $b" in
498 def CRC8_l4r : _FL4RSrcDst<0b000000, (outs GRRegs:$a, GRRegs:$b),
499                            (ins GRRegs:$e, GRRegs:$c, GRRegs:$d),
500                            "crc8 $b, $a, $c, $d", []>;
501
502 // Five operand long
503
504 def LADD_l5r : _FL5R<0b000001, (outs GRRegs:$dst1, GRRegs:$dst2),
505                      (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
506                      "ladd $dst2, $dst1, $src1, $src2, $src3",
507                      []>;
508
509 def LSUB_l5r : _FL5R<0b000010, (outs GRRegs:$dst1, GRRegs:$dst2),
510                      (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
511                      "lsub $dst2, $dst1, $src1, $src2, $src3", []>;
512
513 def LDIVU_l5r : _FL5R<0b000000, (outs GRRegs:$dst1, GRRegs:$dst2),
514                       (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
515                       "ldivu $dst1, $dst2, $src3, $src1, $src2", []>;
516
517 // Six operand long
518
519 def LMUL_l6r : _FL6R<
520   0b00000, (outs GRRegs:$dst1, GRRegs:$dst2),
521   (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3, GRRegs:$src4),
522   "lmul $dst1, $dst2, $src1, $src2, $src3, $src4", []>;
523
524 // Register - U6
525
526 //let Uses = [DP] in ...
527 let neverHasSideEffects = 1, isReMaterializable = 1 in
528 def LDAWDP_ru6: _FRU6<0b011000, (outs RRegs:$a), (ins i32imm:$b),
529                       "ldaw $a, dp[$b]", []>;
530
531 let isReMaterializable = 1 in                    
532 def LDAWDP_lru6: _FLRU6<0b011000, (outs RRegs:$a), (ins i32imm:$b),
533                         "ldaw $a, dp[$b]",
534                         [(set RRegs:$a, (dprelwrapper tglobaladdr:$b))]>;
535
536 let mayLoad=1 in
537 def LDWDP_ru6: _FRU6<0b010110, (outs RRegs:$a), (ins i32imm:$b),
538                      "ldw $a, dp[$b]", []>;
539
540 def LDWDP_lru6: _FLRU6<0b010110, (outs RRegs:$a), (ins i32imm:$b),
541                        "ldw $a, dp[$b]",
542                        [(set RRegs:$a, (load (dprelwrapper tglobaladdr:$b)))]>;
543
544 let mayStore=1 in
545 def STWDP_ru6 : _FRU6<0b010100, (outs), (ins RRegs:$a, i32imm:$b),
546                       "stw $a, dp[$b]", []>;
547
548 def STWDP_lru6 : _FLRU6<0b010100, (outs), (ins RRegs:$a, i32imm:$b),
549                         "stw $a, dp[$b]",
550                         [(store RRegs:$a, (dprelwrapper tglobaladdr:$b))]>;
551
552 //let Uses = [CP] in ..
553 let mayLoad = 1, isReMaterializable = 1, neverHasSideEffects = 1 in {
554 def LDWCP_ru6 : _FRU6<0b011011, (outs RRegs:$a), (ins i32imm:$b),
555                       "ldw $a, cp[$b]", []>;
556 def LDWCP_lru6: _FLRU6<0b011011, (outs RRegs:$a), (ins i32imm:$b),
557                        "ldw $a, cp[$b]",
558                        [(set RRegs:$a, (load (cprelwrapper tglobaladdr:$b)))]>;
559 }
560
561 let Uses = [SP] in {
562 let mayStore=1 in {
563 def STWSP_ru6 : _FRU6<0b010101, (outs), (ins RRegs:$a, i32imm:$b),
564                       "stw $a, sp[$b]",
565                       [(XCoreStwsp RRegs:$a, immU6:$b)]>;
566
567 def STWSP_lru6 : _FLRU6<0b010101, (outs), (ins RRegs:$a, i32imm:$b),
568                         "stw $a, sp[$b]",
569                         [(XCoreStwsp RRegs:$a, immU16:$b)]>;
570 }
571
572 let mayLoad=1 in {
573 def LDWSP_ru6 : _FRU6<0b010111, (outs RRegs:$a), (ins i32imm:$b),
574                       "ldw $a, sp[$b]", []>;
575
576 def LDWSP_lru6 : _FLRU6<0b010111, (outs RRegs:$a), (ins i32imm:$b),
577                         "ldw $a, sp[$b]", []>;
578 }
579
580 let neverHasSideEffects = 1 in {
581 def LDAWSP_ru6 : _FRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b),
582                        "ldaw $a, sp[$b]", []>;
583
584 def LDAWSP_lru6 : _FLRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b),
585                          "ldaw $a, sp[$b]", []>;
586 }
587 }
588
589 let isReMaterializable = 1 in {
590 def LDC_ru6 : _FRU6<0b011010, (outs RRegs:$a), (ins i32imm:$b),
591                     "ldc $a, $b", [(set RRegs:$a, immU6:$b)]>;
592
593 def LDC_lru6 : _FLRU6<0b011010, (outs RRegs:$a), (ins i32imm:$b),
594                       "ldc $a, $b", [(set RRegs:$a, immU16:$b)]>;
595 }
596
597 def SETC_ru6 : _FRU6<0b111010, (outs), (ins GRRegs:$a, i32imm:$b),
598                      "setc res[$a], $b",
599                      [(int_xcore_setc GRRegs:$a, immU6:$b)]>;
600
601 def SETC_lru6 : _FLRU6<0b111010, (outs), (ins GRRegs:$a, i32imm:$b),
602                        "setc res[$a], $b",
603                        [(int_xcore_setc GRRegs:$a, immU16:$b)]>;
604
605 // Operand register - U6
606 let isBranch = 1, isTerminator = 1 in {
607 defm BRFT: FRU6_LRU6_branch<0b011100, "bt">;
608 defm BRBT: FRU6_LRU6_backwards_branch<0b011101, "bt">;
609 defm BRFF: FRU6_LRU6_branch<0b011110, "bf">;
610 defm BRBF: FRU6_LRU6_backwards_branch<0b011111, "bf">;
611 }
612
613 // U6
614 let Defs = [SP], Uses = [SP] in {
615 let neverHasSideEffects = 1 in
616 defm EXTSP : FU6_LU6_np<0b0111011110, "extsp">;
617
618 let mayStore = 1 in
619 defm ENTSP : FU6_LU6_np<0b0111011101, "entsp">;
620
621 let isReturn = 1, isTerminator = 1, mayLoad = 1, isBarrier = 1 in {
622 defm RETSP : FU6_LU6<0b0111011111, "retsp", XCoreRetsp>;
623 }
624 }
625
626 let neverHasSideEffects = 1 in
627 defm EXTDP : FU6_LU6_np<0b0111001110, "extdp">;
628
629 let Uses = [R11], isCall=1 in
630 defm BLAT : FU6_LU6_np<0b0111001101, "blat">;
631
632 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
633 def BRBU_u6 : _FU6<0b0111011100, (outs), (ins brtarget_neg:$a), "bu $a", []>;
634
635 def BRBU_lu6 : _FLU6<0b0111011100, (outs), (ins brtarget_neg:$a), "bu $a", []>;
636
637 def BRFU_u6 : _FU6<0b0111001100, (outs), (ins brtarget:$a), "bu $a", []>;
638
639 def BRFU_lu6 : _FLU6<0b0111001100, (outs), (ins brtarget:$a), "bu $a", []>;
640 }
641
642 //let Uses = [CP] in ...
643 let Defs = [R11], neverHasSideEffects = 1, isReMaterializable = 1 in
644 def LDAWCP_u6: _FU6<0b0111111101, (outs), (ins i32imm:$a), "ldaw r11, cp[$a]",
645                     []>;
646
647 let Defs = [R11], isReMaterializable = 1 in
648 def LDAWCP_lu6: _FLU6<0b0111111101, (outs), (ins i32imm:$a), "ldaw r11, cp[$a]",
649                       [(set R11, (cprelwrapper tglobaladdr:$a))]>;
650
651 let Defs = [R11] in
652 defm GETSR : FU6_LU6_np<0b0111111100, "getsr r11,">;
653
654 defm SETSR : FU6_LU6_int<0b0111101101, "setsr", int_xcore_setsr>;
655
656 defm CLRSR : FU6_LU6_int<0b0111101100, "clrsr", int_xcore_clrsr>;
657
658 // setsr may cause a branch if it is used to enable events. clrsr may
659 // branch if it is executed while events are enabled.
660 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1,
661     isCodeGenOnly = 1 in {
662 defm SETSR_branch : FU6_LU6_np<0b0111101101, "setsr">;
663 defm CLRSR_branch : FU6_LU6_np<0b0111101100, "clrsr">;
664 }
665
666 defm KCALL : FU6_LU6_np<0b0111001111, "kcall">;
667
668 let Uses = [SP], Defs = [SP], mayStore = 1 in
669 defm KENTSP : FU6_LU6_np<0b0111101110, "kentsp">;
670
671 let Uses = [SP], Defs = [SP], mayLoad = 1 in
672 defm KRESTSP : FU6_LU6_np<0b0111101111, "krestsp">;
673
674 // U10
675
676 let Defs = [R11], isReMaterializable = 1 in {
677 let neverHasSideEffects = 1 in
678 def LDAPF_u10 : _FU10<0b110110, (outs), (ins pcrel_imm:$a), "ldap r11, $a", []>;
679
680 def LDAPF_lu10 : _FLU10<0b110110, (outs), (ins pcrel_imm:$a), "ldap r11, $a",
681                         [(set R11, (pcrelwrapper tglobaladdr:$a))]>;
682
683 let neverHasSideEffects = 1 in
684 def LDAPB_u10 : _FU10<0b110111, (outs), (ins pcrel_imm_neg:$a), "ldap r11, $a",
685                       []>;
686
687 let neverHasSideEffects = 1 in
688 def LDAPB_lu10 : _FLU10<0b110111, (outs), (ins pcrel_imm_neg:$a),
689                         "ldap r11, $a",
690                         [(set R11, (pcrelwrapper tglobaladdr:$a))]>;
691
692 let isCodeGenOnly = 1 in
693 def LDAPF_lu10_ba : _FLU10<0b110110, (outs), (ins pcrel_imm:$a), "ldap r11, $a",
694                            [(set R11, (pcrelwrapper tblockaddress:$a))]>;
695 }
696
697 let isCall=1,
698 // All calls clobber the link register and the non-callee-saved registers:
699 Defs = [R0, R1, R2, R3, R11, LR], Uses = [SP] in {
700 def BLACP_u10 : _FU10<0b111000, (outs), (ins i32imm:$a), "bla cp[$a]", []>;
701
702 def BLACP_lu10 : _FLU10<0b111000, (outs), (ins i32imm:$a), "bla cp[$a]", []>;
703
704 def BLRF_u10 : _FU10<0b110100, (outs), (ins pcrel_imm:$a), "bl $a",
705                      [(XCoreBranchLink immU10:$a)]>;
706
707 def BLRF_lu10 : _FLU10<0b110100, (outs), (ins pcrel_imm:$a), "bl $a",
708                        [(XCoreBranchLink immU20:$a)]>;
709
710 def BLRB_u10 : _FU10<0b110101, (outs), (ins pcrel_imm_neg:$a), "bl $a", []>;
711
712 def BLRB_lu10 : _FLU10<0b110101, (outs), (ins pcrel_imm_neg:$a), "bl $a", []>;
713 }
714
715 let Defs = [R11], mayLoad = 1, isReMaterializable = 1,
716     neverHasSideEffects = 1 in {
717 def LDWCP_u10 : _FU10<0b111001, (outs), (ins i32imm:$a), "ldw r11, cp[$a]", []>;
718
719 def LDWCP_lu10 : _FLU10<0b111001, (outs), (ins i32imm:$a), "ldw r11, cp[$a]",
720                         []>;
721 }
722
723 // Two operand short
724 def NOT : _F2R<0b100010, (outs GRRegs:$dst), (ins GRRegs:$b),
725                 "not $dst, $b", [(set GRRegs:$dst, (not GRRegs:$b))]>;
726
727 def NEG : _F2R<0b100100, (outs GRRegs:$dst), (ins GRRegs:$b),
728                 "neg $dst, $b", [(set GRRegs:$dst, (ineg GRRegs:$b))]>;
729
730 let Constraints = "$src1 = $dst" in {
731 def SEXT_rus :
732   _FRUSSrcDstBitp<0b001101, (outs GRRegs:$dst), (ins GRRegs:$src1, i32imm:$src2),
733                   "sext $dst, $src2",
734                   [(set GRRegs:$dst, (int_xcore_sext GRRegs:$src1,
735                                                      immBitp:$src2))]>;
736
737 def SEXT_2r :
738   _F2RSrcDst<0b001100, (outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
739              "sext $dst, $src2",
740              [(set GRRegs:$dst, (int_xcore_sext GRRegs:$src1, GRRegs:$src2))]>;
741
742 def ZEXT_rus :
743   _FRUSSrcDstBitp<0b010001, (outs GRRegs:$dst), (ins GRRegs:$src1, i32imm:$src2),
744                   "zext $dst, $src2",
745                   [(set GRRegs:$dst, (int_xcore_zext GRRegs:$src1,
746                                                      immBitp:$src2))]>;
747
748 def ZEXT_2r :
749   _F2RSrcDst<0b010000, (outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
750              "zext $dst, $src2",
751              [(set GRRegs:$dst, (int_xcore_zext GRRegs:$src1, GRRegs:$src2))]>;
752
753 def ANDNOT_2r :
754   _F2RSrcDst<0b001010, (outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
755              "andnot $dst, $src2",
756              [(set GRRegs:$dst, (and GRRegs:$src1, (not GRRegs:$src2)))]>;
757 }
758
759 let isReMaterializable = 1, neverHasSideEffects = 1 in
760 def MKMSK_rus : _FRUSBitp<0b101001, (outs GRRegs:$dst), (ins i32imm:$size),
761                           "mkmsk $dst, $size", []>;
762
763 def MKMSK_2r : _F2R<0b101000, (outs GRRegs:$dst), (ins GRRegs:$size),
764                     "mkmsk $dst, $size",
765                     [(set GRRegs:$dst, (add (shl 1, GRRegs:$size), -1))]>;
766
767 def GETR_rus : _FRUS<0b100000, (outs GRRegs:$dst), (ins i32imm:$type),
768                      "getr $dst, $type",
769                      [(set GRRegs:$dst, (int_xcore_getr immUs:$type))]>;
770
771 def GETTS_2r : _F2R<0b001110, (outs GRRegs:$dst), (ins GRRegs:$r),
772                     "getts $dst, res[$r]",
773                     [(set GRRegs:$dst, (int_xcore_getts GRRegs:$r))]>;
774
775 def SETPT_2r : _FR2R<0b001111, (outs), (ins GRRegs:$r, GRRegs:$val),
776                      "setpt res[$r], $val",
777                      [(int_xcore_setpt GRRegs:$r, GRRegs:$val)]>;
778
779 def OUTCT_2r : _F2R<0b010010, (outs), (ins GRRegs:$r, GRRegs:$val),
780                     "outct res[$r], $val",
781                     [(int_xcore_outct GRRegs:$r, GRRegs:$val)]>;
782
783 def OUTCT_rus : _FRUS<0b010011, (outs), (ins GRRegs:$r, i32imm:$val),
784                        "outct res[$r], $val",
785                        [(int_xcore_outct GRRegs:$r, immUs:$val)]>;
786
787 def OUTT_2r : _FR2R<0b000011, (outs), (ins GRRegs:$r, GRRegs:$val),
788                     "outt res[$r], $val",
789                     [(int_xcore_outt GRRegs:$r, GRRegs:$val)]>;
790
791 def OUT_2r : _FR2R<0b101010, (outs), (ins GRRegs:$r, GRRegs:$val),
792                    "out res[$r], $val",
793                    [(int_xcore_out GRRegs:$r, GRRegs:$val)]>;
794
795 let Constraints = "$src = $dst" in
796 def OUTSHR_2r :
797   _F2RSrcDst<0b101011, (outs GRRegs:$dst), (ins GRRegs:$src, GRRegs:$r),
798              "outshr res[$r], $src",
799              [(set GRRegs:$dst, (int_xcore_outshr GRRegs:$r, GRRegs:$src))]>;
800
801 def INCT_2r : _F2R<0b100001, (outs GRRegs:$dst), (ins GRRegs:$r),
802                    "inct $dst, res[$r]",
803                    [(set GRRegs:$dst, (int_xcore_inct GRRegs:$r))]>;
804
805 def INT_2r : _F2R<0b100011, (outs GRRegs:$dst), (ins GRRegs:$r),
806                   "int $dst, res[$r]",
807                   [(set GRRegs:$dst, (int_xcore_int GRRegs:$r))]>;
808
809 def IN_2r : _F2R<0b101100, (outs GRRegs:$dst), (ins GRRegs:$r),
810                  "in $dst, res[$r]",
811                  [(set GRRegs:$dst, (int_xcore_in GRRegs:$r))]>;
812
813 let Constraints = "$src = $dst" in
814 def INSHR_2r :
815   _F2RSrcDst<0b101101, (outs GRRegs:$dst), (ins GRRegs:$src, GRRegs:$r),
816              "inshr $dst, res[$r]",
817              [(set GRRegs:$dst, (int_xcore_inshr GRRegs:$r, GRRegs:$src))]>;
818
819 def CHKCT_2r : _F2R<0b110010, (outs), (ins GRRegs:$r, GRRegs:$val),
820                     "chkct res[$r], $val",
821                     [(int_xcore_chkct GRRegs:$r, GRRegs:$val)]>;
822
823 def CHKCT_rus : _FRUSBitp<0b110011, (outs), (ins GRRegs:$r, i32imm:$val),
824                           "chkct res[$r], $val",
825                           [(int_xcore_chkct GRRegs:$r, immUs:$val)]>;
826
827 def TESTCT_2r : _F2R<0b101111, (outs GRRegs:$dst), (ins GRRegs:$src),
828                      "testct $dst, res[$src]",
829                      [(set GRRegs:$dst, (int_xcore_testct GRRegs:$src))]>;
830
831 def TESTWCT_2r : _F2R<0b110001, (outs GRRegs:$dst), (ins GRRegs:$src),
832                       "testwct $dst, res[$src]",
833                       [(set GRRegs:$dst, (int_xcore_testwct GRRegs:$src))]>;
834
835 def SETD_2r : _FR2R<0b000101, (outs), (ins GRRegs:$r, GRRegs:$val),
836                     "setd res[$r], $val",
837                     [(int_xcore_setd GRRegs:$r, GRRegs:$val)]>;
838
839 def SETPSC_2r : _FR2R<0b110000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
840                       "setpsc res[$src1], $src2",
841                       [(int_xcore_setpsc GRRegs:$src1, GRRegs:$src2)]>;
842
843 def GETST_2r : _F2R<0b000001, (outs GRRegs:$dst), (ins GRRegs:$r),
844                     "getst $dst, res[$r]",
845                     [(set GRRegs:$dst, (int_xcore_getst GRRegs:$r))]>;
846
847 def INITSP_2r : _F2R<0b000100, (outs), (ins GRRegs:$src, GRRegs:$t),
848                      "init t[$t]:sp, $src",
849                      [(int_xcore_initsp GRRegs:$t, GRRegs:$src)]>;
850
851 def INITPC_2r : _F2R<0b000000, (outs), (ins GRRegs:$src, GRRegs:$t),
852                      "init t[$t]:pc, $src",
853                      [(int_xcore_initpc GRRegs:$t, GRRegs:$src)]>;
854
855 def INITCP_2r : _F2R<0b000110, (outs), (ins GRRegs:$src, GRRegs:$t),
856                      "init t[$t]:cp, $src",
857                      [(int_xcore_initcp GRRegs:$t, GRRegs:$src)]>;
858
859 def INITDP_2r : _F2R<0b000010, (outs), (ins GRRegs:$src, GRRegs:$t),
860                      "init t[$t]:dp, $src",
861                      [(int_xcore_initdp GRRegs:$t, GRRegs:$src)]>;
862
863 def PEEK_2r : _F2R<0b101110, (outs GRRegs:$dst), (ins GRRegs:$src),
864                     "peek $dst, res[$src]",
865                     [(set GRRegs:$dst, (int_xcore_peek GRRegs:$src))]>;
866
867 def ENDIN_2r : _F2R<0b100101, (outs GRRegs:$dst), (ins GRRegs:$src),
868                      "endin $dst, res[$src]",
869                      [(set GRRegs:$dst, (int_xcore_endin GRRegs:$src))]>;
870
871 def EEF_2r : _F2R<0b001011, (outs), (ins GRRegs:$a, GRRegs:$b),
872                   "eef $a, res[$b]", []>;
873
874 def EET_2r : _F2R<0b001001, (outs), (ins GRRegs:$a, GRRegs:$b),
875                   "eet $a, res[$b]", []>;
876
877 def TSETMR_2r : _F2RImm<0b000111, (outs), (ins i32imm:$a, GRRegs:$b),
878                         "tsetmr r$a, $b", []>;
879
880 // Two operand long
881 def BITREV_l2r : _FL2R<0b0000011000, (outs GRRegs:$dst), (ins GRRegs:$src),
882                        "bitrev $dst, $src",
883                        [(set GRRegs:$dst, (int_xcore_bitrev GRRegs:$src))]>;
884
885 def BYTEREV_l2r : _FL2R<0b0000011001, (outs GRRegs:$dst), (ins GRRegs:$src),
886                         "byterev $dst, $src",
887                         [(set GRRegs:$dst, (bswap GRRegs:$src))]>;
888
889 def CLZ_l2r : _FL2R<0b000111000, (outs GRRegs:$dst), (ins GRRegs:$src),
890                     "clz $dst, $src",
891                     [(set GRRegs:$dst, (ctlz GRRegs:$src))]>;
892
893 def GETD_l2r : _FL2R<0b0001111001, (outs GRRegs:$dst), (ins GRRegs:$src),
894                      "getd $dst, res[$src]", []>;
895
896 def GETN_l2r : _FL2R<0b0011011001, (outs GRRegs:$dst), (ins GRRegs:$src),
897                      "getn $dst, res[$src]", []>;
898
899 def SETC_l2r : _FL2R<0b0010111001, (outs), (ins GRRegs:$r, GRRegs:$val),
900                      "setc res[$r], $val",
901                      [(int_xcore_setc GRRegs:$r, GRRegs:$val)]>;
902
903 def SETTW_l2r : _FLR2R<0b0010011001, (outs), (ins GRRegs:$r, GRRegs:$val),
904                        "settw res[$r], $val",
905                        [(int_xcore_settw GRRegs:$r, GRRegs:$val)]>;
906
907 def GETPS_l2r : _FL2R<0b0001011001, (outs GRRegs:$dst), (ins GRRegs:$src),
908                       "get $dst, ps[$src]",
909                       [(set GRRegs:$dst, (int_xcore_getps GRRegs:$src))]>;
910
911 def SETPS_l2r : _FLR2R<0b0001111000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
912                        "set ps[$src1], $src2",
913                        [(int_xcore_setps GRRegs:$src1, GRRegs:$src2)]>;
914
915 def INITLR_l2r : _FL2R<0b0001011000, (outs), (ins GRRegs:$src, GRRegs:$t),
916                        "init t[$t]:lr, $src",
917                        [(int_xcore_initlr GRRegs:$t, GRRegs:$src)]>;
918
919 def SETCLK_l2r : _FLR2R<0b0000111001, (outs), (ins GRRegs:$src1, GRRegs:$src2),
920                         "setclk res[$src1], $src2",
921                         [(int_xcore_setclk GRRegs:$src1, GRRegs:$src2)]>;
922
923 def SETN_l2r : _FLR2R<0b0011011000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
924                       "setn res[$src1], $src2", []>;
925
926 def SETRDY_l2r : _FLR2R<0b0010111000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
927                         "setrdy res[$src1], $src2",
928                         [(int_xcore_setrdy GRRegs:$src1, GRRegs:$src2)]>;
929
930 def TESTLCL_l2r : _FL2R<0b0010011000, (outs GRRegs:$dst), (ins GRRegs:$src),
931                         "testlcl $dst, res[$src]", []>;
932
933 // One operand short
934 def MSYNC_1r : _F1R<0b000111, (outs), (ins GRRegs:$a),
935                     "msync res[$a]",
936                     [(int_xcore_msync GRRegs:$a)]>;
937 def MJOIN_1r : _F1R<0b000101, (outs), (ins GRRegs:$a),
938                     "mjoin res[$a]",
939                     [(int_xcore_mjoin GRRegs:$a)]>;
940
941 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
942 def BAU_1r : _F1R<0b001001, (outs), (ins GRRegs:$a),
943                  "bau $a",
944                  [(brind GRRegs:$a)]>;
945
946 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
947 def BR_JT : PseudoInstXCore<(outs), (ins InlineJT:$t, GRRegs:$i),
948                             "bru $i\n$t",
949                             [(XCoreBR_JT tjumptable:$t, GRRegs:$i)]>;
950
951 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
952 def BR_JT32 : PseudoInstXCore<(outs), (ins InlineJT32:$t, GRRegs:$i),
953                               "bru $i\n$t",
954                               [(XCoreBR_JT32 tjumptable:$t, GRRegs:$i)]>;
955
956 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
957 def BRU_1r : _F1R<0b001010, (outs), (ins GRRegs:$a), "bru $a", []>;
958
959 let Defs=[SP], neverHasSideEffects=1 in
960 def SETSP_1r : _F1R<0b001011, (outs), (ins GRRegs:$a), "set sp, $a", []>;
961
962 let neverHasSideEffects=1 in
963 def SETDP_1r : _F1R<0b001100, (outs), (ins GRRegs:$a), "set dp, $a", []>;
964
965 let neverHasSideEffects=1 in
966 def SETCP_1r : _F1R<0b001101, (outs), (ins GRRegs:$a), "set cp, $a", []>;
967
968 let hasCtrlDep = 1 in 
969 def ECALLT_1r : _F1R<0b010011, (outs), (ins GRRegs:$a),
970                  "ecallt $a",
971                  []>;
972
973 let hasCtrlDep = 1 in 
974 def ECALLF_1r : _F1R<0b010010, (outs), (ins GRRegs:$a),
975                  "ecallf $a",
976                  []>;
977
978 let isCall=1, 
979 // All calls clobber the link register and the non-callee-saved registers:
980 Defs = [R0, R1, R2, R3, R11, LR], Uses = [SP] in {
981 def BLA_1r : _F1R<0b001000, (outs), (ins GRRegs:$a),
982                  "bla $a",
983                  [(XCoreBranchLink GRRegs:$a)]>;
984 }
985
986 def SYNCR_1r : _F1R<0b100001, (outs), (ins GRRegs:$a),
987                  "syncr res[$a]",
988                  [(int_xcore_syncr GRRegs:$a)]>;
989
990 def FREER_1r : _F1R<0b000100, (outs), (ins GRRegs:$a),
991                "freer res[$a]",
992                [(int_xcore_freer GRRegs:$a)]>;
993
994 let Uses=[R11] in {
995 def SETV_1r : _F1R<0b010001, (outs), (ins GRRegs:$a),
996                    "setv res[$a], r11",
997                    [(int_xcore_setv GRRegs:$a, R11)]>;
998
999 def SETEV_1r : _F1R<0b001111, (outs), (ins GRRegs:$a),
1000                     "setev res[$a], r11",
1001                     [(int_xcore_setev GRRegs:$a, R11)]>;
1002 }
1003
1004 def DGETREG_1r : _F1R<0b001110, (outs GRRegs:$a), (ins), "dgetreg $a", []>;
1005
1006 def EDU_1r : _F1R<0b000000, (outs), (ins GRRegs:$a), "edu res[$a]", []>;
1007
1008 def EEU_1r : _F1R<0b000001, (outs), (ins GRRegs:$a),
1009                "eeu res[$a]",
1010                [(int_xcore_eeu GRRegs:$a)]>;
1011
1012 def KCALL_1r : _F1R<0b010000, (outs), (ins GRRegs:$a), "kcall $a", []>;
1013
1014 def WAITEF_1R : _F1R<0b000011, (outs), (ins GRRegs:$a), "waitef $a", []>;
1015
1016 def WAITET_1R : _F1R<0b000010, (outs), (ins GRRegs:$a), "waitet $a", []>;
1017
1018 def TSTART_1R : _F1R<0b000110, (outs), (ins GRRegs:$a), "start t[$a]", []>;
1019
1020 def CLRPT_1R : _F1R<0b100000, (outs), (ins GRRegs:$a), "clrpt res[$a]", []>;
1021
1022 // Zero operand short
1023
1024 def CLRE_0R : _F0R<0b0000001101, (outs), (ins), "clre", [(int_xcore_clre)]>;
1025
1026 def DCALL_0R : _F0R<0b0000011100, (outs), (ins), "dcall", []>;
1027
1028 let Defs = [SP], Uses = [SP] in
1029 def DENTSP_0R : _F0R<0b0001001100, (outs), (ins), "dentsp", []>;
1030
1031 let Defs = [SP] in
1032 def DRESTSP_0R : _F0R<0b0001001101, (outs), (ins), "drestsp", []>;
1033
1034 def DRET_0R : _F0R<0b0000011110, (outs), (ins), "dret", []>;
1035
1036 def FREET_0R : _F0R<0b0000001111, (outs), (ins), "freet", []>;
1037
1038 let Defs = [R11] in {
1039 def GETID_0R : _F0R<0b0001001110, (outs), (ins),
1040                     "get r11, id",
1041                     [(set R11, (int_xcore_getid))]>;
1042
1043 def GETED_0R : _F0R<0b0000111110, (outs), (ins),
1044                     "get r11, ed",
1045                     [(set R11, (int_xcore_geted))]>;
1046
1047 def GETET_0R : _F0R<0b0000111111, (outs), (ins),
1048                     "get r11, et",
1049                     [(set R11, (int_xcore_getet))]>;
1050
1051 def GETKEP_0R : _F0R<0b0001001111, (outs), (ins),
1052                      "get r11, kep", []>;
1053
1054 def GETKSP_0R : _F0R<0b0001011100, (outs), (ins),
1055                      "get r11, ksp", []>;
1056 }
1057
1058 let Defs = [SP] in
1059 def KRET_0R : _F0R<0b0000011101, (outs), (ins), "kret", []>;
1060
1061 let Uses = [SP], mayLoad = 1 in {
1062 def LDET_0R : _F0R<0b0001011110, (outs), (ins), "ldw et, sp[4]", []>;
1063
1064 def LDSED_0R : _F0R<0b0001011101, (outs), (ins), "ldw sed, sp[3]", []>;
1065
1066 def LDSPC_0R : _F0R<0b0000101100, (outs), (ins), "ldw spc, sp[1]", []>;
1067
1068 def LDSSR_0R : _F0R<0b0000101110, (outs), (ins), "ldw ssr, sp[2]", []>;
1069 }
1070
1071 let Uses=[R11] in
1072 def SETKEP_0R : _F0R<0b0000011111, (outs), (ins), "set kep, r11", []>;
1073
1074 def SSYNC_0r : _F0R<0b0000001110, (outs), (ins),
1075                     "ssync",
1076                     [(int_xcore_ssync)]>;
1077
1078 let Uses = [SP], mayStore = 1 in {
1079 def STET_0R : _F0R<0b0000111101, (outs), (ins), "stw et, sp[4]", []>;
1080
1081 def STSED_0R : _F0R<0b0000111100, (outs), (ins), "stw sed, sp[3]", []>;
1082
1083 def STSPC_0R : _F0R<0b0000101101, (outs), (ins), "stw spc, sp[1]", []>;
1084
1085 def STSSR_0R : _F0R<0b0000101111, (outs), (ins), "stw ssr, sp[2]", []>;
1086 }
1087
1088 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1,
1089     hasSideEffects = 1 in
1090 def WAITEU_0R : _F0R<0b0000001100, (outs), (ins),
1091                      "waiteu",
1092                      [(brind (int_xcore_waitevent))]>;
1093
1094 //===----------------------------------------------------------------------===//
1095 // Non-Instruction Patterns
1096 //===----------------------------------------------------------------------===//
1097
1098 def : Pat<(XCoreBranchLink tglobaladdr:$addr), (BLRF_lu10 tglobaladdr:$addr)>;
1099 def : Pat<(XCoreBranchLink texternalsym:$addr), (BLRF_lu10 texternalsym:$addr)>;
1100
1101 /// sext_inreg
1102 def : Pat<(sext_inreg GRRegs:$b, i1), (SEXT_rus GRRegs:$b, 1)>;
1103 def : Pat<(sext_inreg GRRegs:$b, i8), (SEXT_rus GRRegs:$b, 8)>;
1104 def : Pat<(sext_inreg GRRegs:$b, i16), (SEXT_rus GRRegs:$b, 16)>;
1105
1106 /// loads
1107 def : Pat<(zextloadi8 (add GRRegs:$addr, GRRegs:$offset)),
1108           (LD8U_3r GRRegs:$addr, GRRegs:$offset)>;
1109 def : Pat<(zextloadi8 GRRegs:$addr), (LD8U_3r GRRegs:$addr, (LDC_ru6 0))>;
1110
1111 def : Pat<(sextloadi16 (lda16f GRRegs:$addr, GRRegs:$offset)),
1112           (LD16S_3r GRRegs:$addr, GRRegs:$offset)>;
1113 def : Pat<(sextloadi16 GRRegs:$addr), (LD16S_3r GRRegs:$addr, (LDC_ru6 0))>;
1114
1115 def : Pat<(load (ldawf GRRegs:$addr, GRRegs:$offset)),
1116           (LDW_3r GRRegs:$addr, GRRegs:$offset)>;
1117 def : Pat<(load (add GRRegs:$addr, immUs4:$offset)),
1118           (LDW_2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
1119 def : Pat<(load GRRegs:$addr), (LDW_2rus GRRegs:$addr, 0)>;
1120
1121 /// anyext
1122 def : Pat<(extloadi8 (add GRRegs:$addr, GRRegs:$offset)),
1123           (LD8U_3r GRRegs:$addr, GRRegs:$offset)>;
1124 def : Pat<(extloadi8 GRRegs:$addr), (LD8U_3r GRRegs:$addr, (LDC_ru6 0))>;
1125 def : Pat<(extloadi16 (lda16f GRRegs:$addr, GRRegs:$offset)),
1126           (LD16S_3r GRRegs:$addr, GRRegs:$offset)>;
1127 def : Pat<(extloadi16 GRRegs:$addr), (LD16S_3r GRRegs:$addr, (LDC_ru6 0))>;
1128
1129 /// stores
1130 def : Pat<(truncstorei8 GRRegs:$val, (add GRRegs:$addr, GRRegs:$offset)),
1131           (ST8_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
1132 def : Pat<(truncstorei8 GRRegs:$val, GRRegs:$addr),
1133           (ST8_l3r GRRegs:$val, GRRegs:$addr, (LDC_ru6 0))>;
1134           
1135 def : Pat<(truncstorei16 GRRegs:$val, (lda16f GRRegs:$addr, GRRegs:$offset)),
1136           (ST16_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
1137 def : Pat<(truncstorei16 GRRegs:$val, GRRegs:$addr),
1138           (ST16_l3r GRRegs:$val, GRRegs:$addr, (LDC_ru6 0))>;
1139
1140 def : Pat<(store GRRegs:$val, (ldawf GRRegs:$addr, GRRegs:$offset)),
1141           (STW_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
1142 def : Pat<(store GRRegs:$val, (add GRRegs:$addr, immUs4:$offset)),
1143           (STW_2rus GRRegs:$val, GRRegs:$addr, (div4_xform immUs4:$offset))>;
1144 def : Pat<(store GRRegs:$val, GRRegs:$addr),
1145           (STW_2rus GRRegs:$val, GRRegs:$addr, 0)>;
1146
1147 /// cttz
1148 def : Pat<(cttz GRRegs:$src), (CLZ_l2r (BITREV_l2r GRRegs:$src))>;
1149
1150 /// trap
1151 def : Pat<(trap), (ECALLF_1r (LDC_ru6 0))>;
1152
1153 ///
1154 /// branch patterns
1155 ///
1156
1157 // unconditional branch
1158 def : Pat<(br bb:$addr), (BRFU_lu6 bb:$addr)>;
1159
1160 // direct match equal/notequal zero brcond
1161 def : Pat<(brcond (setne GRRegs:$lhs, 0), bb:$dst),
1162           (BRFT_lru6 GRRegs:$lhs, bb:$dst)>;
1163 def : Pat<(brcond (seteq GRRegs:$lhs, 0), bb:$dst),
1164           (BRFF_lru6 GRRegs:$lhs, bb:$dst)>;
1165
1166 def : Pat<(brcond (setle GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1167           (BRFF_lru6 (LSS_3r GRRegs:$rhs, GRRegs:$lhs), bb:$dst)>;
1168 def : Pat<(brcond (setule GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1169           (BRFF_lru6 (LSU_3r GRRegs:$rhs, GRRegs:$lhs), bb:$dst)>;
1170 def : Pat<(brcond (setge GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1171           (BRFF_lru6 (LSS_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
1172 def : Pat<(brcond (setuge GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1173           (BRFF_lru6 (LSU_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
1174 def : Pat<(brcond (setne GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1175           (BRFF_lru6 (EQ_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
1176 def : Pat<(brcond (setne GRRegs:$lhs, immUs:$rhs), bb:$dst),
1177           (BRFF_lru6 (EQ_2rus GRRegs:$lhs, immUs:$rhs), bb:$dst)>;
1178
1179 // generic brcond pattern
1180 def : Pat<(brcond GRRegs:$cond, bb:$addr), (BRFT_lru6 GRRegs:$cond, bb:$addr)>;
1181
1182
1183 ///
1184 /// Select patterns
1185 ///
1186
1187 // direct match equal/notequal zero select
1188 def : Pat<(select (setne GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
1189         (SELECT_CC GRRegs:$lhs, GRRegs:$T, GRRegs:$F)>;
1190
1191 def : Pat<(select (seteq GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
1192         (SELECT_CC GRRegs:$lhs, GRRegs:$F, GRRegs:$T)>;
1193
1194 def : Pat<(select (setle GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1195           (SELECT_CC (LSS_3r GRRegs:$rhs, GRRegs:$lhs), GRRegs:$F, GRRegs:$T)>;
1196 def : Pat<(select (setule GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1197           (SELECT_CC (LSU_3r GRRegs:$rhs, GRRegs:$lhs), GRRegs:$F, GRRegs:$T)>;
1198 def : Pat<(select (setge GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1199           (SELECT_CC (LSS_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
1200 def : Pat<(select (setuge GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1201           (SELECT_CC (LSU_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
1202 def : Pat<(select (setne GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1203           (SELECT_CC (EQ_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
1204 def : Pat<(select (setne GRRegs:$lhs, immUs:$rhs), GRRegs:$T, GRRegs:$F),
1205           (SELECT_CC (EQ_2rus GRRegs:$lhs, immUs:$rhs), GRRegs:$F, GRRegs:$T)>;
1206
1207 ///
1208 /// setcc patterns, only matched when none of the above brcond
1209 /// patterns match
1210 ///
1211
1212 // setcc 2 register operands
1213 def : Pat<(setle GRRegs:$lhs, GRRegs:$rhs),
1214           (EQ_2rus (LSS_3r GRRegs:$rhs, GRRegs:$lhs), 0)>;
1215 def : Pat<(setule GRRegs:$lhs, GRRegs:$rhs),
1216           (EQ_2rus (LSU_3r GRRegs:$rhs, GRRegs:$lhs), 0)>;
1217
1218 def : Pat<(setgt GRRegs:$lhs, GRRegs:$rhs),
1219           (LSS_3r GRRegs:$rhs, GRRegs:$lhs)>;
1220 def : Pat<(setugt GRRegs:$lhs, GRRegs:$rhs),
1221           (LSU_3r GRRegs:$rhs, GRRegs:$lhs)>;
1222
1223 def : Pat<(setge GRRegs:$lhs, GRRegs:$rhs),
1224           (EQ_2rus (LSS_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
1225 def : Pat<(setuge GRRegs:$lhs, GRRegs:$rhs),
1226           (EQ_2rus (LSU_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
1227
1228 def : Pat<(setlt GRRegs:$lhs, GRRegs:$rhs),
1229           (LSS_3r GRRegs:$lhs, GRRegs:$rhs)>;
1230 def : Pat<(setult GRRegs:$lhs, GRRegs:$rhs),
1231           (LSU_3r GRRegs:$lhs, GRRegs:$rhs)>;
1232
1233 def : Pat<(setne GRRegs:$lhs, GRRegs:$rhs),
1234           (EQ_2rus (EQ_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
1235
1236 def : Pat<(seteq GRRegs:$lhs, GRRegs:$rhs),
1237           (EQ_3r GRRegs:$lhs, GRRegs:$rhs)>;
1238
1239 // setcc reg/imm operands
1240 def : Pat<(seteq GRRegs:$lhs, immUs:$rhs),
1241           (EQ_2rus GRRegs:$lhs, immUs:$rhs)>;
1242 def : Pat<(setne GRRegs:$lhs, immUs:$rhs),
1243           (EQ_2rus (EQ_2rus GRRegs:$lhs, immUs:$rhs), 0)>;
1244
1245 // misc
1246 def : Pat<(add GRRegs:$addr, immUs4:$offset),
1247           (LDAWF_l2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
1248
1249 def : Pat<(sub GRRegs:$addr, immUs4:$offset),
1250           (LDAWB_l2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
1251
1252 def : Pat<(and GRRegs:$val, immMskBitp:$mask),
1253           (ZEXT_rus GRRegs:$val, (msksize_xform immMskBitp:$mask))>;
1254
1255 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
1256 def : Pat<(add GRRegs:$src1, immUsNeg:$src2),
1257           (SUB_2rus GRRegs:$src1, (neg_xform immUsNeg:$src2))>;
1258
1259 def : Pat<(add GRRegs:$src1, immUs4Neg:$src2),
1260           (LDAWB_l2rus GRRegs:$src1, (div4neg_xform immUs4Neg:$src2))>;
1261
1262 ///
1263 /// Some peepholes
1264 ///
1265
1266 def : Pat<(mul GRRegs:$src, 3),
1267           (LDA16F_l3r GRRegs:$src, GRRegs:$src)>;
1268
1269 def : Pat<(mul GRRegs:$src, 5),
1270           (LDAWF_l3r GRRegs:$src, GRRegs:$src)>;
1271
1272 def : Pat<(mul GRRegs:$src, -3),
1273           (LDAWB_l3r GRRegs:$src, GRRegs:$src)>;
1274
1275 // ashr X, 32 is equivalent to ashr X, 31 on the XCore.
1276 def : Pat<(sra GRRegs:$src, 31),
1277           (ASHR_l2rus GRRegs:$src, 32)>;
1278
1279 def : Pat<(brcond (setlt GRRegs:$lhs, 0), bb:$dst),
1280           (BRFT_lru6 (ASHR_l2rus GRRegs:$lhs, 32), bb:$dst)>;
1281
1282 // setge X, 0 is canonicalized to setgt X, -1
1283 def : Pat<(brcond (setgt GRRegs:$lhs, -1), bb:$dst),
1284           (BRFF_lru6 (ASHR_l2rus GRRegs:$lhs, 32), bb:$dst)>;
1285
1286 def : Pat<(select (setlt GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
1287           (SELECT_CC (ASHR_l2rus GRRegs:$lhs, 32), GRRegs:$T, GRRegs:$F)>;
1288
1289 def : Pat<(select (setgt GRRegs:$lhs, -1), GRRegs:$T, GRRegs:$F),
1290           (SELECT_CC (ASHR_l2rus GRRegs:$lhs, 32), GRRegs:$F, GRRegs:$T)>;
1291
1292 def : Pat<(setgt GRRegs:$lhs, -1),
1293           (EQ_2rus (ASHR_l2rus GRRegs:$lhs, 32), 0)>;
1294
1295 def : Pat<(sra (shl GRRegs:$src, immBpwSubBitp:$imm), immBpwSubBitp:$imm),
1296           (SEXT_rus GRRegs:$src, (bpwsub_xform immBpwSubBitp:$imm))>;
1297
1298 def : Pat<(load (cprelwrapper tconstpool:$b)),
1299           (LDWCP_lru6 tconstpool:$b)>;
1300
1301 def : Pat<(cprelwrapper tconstpool:$b),
1302           (LDAWCP_lu6 tconstpool:$b)>;