OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/graph.h" | 6 #include "src/compiler/graph.h" |
7 #include "src/compiler/node.h" | 7 #include "src/compiler/node.h" |
8 #include "src/compiler/operator.h" | 8 #include "src/compiler/operator.h" |
9 #include "test/unittests/compiler/graph-reducer-unittest.h" | 9 #include "test/unittests/compiler/graph-reducer-unittest.h" |
10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 "MockOpControl", 0, 0, 1, 1, 0, 1); | 283 "MockOpControl", 0, 0, 1, 1, 0, 1); |
284 | 284 |
285 const IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught; | 285 const IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught; |
286 | 286 |
287 } // namespace | 287 } // namespace |
288 | 288 |
289 | 289 |
290 TEST_F(AdvancedReducerTest, ReplaceWithValue_ValueUse) { | 290 TEST_F(AdvancedReducerTest, ReplaceWithValue_ValueUse) { |
291 CommonOperatorBuilder common(zone()); | 291 CommonOperatorBuilder common(zone()); |
292 Node* node = graph()->NewNode(&kMockOperator); | 292 Node* node = graph()->NewNode(&kMockOperator); |
293 Node* use_value = graph()->NewNode(common.Return(), node); | 293 Node* start = graph()->NewNode(common.Start(1)); |
| 294 Node* use_value = graph()->NewNode(common.Return(), node, start, start); |
294 Node* replacement = graph()->NewNode(&kMockOperator); | 295 Node* replacement = graph()->NewNode(&kMockOperator); |
295 GraphReducer graph_reducer(zone(), graph(), nullptr); | 296 GraphReducer graph_reducer(zone(), graph(), nullptr); |
296 ReplaceWithValueReducer r(&graph_reducer); | 297 ReplaceWithValueReducer r(&graph_reducer); |
297 r.ReplaceWithValue(node, replacement); | 298 r.ReplaceWithValue(node, replacement); |
298 EXPECT_EQ(replacement, use_value->InputAt(0)); | 299 EXPECT_EQ(replacement, use_value->InputAt(0)); |
299 EXPECT_EQ(0, node->UseCount()); | 300 EXPECT_EQ(0, node->UseCount()); |
300 EXPECT_EQ(1, replacement->UseCount()); | 301 EXPECT_EQ(1, replacement->UseCount()); |
301 EXPECT_THAT(replacement->uses(), ElementsAre(use_value)); | 302 EXPECT_THAT(replacement->uses(), ElementsAre(use_value)); |
302 } | 303 } |
303 | 304 |
304 | 305 |
305 TEST_F(AdvancedReducerTest, ReplaceWithValue_EffectUse) { | 306 TEST_F(AdvancedReducerTest, ReplaceWithValue_EffectUse) { |
306 CommonOperatorBuilder common(zone()); | 307 CommonOperatorBuilder common(zone()); |
307 Node* start = graph()->NewNode(common.Start(1)); | 308 Node* start = graph()->NewNode(common.Start(1)); |
308 Node* node = graph()->NewNode(&kMockOpEffect, start); | 309 Node* node = graph()->NewNode(&kMockOpEffect, start); |
309 Node* use_effect = graph()->NewNode(common.EffectPhi(1), node); | 310 Node* use_control = graph()->NewNode(common.Merge(1), start); |
| 311 Node* use_effect = graph()->NewNode(common.EffectPhi(1), node, use_control); |
310 Node* replacement = graph()->NewNode(&kMockOperator); | 312 Node* replacement = graph()->NewNode(&kMockOperator); |
311 GraphReducer graph_reducer(zone(), graph(), nullptr); | 313 GraphReducer graph_reducer(zone(), graph(), nullptr); |
312 ReplaceWithValueReducer r(&graph_reducer); | 314 ReplaceWithValueReducer r(&graph_reducer); |
313 r.ReplaceWithValue(node, replacement); | 315 r.ReplaceWithValue(node, replacement); |
314 EXPECT_EQ(start, use_effect->InputAt(0)); | 316 EXPECT_EQ(start, use_effect->InputAt(0)); |
315 EXPECT_EQ(0, node->UseCount()); | 317 EXPECT_EQ(0, node->UseCount()); |
316 EXPECT_EQ(2, start->UseCount()); | 318 EXPECT_EQ(3, start->UseCount()); |
317 EXPECT_EQ(0, replacement->UseCount()); | 319 EXPECT_EQ(0, replacement->UseCount()); |
318 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_effect, node)); | 320 EXPECT_THAT(start->uses(), |
| 321 UnorderedElementsAre(use_effect, use_control, node)); |
319 } | 322 } |
320 | 323 |
321 | 324 |
322 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse1) { | 325 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse1) { |
323 CommonOperatorBuilder common(zone()); | 326 CommonOperatorBuilder common(zone()); |
324 Node* start = graph()->NewNode(common.Start(1)); | 327 Node* start = graph()->NewNode(common.Start(1)); |
325 Node* node = graph()->NewNode(&kMockOpControl, start); | 328 Node* node = graph()->NewNode(&kMockOpControl, start); |
326 Node* success = graph()->NewNode(common.IfSuccess(), node); | 329 Node* success = graph()->NewNode(common.IfSuccess(), node); |
327 Node* use_control = graph()->NewNode(common.Merge(1), success); | 330 Node* use_control = graph()->NewNode(common.Merge(1), success); |
328 Node* replacement = graph()->NewNode(&kMockOperator); | 331 Node* replacement = graph()->NewNode(&kMockOperator); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 EXPECT_EQ(&kOpC0, n1->op()); | 851 EXPECT_EQ(&kOpC0, n1->op()); |
849 EXPECT_EQ(&kOpC1, end->op()); | 852 EXPECT_EQ(&kOpC1, end->op()); |
850 EXPECT_EQ(n1, end->InputAt(0)); | 853 EXPECT_EQ(n1, end->InputAt(0)); |
851 } | 854 } |
852 } | 855 } |
853 } | 856 } |
854 | 857 |
855 } // namespace compiler | 858 } // namespace compiler |
856 } // namespace internal | 859 } // namespace internal |
857 } // namespace v8 | 860 } // namespace v8 |
OLD | NEW |