[llvm] [BPF] Support Jump Table (PR #149715)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 22 17:07:31 PDT 2025
================
@@ -259,3 +264,40 @@ unsigned BPFInstrInfo::removeBranch(MachineBasicBlock &MBB,
return Count;
}
+
+int BPFInstrInfo::getJumpTableIndex(const MachineInstr &MI) const {
+ // The pattern looks like:
+ // %0 = LD_imm64 %jump-table.0 ; load jump-table address
+ // %1 = ADD_rr %0, $another_reg ; address + offset
+ // %2 = LDD %1, 0 ; load the actual label
+ // JX %2
+ const MachineFunction &MF = *MI.getParent()->getParent();
+ const MachineRegisterInfo &MRI = MF.getRegInfo();
+
+ Register Reg = MI.getOperand(0).getReg();
+ if (!Reg.isVirtual())
+ return -1;
+ MachineInstr *Ldd = MRI.getUniqueVRegDef(Reg);
+ if (Ldd == nullptr || Ldd->getOpcode() != BPF::LDD)
----------------
eddyz87 wrote:
I inserted a print here, and `getJumpTableIndex` always returns `-1` for [this](https://gist.github.com/eddyz87/c2f7ff145260d52d5ff7e968e8b06dea) test case.
The reason is that `Ldd` is not `BPF::LDD`: `Ldd=%16:gpr = LDWSX killed %15:gpr, 0 :: (load (s32) from jump-table)` .
Given that this method is optional maybe add a test case that is sensitive to matches here or just drop it?
https://github.com/llvm/llvm-project/pull/149715
More information about the llvm-commits
mailing list