OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/control-flow-optimizer.h" | 5 #include "src/compiler/control-flow-optimizer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-operator.h" | 7 #include "src/compiler/js-operator.h" |
8 #include "src/compiler/machine-operator.h" | 8 #include "src/compiler/machine-operator.h" |
9 #include "test/unittests/compiler/graph-unittest.h" | 9 #include "test/unittests/compiler/graph-unittest.h" |
10 #include "test/unittests/compiler/node-test-utils.h" | 10 #include "test/unittests/compiler/node-test-utils.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); | 55 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); |
56 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); | 56 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); |
57 Node* branch1 = graph()->NewNode( | 57 Node* branch1 = graph()->NewNode( |
58 common()->Branch(), | 58 common()->Branch(), |
59 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)), | 59 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)), |
60 if_false0); | 60 if_false0); |
61 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); | 61 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
62 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); | 62 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
63 Node* merge = | 63 Node* merge = |
64 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1); | 64 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1); |
65 graph()->SetEnd(graph()->NewNode(common()->End(), merge)); | 65 graph()->SetEnd(graph()->NewNode(common()->End(1), merge)); |
66 Optimize(); | 66 Optimize(); |
67 Capture<Node*> switch_capture; | 67 Capture<Node*> switch_capture; |
68 EXPECT_THAT(end(), | 68 EXPECT_THAT(end(), |
69 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)), | 69 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)), |
70 IsIfValue(1, CaptureEq(&switch_capture)), | 70 IsIfValue(1, CaptureEq(&switch_capture)), |
71 IsIfDefault(AllOf(CaptureEq(&switch_capture), | 71 IsIfDefault(AllOf(CaptureEq(&switch_capture), |
72 IsSwitch(index, start())))))); | 72 IsSwitch(index, start())))))); |
73 } | 73 } |
74 | 74 |
75 | 75 |
(...skipping 10 matching lines...) Expand all Loading... |
86 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); | 86 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); |
87 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); | 87 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); |
88 Node* branch1 = graph()->NewNode( | 88 Node* branch1 = graph()->NewNode( |
89 common()->Branch(), | 89 common()->Branch(), |
90 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)), | 90 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)), |
91 if_false0); | 91 if_false0); |
92 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); | 92 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
93 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); | 93 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
94 Node* merge = | 94 Node* merge = |
95 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1); | 95 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1); |
96 graph()->SetEnd(graph()->NewNode(common()->End(), merge)); | 96 graph()->SetEnd(graph()->NewNode(common()->End(1), merge)); |
97 Optimize(); | 97 Optimize(); |
98 Capture<Node*> switch_capture; | 98 Capture<Node*> switch_capture; |
99 EXPECT_THAT( | 99 EXPECT_THAT( |
100 end(), | 100 end(), |
101 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)), | 101 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)), |
102 IsIfValue(1, CaptureEq(&switch_capture)), | 102 IsIfValue(1, CaptureEq(&switch_capture)), |
103 IsIfDefault(AllOf(CaptureEq(&switch_capture), | 103 IsIfDefault(AllOf(CaptureEq(&switch_capture), |
104 IsSwitch(index, IsIfSuccess(index))))))); | 104 IsSwitch(index, IsIfSuccess(index))))))); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 TEST_F(ControlFlowOptimizerTest, CloneBranch) { | 108 TEST_F(ControlFlowOptimizerTest, CloneBranch) { |
109 Node* cond0 = Parameter(0); | 109 Node* cond0 = Parameter(0); |
110 Node* cond1 = Parameter(1); | 110 Node* cond1 = Parameter(1); |
111 Node* cond2 = Parameter(2); | 111 Node* cond2 = Parameter(2); |
112 Node* branch0 = graph()->NewNode(common()->Branch(), cond0, start()); | 112 Node* branch0 = graph()->NewNode(common()->Branch(), cond0, start()); |
113 Node* control1 = graph()->NewNode(common()->IfTrue(), branch0); | 113 Node* control1 = graph()->NewNode(common()->IfTrue(), branch0); |
114 Node* control2 = graph()->NewNode(common()->IfFalse(), branch0); | 114 Node* control2 = graph()->NewNode(common()->IfFalse(), branch0); |
115 Node* merge0 = graph()->NewNode(common()->Merge(2), control1, control2); | 115 Node* merge0 = graph()->NewNode(common()->Merge(2), control1, control2); |
116 Node* phi0 = | 116 Node* phi0 = |
117 graph()->NewNode(common()->Phi(kRepBit, 2), cond1, cond2, merge0); | 117 graph()->NewNode(common()->Phi(kRepBit, 2), cond1, cond2, merge0); |
118 Node* branch = graph()->NewNode(common()->Branch(), phi0, merge0); | 118 Node* branch = graph()->NewNode(common()->Branch(), phi0, merge0); |
119 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 119 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
120 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 120 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
121 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 121 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
122 graph()->SetEnd(graph()->NewNode(common()->End(), merge)); | 122 graph()->SetEnd(graph()->NewNode(common()->End(1), merge)); |
123 Optimize(); | 123 Optimize(); |
124 Capture<Node*> branch1_capture, branch2_capture; | 124 Capture<Node*> branch1_capture, branch2_capture; |
125 EXPECT_THAT( | 125 EXPECT_THAT( |
126 end(), | 126 end(), |
127 IsEnd(IsMerge(IsMerge(IsIfTrue(CaptureEq(&branch1_capture)), | 127 IsEnd(IsMerge(IsMerge(IsIfTrue(CaptureEq(&branch1_capture)), |
128 IsIfTrue(CaptureEq(&branch2_capture))), | 128 IsIfTrue(CaptureEq(&branch2_capture))), |
129 IsMerge(IsIfFalse(AllOf(CaptureEq(&branch1_capture), | 129 IsMerge(IsIfFalse(AllOf(CaptureEq(&branch1_capture), |
130 IsBranch(cond1, control1))), | 130 IsBranch(cond1, control1))), |
131 IsIfFalse(AllOf(CaptureEq(&branch2_capture), | 131 IsIfFalse(AllOf(CaptureEq(&branch2_capture), |
132 IsBranch(cond2, control2))))))); | 132 IsBranch(cond2, control2))))))); |
133 } | 133 } |
134 | 134 |
135 } // namespace compiler | 135 } // namespace compiler |
136 } // namespace internal | 136 } // namespace internal |
137 } // namespace v8 | 137 } // namespace v8 |
OLD | NEW |