Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: test/unittests/compiler/node-properties-unittest.cc

Issue 1179543002: [turbofan] Make IfException projections consume effects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 class NodePropertiesTest : public TestWithZone { 18 class NodePropertiesTest : public TestWithZone {
19 public: 19 public:
20 Node* NewMockNode(const Operator* op, int input_count, Node** inputs) { 20 Node* NewMockNode(const Operator* op) {
21 return Node::New(zone(), 0, op, input_count, inputs, false); 21 return Node::New(zone(), 0, op, 0, nullptr, false);
22 }
23 Node* NewMockNode(const Operator* op, Node* n1) {
24 Node* nodes[] = {n1};
25 return Node::New(zone(), 0, op, arraysize(nodes), nodes, false);
26 }
27 Node* NewMockNode(const Operator* op, Node* n1, Node* n2) {
28 Node* nodes[] = {n1, n2};
29 return Node::New(zone(), 0, op, arraysize(nodes), nodes, false);
22 } 30 }
23 }; 31 };
24 32
25 namespace { 33 namespace {
26 34
27 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties, 35 const Operator kMockOperator(IrOpcode::kDead, Operator::kNoProperties,
28 "MockOperator", 0, 0, 0, 1, 1, 2); 36 "MockOperator", 0, 0, 0, 1, 1, 2);
29 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties, 37 const Operator kMockCallOperator(IrOpcode::kCall, Operator::kNoProperties,
30 "MockCallOperator", 0, 0, 0, 0, 0, 2); 38 "MockCallOperator", 0, 0, 0, 0, 0, 2);
31 39
40 const IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught;
41
32 } // namespace 42 } // namespace
33 43
34 44
35 TEST_F(NodePropertiesTest, ReplaceUses) { 45 TEST_F(NodePropertiesTest, ReplaceUses) {
36 CommonOperatorBuilder common(zone()); 46 CommonOperatorBuilder common(zone());
37 IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught; 47 Node* node = NewMockNode(&kMockOperator);
38 Node* node = NewMockNode(&kMockOperator, 0, nullptr); 48 Node* effect = NewMockNode(&kMockOperator);
39 Node* use_value = NewMockNode(common.Return(), 1, &node); 49 Node* use_value = NewMockNode(common.Return(), node);
40 Node* use_effect = NewMockNode(common.EffectPhi(1), 1, &node); 50 Node* use_effect = NewMockNode(common.EffectPhi(1), node);
41 Node* use_success = NewMockNode(common.IfSuccess(), 1, &node); 51 Node* use_success = NewMockNode(common.IfSuccess(), node);
42 Node* use_exception = NewMockNode(common.IfException(kNoHint), 1, &node); 52 Node* use_exception = NewMockNode(common.IfException(kNoHint), effect, node);
43 Node* r_value = NewMockNode(&kMockOperator, 0, nullptr); 53 Node* r_value = NewMockNode(&kMockOperator);
44 Node* r_effect = NewMockNode(&kMockOperator, 0, nullptr); 54 Node* r_effect = NewMockNode(&kMockOperator);
45 Node* r_success = NewMockNode(&kMockOperator, 0, nullptr); 55 Node* r_success = NewMockNode(&kMockOperator);
46 Node* r_exception = NewMockNode(&kMockOperator, 0, nullptr); 56 Node* r_exception = NewMockNode(&kMockOperator);
47 NodeProperties::ReplaceUses(node, r_value, r_effect, r_success, r_exception); 57 NodeProperties::ReplaceUses(node, r_value, r_effect, r_success, r_exception);
48 EXPECT_EQ(r_value, use_value->InputAt(0)); 58 EXPECT_EQ(r_value, use_value->InputAt(0));
49 EXPECT_EQ(r_effect, use_effect->InputAt(0)); 59 EXPECT_EQ(r_effect, use_effect->InputAt(0));
50 EXPECT_EQ(r_success, use_success->InputAt(0)); 60 EXPECT_EQ(r_success, use_success->InputAt(0));
51 EXPECT_EQ(r_exception, use_exception->InputAt(0)); 61 EXPECT_EQ(r_exception, use_exception->InputAt(1));
52 EXPECT_EQ(0, node->UseCount()); 62 EXPECT_EQ(0, node->UseCount());
53 EXPECT_EQ(1, r_value->UseCount()); 63 EXPECT_EQ(1, r_value->UseCount());
54 EXPECT_EQ(1, r_effect->UseCount()); 64 EXPECT_EQ(1, r_effect->UseCount());
55 EXPECT_EQ(1, r_success->UseCount()); 65 EXPECT_EQ(1, r_success->UseCount());
56 EXPECT_EQ(1, r_exception->UseCount()); 66 EXPECT_EQ(1, r_exception->UseCount());
57 EXPECT_THAT(r_value->uses(), ElementsAre(use_value)); 67 EXPECT_THAT(r_value->uses(), ElementsAre(use_value));
58 EXPECT_THAT(r_effect->uses(), ElementsAre(use_effect)); 68 EXPECT_THAT(r_effect->uses(), ElementsAre(use_effect));
59 EXPECT_THAT(r_success->uses(), ElementsAre(use_success)); 69 EXPECT_THAT(r_success->uses(), ElementsAre(use_success));
60 EXPECT_THAT(r_exception->uses(), ElementsAre(use_exception)); 70 EXPECT_THAT(r_exception->uses(), ElementsAre(use_exception));
61 } 71 }
62 72
63 73
64 TEST_F(NodePropertiesTest, FindProjection) { 74 TEST_F(NodePropertiesTest, FindProjection) {
65 CommonOperatorBuilder common(zone()); 75 CommonOperatorBuilder common(zone());
66 Node* start = Node::New(zone(), 0, common.Start(1), 0, nullptr, false); 76 Node* start = NewMockNode(common.Start(1));
67 Node* proj0 = Node::New(zone(), 1, common.Projection(0), 1, &start, false); 77 Node* proj0 = NewMockNode(common.Projection(0), start);
68 Node* proj1 = Node::New(zone(), 2, common.Projection(1), 1, &start, false); 78 Node* proj1 = NewMockNode(common.Projection(1), start);
69 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0)); 79 EXPECT_EQ(proj0, NodeProperties::FindProjection(start, 0));
70 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1)); 80 EXPECT_EQ(proj1, NodeProperties::FindProjection(start, 1));
71 EXPECT_THAT(NodeProperties::FindProjection(start, 2), IsNull()); 81 EXPECT_THAT(NodeProperties::FindProjection(start, 2), IsNull());
72 EXPECT_THAT(NodeProperties::FindProjection(start, 1234567890), IsNull()); 82 EXPECT_THAT(NodeProperties::FindProjection(start, 1234567890), IsNull());
73 } 83 }
74 84
75 85
76 TEST_F(NodePropertiesTest, CollectControlProjections_Branch) { 86 TEST_F(NodePropertiesTest, CollectControlProjections_Branch) {
77 Node* result[2]; 87 Node* result[2];
78 CommonOperatorBuilder common(zone()); 88 CommonOperatorBuilder common(zone());
79 Node* branch = Node::New(zone(), 1, common.Branch(), 0, nullptr, false); 89 Node* branch = NewMockNode(common.Branch());
80 Node* if_false = Node::New(zone(), 2, common.IfFalse(), 1, &branch, false); 90 Node* if_false = NewMockNode(common.IfFalse(), branch);
81 Node* if_true = Node::New(zone(), 3, common.IfTrue(), 1, &branch, false); 91 Node* if_true = NewMockNode(common.IfTrue(), branch);
82 NodeProperties::CollectControlProjections(branch, result, arraysize(result)); 92 NodeProperties::CollectControlProjections(branch, result, arraysize(result));
83 EXPECT_EQ(if_true, result[0]); 93 EXPECT_EQ(if_true, result[0]);
84 EXPECT_EQ(if_false, result[1]); 94 EXPECT_EQ(if_false, result[1]);
85 } 95 }
86 96
87 97
88 TEST_F(NodePropertiesTest, CollectControlProjections_Call) { 98 TEST_F(NodePropertiesTest, CollectControlProjections_Call) {
89 Node* result[2]; 99 Node* result[2];
90 CommonOperatorBuilder common(zone()); 100 CommonOperatorBuilder common(zone());
91 IfExceptionHint h = IfExceptionHint::kLocallyUncaught; 101 Node* call = NewMockNode(&kMockCallOperator);
92 Node* call = Node::New(zone(), 1, &kMockCallOperator, 0, nullptr, false); 102 Node* if_ex = NewMockNode(common.IfException(kNoHint), call, call);
93 Node* if_ex = Node::New(zone(), 2, common.IfException(h), 1, &call, false); 103 Node* if_ok = NewMockNode(common.IfSuccess(), call);
94 Node* if_ok = Node::New(zone(), 3, common.IfSuccess(), 1, &call, false);
95 NodeProperties::CollectControlProjections(call, result, arraysize(result)); 104 NodeProperties::CollectControlProjections(call, result, arraysize(result));
96 EXPECT_EQ(if_ok, result[0]); 105 EXPECT_EQ(if_ok, result[0]);
97 EXPECT_EQ(if_ex, result[1]); 106 EXPECT_EQ(if_ex, result[1]);
98 } 107 }
99 108
100 109
101 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) { 110 TEST_F(NodePropertiesTest, CollectControlProjections_Switch) {
102 Node* result[3]; 111 Node* result[3];
103 CommonOperatorBuilder common(zone()); 112 CommonOperatorBuilder common(zone());
104 Node* sw = Node::New(zone(), 1, common.Switch(3), 0, nullptr, false); 113 Node* sw = NewMockNode(common.Switch(3));
105 Node* if_default = Node::New(zone(), 2, common.IfDefault(), 1, &sw, false); 114 Node* if_default = NewMockNode(common.IfDefault(), sw);
106 Node* if_value1 = Node::New(zone(), 3, common.IfValue(1), 1, &sw, false); 115 Node* if_value1 = NewMockNode(common.IfValue(1), sw);
107 Node* if_value2 = Node::New(zone(), 4, common.IfValue(2), 1, &sw, false); 116 Node* if_value2 = NewMockNode(common.IfValue(2), sw);
108 NodeProperties::CollectControlProjections(sw, result, arraysize(result)); 117 NodeProperties::CollectControlProjections(sw, result, arraysize(result));
109 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2)); 118 EXPECT_THAT(result[0], AnyOf(if_value1, if_value2));
110 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2)); 119 EXPECT_THAT(result[1], AnyOf(if_value1, if_value2));
111 EXPECT_EQ(if_default, result[2]); 120 EXPECT_EQ(if_default, result[2]);
112 } 121 }
113 122
114 } // namespace compiler 123 } // namespace compiler
115 } // namespace internal 124 } // namespace internal
116 } // namespace v8 125 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/graph-reducer-unittest.cc ('k') | test/unittests/compiler/scheduler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698