From 51189f0a1d0b8b6d1490a4e42df4971916fb9235 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 8 Sep 2015 23:28:38 +0000 Subject: [WinEH] Avoid creating MBBs for LLVM BBs that cannot contain code Typically these are catchpads, which hold data used to decide whether to catch the exception or continue unwinding. We also shouldn't create MBBs for catchendpads, cleanupendpads, or terminatepads, since no real code can live in them. This fixes a problem where MI passes (like the register allocator) would try to put code into catchpad blocks, which are not executed by the runtime. In the new world, blocks ending in invokes now have many possible successors. llvm-svn: 247102 --- .../CodeGen/SelectionDAG/FunctionLoweringInfo.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp') diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index 3a51676bc9a..7bbb194ac19 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -212,6 +212,22 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, // also creates the initial PHI MachineInstrs, though none of the input // operands are populated. for (BB = Fn->begin(); BB != EB; ++BB) { + // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks + // are really data, and no instructions can live here. + if (BB->isEHPad()) { + const Instruction *I = BB->getFirstNonPHI(); + if (!isa(I)) + MMI.setHasEHFunclets(true); + if (isa(I) || isa(I) || + isa(I)) { + assert(&*BB->begin() == I && + "WinEHPrepare failed to remove PHIs from imaginary BBs"); + continue; + } else if (!isa(I)) { + llvm_unreachable("unhandled EH pad in MBB graph"); + } + } + MachineBasicBlock *MBB = mf.CreateMachineBasicBlock(BB); MBBMap[BB] = MBB; MF->push_back(MBB); @@ -252,9 +268,9 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, // Mark landing pad blocks. SmallVector LPads; for (BB = Fn->begin(); BB != EB; ++BB) { - if (BB->isEHPad()) - MBBMap[BB]->setIsEHPad(); const Instruction *FNP = BB->getFirstNonPHI(); + if (BB->isEHPad() && !isa(FNP) && !isa(FNP)) + MBBMap[BB]->setIsEHPad(); if (const auto *LPI = dyn_cast(FNP)) LPads.push_back(LPI); } -- cgit v1.2.3