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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/node-properties.h" | 6 #include "src/compiler/node-properties.h" |
7 #include "test/unittests/test-utils.h" | 7 #include "test/unittests/test-utils.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 | 9 |
| 10 using testing::AnyOf; |
10 using testing::IsNull; | 11 using testing::IsNull; |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace compiler { | 15 namespace compiler { |
15 | 16 |
16 typedef TestWithZone NodePropertiesTest; | 17 typedef TestWithZone NodePropertiesTest; |
17 | 18 |
18 | 19 |
19 TEST_F(NodePropertiesTest, FindProjection) { | 20 TEST_F(NodePropertiesTest, FindProjection) { |
20 CommonOperatorBuilder common(zone()); | 21 CommonOperatorBuilder common(zone()); |
21 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | 22 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); |
22 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); | 23 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); |
23 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); | 24 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); |
24 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); | 25 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); |
25 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); | 26 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); |
26 EXPECT_THAT(NodeProperties::FindProjection(start, 2), IsNull()); | 27 EXPECT_THAT(NodeProperties::FindProjection(start, 2), IsNull()); |
27 EXPECT_THAT(NodeProperties::FindProjection(start, 1234567890), IsNull()); | 28 EXPECT_THAT(NodeProperties::FindProjection(start, 1234567890), IsNull()); |
28 } | 29 } |
29 | 30 |
| 31 |
| 32 TEST_F(NodePropertiesTest, CollectControlProjections_Branch) { |
| 33 Node* result[2]; |
| 34 CommonOperatorBuilder common(zone()); |
| 35 Node* branch = Node::New(zone(), 1, common.Branch(), 0, nullptr, false); |
| 36 Node* if_false = Node::New(zone(), 2, common.IfFalse(), 1, &branch, false); |
| 37 Node* if_true = Node::New(zone(), 3, common.IfTrue(), 1, &branch, false); |
| 38 NodeProperties::CollectControlProjections(branch, result, arraysize(result)); |
| 39 EXPECT_EQ(if_true, result[0]); |
| 40 EXPECT_EQ(if_false, result[1]); |
| 41 } |
| 42 |
| 43 |
| 44 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) { |
| 45 Node* result[3]; |
| 46 CommonOperatorBuilder common(zone()); |
| 47 Node* sw = Node::New(zone(), 1, common.Switch(3), 0, nullptr, false); |
| 48 Node* if_default = Node::New(zone(), 2, common.IfDefault(), 1, &sw, false); |
| 49 Node* if_value1 = Node::New(zone(), 3, common.IfValue(1), 1, &sw, false); |
| 50 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); |
| 51 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); |
| 52 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); |
| 53 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); |
| 54 EXPECT_EQ(if_default, result[2]); |
| 55 } |
| 56 |
30 } // namespace compiler | 57 } // namespace compiler |
31 } // namespace internal | 58 } // namespace internal |
32 } // namespace v8 | 59 } // namespace v8 |
OLD | NEW |