summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2015-04-17 01:01:27 +0000
committerReid Kleckner <reid@kleckner.net>2015-04-17 01:01:27 +0000
commitd4523e3c5189dfefe4d59a1d226eefa624edeae1 (patch)
treed8cf75f6bde24a7014ec5264aa8769bbfffc0999 /llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
parentde50d36ab39b9d591bae6562f76a6e0c3169e84b (diff)
downloadbcm5719-llvm-d4523e3c5189dfefe4d59a1d226eefa624edeae1.tar.gz
bcm5719-llvm-d4523e3c5189dfefe4d59a1d226eefa624edeae1.zip
[SEH] Reimplement x64 SEH using WinEHPrepare
This now emits simple, unoptimized xdata tables for __C_specific_handler based on the handlers listed in @llvm.eh.actions calls produced by WinEHPrepare. This adds support for running __finally blocks when exceptions are thrown, and removes the old landingpad fan-in codepath. I ran some manual execution tests on small basic test cases with and without optimization, as well as on Chrome base_unittests, which uses a small amount of SEH. I'm sure there are bugs, and we may need to revert. llvm-svn: 235154
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp56
1 files changed, 53 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
index 4b8ae32e9a5..bb40326ba2d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
@@ -270,12 +270,21 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
}
// Mark landing pad blocks.
- for (BB = Fn->begin(); BB != EB; ++BB)
+ const LandingPadInst *LP = nullptr;
+ for (BB = Fn->begin(); BB != EB; ++BB) {
if (const auto *Invoke = dyn_cast<InvokeInst>(BB->getTerminator()))
MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad();
+ if (BB->isLandingPad())
+ LP = BB->getLandingPadInst();
+ }
- // Calculate EH numbers for WinEH.
- if (fn.hasFnAttribute("wineh-parent")) {
+ // Calculate EH numbers for MSVC C++ EH and save SEH handlers if necessary.
+ EHPersonality Personality = EHPersonality::Unknown;
+ if (LP)
+ Personality = classifyEHPersonality(LP->getPersonalityFn());
+ if (Personality == EHPersonality::MSVC_Win64SEH) {
+ addSEHHandlersForLPads();
+ } else if (Personality == EHPersonality::MSVC_CXX) {
const Function *WinEHParentFn = MMI.getWinEHParent(&fn);
WinEHFuncInfo &FI = MMI.getWinEHFuncInfo(WinEHParentFn);
if (FI.LandingPadStateMap.empty()) {
@@ -287,6 +296,47 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
}
}
+void FunctionLoweringInfo::addSEHHandlersForLPads() {
+ MachineModuleInfo &MMI = MF->getMMI();
+
+ // Iterate over all landing pads with llvm.eh.actions calls.
+ for (const BasicBlock &BB : *Fn) {
+ const LandingPadInst *LP = BB.getLandingPadInst();
+ if (!LP)
+ continue;
+ const IntrinsicInst *ActionsCall =
+ dyn_cast<IntrinsicInst>(LP->getNextNode());
+ if (!ActionsCall ||
+ ActionsCall->getIntrinsicID() != Intrinsic::eh_actions)
+ continue;
+
+ // Parse the llvm.eh.actions call we found.
+ MachineBasicBlock *LPadMBB = MBBMap[LP->getParent()];
+ SmallVector<ActionHandler *, 4> Actions;
+ parseEHActions(ActionsCall, Actions);
+
+ // Iterate EH actions from most to least precedence, which means
+ // iterating in reverse.
+ for (auto I = Actions.rbegin(), E = Actions.rend(); I != E; ++I) {
+ ActionHandler *Action = *I;
+ if (auto *CH = dyn_cast<CatchHandler>(Action)) {
+ const auto *Filter =
+ dyn_cast<Function>(CH->getSelector()->stripPointerCasts());
+ assert((Filter || CH->getSelector()->isNullValue()) &&
+ "expected function or catch-all");
+ const auto *RecoverBA =
+ cast<BlockAddress>(CH->getHandlerBlockOrFunc());
+ MMI.addSEHCatchHandler(LPadMBB, Filter, RecoverBA);
+ } else {
+ assert(isa<CleanupHandler>(Action));
+ const auto *Fini = cast<Function>(Action->getHandlerBlockOrFunc());
+ MMI.addSEHCleanupHandler(LPadMBB, Fini);
+ }
+ }
+ DeleteContainerPointers(Actions);
+ }
+}
+
void WinEHNumbering::createUnwindMapEntry(int ToState, ActionHandler *AH) {
WinEHUnwindMapEntry UME;
UME.ToState = ToState;
OpenPOWER on IntegriCloud