[llvm] r258521 - [WinEH] Make collectFuncletMembers non-recursive
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 22 10:49:51 PST 2016
Author: majnemer
Date: Fri Jan 22 12:49:50 2016
New Revision: 258521
URL: http://llvm.org/viewvc/llvm-project?rev=258521&view=rev
Log:
[WinEH] Make collectFuncletMembers non-recursive
Use a worklist for the pre-order DFS instead of using recursion.
No functionality change is intended.
Modified:
llvm/trunk/lib/CodeGen/Analysis.cpp
Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=258521&r1=258520&r2=258521&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/Analysis.cpp Fri Jan 22 12:49:50 2016
@@ -654,32 +654,30 @@ bool llvm::canBeOmittedFromSymbolTable(c
static void collectFuncletMembers(
DenseMap<const MachineBasicBlock *, int> &FuncletMembership, int Funclet,
const MachineBasicBlock *MBB) {
- // Add this MBB to our funclet.
- auto P = FuncletMembership.insert(std::make_pair(MBB, Funclet));
+ SmallVector<const MachineBasicBlock *, 16> Worklist = {MBB};
+ while (!Worklist.empty()) {
+ const MachineBasicBlock *Visiting = Worklist.pop_back_val();
+ // Don't follow blocks which start new funclets.
+ if (Visiting->isEHPad() && Visiting != MBB)
+ continue;
- // Don't revisit blocks.
- if (!P.second) {
- assert(P.first->second == Funclet && "MBB is part of two funclets!");
- return;
- }
+ // Add this MBB to our funclet.
+ auto P = FuncletMembership.insert(std::make_pair(Visiting, Funclet));
- bool IsReturn = false;
- int NumTerminators = 0;
- for (const MachineInstr &MI : MBB->terminators()) {
- IsReturn |= MI.isReturn();
- ++NumTerminators;
- }
- assert((!IsReturn || NumTerminators == 1) &&
- "Expected only one terminator when a return is present!");
+ // Don't revisit blocks.
+ if (!P.second) {
+ assert(P.first->second == Funclet && "MBB is part of two funclets!");
+ continue;
+ }
- // Returns are boundaries where funclet transfer can occur, don't follow
- // successors.
- if (IsReturn)
- return;
+ // Returns are boundaries where funclet transfer can occur, don't follow
+ // successors.
+ if (Visiting->isReturnBlock())
+ continue;
- for (const MachineBasicBlock *SMBB : MBB->successors())
- if (!SMBB->isEHPad())
- collectFuncletMembers(FuncletMembership, Funclet, SMBB);
+ for (const MachineBasicBlock *Succ : Visiting->successors())
+ Worklist.push_back(Succ);
+ }
}
DenseMap<const MachineBasicBlock *, int>
More information about the llvm-commits
mailing list