diff options
author | Dan Gohman <dan433584@gmail.com> | 2015-12-16 19:06:41 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2015-12-16 19:06:41 +0000 |
commit | b3aa1ecab0b4ebfba8f2fce7dfaec94f231032b3 (patch) | |
tree | 2ce0187a1f606a02bf795d6ab2211cd012b00c58 /llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | |
parent | 7fda3c9ff30fd82e7e0cdf0d97288da3e1a20bf5 (diff) | |
download | llvm-b3aa1ecab0b4ebfba8f2fce7dfaec94f231032b3.zip llvm-b3aa1ecab0b4ebfba8f2fce7dfaec94f231032b3.tar.gz llvm-b3aa1ecab0b4ebfba8f2fce7dfaec94f231032b3.tar.bz2 |
[WebAssembly] Fix the CFG Stackifier to handle unoptimized branches
If a branch both branches to and falls through to the same block, treat it as
an explicit branch.
llvm-svn: 255803
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp index 6412442..6ac5366 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -251,6 +251,19 @@ static void SortBlocks(MachineFunction &MF, const MachineLoopInfo &MLI) { #endif } +/// Test whether Pred has any terminators explicitly branching to MBB, as +/// opposed to falling through. Note that it's possible (eg. in unoptimized +/// code) for a branch instruction to both branch to a block and fallthrough +/// to it, so we check the actual branch operands to see if there are any +/// explicit mentions. +static bool ExplicitlyBranchesTo(MachineBasicBlock *Pred, MachineBasicBlock *MBB) { + for (MachineInstr &MI : Pred->terminators()) + for (MachineOperand &MO : MI.explicit_operands()) + if (MO.isMBB() && MO.getMBB() == MBB) + return true; + return false; +} + /// Insert a BLOCK marker for branches to MBB (if needed). static void PlaceBlockMarker(MachineBasicBlock &MBB, MachineFunction &MF, SmallVectorImpl<MachineBasicBlock *> &ScopeTops, @@ -266,8 +279,7 @@ static void PlaceBlockMarker(MachineBasicBlock &MBB, MachineFunction &MF, for (MachineBasicBlock *Pred : MBB.predecessors()) if (Pred->getNumber() < MBBNumber) { Header = Header ? MDT.findNearestCommonDominator(Header, Pred) : Pred; - if (!Pred->isLayoutSuccessor(&MBB) || - !(Pred->empty() || !Pred->back().isBarrier())) + if (ExplicitlyBranchesTo(Pred, &MBB)) IsBranchedTo = true; } if (!Header) |