[llvm] [X86][GlobalISel] Enable G_BRJT (PR #81811)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 17:57:42 PDT 2024


================
@@ -549,6 +559,64 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
   verify(*STI.getInstrInfo());
 }
 
+bool X86LegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI,
+                                      LostDebugLocObserver &LocObserver) const {
+  switch (MI.getOpcode()) {
+  case G_BRJT:
+    return legalizeBrJT(Helper, MI);
+  default:
+    llvm_unreachable("instruction is not in switch");
+  }
+}
+
+bool X86LegalizerInfo::legalizeBrJT(LegalizerHelper &Helper,
+                                    MachineInstr &MI) const {
+  MachineIRBuilder &MIB = Helper.MIRBuilder;
+  MachineFunction &MF = *MI.getMF();
+  MachineRegisterInfo &MRI = *MIB.getMRI();
+  const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
+
+  unsigned EntrySize = MJTI->getEntrySize(MF.getDataLayout());
+
+  auto PtrReg = MI.getOperand(0).getReg();
+  auto PtrTy = MRI.getType(PtrReg);
+  auto IdxReg = MI.getOperand(2).getReg();
+  auto IdxTy = MRI.getType(IdxReg);
+
+  MachineMemOperand *MMO = MF.getMachineMemOperand(
+      MachinePointerInfo::getJumpTable(MF), MachineMemOperand::MOLoad,
+      PtrTy.getSizeInBytes(), Align(EntrySize));
----------------
e-kud wrote:

```suggestion
      EntrySize, Align(EntrySize));
```

https://github.com/llvm/llvm-project/pull/81811


More information about the llvm-commits mailing list