diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-10-13 08:24:19 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-10-13 08:24:19 +0000 |
commit | 4e68054b20725f6ec1cac33630258f749fe5debe (patch) | |
tree | 567971bd64446d5d55dfa774d96ce8f9c87601b6 /lib | |
parent | 1203fe7fc80d0fe16a30ae3ddb9b0823b17f39ce (diff) |
More closely follow libgcc, which has code after the `ret' instruction to
release the stack segment and reset the stack pointer. Place the code in its own
MBB to make the verifier happy.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141859 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/X86/X86FrameLowering.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index 757cef2d7f..07e0d0ed26 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -1336,15 +1336,28 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const { if (Is64Bit) IsNested = HasNestArgument(&MF); + // The MOV R10, RAX needs to be in a different block, since the RET we emit in + // allocMBB needs to be last (terminating) instruction. + MachineBasicBlock *restoreR10MBB = NULL; + if (IsNested) + restoreR10MBB = MF.CreateMachineBasicBlock(); + for (MachineBasicBlock::livein_iterator i = prologueMBB.livein_begin(), e = prologueMBB.livein_end(); i != e; i++) { allocMBB->addLiveIn(*i); checkMBB->addLiveIn(*i); + + if (IsNested) + restoreR10MBB->addLiveIn(*i); } - if (IsNested) + if (IsNested) { allocMBB->addLiveIn(X86::R10); + restoreR10MBB->addLiveIn(X86::RAX); + } + if (IsNested) + MF.push_front(restoreR10MBB); MF.push_front(allocMBB); MF.push_front(checkMBB); @@ -1414,13 +1427,19 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const { if (!Is64Bit) BuildMI(allocMBB, DL, TII.get(X86::ADD32ri), X86::ESP).addReg(X86::ESP) .addImm(8); + BuildMI(allocMBB, DL, TII.get(X86::RET)); - if (Is64Bit && IsNested) - BuildMI(allocMBB, DL, TII.get(X86::MOV64rr), X86::R10).addReg(X86::RAX); + if (IsNested) + BuildMI(restoreR10MBB, DL, TII.get(X86::MOV64rr), X86::R10) + .addReg(X86::RAX); - BuildMI(allocMBB, DL, TII.get(X86::RET)); + if (IsNested) { + allocMBB->addSuccessor(restoreR10MBB); + restoreR10MBB->addSuccessor(&prologueMBB); + } else { + allocMBB->addSuccessor(&prologueMBB); + } - allocMBB->addSuccessor(&prologueMBB); checkMBB->addSuccessor(allocMBB); checkMBB->addSuccessor(&prologueMBB); |