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 using testing::UnorderedElementsAre; | |
14 | 13 |
15 namespace v8 { | 14 namespace v8 { |
16 namespace internal { | 15 namespace internal { |
17 namespace compiler { | 16 namespace compiler { |
18 | 17 |
19 typedef TestWithZone NodePropertiesTest; | 18 class NodePropertiesTest : public TestWithZone { |
20 | 19 public: |
| 20 Node* NewMockNode(const Operator* op, int input_count, Node** inputs) { |
| 21 return Node::New(zone(), 0, op, input_count, inputs, false); |
| 22 } |
| 23 }; |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, | 27 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, |
25 "MockOperator", 0, 0, 0, 1, 0, 0); | 28 "MockOperator", 0, 0, 0, 1, 1, 2); |
26 const Operator kMockOpEffect(IrOpcode::kDead, Operator::kNoProperties, | |
27 "MockOpEffect", 0, 1, 0, 1, 1, 0); | |
28 const Operator kMockOpControl(IrOpcode::kDead, Operator::kNoProperties, | |
29 "MockOpControl", 0, 0, 1, 1, 0, 1); | |
30 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, | 29 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, |
31 "MockCallOperator", 0, 0, 0, 0, 0, 2); | 30 "MockCallOperator", 0, 0, 0, 0, 0, 2); |
32 | 31 |
33 } // namespace | 32 } // namespace |
34 | 33 |
35 | 34 |
36 TEST_F(NodePropertiesTest, ReplaceWithValue_ValueUse) { | 35 TEST_F(NodePropertiesTest, ReplaceUses) { |
37 CommonOperatorBuilder common(zone()); | 36 CommonOperatorBuilder common(zone()); |
38 Node* node = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 37 IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught; |
39 Node* use_value = Node::New(zone(), 0, common.Return(), 1, &node, false); | 38 Node* node = NewMockNode(&kMockOperator, 0, nullptr); |
40 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 39 Node* use_value = NewMockNode(common.Return(), 1, &node); |
41 NodeProperties::ReplaceWithValue(node, replacement); | 40 Node* use_effect = NewMockNode(common.EffectPhi(1), 1, &node); |
42 EXPECT_EQ(replacement, use_value->InputAt(0)); | 41 Node* use_success = NewMockNode(common.IfSuccess(), 1, &node); |
| 42 Node* use_exception = NewMockNode(common.IfException(kNoHint), 1, &node); |
| 43 Node* r_value = NewMockNode(&kMockOperator, 0, nullptr); |
| 44 Node* r_effect = NewMockNode(&kMockOperator, 0, nullptr); |
| 45 Node* r_success = NewMockNode(&kMockOperator, 0, nullptr); |
| 46 Node* r_exception = NewMockNode(&kMockOperator, 0, nullptr); |
| 47 NodeProperties::ReplaceUses(node, r_value, r_effect, r_success, r_exception); |
| 48 EXPECT_EQ(r_value, use_value->InputAt(0)); |
| 49 EXPECT_EQ(r_effect, use_effect->InputAt(0)); |
| 50 EXPECT_EQ(r_success, use_success->InputAt(0)); |
| 51 EXPECT_EQ(r_exception, use_exception->InputAt(0)); |
43 EXPECT_EQ(0, node->UseCount()); | 52 EXPECT_EQ(0, node->UseCount()); |
44 EXPECT_EQ(1, replacement->UseCount()); | 53 EXPECT_EQ(1, r_value->UseCount()); |
45 EXPECT_THAT(replacement->uses(), ElementsAre(use_value)); | 54 EXPECT_EQ(1, r_effect->UseCount()); |
| 55 EXPECT_EQ(1, r_success->UseCount()); |
| 56 EXPECT_EQ(1, r_exception->UseCount()); |
| 57 EXPECT_THAT(r_value->uses(), ElementsAre(use_value)); |
| 58 EXPECT_THAT(r_effect->uses(), ElementsAre(use_effect)); |
| 59 EXPECT_THAT(r_success->uses(), ElementsAre(use_success)); |
| 60 EXPECT_THAT(r_exception->uses(), ElementsAre(use_exception)); |
46 } | 61 } |
47 | 62 |
48 | 63 |
49 TEST_F(NodePropertiesTest, ReplaceWithValue_EffectUse) { | |
50 CommonOperatorBuilder common(zone()); | |
51 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | |
52 Node* node = Node::New(zone(), 0, &kMockOpEffect, 1, &start, false); | |
53 Node* use_effect = Node::New(zone(), 0, common.EffectPhi(1), 1, &node, false); | |
54 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | |
55 NodeProperties::ReplaceWithValue(node, replacement); | |
56 EXPECT_EQ(start, use_effect->InputAt(0)); | |
57 EXPECT_EQ(0, node->UseCount()); | |
58 EXPECT_EQ(2, start->UseCount()); | |
59 EXPECT_EQ(0, replacement->UseCount()); | |
60 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_effect, node)); | |
61 } | |
62 | |
63 | |
64 TEST_F(NodePropertiesTest, ReplaceWithValue_ControlUse) { | |
65 CommonOperatorBuilder common(zone()); | |
66 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | |
67 Node* node = Node::New(zone(), 0, &kMockOpControl, 1, &start, false); | |
68 Node* success = Node::New(zone(), 0, common.IfSuccess(), 1, &node, false); | |
69 Node* use_control = Node::New(zone(), 0, common.Merge(1), 1, &success, false); | |
70 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | |
71 NodeProperties::ReplaceWithValue(node, replacement); | |
72 EXPECT_EQ(start, use_control->InputAt(0)); | |
73 EXPECT_EQ(0, node->UseCount()); | |
74 EXPECT_EQ(2, start->UseCount()); | |
75 EXPECT_EQ(0, replacement->UseCount()); | |
76 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node)); | |
77 } | |
78 | |
79 | |
80 TEST_F(NodePropertiesTest, FindProjection) { | 64 TEST_F(NodePropertiesTest, FindProjection) { |
81 CommonOperatorBuilder common(zone()); | 65 CommonOperatorBuilder common(zone()); |
82 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | 66 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); |
83 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); | 67 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); |
84 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); | 68 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); |
85 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); | 69 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); |
86 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); | 70 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); |
87 EXPECT_THAT(NodeProperties::FindProjection(start, 2), IsNull()); | 71 EXPECT_THAT(NodeProperties::FindProjection(start, 2), IsNull()); |
88 EXPECT_THAT(NodeProperties::FindProjection(start, 1234567890), IsNull()); | 72 EXPECT_THAT(NodeProperties::FindProjection(start, 1234567890), IsNull()); |
89 } | 73 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); | 107 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); |
124 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); | 108 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); |
125 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); | 109 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); |
126 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); | 110 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); |
127 EXPECT_EQ(if_default, result[2]); | 111 EXPECT_EQ(if_default, result[2]); |
128 } | 112 } |
129 | 113 |
130 } // namespace compiler | 114 } // namespace compiler |
131 } // namespace internal | 115 } // namespace internal |
132 } // namespace v8 | 116 } // namespace v8 |
OLD | NEW |