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/bit-vector.h" | 5 #include "src/bit-vector.h" |
6 #include "src/compiler/escape-analysis.h" | 6 #include "src/compiler/escape-analysis.h" |
7 #include "src/compiler/escape-analysis-reducer.h" | 7 #include "src/compiler/escape-analysis-reducer.h" |
8 #include "src/compiler/graph-visualizer.h" | 8 #include "src/compiler/graph-visualizer.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ExpectVirtual(allocation); | 325 ExpectVirtual(allocation); |
326 ExpectReplacementPhi(load, object1, object2); | 326 ExpectReplacementPhi(load, object1, object2); |
327 Node* replacement_phi = escape_analysis()->GetReplacement(load); | 327 Node* replacement_phi = escape_analysis()->GetReplacement(load); |
328 | 328 |
329 Transformation(); | 329 Transformation(); |
330 | 330 |
331 ASSERT_EQ(replacement_phi, NodeProperties::GetValueInput(result, 0)); | 331 ASSERT_EQ(replacement_phi, NodeProperties::GetValueInput(result, 0)); |
332 } | 332 } |
333 | 333 |
334 | 334 |
| 335 TEST_F(EscapeAnalysisTest, BranchEscapeOne) { |
| 336 Node* object1 = Constant(1); |
| 337 Node* object2 = Constant(2); |
| 338 Node* index = graph()->NewNode(common()->Parameter(0), start()); |
| 339 BeginRegion(); |
| 340 Node* allocation = Allocate(Constant(kPointerSize)); |
| 341 Store(FieldAccessAtIndex(0), allocation, object1); |
| 342 Node* finish = FinishRegion(allocation); |
| 343 Branch(); |
| 344 Node* ifFalse = IfFalse(); |
| 345 Node* ifTrue = IfTrue(); |
| 346 Node* effect1 = |
| 347 Store(FieldAccessAtIndex(0), allocation, object1, finish, ifFalse); |
| 348 Node* effect2 = StoreElement(MakeElementAccess(0), allocation, index, object2, |
| 349 finish, ifTrue); |
| 350 Node* merge = Merge2(ifFalse, ifTrue); |
| 351 Node* phi = graph()->NewNode(common()->EffectPhi(2), effect1, effect2, merge); |
| 352 Node* load = Load(FieldAccessAtIndex(0), finish, phi, merge); |
| 353 Node* result = Return(load, phi); |
| 354 EndGraph(); |
| 355 |
| 356 Analysis(); |
| 357 |
| 358 ExpectEscaped(allocation); |
| 359 ExpectReplacement(load, nullptr); |
| 360 |
| 361 Transformation(); |
| 362 |
| 363 ASSERT_EQ(load, NodeProperties::GetValueInput(result, 0)); |
| 364 } |
| 365 |
| 366 |
| 367 TEST_F(EscapeAnalysisTest, BranchEscapeThroughStore) { |
| 368 Node* object1 = Constant(1); |
| 369 Node* object2 = Constant(2); |
| 370 BeginRegion(); |
| 371 Node* allocation = Allocate(Constant(kPointerSize)); |
| 372 Store(FieldAccessAtIndex(0), allocation, object1); |
| 373 FinishRegion(allocation); |
| 374 BeginRegion(); |
| 375 Node* allocation2 = Allocate(Constant(kPointerSize)); |
| 376 Store(FieldAccessAtIndex(0), allocation, object2); |
| 377 Node* finish2 = FinishRegion(allocation2); |
| 378 Branch(); |
| 379 Node* ifFalse = IfFalse(); |
| 380 Node* ifTrue = IfTrue(); |
| 381 Node* effect1 = |
| 382 Store(FieldAccessAtIndex(0), allocation, allocation2, finish2, ifFalse); |
| 383 Node* merge = Merge2(ifFalse, ifTrue); |
| 384 Node* phi = graph()->NewNode(common()->EffectPhi(2), effect1, finish2, merge); |
| 385 Node* load = Load(FieldAccessAtIndex(0), finish2, phi, merge); |
| 386 Node* result = Return(allocation, phi); |
| 387 EndGraph(); |
| 388 graph()->end()->AppendInput(zone(), load); |
| 389 |
| 390 Analysis(); |
| 391 |
| 392 ExpectEscaped(allocation); |
| 393 ExpectEscaped(allocation2); |
| 394 ExpectReplacement(load, nullptr); |
| 395 |
| 396 Transformation(); |
| 397 |
| 398 ASSERT_EQ(allocation, NodeProperties::GetValueInput(result, 0)); |
| 399 } |
| 400 |
| 401 |
335 TEST_F(EscapeAnalysisTest, DanglingLoadOrder) { | 402 TEST_F(EscapeAnalysisTest, DanglingLoadOrder) { |
336 Node* object1 = Constant(1); | 403 Node* object1 = Constant(1); |
337 Node* object2 = Constant(2); | 404 Node* object2 = Constant(2); |
338 Node* allocation = Allocate(Constant(kPointerSize)); | 405 Node* allocation = Allocate(Constant(kPointerSize)); |
339 Node* store1 = Store(FieldAccessAtIndex(0), allocation, object1); | 406 Node* store1 = Store(FieldAccessAtIndex(0), allocation, object1); |
340 Node* load1 = Load(FieldAccessAtIndex(0), allocation); | 407 Node* load1 = Load(FieldAccessAtIndex(0), allocation); |
341 Node* store2 = Store(FieldAccessAtIndex(0), allocation, object2); | 408 Node* store2 = Store(FieldAccessAtIndex(0), allocation, object2); |
342 Node* load2 = Load(FieldAccessAtIndex(0), allocation, store1); | 409 Node* load2 = Load(FieldAccessAtIndex(0), allocation, store1); |
343 Node* result = Return(load2); | 410 Node* result = Return(load2); |
344 EndGraph(); | 411 EndGraph(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 ASSERT_EQ(object1, NodeProperties::GetValueInput(object_state, 0)); | 503 ASSERT_EQ(object1, NodeProperties::GetValueInput(object_state, 0)); |
437 ASSERT_EQ(object_state, NodeProperties::GetValueInput(object_state, 1)); | 504 ASSERT_EQ(object_state, NodeProperties::GetValueInput(object_state, 1)); |
438 | 505 |
439 Node* object_state2 = NodeProperties::GetValueInput(state_values1, 0); | 506 Node* object_state2 = NodeProperties::GetValueInput(state_values1, 0); |
440 ASSERT_EQ(object_state, object_state2); | 507 ASSERT_EQ(object_state, object_state2); |
441 } | 508 } |
442 | 509 |
443 } // namespace compiler | 510 } // namespace compiler |
444 } // namespace internal | 511 } // namespace internal |
445 } // namespace v8 | 512 } // namespace v8 |
OLD | NEW |