[llvm] [CodeGen][X86] Fix lowering of tailcalls when `-ms-hotpatch` is used (PR #77245)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 10:11:38 PST 2024


================
@@ -948,24 +948,26 @@ void X86AsmPrinter::LowerASAN_CHECK_MEMACCESS(const MachineInstr &MI) {
 
 void X86AsmPrinter::LowerPATCHABLE_OP(const MachineInstr &MI,
                                       X86MCInstLower &MCIL) {
-  // PATCHABLE_OP minsize, opcode, operands
+  // PATCHABLE_OP minsize
 
   NoAutoPaddingScope NoPadScope(*OutStreamer);
 
-  unsigned MinSize = MI.getOperand(0).getImm();
-  unsigned Opcode = MI.getOperand(1).getImm();
-  // Opcode PATCHABLE_OP is a special case: there is no instruction to wrap,
-  // simply emit a nop of size MinSize.
-  bool EmptyInst = (Opcode == TargetOpcode::PATCHABLE_OP);
-
-  MCInst MCI;
-  MCI.setOpcode(Opcode);
-  for (auto &MO : drop_begin(MI.operands(), 2))
-    if (auto MaybeOperand = MCIL.LowerMachineOperand(&MI, MO))
-      MCI.addOperand(*MaybeOperand);
+  // Find the next MachineInstr in this MBB.
+  const MachineInstr *NextMI = MI.getNextNode();
+  while (NextMI) {
+    if (!NextMI->isMetaInstruction())
+      break;
+    NextMI = NextMI->getNextNode();
+  }
 
   SmallString<256> Code;
-  if (!EmptyInst) {
+  unsigned MinSize = MI.getOperand(0).getImm();
+
+  if (NextMI) {
+    // Lower the next MachineInstr to find its byte size.
----------------
sylvain-audi wrote:

To my mind you can keep the reference to #59039 , since your refactor makes this system quite more robust.

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


More information about the llvm-commits mailing list