diff options
author | Dan Gohman <dan433584@gmail.com> | 2015-11-23 19:12:37 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2015-11-23 19:12:37 +0000 |
commit | f6857223c9fd534825cd8307b9cb37ada230ec83 (patch) | |
tree | 13a36c07f79e25ff0d38e247abd05afa0e46cce9 /llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | |
parent | 8e8b4fb678016640be0284f6aa73b8806fb76aec (diff) | |
download | bcm5719-llvm-f6857223c9fd534825cd8307b9cb37ada230ec83.tar.gz bcm5719-llvm-f6857223c9fd534825cd8307b9cb37ada230ec83.zip |
[WebAssembly] Always print loop end labels
WebAssembly is currently using labels to end scopes, so for example a
loop scope looks like this:
BB0_0:
loop BB0_1
...
BB0_1:
with BB0_0 being the label of the first block not in the loop. This
requires that the label be printed even when it's only reachable via
fallthrough. To arrange this, insert a no-op LOOP_END instruction in
such cases at the end of the loop.
llvm-svn: 253901
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp index 78e15f036b2..2ec1ea5f65a 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -289,11 +289,21 @@ static void PlaceMarkers(MachineFunction &MF, const MachineLoopInfo &MLI, MachineBasicBlock *Bottom = Loop->getBottomBlock(); auto Iter = next(MachineFunction::iterator(Bottom)); if (Iter == MF.end()) { - MF.push_back(MF.CreateMachineBasicBlock()); + MachineBasicBlock *Label = MF.CreateMachineBasicBlock(); + // Give it a fake predecessor so that AsmPrinter prints its label. + Label->addSuccessor(Label); + MF.push_back(Label); Iter = next(MachineFunction::iterator(Bottom)); } BuildMI(MBB, MBB.begin(), DebugLoc(), TII.get(WebAssembly::LOOP)) .addMBB(&*Iter); + + // Emit a special no-op telling the asm printer that we need a label + // to close the loop scope, even though the destination is only + // reachable by fallthrough. + if (!Bottom->back().isBarrier()) + BuildMI(*Bottom, Bottom->end(), DebugLoc(), + TII.get(WebAssembly::LOOP_END)); } // Place the BLOCK for MBB if MBB is branched to from above. |