1 //===-- BPFInstrFormats.td - BPF Instruction Formats -------*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
9 class BPFOpClass<bits<3> val> {
13 def BPF_LD : BPFOpClass<0x0>;
14 def BPF_LDX : BPFOpClass<0x1>;
15 def BPF_ST : BPFOpClass<0x2>;
16 def BPF_STX : BPFOpClass<0x3>;
17 def BPF_ALU : BPFOpClass<0x4>;
18 def BPF_JMP : BPFOpClass<0x5>;
19 def BPF_JMP32 : BPFOpClass<0x6>;
20 def BPF_ALU64 : BPFOpClass<0x7>;
22 class BPFSrcType<bits<1> val> {
26 def BPF_K : BPFSrcType<0x0>;
27 def BPF_X : BPFSrcType<0x1>;
29 class BPFArithOp<bits<4> val> {
33 def BPF_ADD : BPFArithOp<0x0>;
34 def BPF_SUB : BPFArithOp<0x1>;
35 def BPF_MUL : BPFArithOp<0x2>;
36 def BPF_DIV : BPFArithOp<0x3>;
37 def BPF_OR : BPFArithOp<0x4>;
38 def BPF_AND : BPFArithOp<0x5>;
39 def BPF_LSH : BPFArithOp<0x6>;
40 def BPF_RSH : BPFArithOp<0x7>;
41 def BPF_NEG : BPFArithOp<0x8>;
42 def BPF_MOD : BPFArithOp<0x9>;
43 def BPF_XOR : BPFArithOp<0xa>;
44 def BPF_MOV : BPFArithOp<0xb>;
45 def BPF_ARSH : BPFArithOp<0xc>;
46 def BPF_END : BPFArithOp<0xd>;
48 def BPF_XCHG : BPFArithOp<0xe>;
49 def BPF_CMPXCHG : BPFArithOp<0xf>;
51 class BPFEndDir<bits<1> val> {
55 def BPF_TO_LE : BPFSrcType<0x0>;
56 def BPF_TO_BE : BPFSrcType<0x1>;
58 class BPFJumpOp<bits<4> val> {
62 def BPF_JA : BPFJumpOp<0x0>;
63 def BPF_JEQ : BPFJumpOp<0x1>;
64 def BPF_JGT : BPFJumpOp<0x2>;
65 def BPF_JGE : BPFJumpOp<0x3>;
66 def BPF_JSET : BPFJumpOp<0x4>;
67 def BPF_JNE : BPFJumpOp<0x5>;
68 def BPF_JSGT : BPFJumpOp<0x6>;
69 def BPF_JSGE : BPFJumpOp<0x7>;
70 def BPF_CALL : BPFJumpOp<0x8>;
71 def BPF_EXIT : BPFJumpOp<0x9>;
72 def BPF_JLT : BPFJumpOp<0xa>;
73 def BPF_JLE : BPFJumpOp<0xb>;
74 def BPF_JSLT : BPFJumpOp<0xc>;
75 def BPF_JSLE : BPFJumpOp<0xd>;
76 def BPF_JCOND : BPFJumpOp<0xe>;
78 class BPFWidthModifer<bits<2> val> {
82 def BPF_W : BPFWidthModifer<0x0>;
83 def BPF_H : BPFWidthModifer<0x1>;
84 def BPF_B : BPFWidthModifer<0x2>;
85 def BPF_DW : BPFWidthModifer<0x3>;
87 class BPFModeModifer<bits<3> val> {
91 def BPF_IMM : BPFModeModifer<0x0>;
92 def BPF_ABS : BPFModeModifer<0x1>;
93 def BPF_IND : BPFModeModifer<0x2>;
94 def BPF_MEM : BPFModeModifer<0x3>;
95 def BPF_MEMSX : BPFModeModifer<0x4>;
96 def BPF_ATOMIC : BPFModeModifer<0x6>;
98 class BPFAtomicFlag<bits<4> val> {
102 def BPF_FETCH : BPFAtomicFlag<0x1>;
104 class InstBPF<dag outs, dag ins, string asmstr, list<dag> pattern>
107 field bits<64> SoftFail = 0;
110 let Namespace = "BPF";
111 let DecoderNamespace = "BPF";
114 let Inst{58-56} = BPFClass.Value;
116 dag OutOperandList = outs;
117 dag InOperandList = ins;
118 let AsmString = asmstr;
119 let Pattern = pattern;
122 // Pseudo instructions
123 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
124 : InstBPF<outs, ins, asmstr, pattern> {