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; |
(...skipping 14 matching lines...) Expand all Loading... | |
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, | 29 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, |
30 "MockCallOperator", 0, 0, 0, 0, 0, 2); | 30 "MockCallOperator", 0, 0, 0, 0, 0, 2); |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 | 34 |
35 // TODO(titzer): These tests shouldn't depend on use list order. | |
36 | |
35 TEST_F(NodePropertiesTest, ReplaceWithValue_ValueUse) { | 37 TEST_F(NodePropertiesTest, ReplaceWithValue_ValueUse) { |
36 CommonOperatorBuilder common(zone()); | 38 CommonOperatorBuilder common(zone()); |
37 Node* node = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 39 Node* node = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); |
38 Node* use_value = Node::New(zone(), 0, common.Return(), 1, &node, false); | 40 Node* use_value = Node::New(zone(), 0, common.Return(), 1, &node, false); |
39 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 41 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); |
40 NodeProperties::ReplaceWithValue(node, replacement); | 42 NodeProperties::ReplaceWithValue(node, replacement); |
41 EXPECT_EQ(replacement, use_value->InputAt(0)); | 43 EXPECT_EQ(replacement, use_value->InputAt(0)); |
42 EXPECT_EQ(0, node->UseCount()); | 44 EXPECT_EQ(0, node->UseCount()); |
43 EXPECT_EQ(1, replacement->UseCount()); | 45 EXPECT_EQ(1, replacement->UseCount()); |
44 EXPECT_THAT(replacement->uses(), ElementsAre(use_value)); | 46 EXPECT_THAT(replacement->uses(), ElementsAre(use_value)); |
45 } | 47 } |
46 | 48 |
47 | 49 |
48 TEST_F(NodePropertiesTest, ReplaceWithValue_EffectUse) { | 50 TEST_F(NodePropertiesTest, ReplaceWithValue_EffectUse) { |
49 CommonOperatorBuilder common(zone()); | 51 CommonOperatorBuilder common(zone()); |
50 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | 52 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); |
51 Node* node = Node::New(zone(), 0, &kMockOpEffect, 1, &start, false); | 53 Node* node = Node::New(zone(), 0, &kMockOpEffect, 1, &start, false); |
52 Node* use_effect = Node::New(zone(), 0, common.EffectPhi(1), 1, &node, false); | 54 Node* use_effect = Node::New(zone(), 0, common.EffectPhi(1), 1, &node, false); |
53 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 55 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); |
54 NodeProperties::ReplaceWithValue(node, replacement); | 56 NodeProperties::ReplaceWithValue(node, replacement); |
55 EXPECT_EQ(start, use_effect->InputAt(0)); | 57 EXPECT_EQ(start, use_effect->InputAt(0)); |
56 EXPECT_EQ(0, node->UseCount()); | 58 EXPECT_EQ(0, node->UseCount()); |
57 EXPECT_EQ(2, start->UseCount()); | 59 EXPECT_EQ(2, start->UseCount()); |
58 EXPECT_EQ(0, replacement->UseCount()); | 60 EXPECT_EQ(0, replacement->UseCount()); |
59 EXPECT_THAT(start->uses(), ElementsAre(node, use_effect)); | 61 EXPECT_THAT(start->uses(), ElementsAre(use_effect, node)); |
Michael Starzinger
2015/03/19 09:40:08
Can we use UnorderedElementsAre here instead and a
titzer
2015/03/19 10:10:31
Done.
| |
60 } | 62 } |
61 | 63 |
62 | 64 |
63 TEST_F(NodePropertiesTest, ReplaceWithValue_ControlUse) { | 65 TEST_F(NodePropertiesTest, ReplaceWithValue_ControlUse) { |
64 CommonOperatorBuilder common(zone()); | 66 CommonOperatorBuilder common(zone()); |
65 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | 67 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); |
66 Node* node = Node::New(zone(), 0, &kMockOpControl, 1, &start, false); | 68 Node* node = Node::New(zone(), 0, &kMockOpControl, 1, &start, false); |
67 Node* success = Node::New(zone(), 0, common.IfSuccess(), 1, &node, false); | 69 Node* success = Node::New(zone(), 0, common.IfSuccess(), 1, &node, false); |
68 Node* use_control = Node::New(zone(), 0, common.Merge(1), 1, &success, false); | 70 Node* use_control = Node::New(zone(), 0, common.Merge(1), 1, &success, false); |
69 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); | 71 Node* replacement = Node::New(zone(), 0, &kMockOperator, 0, nullptr, false); |
70 NodeProperties::ReplaceWithValue(node, replacement); | 72 NodeProperties::ReplaceWithValue(node, replacement); |
71 EXPECT_EQ(start, use_control->InputAt(0)); | 73 EXPECT_EQ(start, use_control->InputAt(0)); |
72 EXPECT_EQ(0, node->UseCount()); | 74 EXPECT_EQ(0, node->UseCount()); |
73 EXPECT_EQ(2, start->UseCount()); | 75 EXPECT_EQ(2, start->UseCount()); |
74 EXPECT_EQ(0, replacement->UseCount()); | 76 EXPECT_EQ(0, replacement->UseCount()); |
75 EXPECT_THAT(start->uses(), ElementsAre(node, use_control)); | 77 EXPECT_THAT(start->uses(), ElementsAre(use_control, node)); |
Michael Starzinger
2015/03/19 09:40:08
Likewise.
titzer
2015/03/19 10:10:31
Done.
| |
76 } | 78 } |
77 | 79 |
78 | 80 |
79 TEST_F(NodePropertiesTest, FindProjection) { | 81 TEST_F(NodePropertiesTest, FindProjection) { |
80 CommonOperatorBuilder common(zone()); | 82 CommonOperatorBuilder common(zone()); |
81 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); | 83 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); |
82 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); | 84 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); |
83 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); | 85 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); |
84 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); | 86 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); |
85 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); | 87 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); | 123 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); |
122 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); | 124 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); |
123 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); | 125 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); |
124 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); | 126 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); |
125 EXPECT_EQ(if_default, result[2]); | 127 EXPECT_EQ(if_default, result[2]); |
126 } | 128 } |
127 | 129 |
128 } // namespace compiler | 130 } // namespace compiler |
129 } // namespace internal | 131 } // namespace internal |
130 } // namespace v8 | 132 } // namespace v8 |
OLD | NEW |