1 //===- XCoreInstrInfo.td - Target Description for XCore ----*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the XCore instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
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
19 //===----------------------------------------------------------------------===//
20 // Instruction format superclass.
21 //===----------------------------------------------------------------------===//
23 include "XCoreInstrFormats.td"
25 //===----------------------------------------------------------------------===//
26 // Feature predicates.
27 //===----------------------------------------------------------------------===//
29 // HasXS1A - This predicate is true when the target processor supports XS1A
31 def HasXS1A : Predicate<"Subtarget.isXS1A()">;
33 // HasXS1B - This predicate is true when the target processor supports XS1B
35 def HasXS1B : Predicate<"Subtarget.isXS1B()">;
37 //===----------------------------------------------------------------------===//
38 // XCore specific DAG Nodes.
42 def SDT_XCoreBranchLink : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
43 def XCoreBranchLink : SDNode<"XCoreISD::BL",SDT_XCoreBranchLink,
44 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
46 def XCoreRetsp : SDNode<"XCoreISD::RETSP", SDTNone,
47 [SDNPHasChain, SDNPOptInFlag]>;
49 def SDT_XCoreAddress : SDTypeProfile<1, 1,
50 [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
52 def pcrelwrapper : SDNode<"XCoreISD::PCRelativeWrapper", SDT_XCoreAddress,
55 def dprelwrapper : SDNode<"XCoreISD::DPRelativeWrapper", SDT_XCoreAddress,
58 def cprelwrapper : SDNode<"XCoreISD::CPRelativeWrapper", SDT_XCoreAddress,
61 def SDT_XCoreStwsp : SDTypeProfile<0, 2, [SDTCisInt<1>]>;
62 def XCoreStwsp : SDNode<"XCoreISD::STWSP", SDT_XCoreStwsp,
65 // These are target-independent nodes, but have target-specific formats.
66 def SDT_XCoreCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
67 def SDT_XCoreCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
70 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_XCoreCallSeqStart,
71 [SDNPHasChain, SDNPOutFlag]>;
72 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_XCoreCallSeqEnd,
73 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
75 //===----------------------------------------------------------------------===//
76 // Instruction Pattern Stuff
77 //===----------------------------------------------------------------------===//
79 def div4_xform : SDNodeXForm<imm, [{
80 // Transformation function: imm/4
81 assert(N->getZExtValue() % 4 == 0);
82 return getI32Imm(N->getZExtValue()/4);
85 def msksize_xform : SDNodeXForm<imm, [{
86 // Transformation function: get the size of a mask
87 assert(isMask_32(N->getZExtValue()));
88 // look for the first non-zero bit
89 return getI32Imm(32 - CountLeadingZeros_32(N->getZExtValue()));
92 def neg_xform : SDNodeXForm<imm, [{
93 // Transformation function: -imm
94 uint32_t value = N->getZExtValue();
95 return getI32Imm(-value);
98 def bpwsub_xform : SDNodeXForm<imm, [{
99 // Transformation function: 32-imm
100 uint32_t value = N->getZExtValue();
101 return getI32Imm(32-value);
104 def div4neg_xform : SDNodeXForm<imm, [{
105 // Transformation function: -imm/4
106 uint32_t value = N->getZExtValue();
107 assert(-value % 4 == 0);
108 return getI32Imm(-value/4);
111 def immUs4Neg : PatLeaf<(imm), [{
112 uint32_t value = (uint32_t)N->getZExtValue();
113 return (-value)%4 == 0 && (-value)/4 <= 11;
116 def immUs4 : PatLeaf<(imm), [{
117 uint32_t value = (uint32_t)N->getZExtValue();
118 return value%4 == 0 && value/4 <= 11;
121 def immUsNeg : PatLeaf<(imm), [{
122 return -((uint32_t)N->getZExtValue()) <= 11;
125 def immUs : PatLeaf<(imm), [{
126 return (uint32_t)N->getZExtValue() <= 11;
129 def immU6 : PatLeaf<(imm), [{
130 return (uint32_t)N->getZExtValue() < (1 << 6);
133 def immU10 : PatLeaf<(imm), [{
134 return (uint32_t)N->getZExtValue() < (1 << 10);
137 def immU16 : PatLeaf<(imm), [{
138 return (uint32_t)N->getZExtValue() < (1 << 16);
141 def immU20 : PatLeaf<(imm), [{
142 return (uint32_t)N->getZExtValue() < (1 << 20);
145 // FIXME check subtarget. Currently we check if the immediate
146 // is in the common subset of legal immediate values for both
148 def immMskBitp : PatLeaf<(imm), [{
149 uint32_t value = (uint32_t)N->getZExtValue();
150 if (!isMask_32(value)) {
153 int msksize = 32 - CountLeadingZeros_32(value);
154 return (msksize >= 1 && msksize <= 8)
160 // FIXME check subtarget. Currently we check if the immediate
161 // is in the common subset of legal immediate values for both
163 def immBitp : PatLeaf<(imm), [{
164 uint32_t value = (uint32_t)N->getZExtValue();
165 return (value >= 1 && value <= 8)
171 def immBpwSubBitp : PatLeaf<(imm), [{
172 uint32_t value = (uint32_t)N->getZExtValue();
173 return (value >= 24 && value <= 31)
179 def lda16f : PatFrag<(ops node:$addr, node:$offset),
180 (add node:$addr, (shl node:$offset, 1))>;
181 def lda16b : PatFrag<(ops node:$addr, node:$offset),
182 (sub node:$addr, (shl node:$offset, 1))>;
183 def ldawf : PatFrag<(ops node:$addr, node:$offset),
184 (add node:$addr, (shl node:$offset, 2))>;
185 def ldawb : PatFrag<(ops node:$addr, node:$offset),
186 (sub node:$addr, (shl node:$offset, 2))>;
188 // Instruction operand types
189 def calltarget : Operand<i32>;
190 def brtarget : Operand<OtherVT>;
191 def pclabel : Operand<i32>;
194 def ADDRspii : ComplexPattern<i32, 2, "SelectADDRspii", [add, frameindex], []>;
195 def ADDRdpii : ComplexPattern<i32, 2, "SelectADDRdpii", [add, dprelwrapper],
197 def ADDRcpii : ComplexPattern<i32, 2, "SelectADDRcpii", [add, cprelwrapper],
201 def MEMii : Operand<i32> {
202 let PrintMethod = "printMemOperand";
203 let MIOperandInfo = (ops i32imm, i32imm);
206 //===----------------------------------------------------------------------===//
207 // Instruction Class Templates
208 //===----------------------------------------------------------------------===//
210 // Three operand short
212 multiclass F3R_2RUS<string OpcStr, SDNode OpNode> {
214 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
215 !strconcat(OpcStr, " $dst, $b, $c"),
216 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
218 (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
219 !strconcat(OpcStr, " $dst, $b, $c"),
220 [(set GRRegs:$dst, (OpNode GRRegs:$b, immUs:$c))]>;
223 multiclass F3R_2RUS_np<string OpcStr> {
225 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
226 !strconcat(OpcStr, " $dst, $b, $c"),
229 (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
230 !strconcat(OpcStr, " $dst, $b, $c"),
234 multiclass F3R_2RBITP<string OpcStr, SDNode OpNode> {
236 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
237 !strconcat(OpcStr, " $dst, $b, $c"),
238 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
240 (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
241 !strconcat(OpcStr, " $dst, $b, $c"),
242 [(set GRRegs:$dst, (OpNode GRRegs:$b, immBitp:$c))]>;
245 class F3R<string OpcStr, SDNode OpNode> : _F3R<
246 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
247 !strconcat(OpcStr, " $dst, $b, $c"),
248 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
250 class F3R_np<string OpcStr> : _F3R<
251 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
252 !strconcat(OpcStr, " $dst, $b, $c"),
254 // Three operand long
256 /// FL3R_L2RUS multiclass - Define a normal FL3R/FL2RUS pattern in one shot.
257 multiclass FL3R_L2RUS<string OpcStr, SDNode OpNode> {
259 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
260 !strconcat(OpcStr, " $dst, $b, $c"),
261 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
262 def _l2rus : _FL2RUS<
263 (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
264 !strconcat(OpcStr, " $dst, $b, $c"),
265 [(set GRRegs:$dst, (OpNode GRRegs:$b, immUs:$c))]>;
268 /// FL3R_L2RUS multiclass - Define a normal FL3R/FL2RUS pattern in one shot.
269 multiclass FL3R_L2RBITP<string OpcStr, SDNode OpNode> {
271 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
272 !strconcat(OpcStr, " $dst, $b, $c"),
273 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
274 def _l2rus : _FL2RUS<
275 (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
276 !strconcat(OpcStr, " $dst, $b, $c"),
277 [(set GRRegs:$dst, (OpNode GRRegs:$b, immBitp:$c))]>;
280 class FL3R<string OpcStr, SDNode OpNode> : _FL3R<
281 (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
282 !strconcat(OpcStr, " $dst, $b, $c"),
283 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
286 // Operand register - U6
287 multiclass FRU6_LRU6_branch<string OpcStr> {
289 (outs), (ins GRRegs:$cond, brtarget:$dest),
290 !strconcat(OpcStr, " $cond, $dest"),
293 (outs), (ins GRRegs:$cond, brtarget:$dest),
294 !strconcat(OpcStr, " $cond, $dest"),
298 multiclass FRU6_LRU6_cp<string OpcStr> {
300 (outs GRRegs:$dst), (ins i32imm:$a),
301 !strconcat(OpcStr, " $dst, cp[$a]"),
304 (outs GRRegs:$dst), (ins i32imm:$a),
305 !strconcat(OpcStr, " $dst, cp[$a]"),
310 multiclass FU6_LU6<string OpcStr, SDNode OpNode> {
312 (outs), (ins i32imm:$b),
313 !strconcat(OpcStr, " $b"),
314 [(OpNode immU6:$b)]>;
316 (outs), (ins i32imm:$b),
317 !strconcat(OpcStr, " $b"),
318 [(OpNode immU16:$b)]>;
321 multiclass FU6_LU6_np<string OpcStr> {
323 (outs), (ins i32imm:$b),
324 !strconcat(OpcStr, " $b"),
327 (outs), (ins i32imm:$b),
328 !strconcat(OpcStr, " $b"),
333 multiclass FU10_LU10_np<string OpcStr> {
335 (outs), (ins i32imm:$b),
336 !strconcat(OpcStr, " $b"),
339 (outs), (ins i32imm:$b),
340 !strconcat(OpcStr, " $b"),
346 class F2R_np<string OpcStr> : _F2R<
347 (outs GRRegs:$dst), (ins GRRegs:$b),
348 !strconcat(OpcStr, " $dst, $b"),
353 //===----------------------------------------------------------------------===//
354 // Pseudo Instructions
355 //===----------------------------------------------------------------------===//
357 let Defs = [SP], Uses = [SP] in {
358 def ADJCALLSTACKDOWN : PseudoInstXCore<(outs), (ins i32imm:$amt),
359 "${:comment} ADJCALLSTACKDOWN $amt",
360 [(callseq_start timm:$amt)]>;
361 def ADJCALLSTACKUP : PseudoInstXCore<(outs), (ins i32imm:$amt1, i32imm:$amt2),
362 "${:comment} ADJCALLSTACKUP $amt1",
363 [(callseq_end timm:$amt1, timm:$amt2)]>;
366 def LDWFI : PseudoInstXCore<(outs GRRegs:$dst), (ins MEMii:$addr),
367 "${:comment} LDWFI $dst, $addr",
368 [(set GRRegs:$dst, (load ADDRspii:$addr))]>;
370 def LDAWFI : PseudoInstXCore<(outs GRRegs:$dst), (ins MEMii:$addr),
371 "${:comment} LDAWFI $dst, $addr",
372 [(set GRRegs:$dst, ADDRspii:$addr)]>;
374 def STWFI : PseudoInstXCore<(outs), (ins GRRegs:$src, MEMii:$addr),
375 "${:comment} STWFI $src, $addr",
376 [(store GRRegs:$src, ADDRspii:$addr)]>;
378 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded by the
379 // scheduler into a branch sequence.
380 let usesCustomDAGSchedInserter = 1 in {
381 def SELECT_CC : PseudoInstXCore<(outs GRRegs:$dst),
382 (ins GRRegs:$cond, GRRegs:$T, GRRegs:$F),
383 "${:comment} SELECT_CC PSEUDO!",
385 (select GRRegs:$cond, GRRegs:$T, GRRegs:$F))]>;
388 //===----------------------------------------------------------------------===//
390 //===----------------------------------------------------------------------===//
392 // Three operand short
393 defm ADD : F3R_2RUS<"add", add>;
394 defm SUB : F3R_2RUS<"sub", sub>;
395 let neverHasSideEffects = 1 in {
396 defm EQ : F3R_2RUS_np<"eq">;
397 def LSS_3r : F3R_np<"lss">;
398 def LSU_3r : F3R_np<"lsu">;
400 def AND_3r : F3R<"and", and>;
401 def OR_3r : F3R<"or", or>;
404 def LDW_3r : _F3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
405 "ldw $dst, $addr[$offset]",
408 def LDW_2rus : _F2RUS<(outs GRRegs:$dst), (ins GRRegs:$addr, i32imm:$offset),
409 "ldw $dst, $addr[$offset]",
412 def LD16S_3r : _F3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
413 "ld16s $dst, $addr[$offset]",
416 def LD8U_3r : _F3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
417 "ld8u $dst, $addr[$offset]",
422 def STW_3r : _F3R<(outs), (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
423 "stw $val, $addr[$offset]",
426 def STW_2rus : _F2RUS<(outs), (ins GRRegs:$val, GRRegs:$addr, i32imm:$offset),
427 "stw $val, $addr[$offset]",
431 defm SHL : F3R_2RBITP<"shl", shl>;
432 defm SHR : F3R_2RBITP<"shr", srl>;
435 // Three operand long
436 def LDAWF_l3r : _FL3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
437 "ldaw $dst, $addr[$offset]",
438 [(set GRRegs:$dst, (ldawf GRRegs:$addr, GRRegs:$offset))]>;
440 let neverHasSideEffects = 1 in
441 def LDAWF_l2rus : _FL2RUS<(outs GRRegs:$dst),
442 (ins GRRegs:$addr, i32imm:$offset),
443 "ldaw $dst, $addr[$offset]",
446 def LDAWB_l3r : _FL3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
447 "ldaw $dst, $addr[-$offset]",
448 [(set GRRegs:$dst, (ldawb GRRegs:$addr, GRRegs:$offset))]>;
450 let neverHasSideEffects = 1 in
451 def LDAWB_l2rus : _FL2RUS<(outs GRRegs:$dst),
452 (ins GRRegs:$addr, i32imm:$offset),
453 "ldaw $dst, $addr[-$offset]",
456 def LDA16F_l3r : _FL3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
457 "lda16 $dst, $addr[$offset]",
458 [(set GRRegs:$dst, (lda16f GRRegs:$addr, GRRegs:$offset))]>;
460 def LDA16B_l3r : _FL3R<(outs GRRegs:$dst), (ins GRRegs:$addr, GRRegs:$offset),
461 "lda16 $dst, $addr[-$offset]",
462 [(set GRRegs:$dst, (lda16b GRRegs:$addr, GRRegs:$offset))]>;
464 def MUL_l3r : FL3R<"mul", mul>;
465 // Instructions which may trap are marked as side effecting.
466 let hasSideEffects = 1 in {
467 def DIVS_l3r : FL3R<"divs", sdiv>;
468 def DIVU_l3r : FL3R<"divu", udiv>;
469 def REMS_l3r : FL3R<"rems", srem>;
470 def REMU_l3r : FL3R<"remu", urem>;
472 def XOR_l3r : FL3R<"xor", xor>;
473 defm ASHR : FL3R_L2RBITP<"ashr", sra>;
474 // TODO crc32, crc8, inpw, outpw
476 def ST16_l3r : _FL3R<(outs), (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
477 "st16 $val, $addr[$offset]",
480 def ST8_l3r : _FL3R<(outs), (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
481 "st8 $val, $addr[$offset]",
486 let Predicates = [HasXS1B], Constraints = "$src1 = $dst1,$src2 = $dst2" in {
487 def MACCU_l4r : _L4R<(outs GRRegs:$dst1, GRRegs:$dst2),
488 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3,
490 "maccu $dst1, $dst2, $src3, $src4",
493 def MACCS_l4r : _L4R<(outs GRRegs:$dst1, GRRegs:$dst2),
494 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3,
496 "maccs $dst1, $dst2, $src3, $src4",
502 let Predicates = [HasXS1B] in {
503 def LADD_l5r : _L5R<(outs GRRegs:$dst1, GRRegs:$dst2),
504 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
505 "ladd $dst1, $dst2, $src1, $src2, $src3",
508 def LSUB_l5r : _L5R<(outs GRRegs:$dst1, GRRegs:$dst2),
509 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
510 "lsub $dst1, $dst2, $src1, $src2, $src3",
513 def LDIV_l5r : _L5R<(outs GRRegs:$dst1, GRRegs:$dst2),
514 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
515 "ldiv $dst1, $dst2, $src1, $src2, $src3",
521 def LMUL_l6r : _L6R<(outs GRRegs:$dst1, GRRegs:$dst2),
522 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3,
524 "lmul $dst1, $dst2, $src1, $src2, $src3, $src4",
527 let Predicates = [HasXS1A] in
528 def MACC_l6r : _L6R<(outs GRRegs:$dst1, GRRegs:$dst2),
529 (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3,
531 "macc $dst1, $dst2, $src1, $src2, $src3, $src4",
536 //let Uses = [DP] in ...
537 let neverHasSideEffects = 1, isReMaterializable = 1 in
538 def LDAWDP_ru6: _FRU6<(outs GRRegs:$dst), (ins MEMii:$a),
542 let isReMaterializable = 1 in
543 def LDAWDP_lru6: _FLRU6<
544 (outs GRRegs:$dst), (ins MEMii:$a),
546 [(set GRRegs:$dst, ADDRdpii:$a)]>;
549 def LDWDP_ru6: _FRU6<(outs GRRegs:$dst), (ins MEMii:$a),
553 def LDWDP_lru6: _FLRU6<
554 (outs GRRegs:$dst), (ins MEMii:$a),
556 [(set GRRegs:$dst, (load ADDRdpii:$a))]>;
559 def STWDP_ru6 : _FRU6<(outs), (ins GRRegs:$val, MEMii:$addr),
560 "stw $val, dp[$addr]",
563 def STWDP_lru6 : _FLRU6<(outs), (ins GRRegs:$val, MEMii:$addr),
564 "stw $val, dp[$addr]",
565 [(store GRRegs:$val, ADDRdpii:$addr)]>;
567 //let Uses = [CP] in ..
568 let mayLoad = 1, isReMaterializable = 1 in
569 defm LDWCP : FRU6_LRU6_cp<"ldw">;
573 def STWSP_ru6 : _FRU6<
574 (outs), (ins GRRegs:$val, i32imm:$index),
575 "stw $val, sp[$index]",
576 [(XCoreStwsp GRRegs:$val, immU6:$index)]>;
578 def STWSP_lru6 : _FLRU6<
579 (outs), (ins GRRegs:$val, i32imm:$index),
580 "stw $val, sp[$index]",
581 [(XCoreStwsp GRRegs:$val, immU16:$index)]>;
585 def LDWSP_ru6 : _FRU6<
586 (outs GRRegs:$dst), (ins i32imm:$b),
590 def LDWSP_lru6 : _FLRU6<
591 (outs GRRegs:$dst), (ins i32imm:$b),
596 let neverHasSideEffects = 1 in {
597 def LDAWSP_ru6 : _FRU6<
598 (outs GRRegs:$dst), (ins i32imm:$b),
602 def LDAWSP_lru6 : _FLRU6<
603 (outs GRRegs:$dst), (ins i32imm:$b),
607 def LDAWSP_ru6_RRegs : _FRU6<
608 (outs RRegs:$dst), (ins i32imm:$b),
612 def LDAWSP_lru6_RRegs : _FLRU6<
613 (outs RRegs:$dst), (ins i32imm:$b),
619 let isReMaterializable = 1 in {
621 (outs GRRegs:$dst), (ins i32imm:$b),
623 [(set GRRegs:$dst, immU6:$b)]>;
625 def LDC_lru6 : _FLRU6<
626 (outs GRRegs:$dst), (ins i32imm:$b),
628 [(set GRRegs:$dst, immU16:$b)]>;
631 // Operand register - U6
633 let isBranch = 1, isTerminator = 1 in {
634 defm BRFT: FRU6_LRU6_branch<"bt">;
635 defm BRBT: FRU6_LRU6_branch<"bt">;
636 defm BRFF: FRU6_LRU6_branch<"bf">;
637 defm BRBF: FRU6_LRU6_branch<"bf">;
641 let Defs = [SP], Uses = [SP] in {
642 let neverHasSideEffects = 1 in
643 defm EXTSP : FU6_LU6_np<"extsp">;
645 defm ENTSP : FU6_LU6_np<"entsp">;
647 let isReturn = 1, isTerminator = 1, mayLoad = 1 in {
648 defm RETSP : FU6_LU6<"retsp", XCoreRetsp>;
652 // TODO extdp, kentsp, krestsp, blat, setsr
653 // clrsr, getsr, kalli
654 let isBranch = 1, isTerminator = 1 in {
657 (ins brtarget:$target),
661 def BRBU_lu6 : _FLU6<
663 (ins brtarget:$target),
669 (ins brtarget:$target),
673 def BRFU_lu6 : _FLU6<
675 (ins brtarget:$target),
680 //let Uses = [CP] in ...
681 let Predicates = [HasXS1B], Defs = [R11], neverHasSideEffects = 1,
682 isReMaterializable = 1 in
683 def LDAWCP_u6: _FRU6<(outs), (ins MEMii:$a),
687 let Predicates = [HasXS1B], Defs = [R11], isReMaterializable = 1 in
688 def LDAWCP_lu6: _FLRU6<
689 (outs), (ins MEMii:$a),
691 [(set R11, ADDRcpii:$a)]>;
694 // TODO ldwcpl, blacp
696 let Defs = [R11], isReMaterializable = 1, neverHasSideEffects = 1 in
697 def LDAP_u10 : _FU10<
703 let Defs = [R11], isReMaterializable = 1 in
704 def LDAP_lu10 : _FLU10<
708 [(set R11, (pcrelwrapper tglobaladdr:$addr))]>;
711 // All calls clobber the the link register and the non-callee-saved registers:
712 Defs = [R0, R1, R2, R3, R11, LR] in {
715 (ins calltarget:$target, variable_ops),
717 [(XCoreBranchLink immU10:$target)]>;
719 def BL_lu10 : _FLU10<
721 (ins calltarget:$target, variable_ops),
723 [(XCoreBranchLink immU20:$target)]>;
728 def NOT : _F2R<(outs GRRegs:$dst), (ins GRRegs:$b),
730 [(set GRRegs:$dst, (not GRRegs:$b))]>;
732 def NEG : _F2R<(outs GRRegs:$dst), (ins GRRegs:$b),
734 [(set GRRegs:$dst, (ineg GRRegs:$b))]>;
736 // TODO setd, eet, eef, getts, setpt, outct, inct, chkct, outt, intt, out,
737 // in, outshr, inshr, testct, testwct, tinitpc, tinitdp, tinitsp, tinitcp,
738 // tsetmr, sext (reg), zext (reg)
739 let isTwoAddress = 1 in {
740 let neverHasSideEffects = 1 in
741 def SEXT_rus : _FRUS<(outs GRRegs:$dst), (ins GRRegs:$src1, i32imm:$src2),
745 let neverHasSideEffects = 1 in
746 def ZEXT_rus : _FRUS<(outs GRRegs:$dst), (ins GRRegs:$src1, i32imm:$src2),
750 def ANDNOT_2r : _F2R<(outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
751 "andnot $dst, $src2",
752 [(set GRRegs:$dst, (and GRRegs:$src1, (not GRRegs:$src2)))]>;
755 let isReMaterializable = 1, neverHasSideEffects = 1 in
756 def MKMSK_rus : _FRUS<(outs GRRegs:$dst), (ins i32imm:$size),
760 def MKMSK_2r : _FRUS<(outs GRRegs:$dst), (ins GRRegs:$size),
762 [(set GRRegs:$dst, (add (shl 1, GRRegs:$size), 0xffffffff))]>;
765 // TODO settw, setclk, setrdy, setpsc, endin, peek,
766 // getd, testlcl, tinitlr, getps, setps
767 def BITREV_l2r : _FL2R<(outs GRRegs:$dst), (ins GRRegs:$src),
769 [(set GRRegs:$dst, (int_xcore_bitrev GRRegs:$src))]>;
771 def BYTEREV_l2r : _FL2R<(outs GRRegs:$dst), (ins GRRegs:$src),
772 "byterev $dst, $src",
773 [(set GRRegs:$dst, (bswap GRRegs:$src))]>;
775 def CLZ_l2r : _FL2R<(outs GRRegs:$dst), (ins GRRegs:$src),
777 [(set GRRegs:$dst, (ctlz GRRegs:$src))]>;
780 // TODO edu, eeu, waitet, waitef, freer, tstart, msync, mjoin, syncr, clrtp
781 // bru, setdp, setcp, setv, setev, kcall
783 let isBranch=1, isIndirectBranch=1, isTerminator=1 in
784 def BAU_1r : _F1R<(outs), (ins GRRegs:$addr),
786 [(brind GRRegs:$addr)]>;
788 let Defs=[SP], neverHasSideEffects=1 in
789 def SETSP_1r : _F1R<(outs), (ins GRRegs:$src),
793 let isBarrier = 1, hasCtrlDep = 1 in
794 def ECALLT_1r : _F1R<(outs), (ins GRRegs:$src),
798 let isBarrier = 1, hasCtrlDep = 1 in
799 def ECALLF_1r : _F1R<(outs), (ins GRRegs:$src),
804 // All calls clobber the the link register and the non-callee-saved registers:
805 Defs = [R0, R1, R2, R3, R11, LR] in {
806 def BLA_1r : _F1R<(outs), (ins GRRegs:$addr, variable_ops),
808 [(XCoreBranchLink GRRegs:$addr)]>;
811 // Zero operand short
812 // TODO waiteu, clre, ssync, freet, ldspc, stspc, ldssr, stssr, ldsed, stsed,
813 // stet, geted, getet, getkep, getksp, setkep, getid, kret, dcall, dret,
817 def GETID_0R : _F0R<(outs), (ins),
819 [(set R11, (int_xcore_getid))]>;
821 //===----------------------------------------------------------------------===//
822 // Non-Instruction Patterns
823 //===----------------------------------------------------------------------===//
825 def : Pat<(XCoreBranchLink tglobaladdr:$addr), (BL_lu10 tglobaladdr:$addr)>;
826 def : Pat<(XCoreBranchLink texternalsym:$addr), (BL_lu10 texternalsym:$addr)>;
829 def : Pat<(sext_inreg GRRegs:$b, i1), (SEXT_rus GRRegs:$b, 1)>;
830 def : Pat<(sext_inreg GRRegs:$b, i8), (SEXT_rus GRRegs:$b, 8)>;
831 def : Pat<(sext_inreg GRRegs:$b, i16), (SEXT_rus GRRegs:$b, 16)>;
834 def : Pat<(zextloadi8 (add GRRegs:$addr, GRRegs:$offset)),
835 (LD8U_3r GRRegs:$addr, GRRegs:$offset)>;
836 def : Pat<(zextloadi8 GRRegs:$addr), (LD8U_3r GRRegs:$addr, (LDC_ru6 0))>;
838 def : Pat<(sextloadi16 (lda16f GRRegs:$addr, GRRegs:$offset)),
839 (LD16S_3r GRRegs:$addr, GRRegs:$offset)>;
840 def : Pat<(sextloadi16 GRRegs:$addr), (LD16S_3r GRRegs:$addr, (LDC_ru6 0))>;
842 def : Pat<(load (ldawf GRRegs:$addr, GRRegs:$offset)),
843 (LDW_3r GRRegs:$addr, GRRegs:$offset)>;
844 def : Pat<(load (add GRRegs:$addr, immUs4:$offset)),
845 (LDW_2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
846 def : Pat<(load GRRegs:$addr), (LDW_2rus GRRegs:$addr, 0)>;
849 def : Pat<(extloadi8 (add GRRegs:$addr, GRRegs:$offset)),
850 (LD8U_3r GRRegs:$addr, GRRegs:$offset)>;
851 def : Pat<(extloadi8 GRRegs:$addr), (LD8U_3r GRRegs:$addr, (LDC_ru6 0))>;
852 def : Pat<(extloadi16 (lda16f GRRegs:$addr, GRRegs:$offset)),
853 (LD16S_3r GRRegs:$addr, GRRegs:$offset)>;
854 def : Pat<(extloadi16 GRRegs:$addr), (LD16S_3r GRRegs:$addr, (LDC_ru6 0))>;
857 def : Pat<(truncstorei8 GRRegs:$val, (add GRRegs:$addr, GRRegs:$offset)),
858 (ST8_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
859 def : Pat<(truncstorei8 GRRegs:$val, GRRegs:$addr),
860 (ST8_l3r GRRegs:$val, GRRegs:$addr, (LDC_ru6 0))>;
862 def : Pat<(truncstorei16 GRRegs:$val, (lda16f GRRegs:$addr, GRRegs:$offset)),
863 (ST16_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
864 def : Pat<(truncstorei16 GRRegs:$val, GRRegs:$addr),
865 (ST16_l3r GRRegs:$val, GRRegs:$addr, (LDC_ru6 0))>;
867 def : Pat<(store GRRegs:$val, (ldawf GRRegs:$addr, GRRegs:$offset)),
868 (STW_3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
869 def : Pat<(store GRRegs:$val, (add GRRegs:$addr, immUs4:$offset)),
870 (STW_2rus GRRegs:$val, GRRegs:$addr, (div4_xform immUs4:$offset))>;
871 def : Pat<(store GRRegs:$val, GRRegs:$addr),
872 (STW_2rus GRRegs:$val, GRRegs:$addr, 0)>;
875 def : Pat<(cttz GRRegs:$src), (CLZ_l2r (BITREV_l2r GRRegs:$src))>;
878 def : Pat<(trap), (ECALLF_1r (LDC_ru6 0))>;
884 // unconditional branch
885 def : Pat<(br bb:$addr), (BRFU_lu6 bb:$addr)>;
887 // direct match equal/notequal zero brcond
888 def : Pat<(brcond (setne GRRegs:$lhs, 0), bb:$dst),
889 (BRFT_lru6 GRRegs:$lhs, bb:$dst)>;
890 def : Pat<(brcond (seteq GRRegs:$lhs, 0), bb:$dst),
891 (BRFF_lru6 GRRegs:$lhs, bb:$dst)>;
893 def : Pat<(brcond (setle GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
894 (BRFF_lru6 (LSS_3r GRRegs:$rhs, GRRegs:$lhs), bb:$dst)>;
895 def : Pat<(brcond (setule GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
896 (BRFF_lru6 (LSU_3r GRRegs:$rhs, GRRegs:$lhs), bb:$dst)>;
897 def : Pat<(brcond (setge GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
898 (BRFF_lru6 (LSS_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
899 def : Pat<(brcond (setuge GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
900 (BRFF_lru6 (LSU_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
901 def : Pat<(brcond (setne GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
902 (BRFF_lru6 (EQ_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
903 def : Pat<(brcond (setne GRRegs:$lhs, immUs:$rhs), bb:$dst),
904 (BRFF_lru6 (EQ_2rus GRRegs:$lhs, immUs:$rhs), bb:$dst)>;
906 // generic brcond pattern
907 def : Pat<(brcond GRRegs:$cond, bb:$addr), (BRFT_lru6 GRRegs:$cond, bb:$addr)>;
914 // direct match equal/notequal zero select
915 def : Pat<(select (setne GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
916 (SELECT_CC GRRegs:$lhs, GRRegs:$T, GRRegs:$F)>;
918 def : Pat<(select (seteq GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
919 (SELECT_CC GRRegs:$lhs, GRRegs:$F, GRRegs:$T)>;
921 def : Pat<(select (setle GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
922 (SELECT_CC (LSS_3r GRRegs:$rhs, GRRegs:$lhs), GRRegs:$F, GRRegs:$T)>;
923 def : Pat<(select (setule GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
924 (SELECT_CC (LSU_3r GRRegs:$rhs, GRRegs:$lhs), GRRegs:$F, GRRegs:$T)>;
925 def : Pat<(select (setge GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
926 (SELECT_CC (LSS_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
927 def : Pat<(select (setuge GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
928 (SELECT_CC (LSU_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
929 def : Pat<(select (setne GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
930 (SELECT_CC (EQ_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
931 def : Pat<(select (setne GRRegs:$lhs, immUs:$rhs), GRRegs:$T, GRRegs:$F),
932 (SELECT_CC (EQ_2rus GRRegs:$lhs, immUs:$rhs), GRRegs:$F, GRRegs:$T)>;
935 /// setcc patterns, only matched when none of the above brcond
939 // setcc 2 register operands
940 def : Pat<(setle GRRegs:$lhs, GRRegs:$rhs),
941 (EQ_2rus (LSS_3r GRRegs:$rhs, GRRegs:$lhs), 0)>;
942 def : Pat<(setule GRRegs:$lhs, GRRegs:$rhs),
943 (EQ_2rus (LSU_3r GRRegs:$rhs, GRRegs:$lhs), 0)>;
945 def : Pat<(setgt GRRegs:$lhs, GRRegs:$rhs),
946 (LSS_3r GRRegs:$rhs, GRRegs:$lhs)>;
947 def : Pat<(setugt GRRegs:$lhs, GRRegs:$rhs),
948 (LSU_3r GRRegs:$rhs, GRRegs:$lhs)>;
950 def : Pat<(setge GRRegs:$lhs, GRRegs:$rhs),
951 (EQ_2rus (LSS_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
952 def : Pat<(setuge GRRegs:$lhs, GRRegs:$rhs),
953 (EQ_2rus (LSU_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
955 def : Pat<(setlt GRRegs:$lhs, GRRegs:$rhs),
956 (LSS_3r GRRegs:$lhs, GRRegs:$rhs)>;
957 def : Pat<(setult GRRegs:$lhs, GRRegs:$rhs),
958 (LSU_3r GRRegs:$lhs, GRRegs:$rhs)>;
960 def : Pat<(setne GRRegs:$lhs, GRRegs:$rhs),
961 (EQ_2rus (EQ_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
963 def : Pat<(seteq GRRegs:$lhs, GRRegs:$rhs),
964 (EQ_3r GRRegs:$lhs, GRRegs:$rhs)>;
966 // setcc reg/imm operands
967 def : Pat<(seteq GRRegs:$lhs, immUs:$rhs),
968 (EQ_2rus GRRegs:$lhs, immUs:$rhs)>;
969 def : Pat<(setne GRRegs:$lhs, immUs:$rhs),
970 (EQ_2rus (EQ_2rus GRRegs:$lhs, immUs:$rhs), 0)>;
973 def : Pat<(add GRRegs:$addr, immUs4:$offset),
974 (LDAWF_l2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
976 def : Pat<(sub GRRegs:$addr, immUs4:$offset),
977 (LDAWB_l2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
979 def : Pat<(and GRRegs:$val, immMskBitp:$mask),
980 (ZEXT_rus GRRegs:$val, (msksize_xform immMskBitp:$mask))>;
982 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
983 def : Pat<(add GRRegs:$src1, immUsNeg:$src2),
984 (SUB_2rus GRRegs:$src1, (neg_xform immUsNeg:$src2))>;
986 def : Pat<(add GRRegs:$src1, immUs4Neg:$src2),
987 (LDAWB_l2rus GRRegs:$src1, (div4neg_xform immUs4Neg:$src2))>;
993 def : Pat<(mul GRRegs:$src, 3),
994 (LDA16F_l3r GRRegs:$src, GRRegs:$src)>;
996 def : Pat<(mul GRRegs:$src, 5),
997 (LDAWF_l3r GRRegs:$src, GRRegs:$src)>;
999 def : Pat<(mul GRRegs:$src, -3),
1000 (LDAWB_l3r GRRegs:$src, GRRegs:$src)>;
1002 // ashr X, 32 is equivalent to ashr X, 31 on the XCore.
1003 def : Pat<(sra GRRegs:$src, 31),
1004 (ASHR_l2rus GRRegs:$src, 32)>;
1006 def : Pat<(sra (shl GRRegs:$src, immBpwSubBitp:$imm), immBpwSubBitp:$imm),
1007 (SEXT_rus GRRegs:$src, (bpwsub_xform immBpwSubBitp:$imm))>;