Index: include/llvm/CodeGen/MachineFunction.h =================================================================== --- include/llvm/CodeGen/MachineFunction.h +++ include/llvm/CodeGen/MachineFunction.h @@ -822,7 +822,9 @@ void addInvoke(MachineBasicBlock *LandingPad, MCSymbol *BeginLabel, MCSymbol *EndLabel); - /// Add a new panding pad. Returns the label ID for the landing pad entry. + /// Add a new panding pad, and extract the exception handling information from + /// the landingpad instruction. Returns the label ID for the landing pad + /// entry. MCSymbol *addLandingPad(MachineBasicBlock *LandingPad); /// Provide the catch typeinfo for a landing pad. @@ -914,15 +916,6 @@ } }; -/// \name Exception Handling -/// \{ - -/// Extract the exception handling information from the landingpad instruction -/// and add them to the specified machine module info. -void addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB); - -/// \} - //===--------------------------------------------------------------------===// // GraphTraits specializations for function basic block graphs (CFGs) //===--------------------------------------------------------------------===// Index: lib/CodeGen/GlobalISel/IRTranslator.cpp =================================================================== --- lib/CodeGen/GlobalISel/IRTranslator.cpp +++ lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -1145,7 +1145,6 @@ const LandingPadInst &LP = cast(U); MachineBasicBlock &MBB = MIRBuilder.getMBB(); - addLandingPadInfo(LP, MBB); MBB.setIsEHPad(); Index: lib/CodeGen/MachineFunction.cpp =================================================================== --- lib/CodeGen/MachineFunction.cpp +++ lib/CodeGen/MachineFunction.cpp @@ -626,6 +626,44 @@ MCSymbol *LandingPadLabel = Ctx.createTempSymbol(); LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); LP.LandingPadLabel = LandingPadLabel; + + const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI(); + if (const auto *LPI = dyn_cast(FirstI)) { + if (const auto *PF = + dyn_cast(F.getPersonalityFn()->stripPointerCasts())) + getMMI().addPersonality(PF); + + if (LPI->isCleanup()) + addCleanup(LandingPad); + + // FIXME: New EH - Add the clauses in reverse order. This isn't 100% + // correct, + // but we need to do it this way because of how the DWARF EH emitter + // processes the clauses. + for (unsigned I = LPI->getNumClauses(); I != 0; --I) { + Value *Val = LPI->getClause(I - 1); + if (LPI->isCatch(I - 1)) { + addCatchTypeInfo(LandingPad, + dyn_cast(Val->stripPointerCasts())); + } else { + // Add filters in a list. + auto *CVal = cast(Val); + SmallVector FilterList; + for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end(); + II != IE; ++II) + FilterList.push_back(cast((*II)->stripPointerCasts())); + + addFilterTypeInfo(LandingPad, FilterList); + } + } + + } else if (const auto *CPI = dyn_cast(FirstI)) { + // TODO + + } else { + assert(isa(FirstI) && "Invalid landingpad!"); + } + return LandingPadLabel; } @@ -754,36 +792,6 @@ return FilterID; } -void llvm::addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB) { - MachineFunction &MF = *MBB.getParent(); - if (const auto *PF = dyn_cast( - I.getParent()->getParent()->getPersonalityFn()->stripPointerCasts())) - MF.getMMI().addPersonality(PF); - - if (I.isCleanup()) - MF.addCleanup(&MBB); - - // FIXME: New EH - Add the clauses in reverse order. This isn't 100% correct, - // but we need to do it this way because of how the DWARF EH emitter - // processes the clauses. - for (unsigned i = I.getNumClauses(); i != 0; --i) { - Value *Val = I.getClause(i - 1); - if (I.isCatch(i - 1)) { - MF.addCatchTypeInfo(&MBB, - dyn_cast(Val->stripPointerCasts())); - } else { - // Add filters in a list. - Constant *CVal = cast(Val); - SmallVector FilterList; - for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end(); - II != IE; ++II) - FilterList.push_back(cast((*II)->stripPointerCasts())); - - MF.addFilterTypeInfo(&MBB, FilterList); - } - } -} - /// \} //===----------------------------------------------------------------------===// Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2530,9 +2530,6 @@ assert(FuncInfo.MBB->isEHPad() && "Call to landingpad not in landing pad!"); - MachineBasicBlock *MBB = FuncInfo.MBB; - addLandingPadInfo(LP, *MBB); - // If there aren't registers to copy the values into (e.g., during SjLj // exceptions), then don't bother to create these DAG nodes. const TargetLowering &TLI = DAG.getTargetLoweringInfo();