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::AnyOf; |
11 using testing::ElementsAre; | 11 using testing::ElementsAre; |
12 using testing::IsNull; | 12 using testing::IsNull; |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 namespace compiler { | 16 namespace compiler { |
17 | 17 |
18 typedef TestWithZone NodePropertiesTest; | 18 typedef TestWithZone NodePropertiesTest; |
19 | 19 |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, | 23 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, |
24 "MockOperator", 0, 0, 0, 1, 0, 0); | 24 "MockOperator", 0, 0, 0, 1, 0, 0); |
25 const Operator kMockOpEffect(IrOpcode::kDead, Operator::kNoProperties, | 25 const Operator kMockOpEffect(IrOpcode::kDead, Operator::kNoProperties, |
26 "MockOpEffect", 0, 1, 0, 1, 1, 0); | 26 "MockOpEffect", 0, 1, 0, 1, 1, 0); |
27 const Operator kMockOpControl(IrOpcode::kDead, Operator::kNoProperties, | 27 const Operator kMockOpControl(IrOpcode::kDead, Operator::kNoProperties, |
28 "MockOpControl", 0, 0, 1, 1, 0, 1); | 28 "MockOpControl", 0, 0, 1, 1, 0, 1); |
| 29 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, |
| 30 "MockCallOperator", 0, 0, 0, 0, 0, 2); |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 | 34 |
33 TEST_F(NodePropertiesTest, ReplaceWithValue_ValueUse) { | 35 TEST_F(NodePropertiesTest, ReplaceWithValue_ValueUse) { |
34 CommonOperatorBuilder common(zone()); | 36 CommonOperatorBuilder common(zone()); |
35 Node* node = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 37 Node* node = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); |
36 Node* use_value = Node::New(zone(), 0, common.Return(), 1, &node, false); | 38 Node* use_value = Node::New(zone(), 0, common.Return(), 1, &node, false); |
37 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 39 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); |
38 NodeProperties::ReplaceWithValue(node, replacement); | 40 NodeProperties::ReplaceWithValue(node, replacement); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 CommonOperatorBuilder common(zone()); | 93 CommonOperatorBuilder common(zone()); |
92 Node* branch = Node::New(zone(), 1, common.Branch(), 0, nullptr, false); | 94 Node* branch = Node::New(zone(), 1, common.Branch(), 0, nullptr, false); |
93 Node* if_false = Node::New(zone(), 2, common.IfFalse(), 1, &branch, false); | 95 Node* if_false = Node::New(zone(), 2, common.IfFalse(), 1, &branch, false); |
94 Node* if_true = Node::New(zone(), 3, common.IfTrue(), 1, &branch, false); | 96 Node* if_true = Node::New(zone(), 3, common.IfTrue(), 1, &branch, false); |
95 NodeProperties::CollectControlProjections(branch, result, arraysize(result)); | 97 NodeProperties::CollectControlProjections(branch, result, arraysize(result)); |
96 EXPECT_EQ(if_true, result[0]); | 98 EXPECT_EQ(if_true, result[0]); |
97 EXPECT_EQ(if_false, result[1]); | 99 EXPECT_EQ(if_false, result[1]); |
98 } | 100 } |
99 | 101 |
100 | 102 |
| 103 TEST_F(NodePropertiesTest, CollectControlProjections_Call) { |
| 104 Node* result[2]; |
| 105 CommonOperatorBuilder common(zone()); |
| 106 Node* call = Node::New(zone(), 1, &kMockCallOperator, 0, nullptr, false); |
| 107 Node* if_ex = Node::New(zone(), 2, common.IfException(), 1, &call, false); |
| 108 Node* if_ok = Node::New(zone(), 3, common.IfSuccess(), 1, &call, false); |
| 109 NodeProperties::CollectControlProjections(call, result, arraysize(result)); |
| 110 EXPECT_EQ(if_ok, result[0]); |
| 111 EXPECT_EQ(if_ex, result[1]); |
| 112 } |
| 113 |
| 114 |
101 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) { | 115 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) { |
102 Node* result[3]; | 116 Node* result[3]; |
103 CommonOperatorBuilder common(zone()); | 117 CommonOperatorBuilder common(zone()); |
104 Node* sw = Node::New(zone(), 1, common.Switch(3), 0, nullptr, false); | 118 Node* sw = Node::New(zone(), 1, common.Switch(3), 0, nullptr, false); |
105 Node* if_default = Node::New(zone(), 2, common.IfDefault(), 1, &sw, false); | 119 Node* if_default = Node::New(zone(), 2, common.IfDefault(), 1, &sw, false); |
106 Node* if_value1 = Node::New(zone(), 3, common.IfValue(1), 1, &sw, false); | 120 Node* if_value1 = Node::New(zone(), 3, common.IfValue(1), 1, &sw, false); |
107 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); | 121 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); |
108 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); | 122 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); |
109 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); | 123 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); |
110 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); | 124 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); |
111 EXPECT_EQ(if_default, result[2]); | 125 EXPECT_EQ(if_default, result[2]); |
112 } | 126 } |
113 | 127 |
114 } // namespace compiler | 128 } // namespace compiler |
115 } // namespace internal | 129 } // namespace internal |
116 } // namespace v8 | 130 } // namespace v8 |
OLD | NEW |