[llvm] r283502 - [WebAssembly] Remove loop's bottom label.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 15:10:23 PDT 2016
Author: djg
Date: Thu Oct 6 17:10:23 2016
New Revision: 283502
URL: http://llvm.org/viewvc/llvm-project?rev=283502&view=rev
Log:
[WebAssembly] Remove loop's bottom label.
Per spec changes, loop constructs no longer have a bottom label.
https://reviews.llvm.org/D25118
Modified:
llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll
Modified: llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp?rev=283502&r1=283501&r2=283502&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp Thu Oct 6 17:10:23 2016
@@ -69,11 +69,8 @@ void WebAssemblyInstPrinter::printInst(c
default:
break;
case WebAssembly::LOOP: {
- // Grab the TopLabel value first so that labels print in numeric order.
- uint64_t TopLabel = ControlFlowCounter++;
- ControlFlowStack.push_back(std::make_pair(ControlFlowCounter++, false));
- printAnnotation(OS, "label" + utostr(TopLabel) + ':');
- ControlFlowStack.push_back(std::make_pair(TopLabel, true));
+ printAnnotation(OS, "label" + utostr(ControlFlowCounter) + ':');
+ ControlFlowStack.push_back(std::make_pair(ControlFlowCounter++, true));
break;
}
case WebAssembly::BLOCK:
@@ -81,8 +78,6 @@ void WebAssemblyInstPrinter::printInst(c
break;
case WebAssembly::END_LOOP:
ControlFlowStack.pop_back();
- printAnnotation(
- OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':');
break;
case WebAssembly::END_BLOCK:
printAnnotation(
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp?rev=283502&r1=283501&r2=283502&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp Thu Oct 6 17:10:23 2016
@@ -306,12 +306,14 @@ static bool IsChild(const MachineInstr &
}
/// Insert a BLOCK marker for branches to MBB (if needed).
-static void PlaceBlockMarker(MachineBasicBlock &MBB, MachineFunction &MF,
- SmallVectorImpl<MachineBasicBlock *> &ScopeTops,
- const WebAssemblyInstrInfo &TII,
- const MachineLoopInfo &MLI,
- MachineDominatorTree &MDT,
- WebAssemblyFunctionInfo &MFI) {
+static void PlaceBlockMarker(
+ MachineBasicBlock &MBB, MachineFunction &MF,
+ SmallVectorImpl<MachineBasicBlock *> &ScopeTops,
+ DenseMap<const MachineInstr *, const MachineBasicBlock *> &LoopTops,
+ const WebAssemblyInstrInfo &TII,
+ const MachineLoopInfo &MLI,
+ MachineDominatorTree &MDT,
+ WebAssemblyFunctionInfo &MFI) {
// First compute the nearest common dominator of all forward non-fallthrough
// predecessors so that we minimize the time that the BLOCK is on the stack,
// which reduces overall stack height.
@@ -347,13 +349,6 @@ static void PlaceBlockMarker(MachineBasi
}
}
- // If there's a loop which ends just before MBB which contains Header, we can
- // reuse its label instead of inserting a new BLOCK.
- for (MachineLoop *Loop = MLI.getLoopFor(LayoutPred);
- Loop && Loop->contains(LayoutPred); Loop = Loop->getParentLoop())
- if (Loop && LoopBottom(Loop) == LayoutPred && Loop->contains(Header))
- return;
-
// Decide where in Header to put the BLOCK.
MachineBasicBlock::iterator InsertPos;
MachineLoop *HeaderLoop = MLI.getLoopFor(Header);
@@ -361,7 +356,8 @@ static void PlaceBlockMarker(MachineBasi
// Header is the header of a loop that does not lexically contain MBB, so
// the BLOCK needs to be above the LOOP, after any END constructs.
InsertPos = Header->begin();
- while (InsertPos->getOpcode() != WebAssembly::LOOP)
+ while (InsertPos->getOpcode() == WebAssembly::END_BLOCK ||
+ InsertPos->getOpcode() == WebAssembly::END_LOOP)
++InsertPos;
} else {
// Otherwise, insert the BLOCK as late in Header as we can, but before the
@@ -381,7 +377,8 @@ static void PlaceBlockMarker(MachineBasi
// Mark the end of the block.
InsertPos = MBB.begin();
while (InsertPos != MBB.end() &&
- InsertPos->getOpcode() == WebAssembly::END_LOOP)
+ InsertPos->getOpcode() == WebAssembly::END_LOOP &&
+ LoopTops[&*InsertPos]->getNumber() >= Header->getNumber())
++InsertPos;
BuildMI(MBB, InsertPos, DebugLoc(), TII.get(WebAssembly::END_BLOCK));
@@ -468,7 +465,7 @@ static void PlaceMarkers(MachineFunction
PlaceLoopMarker(MBB, MF, ScopeTops, LoopTops, TII, MLI);
// Place the BLOCK for MBB if MBB is branched to from above.
- PlaceBlockMarker(MBB, MF, ScopeTops, TII, MLI, MDT, MFI);
+ PlaceBlockMarker(MBB, MF, ScopeTops, LoopTops, TII, MLI, MDT, MFI);
}
// Now rewrite references to basic blocks to be depth immediates.
@@ -477,20 +474,18 @@ static void PlaceMarkers(MachineFunction
for (auto &MI : reverse(MBB)) {
switch (MI.getOpcode()) {
case WebAssembly::BLOCK:
- assert(ScopeTops[Stack.back()->getNumber()] == &MBB &&
+ assert(ScopeTops[Stack.back()->getNumber()]->getNumber() <= MBB.getNumber() &&
"Block should be balanced");
Stack.pop_back();
break;
case WebAssembly::LOOP:
assert(Stack.back() == &MBB && "Loop top should be balanced");
Stack.pop_back();
- Stack.pop_back();
break;
case WebAssembly::END_BLOCK:
Stack.push_back(&MBB);
break;
case WebAssembly::END_LOOP:
- Stack.push_back(&MBB);
Stack.push_back(LoopTops[&MI]);
break;
default:
Modified: llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll?rev=283502&r1=283501&r2=283502&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll Thu Oct 6 17:10:23 2016
@@ -576,7 +576,7 @@ default:
; CHECK: .LBB14_1:
; CHECK-NEXT: block{{$}}
; CHECK-NEXT: loop{{$}}
-; CHECK: br_if 2, {{[^,]+}}{{$}}
+; CHECK: br_if 1, {{[^,]+}}{{$}}
; CHECK: br_if 0, {{[^,]+}}{{$}}
; CHECK-NEXT: end_loop{{$}}
; CHECK: return{{$}}
@@ -586,7 +586,7 @@ default:
; OPT: .LBB14_1:
; OPT-NEXT: block{{$}}
; OPT-NEXT: loop{{$}}
-; OPT: br_if 2, {{[^,]+}}{{$}}
+; OPT: br_if 1, {{[^,]+}}{{$}}
; OPT: br_if 0, {{[^,]+}}{{$}}
; OPT-NEXT: end_loop{{$}}
; OPT: return{{$}}
@@ -623,10 +623,10 @@ return:
; CHECK-NEXT: block{{$}}
; CHECK-NEXT: loop{{$}}
; CHECK-NOT: block
-; CHECK: br_if 3, {{[^,]+}}{{$}}
-; CHECK-NOT: block
; CHECK: br_if 2, {{[^,]+}}{{$}}
; CHECK-NOT: block
+; CHECK: br_if 1, {{[^,]+}}{{$}}
+; CHECK-NOT: block
; CHECK: br_if 0, {{[^,]+}}{{$}}
; CHECK-NEXT: end_loop{{$}}
; CHECK-NOT: block
@@ -644,10 +644,10 @@ return:
; OPT-NEXT: block{{$}}
; OPT-NEXT: loop{{$}}
; OPT-NOT: block
-; OPT: br_if 3, {{[^,]+}}{{$}}
-; OPT-NOT: block
; OPT: br_if 2, {{[^,]+}}{{$}}
; OPT-NOT: block
+; OPT: br_if 1, {{[^,]+}}{{$}}
+; OPT-NOT: block
; OPT: br_if 0, {{[^,]+}}{{$}}
; OPT-NEXT: end_loop{{$}}
; OPT-NOT: block
@@ -718,7 +718,7 @@ second:
; OPT: br_if 0, {{[^,]+}}{{$}}
; OPT-NOT: block
; OPT: br_if 1, {{[^,]+}}{{$}}
-; OPT: br 3{{$}}
+; OPT: br 2{{$}}
; OPT-NEXT: .LBB16_3:
; OPT-NEXT: end_block
; OPT-NOT: block
@@ -796,6 +796,7 @@ bb3:
; CHECK-LABEL: test9:
; CHECK: .LBB18_1:
+; CHECK-NEXT: block{{$}}
; CHECK-NEXT: loop{{$}}
; CHECK-NOT: block
; CHECK: br_if 1, {{[^,]+}}{{$}}
@@ -806,18 +807,21 @@ bb3:
; CHECK-NOT: block
; CHECK: br_if 0, {{[^,]+}}{{$}}
; CHECK-NOT: block
-; CHECK: br_if 3, {{[^,]+}}{{$}}
+; CHECK: br_if 2, {{[^,]+}}{{$}}
; CHECK-NEXT: br 1{{$}}
; CHECK-NEXT: .LBB18_4:
; CHECK-NEXT: end_block{{$}}
; CHECK-NOT: block
-; CHECK: br_if 2, {{[^,]+}}{{$}}
+; CHECK: br_if 1, {{[^,]+}}{{$}}
; CHECK-NEXT: br 0{{$}}
; CHECK-NEXT: .LBB18_5:
; CHECK-NOT: block
+; CHECK: end_block
+; CHECK-NOT: block
; CHECK: return{{$}}
; OPT-LABEL: test9:
; OPT: .LBB18_1:
+; OPT-NEXT: block{{$}}
; OPT-NEXT: loop{{$}}
; OPT-NOT: block
; OPT: br_if 1, {{[^,]+}}{{$}}
@@ -829,14 +833,16 @@ bb3:
; OPT: br_if 0, {{[^,]+}}{{$}}
; OPT-NOT: block
; OPT: br_if 1, {{[^,]+}}{{$}}
-; OPT-NEXT: br 3{{$}}
+; OPT-NEXT: br 2{{$}}
; OPT-NEXT: .LBB18_4:
; OPT-NEXT: end_block{{$}}
; OPT-NOT: block
; OPT: br_if 0, {{[^,]+}}{{$}}
-; OPT-NEXT: br 2{{$}}
+; OPT-NEXT: br 1{{$}}
; OPT-NEXT: .LBB18_5:
; OPT-NOT: block
+; OPT: end_block
+; OPT-NOT: block
; OPT: return{{$}}
declare i1 @a()
define void @test9() {
@@ -884,10 +890,11 @@ end:
; CHECK: .LBB19_4:
; CHECK-NEXT: loop{{$}}
; CHECK-NOT: block
-; CHECK: br_if 5, {{[^,]+}}{{$}}
-; CHECK-NOT: block
-; CHECK: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
+; CHECK: br_if 3, {{[^,]+}}{{$}}
+; CHECK: block{{$}}
+; CHECK: br_table {{[^,]+}}, 1, 0, 4, 2, 3, 1{{$}}
; CHECK-NEXT: .LBB19_6:
+; CHECK-NEXT: end_block{{$}}
; CHECK-NEXT: end_loop{{$}}
; CHECK-NEXT: end_loop{{$}}
; CHECK-NEXT: return{{$}}
@@ -908,10 +915,11 @@ end:
; OPT: .LBB19_4:
; OPT-NEXT: loop{{$}}
; OPT-NOT: block
-; OPT: br_if 5, {{[^,]+}}{{$}}
-; OPT-NOT: block
-; OPT: br_table {{[^,]+}}, 0, 1, 5, 2, 4, 0{{$}}
+; OPT: br_if 3, {{[^,]+}}{{$}}
+; OPT: block
+; OPT: br_table {{[^,]+}}, 1, 0, 4, 2, 3, 1{{$}}
; OPT-NEXT: .LBB19_6:
+; OPT-NEXT: end_block{{$}}
; OPT-NEXT: end_loop{{$}}
; OPT-NEXT: end_loop{{$}}
; OPT-NEXT: return{{$}}
@@ -1055,6 +1063,7 @@ bb8:
; CHECK-LABEL: test12:
; CHECK: .LBB21_1:
+; CHECK-NEXT: block{{$}}
; CHECK-NEXT: loop{{$}}
; CHECK-NOT: block
; CHECK: block{{$}}
@@ -1077,9 +1086,11 @@ bb8:
; CHECK: br 0{{$}}
; CHECK-NEXT: .LBB21_7:
; CHECK-NEXT: end_loop{{$}}
+; CHECK-NEXT: end_block{{$}}
; CHECK-NEXT: return{{$}}
; OPT-LABEL: test12:
; OPT: .LBB21_1:
+; OPT-NEXT: block{{$}}
; OPT-NEXT: loop{{$}}
; OPT-NOT: block
; OPT: block{{$}}
@@ -1101,6 +1112,7 @@ bb8:
; OPT: br 0{{$}}
; OPT-NEXT: .LBB21_7:
; OPT-NEXT: end_loop{{$}}
+; OPT-NEXT: end_block{{$}}
; OPT-NEXT: return{{$}}
define void @test12(i8* %arg) {
bb:
@@ -1250,6 +1262,7 @@ bb50:
; CHECK: br_if 0, $pop{{.*}}{{$}}
; CHECK: .LBB24_2:
; CHECK-NEXT: block{{$}}
+; CHECK-NEXT: block{{$}}
; CHECK-NEXT: loop{{$}}
; CHECK: br_if 1, $pop{{.*}}{{$}}
; CHECK: br_if 0, ${{.*}}{{$}}
@@ -1278,6 +1291,7 @@ bb50:
; OPT-NEXT: i32.const
; OPT-NEXT: .LBB24_3:
; OPT-NEXT: block
+; OPT-NEXT: block
; OPT-NEXT: loop
%0 = type { i8, i32 }
declare void @test15_callee0()
More information about the llvm-commits
mailing list