[llvm] r249910 - [WinEH] Insert the catchpad return before CSR restoration
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 15:18:46 PDT 2015
Author: majnemer
Date: Fri Oct 9 17:18:45 2015
New Revision: 249910
URL: http://llvm.org/viewvc/llvm-project?rev=249910&view=rev
Log:
[WinEH] Insert the catchpad return before CSR restoration
x64 catchpads use rax to inform the unwinder where control should go
next. However, we must initialize rax before the epilogue sequence so
as to not perturb the unwinder.
Modified:
llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll
Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=249910&r1=249909&r2=249910&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Fri Oct 9 17:18:45 2015
@@ -1058,6 +1058,7 @@ void X86FrameLowering::emitEpilogue(Mach
bool NeedsWinCFI =
IsWin64Prologue && MF.getFunction()->needsUnwindTableEntry();
bool IsFunclet = isFuncletReturnInstr(MBBI);
+ MachineBasicBlock *RestoreMBB = nullptr;
// Get the number of bytes to allocate from the FrameInfo.
uint64_t StackSize = MFI->getStackSize();
@@ -1082,7 +1083,7 @@ void X86FrameLowering::emitEpilogue(Mach
}
// For 32-bit, create a new block for the restore code.
- MachineBasicBlock *RestoreMBB = TargetMBB;
+ RestoreMBB = TargetMBB;
if (STI.is32Bit()) {
RestoreMBB = MF.CreateMachineBasicBlock(MBB.getBasicBlock());
MF.insert(TargetMBB, RestoreMBB);
@@ -1092,23 +1093,6 @@ void X86FrameLowering::emitEpilogue(Mach
MBBI->getOperand(0).setMBB(RestoreMBB);
}
- // Fill EAX/RAX with the address of the target block.
- unsigned ReturnReg = STI.is64Bit() ? X86::RAX : X86::EAX;
- if (STI.is64Bit()) {
- // LEA64r RestoreMBB(%rip), %rax
- BuildMI(MBB, MBBI, DL, TII.get(X86::LEA64r), ReturnReg)
- .addReg(X86::RIP)
- .addImm(0)
- .addReg(0)
- .addMBB(RestoreMBB)
- .addReg(0);
- } else {
- // MOV32ri $RestoreMBB, %eax
- BuildMI(MBB, MBBI, DL, TII.get(X86::MOV32ri))
- .addReg(ReturnReg)
- .addMBB(RestoreMBB);
- }
-
// Pop EBP.
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
MachineFramePtr)
@@ -1161,6 +1145,25 @@ void X86FrameLowering::emitEpilogue(Mach
}
MachineBasicBlock::iterator FirstCSPop = MBBI;
+ if (RestoreMBB) {
+ // Fill EAX/RAX with the address of the target block.
+ unsigned ReturnReg = STI.is64Bit() ? X86::RAX : X86::EAX;
+ if (STI.is64Bit()) {
+ // LEA64r RestoreMBB(%rip), %rax
+ BuildMI(MBB, FirstCSPop, DL, TII.get(X86::LEA64r), ReturnReg)
+ .addReg(X86::RIP)
+ .addImm(0)
+ .addReg(0)
+ .addMBB(RestoreMBB)
+ .addReg(0);
+ } else {
+ // MOV32ri $RestoreMBB, %eax
+ BuildMI(MBB, FirstCSPop, DL, TII.get(X86::MOV32ri))
+ .addReg(ReturnReg)
+ .addMBB(RestoreMBB);
+ }
+ }
+
if (MBBI != MBB.end())
DL = MBBI->getDebugLoc();
Modified: llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll?rev=249910&r1=249909&r2=249910&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll Fri Oct 9 17:18:45 2015
@@ -123,6 +123,8 @@ catchendblock:
; X64: movq %rdx, 16(%rsp)
; X64: pushq %rbp
; X64: .seh_pushreg 5
+; X64: pushq %rsi
+; X64: .seh_pushreg 6
; X64: subq $32, %rsp
; X64: .seh_stackalloc 32
; X64: leaq 32(%rdx), %rbp
@@ -131,6 +133,7 @@ catchendblock:
; X64: callq f
; X64: leaq [[contbb]](%rip), %rax
; X64: addq $32, %rsp
+; X64: popq %rsi
; X64: popq %rbp
; X64: retq
More information about the llvm-commits
mailing list