Skip to content

Commit e247e6f

Browse files
[BPF] Add asm support for JSET insn (#73161)
BPF upstream reported that JSET insn is not supported in inline asm ([1]). BPF_JSET insn is part of BPF ISA so let us add asm support for it now. [1] https://lore.kernel.org/bpf/[email protected]/
1 parent 5d59e97 commit e247e6f

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

llvm/lib/Target/BPF/BPFInstrFormats.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def BPF_JA : BPFJumpOp<0x0>;
6363
def BPF_JEQ : BPFJumpOp<0x1>;
6464
def BPF_JGT : BPFJumpOp<0x2>;
6565
def BPF_JGE : BPFJumpOp<0x3>;
66+
def BPF_JSET : BPFJumpOp<0x4>;
6667
def BPF_JNE : BPFJumpOp<0x5>;
6768
def BPF_JSGT : BPFJumpOp<0x6>;
6869
def BPF_JSGE : BPFJumpOp<0x7>;

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def BPF_CC_LTU_32 : PatLeaf<(i32 imm),
149149
[{return (N->getZExtValue() == ISD::SETULT);}]>;
150150
def BPF_CC_LEU_32 : PatLeaf<(i32 imm),
151151
[{return (N->getZExtValue() == ISD::SETULE);}]>;
152+
def NoCond : PatLeaf<(vt)> {}
152153

153154
// For arithmetic and jump instructions the 8-bit 'code'
154155
// field is divided into three parts:
@@ -265,6 +266,7 @@ defm JULT : J<BPF_JLT, "<", BPF_CC_LTU, BPF_CC_LTU_32>;
265266
defm JULE : J<BPF_JLE, "<=", BPF_CC_LEU, BPF_CC_LEU_32>;
266267
defm JSLT : J<BPF_JSLT, "s<", BPF_CC_LT, BPF_CC_LT_32>;
267268
defm JSLE : J<BPF_JSLE, "s<=", BPF_CC_LE, BPF_CC_LE_32>;
269+
defm JSET : J<BPF_JSET, "&", NoCond, NoCond>;
268270
}
269271

270272
// ALU instructions

llvm/test/MC/BPF/insn-unit-32.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
// CHECK: b4 09 00 00 ff ff ff ff w9 = -1
5656
// CHECK: c4 0a 00 00 40 00 00 00 w10 s>>= 64
5757

58+
if w1 & w2 goto Llabel0 // BPF_JSET | BPF_X
59+
if w1 & 0xff goto Llabel0 // BPF_JSET | BPF_K
60+
// CHECK: 4e 21 0d 00 00 00 00 00 if w1 & w2 goto +13
61+
// CHECK: 46 01 0c 00 ff 00 00 00 if w1 & 255 goto +12
62+
5863
if w0 == w1 goto Llabel0 // BPF_JEQ | BPF_X
5964
if w3 != w4 goto Llabel0 // BPF_JNE | BPF_X
6065
// CHECK: 1e 10 0b 00 00 00 00 00 if w0 == w1 goto +11

llvm/test/MC/BPF/insn-unit.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
// CHECK: db a3 e2 ff 00 00 00 00 lock *(u64 *)(r3 - 30) += r10
6363

6464
// ======== BPF_JMP Class ========
65+
if r1 & r2 goto Llabel0 // BPF_JSET | BPF_X
66+
if r1 & 0xffff goto Llabel0 // BPF_JSET | BPF_K
67+
// CHECK: 4d 21 1d 00 00 00 00 00 if r1 & r2 goto +29
68+
// CHECK: 45 01 1c 00 ff ff 00 00 if r1 & 65535 goto +28
69+
6570
goto Llabel0 // BPF_JA
6671
call 1 // BPF_CALL
6772
exit // BPF_EXIT

0 commit comments

Comments
 (0)