diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2015-09-16 20:42:16 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2015-09-16 20:42:16 +0000 |
| commit | 67bff0d88b0e5a1d20bc7c2545fb2e005ce3ce82 (patch) | |
| tree | 7c5f7b235e057abe14b4bf09d541dbd08b230334 /llvm/lib | |
| parent | ff6a2a6f5081b8b6577ae65731838bd8e54b96c3 (diff) | |
| download | bcm5719-llvm-67bff0d88b0e5a1d20bc7c2545fb2e005ce3ce82.tar.gz bcm5719-llvm-67bff0d88b0e5a1d20bc7c2545fb2e005ce3ce82.zip | |
[WinEHPrepare] Turn terminatepad into a cleanuppad + call + cleanupret
The MSVC doesn't really support exception specifications so let's just
turn these into cleanuppads. Later, we might use terminatepad to more
efficiently encode the "noexcept"-ness of a function body.
llvm-svn: 247848
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/WinEHPrepare.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp index fefb444cea9..3eed086a40d 100644 --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -144,6 +144,7 @@ private: Function &F); bool prepareExplicitEH(Function &F, SmallVectorImpl<BasicBlock *> &EntryBlocks); + void replaceTerminatePadWithCleanup(Function &F); void colorFunclets(Function &F, SmallVectorImpl<BasicBlock *> &EntryBlocks); void demotePHIsOnFunclets(Function &F); void demoteUsesBetweenFunclets(Function &F); @@ -3206,6 +3207,44 @@ void llvm::calculateWinCXXEHStateNumbers(const Function *ParentFn, Num.processCallSite(None, ImmutableCallSite()); } +void WinEHPrepare::replaceTerminatePadWithCleanup(Function &F) { + if (Personality != EHPersonality::MSVC_CXX) + return; + for (BasicBlock &BB : F) { + Instruction *First = BB.getFirstNonPHI(); + auto *TPI = dyn_cast<TerminatePadInst>(First); + if (!TPI) + continue; + + if (TPI->getNumArgOperands() != 1) + report_fatal_error( + "Expected a unary terminatepad for MSVC C++ personalities!"); + + auto *TerminateFn = dyn_cast<Function>(TPI->getArgOperand(0)); + if (!TerminateFn) + report_fatal_error("Function operand expected in terminatepad for MSVC " + "C++ personalities!"); + + // Insert the cleanuppad instruction. + auto *CPI = CleanupPadInst::Create( + BB.getContext(), {}, Twine("terminatepad.for.", BB.getName()), &BB); + + // Insert the call to the terminate instruction. + auto *CallTerminate = CallInst::Create(TerminateFn, {}, &BB); + CallTerminate->setDoesNotThrow(); + CallTerminate->setDoesNotReturn(); + CallTerminate->setCallingConv(TerminateFn->getCallingConv()); + + // Insert a new terminator for the cleanuppad using the same successor as + // the terminatepad. + CleanupReturnInst::Create(CPI, TPI->getUnwindDest(), &BB); + + // Let's remove the terminatepad now that we've inserted the new + // instructions. + TPI->eraseFromParent(); + } +} + void WinEHPrepare::colorFunclets(Function &F, SmallVectorImpl<BasicBlock *> &EntryBlocks) { SmallVector<std::pair<BasicBlock *, BasicBlock *>, 16> Worklist; @@ -3560,6 +3599,8 @@ bool WinEHPrepare::prepareExplicitEH( // not. removeUnreachableBlocks(F); + replaceTerminatePadWithCleanup(F); + // Determine which blocks are reachable from which funclet entries. colorFunclets(F, EntryBlocks); |

