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/escape-analysis-reducer.h" | 5 #include "src/compiler/escape-analysis-reducer.h" |
6 | 6 |
7 #include "src/compiler/all-nodes.h" | 7 #include "src/compiler/all-nodes.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/simplified-operator.h" |
| 10 #include "src/compiler/type-cache.h" |
9 #include "src/counters.h" | 11 #include "src/counters.h" |
10 | 12 |
11 namespace v8 { | 13 namespace v8 { |
12 namespace internal { | 14 namespace internal { |
13 namespace compiler { | 15 namespace compiler { |
14 | 16 |
15 #ifdef DEBUG | 17 #ifdef DEBUG |
16 #define TRACE(...) \ | 18 #define TRACE(...) \ |
17 do { \ | 19 do { \ |
18 if (FLAG_trace_turbo_escape) PrintF(__VA_ARGS__); \ | 20 if (FLAG_trace_turbo_escape) PrintF(__VA_ARGS__); \ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 break; | 81 break; |
80 default: | 82 default: |
81 break; | 83 break; |
82 } | 84 } |
83 } | 85 } |
84 if (!depends_on_object_state) { | 86 if (!depends_on_object_state) { |
85 fully_reduced_.Add(node->id()); | 87 fully_reduced_.Add(node->id()); |
86 } | 88 } |
87 return NoChange(); | 89 return NoChange(); |
88 } | 90 } |
| 91 case IrOpcode::kNewUnmappedArgumentsElements: |
| 92 arguments_elements_.insert(node); |
| 93 // Fallthrough. |
89 default: | 94 default: |
90 // TODO(sigurds): Change this to GetFrameStateInputCount once | 95 // TODO(sigurds): Change this to GetFrameStateInputCount once |
91 // it is working. For now we use EffectInputCount > 0 to determine | 96 // it is working. For now we use EffectInputCount > 0 to determine |
92 // whether a node might have a frame state input. | 97 // whether a node might have a frame state input. |
93 if (exists_virtual_allocate_ && node->op()->EffectInputCount() > 0) { | 98 if (exists_virtual_allocate_ && node->op()->EffectInputCount() > 0) { |
94 return ReduceFrameStateUses(node); | 99 return ReduceFrameStateUses(node); |
95 } | 100 } |
96 break; | 101 break; |
97 } | 102 } |
98 return NoChange(); | 103 return NoChange(); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 #ifdef DEBUG | 395 #ifdef DEBUG |
391 AllNodes all(zone(), jsgraph()->graph()); | 396 AllNodes all(zone(), jsgraph()->graph()); |
392 for (Node* node : all.reachable) { | 397 for (Node* node : all.reachable) { |
393 if (node->opcode() == IrOpcode::kAllocate) { | 398 if (node->opcode() == IrOpcode::kAllocate) { |
394 CHECK(!escape_analysis_->IsVirtual(node)); | 399 CHECK(!escape_analysis_->IsVirtual(node)); |
395 } | 400 } |
396 } | 401 } |
397 #endif // DEBUG | 402 #endif // DEBUG |
398 } | 403 } |
399 | 404 |
| 405 void EscapeAnalysisReducer::Finalize() { |
| 406 for (Node* node : arguments_elements_) { |
| 407 DCHECK(node->opcode() == IrOpcode::kNewUnmappedArgumentsElements); |
| 408 |
| 409 Node* arguments_frame = NodeProperties::GetValueInput(node, 0); |
| 410 if (arguments_frame->opcode() != IrOpcode::kArgumentsFrame) continue; |
| 411 Node* arguments_length = NodeProperties::GetValueInput(node, 1); |
| 412 if (arguments_length->opcode() != IrOpcode::kArgumentsLength) continue; |
| 413 |
| 414 bool escaping_use = false; |
| 415 ZoneVector<Node*> loads(zone()); |
| 416 for (Edge edge : node->use_edges()) { |
| 417 Node* use = edge.from(); |
| 418 if (!NodeProperties::IsValueEdge(edge)) continue; |
| 419 switch (use->opcode()) { |
| 420 case IrOpcode::kStateValues: |
| 421 case IrOpcode::kTypedStateValues: |
| 422 case IrOpcode::kObjectState: |
| 423 case IrOpcode::kTypedObjectState: |
| 424 break; |
| 425 case IrOpcode::kLoadElement: |
| 426 loads.push_back(use); |
| 427 break; |
| 428 case IrOpcode::kLoadField: |
| 429 if (FieldAccessOf(use->op()).offset == FixedArray::kLengthOffset) { |
| 430 loads.push_back(use); |
| 431 break; |
| 432 } |
| 433 // Fallthrough. |
| 434 default: |
| 435 if (!use->use_edges().empty()) { |
| 436 escaping_use = true; |
| 437 break; |
| 438 } |
| 439 } |
| 440 if (escaping_use) break; |
| 441 } |
| 442 if (!escaping_use) { |
| 443 int formal_parameter_count = |
| 444 FormalParameterCountOf(arguments_length->op()); |
| 445 int skipped_arguments = |
| 446 IsRestLengthOf(arguments_length->op()) ? formal_parameter_count : 0; |
| 447 Node* arguments_elements_state = jsgraph()->graph()->NewNode( |
| 448 jsgraph()->common()->ArgumentsElementsState(skipped_arguments)); |
| 449 NodeProperties::SetType(arguments_elements_state, Type::OtherInternal()); |
| 450 ReplaceWithValue(node, arguments_elements_state); |
| 451 |
| 452 ElementAccess stack_access; |
| 453 stack_access.base_is_tagged = BaseTaggedness::kUntaggedBase; |
| 454 // Reduce base address by {kPointerSize} such that (length - index) |
| 455 // resolves to the right position. |
| 456 stack_access.header_size = |
| 457 CommonFrameConstants::kFixedFrameSizeAboveFp - kPointerSize; |
| 458 stack_access.type = Type::NonInternal(); |
| 459 stack_access.machine_type = MachineType::AnyTagged(); |
| 460 stack_access.write_barrier_kind = WriteBarrierKind::kNoWriteBarrier; |
| 461 const Operator* load_stack_op = |
| 462 jsgraph()->simplified()->LoadElement(stack_access); |
| 463 |
| 464 for (Node* load : loads) { |
| 465 switch (load->opcode()) { |
| 466 case IrOpcode::kLoadElement: { |
| 467 Node* index = NodeProperties::GetValueInput(load, 1); |
| 468 // {offset} is a reverted index starting from 1. The base address is |
| 469 // adapted to allow offsets starting from 1. |
| 470 Node* offset = jsgraph()->graph()->NewNode( |
| 471 jsgraph()->simplified()->NumberSubtract(), arguments_length, |
| 472 index); |
| 473 NodeProperties::SetType(offset, |
| 474 TypeCache::Get().kArgumentsLengthType); |
| 475 NodeProperties::ReplaceValueInput(load, arguments_frame, 0); |
| 476 NodeProperties::ReplaceValueInput(load, offset, 1); |
| 477 NodeProperties::ChangeOp(load, load_stack_op); |
| 478 break; |
| 479 } |
| 480 case IrOpcode::kLoadField: { |
| 481 DCHECK_EQ(FieldAccessOf(load->op()).offset, |
| 482 FixedArray::kLengthOffset); |
| 483 Node* length = NodeProperties::GetValueInput(node, 1); |
| 484 ReplaceWithValue(load, length); |
| 485 break; |
| 486 } |
| 487 default: |
| 488 UNREACHABLE(); |
| 489 } |
| 490 } |
| 491 } |
| 492 } |
| 493 } |
| 494 |
400 } // namespace compiler | 495 } // namespace compiler |
401 } // namespace internal | 496 } // namespace internal |
402 } // namespace v8 | 497 } // namespace v8 |
OLD | NEW |