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

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

Issue 851263002: [turbofan] Initial attempt to cleanup Node and related classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « test/unittests/compiler/node-properties-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/compiler/node.h"
6 #include "src/compiler/operator.h"
7 #include "test/unittests/test-utils.h"
8 #include "testing/gmock-support.h"
9
10 using testing::ElementsAre;
11 using testing::UnorderedElementsAre;
12
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16
17 typedef TestWithZone NodeTest;
18
19
20 namespace {
21
22 const IrOpcode::Value kOpcode0 = static_cast<IrOpcode::Value>(0);
23 const IrOpcode::Value kOpcode1 = static_cast<IrOpcode::Value>(1);
24 const IrOpcode::Value kOpcode2 = static_cast<IrOpcode::Value>(2);
25
26 const Operator kOp0(kOpcode0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 0, 0);
27 const Operator kOp1(kOpcode1, Operator::kNoProperties, "Op1", 1, 0, 0, 1, 0, 0);
28 const Operator kOp2(kOpcode2, Operator::kNoProperties, "Op2", 2, 0, 0, 1, 0, 0);
29
30 } // namespace
31
32
33 TEST_F(NodeTest, New) {
34 Node* const node = Node::New(zone(), 1, &kOp0, 0, nullptr, false);
35 EXPECT_EQ(1, node->id());
36 EXPECT_EQ(0, node->UseCount());
37 EXPECT_TRUE(node->uses().empty());
38 EXPECT_EQ(0, node->InputCount());
39 EXPECT_TRUE(node->inputs().empty());
40 EXPECT_EQ(&kOp0, node->op());
41 EXPECT_EQ(kOpcode0, node->opcode());
42 }
43
44
45 TEST_F(NodeTest, NewWithInputs) {
46 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
47 EXPECT_EQ(0, n0->UseCount());
48 EXPECT_EQ(0, n0->InputCount());
49 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
50 EXPECT_EQ(1, n0->UseCount());
51 EXPECT_EQ(n1, n0->UseAt(0));
52 EXPECT_EQ(0, n1->UseCount());
53 EXPECT_EQ(1, n1->InputCount());
54 EXPECT_EQ(n0, n1->InputAt(0));
55 Node* n0_n1[] = {n0, n1};
56 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false);
57 EXPECT_EQ(2, n0->UseCount());
58 EXPECT_EQ(n1, n0->UseAt(0));
59 EXPECT_EQ(n2, n0->UseAt(1));
60 EXPECT_EQ(2, n2->InputCount());
61 EXPECT_EQ(n0, n2->InputAt(0));
62 EXPECT_EQ(n1, n2->InputAt(1));
63 }
64
65
66 TEST_F(NodeTest, InputIteratorEmpty) {
67 Node* node = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
68 EXPECT_EQ(node->inputs().begin(), node->inputs().end());
69 }
70
71
72 TEST_F(NodeTest, InputIteratorOne) {
73 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
74 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
75 EXPECT_THAT(n1->inputs(), ElementsAre(n0));
76 }
77
78
79 TEST_F(NodeTest, InputIteratorTwo) {
80 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
81 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
82 Node* n0_n1[] = {n0, n1};
83 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false);
84 EXPECT_THAT(n2->inputs(), ElementsAre(n0, n1));
85 }
86
87
88 TEST_F(NodeTest, UseIteratorEmpty) {
89 Node* node = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
90 EXPECT_EQ(node->uses().begin(), node->uses().end());
91 }
92
93
94 TEST_F(NodeTest, UseIteratorOne) {
95 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
96 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
97 EXPECT_THAT(n0->uses(), ElementsAre(n1));
98 }
99
100
101 TEST_F(NodeTest, UseIteratorTwo) {
102 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
103 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
104 Node* n0_n1[] = {n0, n1};
105 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false);
106 EXPECT_THAT(n0->uses(), UnorderedElementsAre(n1, n2));
107 }
108
109
110 TEST_F(NodeTest, OwnedBy) {
111 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
112 EXPECT_FALSE(n0->OwnedBy(n0));
113 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
114 EXPECT_FALSE(n0->OwnedBy(n0));
115 EXPECT_FALSE(n1->OwnedBy(n1));
116 EXPECT_TRUE(n0->OwnedBy(n1));
117 Node* n0_n1[] = {n0, n1};
118 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false);
119 EXPECT_FALSE(n0->OwnedBy(n0));
120 EXPECT_FALSE(n1->OwnedBy(n1));
121 EXPECT_FALSE(n2->OwnedBy(n2));
122 EXPECT_FALSE(n0->OwnedBy(n1));
123 EXPECT_FALSE(n0->OwnedBy(n2));
124 EXPECT_TRUE(n1->OwnedBy(n2));
125 n2->ReplaceInput(0, n2);
126 EXPECT_TRUE(n0->OwnedBy(n1));
127 EXPECT_TRUE(n1->OwnedBy(n2));
128 n2->ReplaceInput(1, n0);
129 EXPECT_FALSE(n0->OwnedBy(n1));
130 EXPECT_FALSE(n1->OwnedBy(n2));
131 }
132
133
134 TEST_F(NodeTest, ReplaceUsesNone) {
135 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
136 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
137 Node* n0_n1[] = {n0, n1};
138 Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false);
139 Node* node = Node::New(zone(), 42, &kOp0, 0, nullptr, false);
140 EXPECT_TRUE(node->uses().empty());
141 node->ReplaceUses(n0);
142 EXPECT_TRUE(node->uses().empty());
143 node->ReplaceUses(n1);
144 EXPECT_TRUE(node->uses().empty());
145 node->ReplaceUses(n2);
146 EXPECT_TRUE(node->uses().empty());
147 }
148
149
150 TEST_F(NodeTest, AppendInput) {
151 Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
152 Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
153 Node* node = Node::New(zone(), 12345, &kOp0, 0, nullptr, true);
154 EXPECT_TRUE(node->inputs().empty());
155 node->AppendInput(zone(), n0);
156 EXPECT_FALSE(node->inputs().empty());
157 EXPECT_THAT(node->inputs(), ElementsAre(n0));
158 node->AppendInput(zone(), n1);
159 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1));
160 node->AppendInput(zone(), n0);
161 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0));
162 node->AppendInput(zone(), n0);
163 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0));
164 node->AppendInput(zone(), n1);
165 EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0, n1));
166 }
167
168 } // namespace compiler
169 } // namespace internal
170 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/node-properties-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698