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 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, | 35 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, |
36 "MockOperator", 0, 0, 0, 1, 1, 2); | 36 "MockOperator", 0, 0, 0, 1, 1, 2); |
37 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, | 37 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, |
38 "MockCallOperator", 0, 0, 0, 0, 0, 2); | 38 "MockCallOperator", 0, 0, 0, 0, 0, 2); |
39 | 39 |
40 const IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught; | |
41 | |
42 } // namespace | 40 } // namespace |
43 | 41 |
44 | 42 |
45 TEST_F(NodePropertiesTest, ReplaceUses) { | 43 TEST_F(NodePropertiesTest, ReplaceUses) { |
46 CommonOperatorBuilder common(zone()); | 44 CommonOperatorBuilder common(zone()); |
47 Node* node = NewMockNode(&kMockOperator); | 45 Node* node = NewMockNode(&kMockOperator); |
48 Node* effect = NewMockNode(&kMockOperator); | 46 Node* effect = NewMockNode(&kMockOperator); |
49 Node* use_value = NewMockNode(common.Return(), node); | 47 Node* use_value = NewMockNode(common.Return(), node); |
50 Node* use_effect = NewMockNode(common.EffectPhi(1), node); | 48 Node* use_effect = NewMockNode(common.EffectPhi(1), node); |
51 Node* use_success = NewMockNode(common.IfSuccess(), node); | 49 Node* use_success = NewMockNode(common.IfSuccess(), node); |
52 Node* use_exception = NewMockNode(common.IfException(kNoHint), effect, node); | 50 Node* use_exception = NewMockNode(common.IfException(), effect, node); |
53 Node* r_value = NewMockNode(&kMockOperator); | 51 Node* r_value = NewMockNode(&kMockOperator); |
54 Node* r_effect = NewMockNode(&kMockOperator); | 52 Node* r_effect = NewMockNode(&kMockOperator); |
55 Node* r_success = NewMockNode(&kMockOperator); | 53 Node* r_success = NewMockNode(&kMockOperator); |
56 Node* r_exception = NewMockNode(&kMockOperator); | 54 Node* r_exception = NewMockNode(&kMockOperator); |
57 NodeProperties::ReplaceUses(node, r_value, r_effect, r_success, r_exception); | 55 NodeProperties::ReplaceUses(node, r_value, r_effect, r_success, r_exception); |
58 EXPECT_EQ(r_value, use_value->InputAt(0)); | 56 EXPECT_EQ(r_value, use_value->InputAt(0)); |
59 EXPECT_EQ(r_effect, use_effect->InputAt(0)); | 57 EXPECT_EQ(r_effect, use_effect->InputAt(0)); |
60 EXPECT_EQ(r_success, use_success->InputAt(0)); | 58 EXPECT_EQ(r_success, use_success->InputAt(0)); |
61 EXPECT_EQ(r_exception, use_exception->InputAt(1)); | 59 EXPECT_EQ(r_exception, use_exception->InputAt(1)); |
62 EXPECT_EQ(0, node->UseCount()); | 60 EXPECT_EQ(0, node->UseCount()); |
(...skipping 29 matching lines...) Expand all Loading... |
92 NodeProperties::CollectControlProjections(branch, result, arraysize(result)); | 90 NodeProperties::CollectControlProjections(branch, result, arraysize(result)); |
93 EXPECT_EQ(if_true, result[0]); | 91 EXPECT_EQ(if_true, result[0]); |
94 EXPECT_EQ(if_false, result[1]); | 92 EXPECT_EQ(if_false, result[1]); |
95 } | 93 } |
96 | 94 |
97 | 95 |
98 TEST_F(NodePropertiesTest, CollectControlProjections_Call) { | 96 TEST_F(NodePropertiesTest, CollectControlProjections_Call) { |
99 Node* result[2]; | 97 Node* result[2]; |
100 CommonOperatorBuilder common(zone()); | 98 CommonOperatorBuilder common(zone()); |
101 Node* call = NewMockNode(&kMockCallOperator); | 99 Node* call = NewMockNode(&kMockCallOperator); |
102 Node* if_ex = NewMockNode(common.IfException(kNoHint), call, call); | 100 Node* if_ex = NewMockNode(common.IfException(), call, call); |
103 Node* if_ok = NewMockNode(common.IfSuccess(), call); | 101 Node* if_ok = NewMockNode(common.IfSuccess(), call); |
104 NodeProperties::CollectControlProjections(call, result, arraysize(result)); | 102 NodeProperties::CollectControlProjections(call, result, arraysize(result)); |
105 EXPECT_EQ(if_ok, result[0]); | 103 EXPECT_EQ(if_ok, result[0]); |
106 EXPECT_EQ(if_ex, result[1]); | 104 EXPECT_EQ(if_ex, result[1]); |
107 } | 105 } |
108 | 106 |
109 | 107 |
110 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) { | 108 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) { |
111 Node* result[3]; | 109 Node* result[3]; |
112 CommonOperatorBuilder common(zone()); | 110 CommonOperatorBuilder common(zone()); |
113 Node* sw = NewMockNode(common.Switch(3)); | 111 Node* sw = NewMockNode(common.Switch(3)); |
114 Node* if_default = NewMockNode(common.IfDefault(), sw); | 112 Node* if_default = NewMockNode(common.IfDefault(), sw); |
115 Node* if_value1 = NewMockNode(common.IfValue(1), sw); | 113 Node* if_value1 = NewMockNode(common.IfValue(1), sw); |
116 Node* if_value2 = NewMockNode(common.IfValue(2), sw); | 114 Node* if_value2 = NewMockNode(common.IfValue(2), sw); |
117 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); | 115 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); |
118 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); | 116 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); |
119 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); | 117 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); |
120 EXPECT_EQ(if_default, result[2]); | 118 EXPECT_EQ(if_default, result[2]); |
121 } | 119 } |
122 | 120 |
123 } // namespace compiler | 121 } // namespace compiler |
124 } // namespace internal | 122 } // namespace internal |
125 } // namespace v8 | 123 } // namespace v8 |
OLD | NEW |