xref: /freebsd/contrib/llvm-project/llvm/lib/Target/BPF/BPFInstrFormats.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1//===-- BPFInstrFormats.td - BPF Instruction Formats -------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9class BPFOpClass<bits<3> val> {
10  bits<3> Value = val;
11}
12
13def BPF_LD    : BPFOpClass<0x0>;
14def BPF_LDX   : BPFOpClass<0x1>;
15def BPF_ST    : BPFOpClass<0x2>;
16def BPF_STX   : BPFOpClass<0x3>;
17def BPF_ALU   : BPFOpClass<0x4>;
18def BPF_JMP   : BPFOpClass<0x5>;
19def BPF_JMP32 : BPFOpClass<0x6>;
20def BPF_ALU64 : BPFOpClass<0x7>;
21
22class BPFSrcType<bits<1> val> {
23  bits<1> Value = val;
24}
25
26def BPF_K : BPFSrcType<0x0>;
27def BPF_X : BPFSrcType<0x1>;
28
29class BPFArithOp<bits<4> val> {
30  bits<4> Value = val;
31}
32
33def BPF_ADD  : BPFArithOp<0x0>;
34def BPF_SUB  : BPFArithOp<0x1>;
35def BPF_MUL  : BPFArithOp<0x2>;
36def BPF_DIV  : BPFArithOp<0x3>;
37def BPF_OR   : BPFArithOp<0x4>;
38def BPF_AND  : BPFArithOp<0x5>;
39def BPF_LSH  : BPFArithOp<0x6>;
40def BPF_RSH  : BPFArithOp<0x7>;
41def BPF_NEG  : BPFArithOp<0x8>;
42def BPF_MOD  : BPFArithOp<0x9>;
43def BPF_XOR  : BPFArithOp<0xa>;
44def BPF_MOV  : BPFArithOp<0xb>;
45def BPF_ARSH : BPFArithOp<0xc>;
46def BPF_END  : BPFArithOp<0xd>;
47
48def BPF_XCHG    : BPFArithOp<0xe>;
49def BPF_CMPXCHG : BPFArithOp<0xf>;
50
51class BPFEndDir<bits<1> val> {
52  bits<1> Value = val;
53}
54
55def BPF_TO_LE : BPFSrcType<0x0>;
56def BPF_TO_BE : BPFSrcType<0x1>;
57
58class BPFJumpOp<bits<4> val> {
59  bits<4> Value = val;
60}
61
62def BPF_JA   : BPFJumpOp<0x0>;
63def BPF_JEQ  : BPFJumpOp<0x1>;
64def BPF_JGT  : BPFJumpOp<0x2>;
65def BPF_JGE  : BPFJumpOp<0x3>;
66def BPF_JSET : BPFJumpOp<0x4>;
67def BPF_JNE  : BPFJumpOp<0x5>;
68def BPF_JSGT : BPFJumpOp<0x6>;
69def BPF_JSGE : BPFJumpOp<0x7>;
70def BPF_CALL : BPFJumpOp<0x8>;
71def BPF_EXIT : BPFJumpOp<0x9>;
72def BPF_JLT  : BPFJumpOp<0xa>;
73def BPF_JLE  : BPFJumpOp<0xb>;
74def BPF_JSLT : BPFJumpOp<0xc>;
75def BPF_JSLE : BPFJumpOp<0xd>;
76def BPF_JCOND : BPFJumpOp<0xe>;
77
78class BPFWidthModifer<bits<2> val> {
79  bits<2> Value = val;
80}
81
82def BPF_W  : BPFWidthModifer<0x0>;
83def BPF_H  : BPFWidthModifer<0x1>;
84def BPF_B  : BPFWidthModifer<0x2>;
85def BPF_DW : BPFWidthModifer<0x3>;
86
87class BPFModeModifer<bits<3> val> {
88  bits<3> Value = val;
89}
90
91def BPF_IMM  : BPFModeModifer<0x0>;
92def BPF_ABS  : BPFModeModifer<0x1>;
93def BPF_IND  : BPFModeModifer<0x2>;
94def BPF_MEM  : BPFModeModifer<0x3>;
95def BPF_MEMSX  : BPFModeModifer<0x4>;
96def BPF_ATOMIC : BPFModeModifer<0x6>;
97
98class BPFAtomicFlag<bits<4> val> {
99  bits<4> Value = val;
100}
101
102def BPF_FETCH : BPFAtomicFlag<0x1>;
103
104class InstBPF<dag outs, dag ins, string asmstr, list<dag> pattern>
105  : Instruction {
106  field bits<64> Inst;
107  field bits<64> SoftFail = 0;
108  let Size = 8;
109
110  let Namespace = "BPF";
111  let DecoderNamespace = "BPF";
112
113  BPFOpClass BPFClass;
114  let Inst{58-56} = BPFClass.Value;
115
116  dag OutOperandList = outs;
117  dag InOperandList = ins;
118  let AsmString = asmstr;
119  let Pattern = pattern;
120}
121
122// Pseudo instructions
123class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
124  : InstBPF<outs, ins, asmstr, pattern> {
125  let Inst{63-0} = 0;
126  let isPseudo = 1;
127}
128