59a02ebdbe
Up until now we used a special Terminate node to artifically connect non terminating loops to the End node, but this was kind of adhoc and didn't work for the CFG. So without all kinds of weird hacks, the end block in the CFG will not be connected to NTLs, which makes it impossible to compute post dominance / control dependence in the current setting. So instead of Terminate, we add a special Branch to NTLs, whose condition is the special Always node, which corresponds to True, except that it cannot be folded away. This way we don't need any special machinery in the scheduler, since it's just a regular Branch. R=titzer@chromium.org Review URL: https://codereview.chromium.org/875263004 Cr-Commit-Position: refs/heads/master@{#26294}
125 lines
4.4 KiB
C++
125 lines
4.4 KiB
C++
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/compiler/control-reducer.h"
|
|
#include "src/compiler/js-graph.h"
|
|
#include "src/compiler/js-operator.h"
|
|
#include "src/compiler/machine-operator.h"
|
|
#include "src/compiler/node.h"
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
|
#include "testing/gmock-support.h"
|
|
|
|
using testing::_;
|
|
using testing::AllOf;
|
|
using testing::Capture;
|
|
using testing::CaptureEq;
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace compiler {
|
|
|
|
class ControlReducerTest : public GraphTest {
|
|
protected:
|
|
void ReduceGraph() {
|
|
JSOperatorBuilder javascript(zone());
|
|
MachineOperatorBuilder machine(zone());
|
|
JSGraph jsgraph(isolate(), graph(), common(), &javascript, &machine);
|
|
ControlReducer::ReduceGraph(zone(), &jsgraph, common());
|
|
}
|
|
};
|
|
|
|
|
|
TEST_F(ControlReducerTest, NonTerminatingLoop) {
|
|
Node* loop = graph()->NewNode(common()->Loop(2), graph()->start());
|
|
loop->AppendInput(graph()->zone(), loop);
|
|
ReduceGraph();
|
|
Capture<Node*> branch;
|
|
EXPECT_THAT(
|
|
graph()->end(),
|
|
IsEnd(IsMerge(
|
|
graph()->start(),
|
|
IsReturn(IsUndefinedConstant(), graph()->start(),
|
|
IsIfFalse(
|
|
AllOf(CaptureEq(&branch),
|
|
IsBranch(IsAlways(),
|
|
AllOf(loop, IsLoop(graph()->start(),
|
|
IsIfTrue(CaptureEq(
|
|
&branch)))))))))));
|
|
}
|
|
|
|
|
|
TEST_F(ControlReducerTest, NonTerminatingLoopWithEffectPhi) {
|
|
Node* loop = graph()->NewNode(common()->Loop(2), graph()->start());
|
|
loop->AppendInput(graph()->zone(), loop);
|
|
Node* ephi = graph()->NewNode(common()->EffectPhi(2), graph()->start());
|
|
ephi->AppendInput(graph()->zone(), ephi);
|
|
ephi->AppendInput(graph()->zone(), loop);
|
|
ReduceGraph();
|
|
Capture<Node*> branch;
|
|
EXPECT_THAT(
|
|
graph()->end(),
|
|
IsEnd(IsMerge(
|
|
graph()->start(),
|
|
IsReturn(IsUndefinedConstant(),
|
|
AllOf(ephi, IsEffectPhi(graph()->start(), ephi, loop)),
|
|
IsIfFalse(
|
|
AllOf(CaptureEq(&branch),
|
|
IsBranch(IsAlways(),
|
|
AllOf(loop, IsLoop(graph()->start(),
|
|
IsIfTrue(CaptureEq(
|
|
&branch)))))))))));
|
|
}
|
|
|
|
|
|
TEST_F(ControlReducerTest, NonTerminatingLoopWithTwoEffectPhis) {
|
|
Node* loop = graph()->NewNode(common()->Loop(2), graph()->start());
|
|
loop->AppendInput(graph()->zone(), loop);
|
|
Node* ephi1 = graph()->NewNode(common()->EffectPhi(2), graph()->start());
|
|
ephi1->AppendInput(graph()->zone(), ephi1);
|
|
ephi1->AppendInput(graph()->zone(), loop);
|
|
Node* ephi2 = graph()->NewNode(common()->EffectPhi(2), graph()->start());
|
|
ephi2->AppendInput(graph()->zone(), ephi2);
|
|
ephi2->AppendInput(graph()->zone(), loop);
|
|
ReduceGraph();
|
|
Capture<Node*> branch;
|
|
EXPECT_THAT(
|
|
graph()->end(),
|
|
IsEnd(IsMerge(
|
|
graph()->start(),
|
|
IsReturn(
|
|
IsUndefinedConstant(),
|
|
IsEffectSet(
|
|
AllOf(ephi1, IsEffectPhi(graph()->start(), ephi1, loop)),
|
|
AllOf(ephi2, IsEffectPhi(graph()->start(), ephi2, loop))),
|
|
IsIfFalse(AllOf(
|
|
CaptureEq(&branch),
|
|
IsBranch(
|
|
IsAlways(),
|
|
AllOf(loop, IsLoop(graph()->start(),
|
|
IsIfTrue(CaptureEq(&branch)))))))))));
|
|
}
|
|
|
|
|
|
TEST_F(ControlReducerTest, NonTerminatingLoopWithDeadEnd) {
|
|
Node* loop = graph()->NewNode(common()->Loop(2), graph()->start());
|
|
loop->AppendInput(graph()->zone(), loop);
|
|
graph()->end()->ReplaceInput(0, graph()->NewNode(common()->Dead()));
|
|
ReduceGraph();
|
|
Capture<Node*> branch;
|
|
EXPECT_THAT(
|
|
graph()->end(),
|
|
IsEnd(IsReturn(
|
|
IsUndefinedConstant(), graph()->start(),
|
|
IsIfFalse(AllOf(
|
|
CaptureEq(&branch),
|
|
IsBranch(IsAlways(),
|
|
AllOf(loop, IsLoop(graph()->start(),
|
|
IsIfTrue(CaptureEq(&branch))))))))));
|
|
}
|
|
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|