[llvm] [BPF] Add asm support for JSET insn (PR #73161)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 12:44:37 PST 2023
eddyz87 wrote:
Looks good as is, but I have a suggestion to minimize code duplication, seems to pass all tests.
Feel free to ignore if you think it's too hacky.
```diff
diff --git a/llvm/lib/Target/BPF/BPFInstrInfo.td b/llvm/lib/Target/BPF/BPFInstrInfo.td
index 9e75f35efe70..7a440cf94f5d 100644
--- a/llvm/lib/Target/BPF/BPFInstrInfo.td
+++ b/llvm/lib/Target/BPF/BPFInstrInfo.td
@@ -181,13 +181,18 @@ class TYPE_LD_ST<bits<3> mode, bits<2> size,
let Inst{60-59} = size;
}
+class NoCond : PatLeaf<(vt)> {}
+
// jump instructions
class JMP_RR<BPFJumpOp Opc, string OpcodeStr, PatLeaf Cond>
: TYPE_ALU_JMP<Opc.Value, BPF_X.Value,
(outs),
(ins GPR:$dst, GPR:$src, brtarget:$BrDst),
"if $dst "#OpcodeStr#" $src goto $BrDst",
- [(BPFbrcc i64:$dst, i64:$src, Cond, bb:$BrDst)]> {
+ !if(!isa<NoCond>(Cond),
+ [],
+ [(BPFbrcc i64:$dst, i64:$src, Cond, bb:$BrDst)])>
+{
bits<4> dst;
bits<4> src;
bits<16> BrDst;
@@ -246,70 +251,6 @@ class JMP_RI_32<BPFJumpOp Opc, string OpcodeStr, PatLeaf Cond>
let BPFClass = BPF_JMP32;
}
-class JSET_RR<string OpcodeStr>
- : TYPE_ALU_JMP<BPF_JSET.Value, BPF_X.Value,
- (outs),
- (ins GPR:$dst, GPR:$src, brtarget:$BrDst),
- "if $dst "#OpcodeStr#" $src goto $BrDst",
- []> {
- bits<4> dst;
- bits<4> src;
- bits<16> BrDst;
-
- let Inst{55-52} = src;
- let Inst{51-48} = dst;
- let Inst{47-32} = BrDst;
- let BPFClass = BPF_JMP;
-}
-
-class JSET_RI<string OpcodeStr>
- : TYPE_ALU_JMP<BPF_JSET.Value, BPF_K.Value,
- (outs),
- (ins GPR:$dst, i64imm:$imm, brtarget:$BrDst),
- "if $dst "#OpcodeStr#" $imm goto $BrDst",
- []> {
- bits<4> dst;
- bits<16> BrDst;
- bits<32> imm;
-
- let Inst{51-48} = dst;
- let Inst{47-32} = BrDst;
- let Inst{31-0} = imm;
- let BPFClass = BPF_JMP;
-}
-
-class JSET_RR_32<string OpcodeStr>
- : TYPE_ALU_JMP<BPF_JSET.Value, BPF_X.Value,
- (outs),
- (ins GPR32:$dst, GPR32:$src, brtarget:$BrDst),
- "if $dst "#OpcodeStr#" $src goto $BrDst",
- []> {
- bits<4> dst;
- bits<4> src;
- bits<16> BrDst;
-
- let Inst{55-52} = src;
- let Inst{51-48} = dst;
- let Inst{47-32} = BrDst;
- let BPFClass = BPF_JMP32;
-}
-
-class JSET_RI_32<string OpcodeStr>
- : TYPE_ALU_JMP<BPF_JSET.Value, BPF_K.Value,
- (outs),
- (ins GPR32:$dst, i32imm:$imm, brtarget:$BrDst),
- "if $dst "#OpcodeStr#" $imm goto $BrDst",
- []> {
- bits<4> dst;
- bits<16> BrDst;
- bits<32> imm;
-
- let Inst{51-48} = dst;
- let Inst{47-32} = BrDst;
- let Inst{31-0} = imm;
- let BPFClass = BPF_JMP32;
-}
-
multiclass J<BPFJumpOp Opc, string OpcodeStr, PatLeaf Cond, PatLeaf Cond32> {
def _rr : JMP_RR<Opc, OpcodeStr, Cond>;
def _ri : JMP_RI<Opc, OpcodeStr, Cond>;
@@ -329,10 +270,7 @@ defm JULT : J<BPF_JLT, "<", BPF_CC_LTU, BPF_CC_LTU_32>;
defm JULE : J<BPF_JLE, "<=", BPF_CC_LEU, BPF_CC_LEU_32>;
defm JSLT : J<BPF_JSLT, "s<", BPF_CC_LT, BPF_CC_LT_32>;
defm JSLE : J<BPF_JSLE, "s<=", BPF_CC_LE, BPF_CC_LE_32>;
-def JSET_RR : JSET_RR<"&">;
-def JSET_RI : JSET_RI<"&">;
-def JSET_RR_32 : JSET_RR_32<"&">;
-def JSET_RI_32 : JSET_RI_32<"&">;
+defm JSET : J<BPF_JSET, "&", NoCond<>, NoCond<>>;
}
// ALU instructions
```
https://github.com/llvm/llvm-project/pull/73161
More information about the llvm-commits
mailing list