[llvm] [CodeGen][X86] Fix lowering of tailcalls when `-ms-hotpatch` is used (PR #77245)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 10:04:37 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.
----------------
aganea wrote:
I fear that would require a massive refactoring. `X86AsmPrinter::emitInstruction` is manipulating state (like `OutStreamer` or the counting) that we would need to reset if the instruction isn't large enough (for patchable op).
I used `X86MCInstLower::Lower` which should bring us closer to what you suggested. I can remove the reference to https://github.com/llvm/llvm-project/issues/59039 is you think more is needed in the future.
https://github.com/llvm/llvm-project/pull/77245
More information about the llvm-commits
mailing list