1 //===- XtensaInstrInfo.td - Target Description for Xtensa -*- tablegen -*--===//
3 // The LLVM Compiler Infrastructure
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file describes the Xtensa instructions in TableGen format.
13 //===----------------------------------------------------------------------===//
15 include "XtensaInstrFormats.td"
16 include "XtensaOperands.td"
17 include "XtensaOperators.td"
19 //===----------------------------------------------------------------------===//
20 // Arithmetic & Logical instructions
21 //===----------------------------------------------------------------------===//
23 class ArithLogic_RRR<bits<4> oper2, bits<4> oper1, string instrAsm,
24 SDPatternOperator opNode, bit isComm = 0>
25 : RRR_Inst<0x00, oper1, oper2, (outs AR:$r), (ins AR:$s, AR:$t),
26 instrAsm#"\t$r, $s, $t",
27 [(set AR:$r, (opNode AR:$s, AR:$t))]> {
28 let isCommutable = isComm;
29 let isReMaterializable = 0;
32 def ADD : ArithLogic_RRR<0x08, 0x00, "add", add, 1>;
33 def SUB : ArithLogic_RRR<0x0C, 0x00, "sub", sub>;
34 def AND : ArithLogic_RRR<0x01, 0x00, "and", and, 1>;
35 def OR : ArithLogic_RRR<0x02, 0x00, "or", or, 1>;
36 def XOR : ArithLogic_RRR<0x03, 0x00, "xor", xor, 1>;
38 class ADDX<bits<4> oper, string instrAsm, list<dag> pattern>
39 : RRR_Inst<0x00, 0x00, oper, (outs AR:$r), (ins AR:$s, AR:$t),
40 instrAsm#"\t$r, $s, $t", pattern>;
42 def ADDX2 : ADDX<0x09, "addx2", [(set AR:$r, (add AR:$t, (shl AR:$s, (i32 1))))]>;
43 def ADDX4 : ADDX<0x0A, "addx4", [(set AR:$r, (add AR:$t, (shl AR:$s, (i32 2))))]>;
44 def ADDX8 : ADDX<0x0B, "addx8", [(set AR:$r, (add AR:$t, (shl AR:$s, (i32 3))))]>;
46 class SUBX<bits<4> oper, string instrAsm, list<dag> pattern>
47 : RRR_Inst<0x00, 0x00, oper, (outs AR:$r), (ins AR:$s, AR:$t),
48 instrAsm#"\t$r, $s, $t", pattern>;
50 def SUBX2 : SUBX<0x0D, "subx2", [(set AR:$r, (sub (shl AR:$s, (i32 1)), AR:$t))]>;
51 def SUBX4 : SUBX<0x0E, "subx4", [(set AR:$r, (sub (shl AR:$s, (i32 2)), AR:$t))]>;
52 def SUBX8 : SUBX<0x0F, "subx8", [(set AR:$r, (sub (shl AR:$s, (i32 3)), AR:$t))]>;
54 def ABS : RRR_Inst<0x00, 0x00, 0x06, (outs AR:$r), (ins AR:$t),
59 def ADDI : RRI8_Inst<0x02, (outs AR:$t), (ins AR:$s, imm8:$imm8),
60 "addi\t$t, $s, $imm8",
61 [(set AR:$t, (add AR:$s, imm8:$imm8))]> {
65 def ADDMI : RRI8_Inst<0x02, (outs AR:$t), (ins AR:$s, imm8_sh8:$imm_sh8),
66 "addmi\t$t, $s, $imm_sh8",
67 [(set AR:$t, (add AR:$s, imm8_sh8:$imm_sh8))]> {
71 let imm8 = imm_sh8{15-8};
74 def NEG : RRR_Inst<0x00, 0x00, 0x06, (outs AR:$r), (ins AR:$t),
76 [(set AR:$r, (ineg AR:$t))]> {
80 //===----------------------------------------------------------------------===//
82 //===----------------------------------------------------------------------===//
83 def MOVI : RRI8_Inst<0x02, (outs AR:$t), (ins imm12m:$imm),
85 [(set AR:$t, imm12m:$imm)]> {
88 let imm8{7-0} = imm{7-0};
89 let s{3-0} = imm{11-8};
93 def MOVEQZ : RRR_Inst<0x00, 0x03, 0x08, (outs AR:$r), (ins AR:$s, AR:$t),
94 "moveqz\t$r, $s, $t", []>;
95 def MOVNEZ : RRR_Inst<0x00, 0x03, 0x09, (outs AR:$r), (ins AR:$s, AR:$t),
96 "movnez\t$r, $s, $t", []>;
97 def MOVLTZ : RRR_Inst<0x00, 0x03, 0x0A, (outs AR:$r), (ins AR:$s, AR:$t),
98 "movltz\t$r, $s, $t", []>;
99 def MOVGEZ : RRR_Inst<0x00, 0x03, 0x0B, (outs AR:$r), (ins AR:$s, AR:$t),
100 "movgez\t$r, $s, $t", []>;
102 //===----------------------------------------------------------------------===//
103 // Shift instructions
104 //===----------------------------------------------------------------------===//
106 let Uses = [SAR] in {
107 def SLL : RRR_Inst<0x00, 0x01, 0x0A, (outs AR:$r), (ins AR:$s),
112 def SRA : RRR_Inst<0x00, 0x01, 0x0B, (outs AR:$r), (ins AR:$t),
117 def SRC : RRR_Inst<0x00, 0x01, 0x08, (outs AR:$r), (ins AR:$s, AR:$t),
118 "src\t$r, $s, $t", []>;
120 def SRL : RRR_Inst<0x00, 0x01, 0x09, (outs AR:$r), (ins AR:$t),
126 let Defs = [SAR] in {
127 def SSL : RRR_Inst<0x00, 0x00, 0x04, (outs), (ins AR:$s),
133 def SSR : RRR_Inst<0x00, 0x00, 0x04, (outs), (ins AR:$s),
140 def EXTUI : RRR_Inst<0x00, 0x04, 0x00, (outs AR:$r), (ins AR:$t, uimm5:$imm1, imm1_16:$imm2),
141 "extui\t$r, $t, $imm1, $imm2",
142 [(set AR:$r, (Xtensa_extui AR:$t, uimm5:$imm1, imm1_16:$imm2))]> {
147 let Inst{16} = imm1{4};
148 let Inst{23-20} = imm2;
151 def SRAI : RRR_Inst<0x00, 0x01, 0x02, (outs AR:$r), (ins AR:$t, uimm5:$sa),
153 [(set AR:$r, (sra AR:$t, uimm5:$sa))]> {
156 let Inst{20} = sa{4};
160 def SRLI : RRR_Inst<0x00, 0x01, 0x04, (outs AR:$r), (ins AR:$t, uimm4:$sa),
162 [(set AR:$r, (srl AR:$t, uimm4:$sa))]> {
168 def SLLI : RRR_Inst<0x00, 0x01, 0x00, (outs AR:$r), (ins AR:$s, shimm1_31:$sa),
170 [(set AR:$r, (shl AR:$s, shimm1_31:$sa))]> {
173 let Inst{20} = sa{4};
177 def SSA8L : RRR_Inst<0x00, 0x00, 0x04, (outs), (ins AR:$s),
183 def SSAI : RRR_Inst<0x00, 0x00, 0x04, (outs), (ins uimm5:$imm),
193 //===----------------------------------------------------------------------===//
194 // Load and store instructions
195 //===----------------------------------------------------------------------===//
198 let mayLoad = 1, usesCustomInserter = 1 in {
200 class Load_RRI8<bits<4> oper, string instrAsm, SDPatternOperator opNode,
201 ComplexPattern addrOp, Operand memOp>
202 : RRI8_Inst<0x02, (outs AR:$t), (ins memOp:$addr),
203 instrAsm#"\t$t, $addr",
204 [(set AR:$t, (opNode addrOp:$addr))]> {
208 let imm8{7-0} = addr{11-4};
209 let s{3-0} = addr{3-0};
213 def L8UI : Load_RRI8<0x00, "l8ui", zextloadi8, addr_ish1, mem8>;
214 def L16SI : Load_RRI8<0x09, "l16si", sextloadi16, addr_ish2, mem16>;
215 def L16UI : Load_RRI8<0x01, "l16ui", zextloadi16, addr_ish2, mem16>;
216 def L32I : Load_RRI8<0x02, "l32i", load, addr_ish4, mem32>;
218 // Store instructions
219 let mayStore = 1, usesCustomInserter = 1 in {
220 class Store_II8<bits<4> oper, string instrAsm, SDPatternOperator opNode,
221 ComplexPattern addrOp, Operand memOp>
222 : RRI8_Inst<0x02, (outs), (ins AR:$t, memOp:$addr),
223 instrAsm#"\t$t, $addr",
224 [(opNode AR:$t, addrOp:$addr)]> {
228 let imm8{7-0} = addr{11-4};
229 let s{3-0} = addr{3-0};
233 def S8I : Store_II8<0x04, "s8i", truncstorei8, addr_ish1, mem8>;
234 def S16I : Store_II8<0x05, "s16i", truncstorei16, addr_ish2, mem16>;
235 def S32I : Store_II8<0x06, "s32i", store, addr_ish4, mem32>;
237 def L32R : RI16_Inst<0x01, (outs AR:$t), (ins L32Rtarget:$label),
238 "l32r\t$t, $label", []> {
243 // pcrel addr loading using L32R
244 def : Pat<(Xtensa_pcrel_wrapper tconstpool : $in), (L32R tconstpool : $in)>;
246 // FrameIndexes are legalized when they are operands from load/store
247 // instructions. The same not happens for stack address copies, so an
248 // add op with mem ComplexPattern is used and the stack address copy
250 // Setting of attribute mayLoad is trick to process instruction operands
251 // in function XtensaRegisterInfo::eliminateFI
253 let isCodeGenOnly = 1, mayLoad = 1 in {
255 def LEA_ADD : RRI8_Inst<0x02, (outs AR:$t), (ins mem32:$addr),
257 [(set AR:$t, addr_ish4:$addr)]> {
261 let imm8{7-0} = addr{11-4};
262 let s{3-0} = addr{3-0};
267 def : Pat<(i32 (extloadi1 addr_ish1:$addr)), (L8UI addr_ish1:$addr)>;
268 def : Pat<(i32 (extloadi8 addr_ish1:$addr)), (L8UI addr_ish1:$addr)>;
269 def : Pat<(i32 (extloadi16 addr_ish2:$addr)), (L16UI addr_ish2:$addr)>;
271 //===----------------------------------------------------------------------===//
272 // Conditional branch instructions
273 //===----------------------------------------------------------------------===//
274 let isBranch = 1, isTerminator = 1 in {
275 class Branch_RR<bits<4> oper, string instrAsm, CondCode CC>
276 : RRI8_Inst<0x07, (outs),
277 (ins AR:$s, AR:$t, brtarget:$target),
278 instrAsm#"\t$s, $t, $target",
279 [(brcc CC, AR:$s, AR:$t, bb:$target)]> {
286 class Branch_RI<bits<4> oper, string instrAsm, CondCode CC>
287 : RRI8_Inst<0x06, (outs),
288 (ins AR:$s, b4const:$imm, brtarget:$target),
289 instrAsm#"\t$s, $imm, $target",
290 [(brcc CC, AR:$s, b4const:$imm, bb:$target)]> {
299 class Branch_RIU<bits<4> oper, string instrAsm, CondCode CC>
300 : RRI8_Inst<0x06, (outs),
301 (ins AR:$s, b4constu:$imm, brtarget:$target),
302 instrAsm#"\t$s, $imm, $target",
303 [(brcc CC, AR:$s, b4constu:$imm, bb:$target)]> {
312 class Branch_RZ<bits<2> n, bits<2> m, string instrAsm, CondCode CC>
313 : BRI12_Inst<0x06, n, m, (outs),
314 (ins AR:$s, brtarget:$target),
315 instrAsm#"\t$s, $target",
316 [(brcc CC, AR:$s, (i32 0), bb:$target)]> {
323 def BEQ : Branch_RR<0x01, "beq", SETEQ>;
324 def BNE : Branch_RR<0x09, "bne", SETNE>;
325 def BGE : Branch_RR<0x0A, "bge", SETGE>;
326 def BLT : Branch_RR<0x02, "blt", SETLT>;
327 def BGEU : Branch_RR<0x0B, "bgeu", SETUGE>;
328 def BLTU : Branch_RR<0x03, "bltu", SETULT>;
330 def BEQI : Branch_RI<0x02, "beqi", SETEQ>;
331 def BNEI : Branch_RI<0x06, "bnei", SETNE>;
332 def BGEI : Branch_RI<0x0E, "bgei", SETGE>;
333 def BLTI : Branch_RI<0x0A, "blti", SETLT>;
334 def BGEUI : Branch_RIU<0x0F, "bgeui", SETUGE>;
335 def BLTUI : Branch_RIU<0x0B, "bltui", SETULT>;
337 def BEQZ : Branch_RZ<0x01, 0x00, "beqz", SETEQ>;
338 def BNEZ : Branch_RZ<0x01, 0x01, "bnez", SETNE>;
339 def BGEZ : Branch_RZ<0x01, 0x03, "bgez", SETGE>;
340 def BLTZ : Branch_RZ<0x01, 0x02, "bltz", SETLT>;
342 def BALL : RRI8_Inst<0x07, (outs),
343 (ins AR:$s, AR:$t, brtarget:$target),
344 "ball\t$s, $t, $target", []> {
351 def BANY : RRI8_Inst<0x07, (outs),
352 (ins AR:$s, AR:$t, brtarget:$target),
353 "bany\t$s, $t, $target", []> {
360 def BBC : RRI8_Inst<0x07, (outs),
361 (ins AR:$s, AR:$t, brtarget:$target),
362 "bbc\t$s, $t, $target", []> {
369 def BBS : RRI8_Inst<0x07, (outs),
370 (ins AR:$s, AR:$t, brtarget:$target),
371 "bbs\t$s, $t, $target", []> {
378 def BNALL : RRI8_Inst<0x07, (outs),
379 (ins AR:$s, AR:$t, brtarget:$target),
380 "bnall\t$s, $t, $target", []> {
387 def BNONE : RRI8_Inst<0x07, (outs),
388 (ins AR:$s, AR:$t, brtarget:$target),
389 "bnone\t$s, $t, $target", []> {
396 def BBCI : RRI8_Inst<0x07, (outs),
397 (ins AR:$s, uimm5:$imm, brtarget:$target),
398 "bbci\t$s, $imm, $target", []> {
404 let t{3-0} = imm{3-0};
408 def BBSI : RRI8_Inst<0x07, (outs),
409 (ins AR:$s, uimm5:$imm, brtarget:$target),
410 "bbsi\t$s, $imm, $target", []> {
416 let t{3-0} = imm{3-0};
420 def : Pat<(brcond AR:$s, bb:$target), (BNEZ AR:$s, bb:$target)>;
422 //===----------------------------------------------------------------------===//
423 // Call and jump instructions
424 //===----------------------------------------------------------------------===//
426 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
427 def J : CALL_Inst<0x06, (outs), (ins jumptarget:$offset),
433 def JX : CALLX_Inst<0x00, 0x00, 0x00, (outs), (ins AR:$s),
439 let isIndirectBranch = 1;
443 let isCall = 1, Defs = [A0] in {
444 def CALL0 : CALL_Inst<0x05, (outs), (ins pcrel32call:$offset),
445 "call0\t$offset", []> {
449 def CALLX0 : CALLX_Inst<0x00, 0x00, 0x00, (outs), (ins AR:$s),
457 let isReturn = 1, isTerminator = 1,
458 isBarrier = 1, Uses = [A0] in {
460 def RET : CALLX_Inst<0x00, 0x00, 0x00, (outs), (ins),
461 "ret", [(Xtensa_ret)]> {
470 def : Pat<(Xtensa_call (i32 tglobaladdr:$dst)),
471 (CALL0 tglobaladdr:$dst)>;
472 def : Pat<(Xtensa_call (i32 texternalsym:$dst)),
473 (CALL0 texternalsym:$dst)>;
474 def : Pat<(Xtensa_call AR:$dst),
477 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1, Size = 3 in {
478 def BR_JT: Pseudo<(outs), (ins AR:$s, i32imm:$jt),
480 [(Xtensa_brjt AR:$s, tjumptable:$jt)]>;
483 //===----------------------------------------------------------------------===//
484 // Mem barrier instructions
485 //===----------------------------------------------------------------------===//
487 def MEMW : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
494 def EXTW : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
499 let hasSideEffects = 1;
502 //===----------------------------------------------------------------------===//
503 // Processor control instructions
504 //===----------------------------------------------------------------------===//
506 def DSYNC : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
511 let hasSideEffects = 1;
514 def ISYNC : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
519 let hasSideEffects = 1;
522 def RSYNC : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
527 let hasSideEffects = 1;
530 def ESYNC : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
535 let hasSideEffects = 1;
538 def NOP : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
545 def WSR : RSR_Inst<0x00, 0x03, 0x01, (outs SR:$sr), (ins AR:$t),
548 def RSR : RSR_Inst<0x00, 0x03, 0x00, (outs AR:$t), (ins SR:$sr),
551 def XSR : RSR_Inst<0x00, 0x01, 0x06, (outs AR:$ard, SR:$srd), (ins AR:$t, SR:$sr),
552 "xsr\t$t, $sr", []> {
553 let Constraints = "$ard = $t, $srd = $sr";
556 //===----------------------------------------------------------------------===//
558 //===----------------------------------------------------------------------===//
560 // ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
561 // a stack adjustment and the codegen must know that they may modify the stack
562 // pointer before prolog-epilog rewriting occurs.
563 let Defs = [SP], Uses = [SP] in {
564 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
566 [(Xtensa_callseq_start timm:$amt1, timm:$amt2)]>;
567 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
569 [(Xtensa_callseq_end timm:$amt1, timm:$amt2)]>;
572 //===----------------------------------------------------------------------===//
573 // Generic select instruction
574 //===----------------------------------------------------------------------===//
575 let usesCustomInserter = 1 in {
576 def SELECT : Pseudo<(outs AR:$dst), (ins AR:$lhs, AR:$rhs, AR:$t, AR:$f, i32imm:$cond),
577 "!select $dst, $lhs, $rhs, $t, $f, $cond",
578 [(set i32:$dst, (Xtensa_select_cc i32:$lhs, i32:$rhs, i32:$t, i32:$f, imm:$cond))]>;
581 //===----------------------------------------------------------------------===//
582 // Code Density instructions
583 //===----------------------------------------------------------------------===//
585 class ArithLogic_RRRN<bits<4> oper0, string instrAsm,
586 SDPatternOperator opNode, bit isComm = 0>
587 : RRRN_Inst<oper0, (outs AR:$r), (ins AR:$s, AR:$t),
588 instrAsm#"\t$r, $s, $t",
589 [(set AR:$r, (opNode AR:$s, AR:$t))]>, Requires<[HasDensity]> {
590 let isCommutable = isComm;
591 let isReMaterializable = 0;
594 def ADD_N : ArithLogic_RRRN<0x0a, "add.n", add, 1>;
596 def ADDI_N : RRRN_Inst<0x0B, (outs AR:$r), (ins AR:$s, imm1n_15:$imm),
597 "addi.n\t$r, $s, $imm",
598 [(set AR:$r, (add AR:$s, imm1n_15:$imm))]>, Requires<[HasDensity]> {
604 // Conditional branch instructions.
605 let isBranch = 1, isTerminator = 1 in {
606 def BEQZ_N : RI6_Inst<0xC, 0x1, 0x0, (outs), (ins AR:$s, brtarget:$target),
607 "beqz.n\t$s, $target", []>, Requires<[HasDensity]> {
613 def BNEZ_N : RI6_Inst<0xC, 0x1, 0x1, (outs), (ins AR:$s, brtarget:$target),
614 "bnez.n\t$s, $target", []>, Requires<[HasDensity]> {
621 def ILL_N : RRRN_Inst<0x0D, (outs), (ins),
622 "ill.n", []>, Requires<[HasDensity]> {
628 def MOV_N : RRRN_Inst<0x0D, (outs AR:$t), (ins AR:$s),
629 "mov.n\t$t, $s", []>, Requires<[HasDensity]> {
633 def : InstAlias<"mov\t $t, $s", (OR AR:$t, AR:$s, AR:$s)>;
635 def MOVI_N : RI7_Inst<0xc, 0x0, (outs AR:$s), (ins imm32n_95:$imm7),
637 [(set AR:$s, imm32n_95:$imm7)]>, Requires<[HasDensity]>;
639 def : InstAlias<"_movi.n\t$s, $imm7", (MOVI_N AR:$s, imm32n_95:$imm7)>;
641 def NOP_N : RRRN_Inst<0x0D, (outs), (ins),
642 "nop.n", []>, Requires<[HasDensity]> {
649 let mayLoad = 1, usesCustomInserter = 1 in {
650 def L32I_N : RRRN_Inst<0x8, (outs AR:$t), (ins mem32n:$addr),
651 "l32i.n\t$t, $addr", []>, Requires<[HasDensity]> {
654 let r{3-0} = addr{7-4};
655 let s{3-0} = addr{3-0};
660 let mayStore = 1, usesCustomInserter = 1 in {
661 def S32I_N : RRRN_Inst<0x9, (outs), (ins AR:$t, mem32n:$addr),
662 "s32i.n\t$t, $addr", []>, Requires<[HasDensity]> {
665 let r{3-0} = addr{7-4};
666 let s{3-0} = addr{3-0};
671 let isReturn = 1, isTerminator = 1,
672 isBarrier = 1, Uses = [A0] in {
673 def RET_N : RRRN_Inst<0x0D, (outs), (ins),
674 "ret.n", [(Xtensa_ret)]>,
675 Requires<[HasDensity]> {