From 1e4d35044f7c5346cb3a860361c09a93d4def86c Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 23 May 2018 00:32:46 +0000 Subject: [WebAssembly] Add functions for EHScopes Summary: There are functions using the term 'funclet' to refer to both 1. an EH scopes, the structure of BBs that starts with catchpad/cleanuppad and ends with catchret/cleanupret, and 2. a small function that gets outlined in AsmPrinter, which is the original meaning of 'funclet'. So far the two have been the same thing; EH scopes are always outlined in AsmPrinter as funclets at the end of the compilation pipeline. But now wasm also uses scope-based EH but does not outline those, so we now need to correctly distinguish those two use cases in functions. This patch splits `MachineBasicBlock::isFuncletEntry` into `isFuncletEntry` and `isEHScopeEntry`, and `MachineFunction::hasFunclets` into `hasFunclets` and `hasEHScopes`, in order to distinguish the two different use cases. And this also changes some uses of the term 'funclet' to 'scope' in `getFuncletMembership` and change the function name to `getEHScopeMembership` because this function is not about outlined funclets but about EH scope memberships. This change is in the same vein as D45559. Reviewers: majnemer, dschuff Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D47005 llvm-svn: 333045 --- llvm/lib/CodeGen/Analysis.cpp | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'llvm/lib/CodeGen/Analysis.cpp') diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index 0731ae57543..e7e4bc666d7 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -629,26 +629,26 @@ bool llvm::returnTypeIsEligibleForTailCall(const Function *F, return true; } -static void collectFuncletMembers( - DenseMap &FuncletMembership, int Funclet, - const MachineBasicBlock *MBB) { +static void +collectEHScopeMembers(DenseMap &ScopeMembership, + int Scope, const MachineBasicBlock *MBB) { SmallVector Worklist = {MBB}; while (!Worklist.empty()) { const MachineBasicBlock *Visiting = Worklist.pop_back_val(); - // Don't follow blocks which start new funclets. + // Don't follow blocks which start new scopes. if (Visiting->isEHPad() && Visiting != MBB) continue; - // Add this MBB to our funclet. - auto P = FuncletMembership.insert(std::make_pair(Visiting, Funclet)); + // Add this MBB to our scope. + auto P = ScopeMembership.insert(std::make_pair(Visiting, Scope)); // Don't revisit blocks. if (!P.second) { - assert(P.first->second == Funclet && "MBB is part of two funclets!"); + assert(P.first->second == Scope && "MBB is part of two scopes!"); continue; } - // Returns are boundaries where funclet transfer can occur, don't follow + // Returns are boundaries where scope transfer can occur, don't follow // successors. if (Visiting->isReturnBlock()) continue; @@ -659,25 +659,25 @@ static void collectFuncletMembers( } DenseMap -llvm::getFuncletMembership(const MachineFunction &MF) { - DenseMap FuncletMembership; +llvm::getEHScopeMembership(const MachineFunction &MF) { + DenseMap ScopeMembership; // We don't have anything to do if there aren't any EH pads. - if (!MF.hasEHFunclets()) - return FuncletMembership; + if (!MF.hasEHScopes()) + return ScopeMembership; int EntryBBNumber = MF.front().getNumber(); bool IsSEH = isAsynchronousEHPersonality( classifyEHPersonality(MF.getFunction().getPersonalityFn())); const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo(); - SmallVector FuncletBlocks; + SmallVector ScopeBlocks; SmallVector UnreachableBlocks; SmallVector SEHCatchPads; SmallVector, 16> CatchRetSuccessors; for (const MachineBasicBlock &MBB : MF) { - if (MBB.isEHFuncletEntry()) { - FuncletBlocks.push_back(&MBB); + if (MBB.isEHScopeEntry()) { + ScopeBlocks.push_back(&MBB); } else if (IsSEH && MBB.isEHPad()) { SEHCatchPads.push_back(&MBB); } else if (MBB.pred_empty()) { @@ -686,8 +686,8 @@ llvm::getFuncletMembership(const MachineFunction &MF) { MachineBasicBlock::const_iterator MBBI = MBB.getFirstTerminator(); - // CatchPads are not funclets for SEH so do not consider CatchRet to - // transfer control to another funclet. + // CatchPads are not scopes for SEH so do not consider CatchRet to + // transfer control to another scope. if (MBBI == MBB.end() || MBBI->getOpcode() != TII->getCatchReturnOpcode()) continue; @@ -700,24 +700,24 @@ llvm::getFuncletMembership(const MachineFunction &MF) { } // We don't have anything to do if there aren't any EH pads. - if (FuncletBlocks.empty()) - return FuncletMembership; + if (ScopeBlocks.empty()) + return ScopeMembership; // Identify all the basic blocks reachable from the function entry. - collectFuncletMembers(FuncletMembership, EntryBBNumber, &MF.front()); - // All blocks not part of a funclet are in the parent function. + collectEHScopeMembers(ScopeMembership, EntryBBNumber, &MF.front()); + // All blocks not part of a scope are in the parent function. for (const MachineBasicBlock *MBB : UnreachableBlocks) - collectFuncletMembers(FuncletMembership, EntryBBNumber, MBB); - // Next, identify all the blocks inside the funclets. - for (const MachineBasicBlock *MBB : FuncletBlocks) - collectFuncletMembers(FuncletMembership, MBB->getNumber(), MBB); - // SEH CatchPads aren't really funclets, handle them separately. + collectEHScopeMembers(ScopeMembership, EntryBBNumber, MBB); + // Next, identify all the blocks inside the scopes. + for (const MachineBasicBlock *MBB : ScopeBlocks) + collectEHScopeMembers(ScopeMembership, MBB->getNumber(), MBB); + // SEH CatchPads aren't really scopes, handle them separately. for (const MachineBasicBlock *MBB : SEHCatchPads) - collectFuncletMembers(FuncletMembership, EntryBBNumber, MBB); + collectEHScopeMembers(ScopeMembership, EntryBBNumber, MBB); // Finally, identify all the targets of a catchret. for (std::pair CatchRetPair : CatchRetSuccessors) - collectFuncletMembers(FuncletMembership, CatchRetPair.second, + collectEHScopeMembers(ScopeMembership, CatchRetPair.second, CatchRetPair.first); - return FuncletMembership; + return ScopeMembership; } -- cgit v1.2.3