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

Side by Side Diff: test/unittests/compiler/dead-code-elimination-unittest.cc

Issue 1513543003: [turbofan] Make MachineType a pair of enums. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moar rebase Created 5 years 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/dead-code-elimination.h" 6 #include "src/compiler/dead-code-elimination.h"
7 #include "test/unittests/compiler/graph-reducer-unittest.h" 7 #include "test/unittests/compiler/graph-reducer-unittest.h"
8 #include "test/unittests/compiler/graph-unittest.h" 8 #include "test/unittests/compiler/graph-unittest.h"
9 #include "test/unittests/compiler/node-test-utils.h" 9 #include "test/unittests/compiler/node-test-utils.h"
10 #include "testing/gmock-support.h" 10 #include "testing/gmock-support.h"
(...skipping 18 matching lines...) Expand all
29 29
30 Reduction Reduce(Node* node) { 30 Reduction Reduce(Node* node) {
31 StrictMock<MockAdvancedReducerEditor> editor; 31 StrictMock<MockAdvancedReducerEditor> editor;
32 return Reduce(&editor, node); 32 return Reduce(&editor, node);
33 } 33 }
34 }; 34 };
35 35
36 36
37 namespace { 37 namespace {
38 38
39 const MachineType kMachineTypes[] = { 39 const MachineRepresentation kMachineRepresentations[] = {
40 kMachFloat32, kMachFloat64, kMachInt8, kMachUint8, kMachInt16, 40 MachineRepresentation::kBit, MachineRepresentation::kWord8,
41 kMachUint16, kMachInt32, kMachUint32, kMachInt64, kMachUint64, 41 MachineRepresentation::kWord16, MachineRepresentation::kWord32,
42 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16, 42 MachineRepresentation::kWord64, MachineRepresentation::kFloat32,
43 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged}; 43 MachineRepresentation::kFloat64, MachineRepresentation::kTagged};
44 44
45 45
46 const int kMaxInputs = 16; 46 const int kMaxInputs = 16;
47 47
48 48
49 const Operator kOp0(0, Operator::kNoProperties, "Op0", 1, 1, 1, 1, 1, 1); 49 const Operator kOp0(0, Operator::kNoProperties, "Op0", 1, 1, 1, 1, 1, 1);
50 50
51 } // namespace 51 } // namespace
52 52
53 53
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 TEST_F(DeadCodeEliminationTest, MergeWithOneLiveAndOneDeadInput) { 184 TEST_F(DeadCodeEliminationTest, MergeWithOneLiveAndOneDeadInput) {
185 Node* const v0 = Parameter(0); 185 Node* const v0 = Parameter(0);
186 Node* const v1 = Parameter(1); 186 Node* const v1 = Parameter(1);
187 Node* const c0 = 187 Node* const c0 =
188 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start()); 188 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start());
189 Node* const c1 = graph()->NewNode(common()->Dead()); 189 Node* const c1 = graph()->NewNode(common()->Dead());
190 Node* const e0 = graph()->NewNode(&kOp0, v0, graph()->start(), c0); 190 Node* const e0 = graph()->NewNode(&kOp0, v0, graph()->start(), c0);
191 Node* const e1 = graph()->NewNode(&kOp0, v1, graph()->start(), c1); 191 Node* const e1 = graph()->NewNode(&kOp0, v1, graph()->start(), c1);
192 Node* const merge = graph()->NewNode(common()->Merge(2), c0, c1); 192 Node* const merge = graph()->NewNode(common()->Merge(2), c0, c1);
193 Node* const phi = 193 Node* const phi = graph()->NewNode(
194 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), v0, v1, merge); 194 common()->Phi(MachineRepresentation::kTagged, 2), v0, v1, merge);
195 Node* const ephi = graph()->NewNode(common()->EffectPhi(2), e0, e1, merge); 195 Node* const ephi = graph()->NewNode(common()->EffectPhi(2), e0, e1, merge);
196 StrictMock<MockAdvancedReducerEditor> editor; 196 StrictMock<MockAdvancedReducerEditor> editor;
197 EXPECT_CALL(editor, Replace(phi, v0)); 197 EXPECT_CALL(editor, Replace(phi, v0));
198 EXPECT_CALL(editor, Replace(ephi, e0)); 198 EXPECT_CALL(editor, Replace(ephi, e0));
199 Reduction const r = Reduce(&editor, merge); 199 Reduction const r = Reduce(&editor, merge);
200 ASSERT_TRUE(r.Changed()); 200 ASSERT_TRUE(r.Changed());
201 EXPECT_EQ(c0, r.replacement()); 201 EXPECT_EQ(c0, r.replacement());
202 } 202 }
203 203
204 204
205 TEST_F(DeadCodeEliminationTest, MergeWithTwoLiveAndTwoDeadInputs) { 205 TEST_F(DeadCodeEliminationTest, MergeWithTwoLiveAndTwoDeadInputs) {
206 Node* const v0 = Parameter(0); 206 Node* const v0 = Parameter(0);
207 Node* const v1 = Parameter(1); 207 Node* const v1 = Parameter(1);
208 Node* const v2 = Parameter(2); 208 Node* const v2 = Parameter(2);
209 Node* const v3 = Parameter(3); 209 Node* const v3 = Parameter(3);
210 Node* const c0 = 210 Node* const c0 =
211 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start()); 211 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start());
212 Node* const c1 = graph()->NewNode(common()->Dead()); 212 Node* const c1 = graph()->NewNode(common()->Dead());
213 Node* const c2 = graph()->NewNode(common()->Dead()); 213 Node* const c2 = graph()->NewNode(common()->Dead());
214 Node* const c3 = graph()->NewNode(&kOp0, v3, graph()->start(), c0); 214 Node* const c3 = graph()->NewNode(&kOp0, v3, graph()->start(), c0);
215 Node* const e0 = graph()->start(); 215 Node* const e0 = graph()->start();
216 Node* const e1 = graph()->NewNode(&kOp0, v1, e0, c0); 216 Node* const e1 = graph()->NewNode(&kOp0, v1, e0, c0);
217 Node* const e2 = graph()->NewNode(&kOp0, v2, e1, c0); 217 Node* const e2 = graph()->NewNode(&kOp0, v2, e1, c0);
218 Node* const e3 = graph()->NewNode(&kOp0, v3, graph()->start(), c3); 218 Node* const e3 = graph()->NewNode(&kOp0, v3, graph()->start(), c3);
219 Node* const merge = graph()->NewNode(common()->Merge(4), c0, c1, c2, c3); 219 Node* const merge = graph()->NewNode(common()->Merge(4), c0, c1, c2, c3);
220 Node* const phi = 220 Node* const phi = graph()->NewNode(
221 graph()->NewNode(common()->Phi(kMachAnyTagged, 4), v0, v1, v2, v3, merge); 221 common()->Phi(MachineRepresentation::kTagged, 4), v0, v1, v2, v3, merge);
222 Node* const ephi = 222 Node* const ephi =
223 graph()->NewNode(common()->EffectPhi(4), e0, e1, e2, e3, merge); 223 graph()->NewNode(common()->EffectPhi(4), e0, e1, e2, e3, merge);
224 StrictMock<MockAdvancedReducerEditor> editor; 224 StrictMock<MockAdvancedReducerEditor> editor;
225 EXPECT_CALL(editor, Revisit(phi)); 225 EXPECT_CALL(editor, Revisit(phi));
226 EXPECT_CALL(editor, Revisit(ephi)); 226 EXPECT_CALL(editor, Revisit(ephi));
227 Reduction const r = Reduce(&editor, merge); 227 Reduction const r = Reduce(&editor, merge);
228 ASSERT_TRUE(r.Changed()); 228 ASSERT_TRUE(r.Changed());
229 EXPECT_THAT(r.replacement(), IsMerge(c0, c3)); 229 EXPECT_THAT(r.replacement(), IsMerge(c0, c3));
230 EXPECT_THAT(phi, IsPhi(kMachAnyTagged, v0, v3, r.replacement())); 230 EXPECT_THAT(phi,
231 IsPhi(MachineRepresentation::kTagged, v0, v3, r.replacement()));
231 EXPECT_THAT(ephi, IsEffectPhi(e0, e3, r.replacement())); 232 EXPECT_THAT(ephi, IsEffectPhi(e0, e3, r.replacement()));
232 } 233 }
233 234
234 235
235 // ----------------------------------------------------------------------------- 236 // -----------------------------------------------------------------------------
236 // Loop 237 // Loop
237 238
238 239
239 TEST_F(DeadCodeEliminationTest, LoopWithDeadFirstInput) { 240 TEST_F(DeadCodeEliminationTest, LoopWithDeadFirstInput) {
240 Node* inputs[kMaxInputs + 1]; 241 Node* inputs[kMaxInputs + 1];
(...skipping 26 matching lines...) Expand all
267 268
268 TEST_F(DeadCodeEliminationTest, LoopWithOneLiveAndOneDeadInput) { 269 TEST_F(DeadCodeEliminationTest, LoopWithOneLiveAndOneDeadInput) {
269 Node* const v0 = Parameter(0); 270 Node* const v0 = Parameter(0);
270 Node* const v1 = Parameter(1); 271 Node* const v1 = Parameter(1);
271 Node* const c0 = 272 Node* const c0 =
272 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start()); 273 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start());
273 Node* const c1 = graph()->NewNode(common()->Dead()); 274 Node* const c1 = graph()->NewNode(common()->Dead());
274 Node* const e0 = graph()->NewNode(&kOp0, v0, graph()->start(), c0); 275 Node* const e0 = graph()->NewNode(&kOp0, v0, graph()->start(), c0);
275 Node* const e1 = graph()->NewNode(&kOp0, v1, graph()->start(), c1); 276 Node* const e1 = graph()->NewNode(&kOp0, v1, graph()->start(), c1);
276 Node* const loop = graph()->NewNode(common()->Loop(2), c0, c1); 277 Node* const loop = graph()->NewNode(common()->Loop(2), c0, c1);
277 Node* const phi = 278 Node* const phi = graph()->NewNode(
278 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), v0, v1, loop); 279 common()->Phi(MachineRepresentation::kTagged, 2), v0, v1, loop);
279 Node* const ephi = graph()->NewNode(common()->EffectPhi(2), e0, e1, loop); 280 Node* const ephi = graph()->NewNode(common()->EffectPhi(2), e0, e1, loop);
280 Node* const terminate = graph()->NewNode(common()->Terminate(), ephi, loop); 281 Node* const terminate = graph()->NewNode(common()->Terminate(), ephi, loop);
281 StrictMock<MockAdvancedReducerEditor> editor; 282 StrictMock<MockAdvancedReducerEditor> editor;
282 EXPECT_CALL(editor, Replace(phi, v0)); 283 EXPECT_CALL(editor, Replace(phi, v0));
283 EXPECT_CALL(editor, Replace(ephi, e0)); 284 EXPECT_CALL(editor, Replace(ephi, e0));
284 EXPECT_CALL(editor, Replace(terminate, IsDead())); 285 EXPECT_CALL(editor, Replace(terminate, IsDead()));
285 Reduction const r = Reduce(&editor, loop); 286 Reduction const r = Reduce(&editor, loop);
286 ASSERT_TRUE(r.Changed()); 287 ASSERT_TRUE(r.Changed());
287 EXPECT_EQ(c0, r.replacement()); 288 EXPECT_EQ(c0, r.replacement());
288 } 289 }
289 290
290 291
291 TEST_F(DeadCodeEliminationTest, LoopWithTwoLiveAndTwoDeadInputs) { 292 TEST_F(DeadCodeEliminationTest, LoopWithTwoLiveAndTwoDeadInputs) {
292 Node* const v0 = Parameter(0); 293 Node* const v0 = Parameter(0);
293 Node* const v1 = Parameter(1); 294 Node* const v1 = Parameter(1);
294 Node* const v2 = Parameter(2); 295 Node* const v2 = Parameter(2);
295 Node* const v3 = Parameter(3); 296 Node* const v3 = Parameter(3);
296 Node* const c0 = 297 Node* const c0 =
297 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start()); 298 graph()->NewNode(&kOp0, v0, graph()->start(), graph()->start());
298 Node* const c1 = graph()->NewNode(common()->Dead()); 299 Node* const c1 = graph()->NewNode(common()->Dead());
299 Node* const c2 = graph()->NewNode(common()->Dead()); 300 Node* const c2 = graph()->NewNode(common()->Dead());
300 Node* const c3 = graph()->NewNode(&kOp0, v3, graph()->start(), c0); 301 Node* const c3 = graph()->NewNode(&kOp0, v3, graph()->start(), c0);
301 Node* const e0 = graph()->start(); 302 Node* const e0 = graph()->start();
302 Node* const e1 = graph()->NewNode(&kOp0, v1, e0, c0); 303 Node* const e1 = graph()->NewNode(&kOp0, v1, e0, c0);
303 Node* const e2 = graph()->NewNode(&kOp0, v2, e1, c0); 304 Node* const e2 = graph()->NewNode(&kOp0, v2, e1, c0);
304 Node* const e3 = graph()->NewNode(&kOp0, v3, graph()->start(), c3); 305 Node* const e3 = graph()->NewNode(&kOp0, v3, graph()->start(), c3);
305 Node* const loop = graph()->NewNode(common()->Loop(4), c0, c1, c2, c3); 306 Node* const loop = graph()->NewNode(common()->Loop(4), c0, c1, c2, c3);
306 Node* const phi = 307 Node* const phi = graph()->NewNode(
307 graph()->NewNode(common()->Phi(kMachAnyTagged, 4), v0, v1, v2, v3, loop); 308 common()->Phi(MachineRepresentation::kTagged, 4), v0, v1, v2, v3, loop);
308 Node* const ephi = 309 Node* const ephi =
309 graph()->NewNode(common()->EffectPhi(4), e0, e1, e2, e3, loop); 310 graph()->NewNode(common()->EffectPhi(4), e0, e1, e2, e3, loop);
310 StrictMock<MockAdvancedReducerEditor> editor; 311 StrictMock<MockAdvancedReducerEditor> editor;
311 EXPECT_CALL(editor, Revisit(phi)); 312 EXPECT_CALL(editor, Revisit(phi));
312 EXPECT_CALL(editor, Revisit(ephi)); 313 EXPECT_CALL(editor, Revisit(ephi));
313 Reduction const r = Reduce(&editor, loop); 314 Reduction const r = Reduce(&editor, loop);
314 ASSERT_TRUE(r.Changed()); 315 ASSERT_TRUE(r.Changed());
315 EXPECT_THAT(r.replacement(), IsLoop(c0, c3)); 316 EXPECT_THAT(r.replacement(), IsLoop(c0, c3));
316 EXPECT_THAT(phi, IsPhi(kMachAnyTagged, v0, v3, r.replacement())); 317 EXPECT_THAT(phi,
318 IsPhi(MachineRepresentation::kTagged, v0, v3, r.replacement()));
317 EXPECT_THAT(ephi, IsEffectPhi(e0, e3, r.replacement())); 319 EXPECT_THAT(ephi, IsEffectPhi(e0, e3, r.replacement()));
318 } 320 }
319 321
320 322
321 // ----------------------------------------------------------------------------- 323 // -----------------------------------------------------------------------------
322 // Phi 324 // Phi
323 325
324 326
325 TEST_F(DeadCodeEliminationTest, PhiWithDeadControlInput) { 327 TEST_F(DeadCodeEliminationTest, PhiWithDeadControlInput) {
326 Node* inputs[kMaxInputs + 1]; 328 Node* inputs[kMaxInputs + 1];
327 TRACED_FOREACH(MachineType, type, kMachineTypes) { 329 TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) {
328 TRACED_FORRANGE(int, input_count, 1, kMaxInputs) { 330 TRACED_FORRANGE(int, input_count, 1, kMaxInputs) {
329 for (int i = 0; i < input_count; ++i) { 331 for (int i = 0; i < input_count; ++i) {
330 inputs[i] = Parameter(i); 332 inputs[i] = Parameter(i);
331 } 333 }
332 inputs[input_count] = graph()->NewNode(common()->Dead()); 334 inputs[input_count] = graph()->NewNode(common()->Dead());
333 Reduction const r = Reduce(graph()->NewNode( 335 Reduction const r = Reduce(graph()->NewNode(
334 common()->Phi(type, input_count), input_count + 1, inputs)); 336 common()->Phi(rep, input_count), input_count + 1, inputs));
335 ASSERT_TRUE(r.Changed()); 337 ASSERT_TRUE(r.Changed());
336 EXPECT_THAT(r.replacement(), IsDead()); 338 EXPECT_THAT(r.replacement(), IsDead());
337 } 339 }
338 } 340 }
339 } 341 }
340 342
341 343
342 // ----------------------------------------------------------------------------- 344 // -----------------------------------------------------------------------------
343 // EffectPhi 345 // EffectPhi
344 346
(...skipping 21 matching lines...) Expand all
366 Reduction const r = 368 Reduction const r =
367 Reduce(graph()->NewNode(common()->Terminate(), graph()->start(), 369 Reduce(graph()->NewNode(common()->Terminate(), graph()->start(),
368 graph()->NewNode(common()->Dead()))); 370 graph()->NewNode(common()->Dead())));
369 ASSERT_TRUE(r.Changed()); 371 ASSERT_TRUE(r.Changed());
370 EXPECT_THAT(r.replacement(), IsDead()); 372 EXPECT_THAT(r.replacement(), IsDead());
371 } 373 }
372 374
373 } // namespace compiler 375 } // namespace compiler
374 } // namespace internal 376 } // namespace internal
375 } // namespace v8 377 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/control-flow-optimizer-unittest.cc ('k') | test/unittests/compiler/diamond-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698