Index: test/unittests/compiler/control-flow-optimizer-unittest.cc |
diff --git a/test/unittests/compiler/control-flow-optimizer-unittest.cc b/test/unittests/compiler/control-flow-optimizer-unittest.cc |
index f5c182934ba08ec5d481928c93d8dd0622125622..f300d07767c6e6c205f24b4bb7fe3402edb170ea 100644 |
--- a/test/unittests/compiler/control-flow-optimizer-unittest.cc |
+++ b/test/unittests/compiler/control-flow-optimizer-unittest.cc |
@@ -21,25 +21,32 @@ namespace compiler { |
class ControlFlowOptimizerTest : public GraphTest { |
public: |
explicit ControlFlowOptimizerTest(int num_parameters = 3) |
- : GraphTest(num_parameters), machine_(zone()) {} |
+ : GraphTest(num_parameters), |
+ machine_(zone()), |
+ javascript_(zone()), |
+ jsgraph_(isolate(), graph(), common(), javascript(), machine()) {} |
~ControlFlowOptimizerTest() OVERRIDE {} |
protected: |
void Optimize() { |
- JSOperatorBuilder javascript(zone()); |
- JSGraph jsgraph(isolate(), graph(), common(), &javascript, machine()); |
- ControlFlowOptimizer optimizer(&jsgraph, zone()); |
+ ControlFlowOptimizer optimizer(jsgraph(), zone()); |
optimizer.Optimize(); |
} |
+ Node* EmptyFrameState() { return jsgraph()->EmptyFrameState(); } |
+ |
+ JSGraph* jsgraph() { return &jsgraph_; } |
+ JSOperatorBuilder* javascript() { return &javascript_; } |
MachineOperatorBuilder* machine() { return &machine_; } |
private: |
MachineOperatorBuilder machine_; |
+ JSOperatorBuilder javascript_; |
+ JSGraph jsgraph_; |
}; |
-TEST_F(ControlFlowOptimizerTest, BuildSwitch) { |
+TEST_F(ControlFlowOptimizerTest, BuildSwitch1) { |
Node* index = Parameter(0); |
Node* branch0 = graph()->NewNode( |
common()->Branch(), |
@@ -66,6 +73,41 @@ TEST_F(ControlFlowOptimizerTest, BuildSwitch) { |
} |
+TEST_F(ControlFlowOptimizerTest, BuildSwitch2) { |
+ Node* input = Parameter(0); |
+ Node* context = Parameter(1); |
+ Node* index = FLAG_turbo_deoptimization |
+ ? graph()->NewNode(javascript()->ToNumber(), input, context, |
+ EmptyFrameState(), start(), start()) |
+ : graph()->NewNode(javascript()->ToNumber(), input, context, |
+ start(), start()); |
+ Node* if_success = graph()->NewNode(common()->IfSuccess(), index); |
+ Node* branch0 = graph()->NewNode( |
+ common()->Branch(), |
+ graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(0)), |
+ if_success); |
+ Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); |
+ Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); |
+ Node* branch1 = graph()->NewNode( |
+ common()->Branch(), |
+ graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)), |
+ if_false0); |
+ Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
+ Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
+ Node* merge = |
+ graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1); |
+ graph()->SetEnd(graph()->NewNode(common()->End(), merge)); |
+ Optimize(); |
+ Capture<Node*> switch_capture; |
+ EXPECT_THAT( |
+ end(), |
+ IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)), |
+ IsIfValue(1, CaptureEq(&switch_capture)), |
+ IsIfDefault(AllOf(CaptureEq(&switch_capture), |
+ IsSwitch(index, IsIfSuccess(index))))))); |
+} |
+ |
+ |
TEST_F(ControlFlowOptimizerTest, CloneBranch) { |
Node* cond0 = Parameter(0); |
Node* cond1 = Parameter(1); |