| 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/bytecode-graph-builder.h" | 5 #include "src/compiler/bytecode-graph-builder.h" | 
| 6 | 6 | 
| 7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" | 
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" | 
| 9 #include "src/compilation-info.h" | 9 #include "src/compilation-info.h" | 
| 10 #include "src/compiler/bytecode-branch-analysis.h" | 10 #include "src/compiler/bytecode-branch-analysis.h" | 
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 562 | 562 | 
| 563 | 563 | 
| 564 VectorSlotPair BytecodeGraphBuilder::CreateVectorSlotPair(int slot_id) { | 564 VectorSlotPair BytecodeGraphBuilder::CreateVectorSlotPair(int slot_id) { | 
| 565   FeedbackVectorSlot slot; | 565   FeedbackVectorSlot slot; | 
| 566   if (slot_id >= TypeFeedbackVector::kReservedIndexCount) { | 566   if (slot_id >= TypeFeedbackVector::kReservedIndexCount) { | 
| 567     slot = feedback_vector()->ToSlot(slot_id); | 567     slot = feedback_vector()->ToSlot(slot_id); | 
| 568   } | 568   } | 
| 569   return VectorSlotPair(feedback_vector(), slot); | 569   return VectorSlotPair(feedback_vector(), slot); | 
| 570 } | 570 } | 
| 571 | 571 | 
| 572 bool BytecodeGraphBuilder::CreateGraph() { | 572 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { | 
| 573   // Set up the basic structure of the graph. Outputs for {Start} are the formal | 573   // Set up the basic structure of the graph. Outputs for {Start} are the formal | 
| 574   // parameters (including the receiver) plus new target, number of arguments, | 574   // parameters (including the receiver) plus new target, number of arguments, | 
| 575   // context and closure. | 575   // context and closure. | 
| 576   int actual_parameter_count = bytecode_array()->parameter_count() + 4; | 576   int actual_parameter_count = bytecode_array()->parameter_count() + 4; | 
| 577   graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); | 577   graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); | 
| 578 | 578 | 
| 579   Environment env(this, bytecode_array()->register_count(), | 579   Environment env(this, bytecode_array()->register_count(), | 
| 580                   bytecode_array()->parameter_count(), graph()->start(), | 580                   bytecode_array()->parameter_count(), graph()->start(), | 
| 581                   GetFunctionContext()); | 581                   GetFunctionContext()); | 
| 582   set_environment(&env); | 582   set_environment(&env); | 
| 583 | 583 | 
| 584   VisitBytecodes(); | 584   VisitBytecodes(stack_check); | 
| 585 | 585 | 
| 586   // Finish the basic structure of the graph. | 586   // Finish the basic structure of the graph. | 
| 587   DCHECK_NE(0u, exit_controls_.size()); | 587   DCHECK_NE(0u, exit_controls_.size()); | 
| 588   int const input_count = static_cast<int>(exit_controls_.size()); | 588   int const input_count = static_cast<int>(exit_controls_.size()); | 
| 589   Node** const inputs = &exit_controls_.front(); | 589   Node** const inputs = &exit_controls_.front(); | 
| 590   Node* end = graph()->NewNode(common()->End(input_count), input_count, inputs); | 590   Node* end = graph()->NewNode(common()->End(input_count), input_count, inputs); | 
| 591   graph()->SetEnd(end); | 591   graph()->SetEnd(end); | 
| 592 | 592 | 
| 593   ClearNonLiveSlotsInFrameStates(); | 593   ClearNonLiveSlotsInFrameStates(); | 
| 594 | 594 | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 634   NonLiveFrameStateSlotReplacer replacer( | 634   NonLiveFrameStateSlotReplacer replacer( | 
| 635       &state_values_cache_, jsgraph()->OptimizedOutConstant(), | 635       &state_values_cache_, jsgraph()->OptimizedOutConstant(), | 
| 636       liveness_analyzer()->local_count(), true, local_zone()); | 636       liveness_analyzer()->local_count(), true, local_zone()); | 
| 637   liveness_analyzer()->Run(&replacer); | 637   liveness_analyzer()->Run(&replacer); | 
| 638   if (FLAG_trace_environment_liveness) { | 638   if (FLAG_trace_environment_liveness) { | 
| 639     OFStream os(stdout); | 639     OFStream os(stdout); | 
| 640     liveness_analyzer()->Print(os); | 640     liveness_analyzer()->Print(os); | 
| 641   } | 641   } | 
| 642 } | 642 } | 
| 643 | 643 | 
| 644 void BytecodeGraphBuilder::VisitBytecodes() { | 644 void BytecodeGraphBuilder::VisitBytecodes(bool stack_check) { | 
| 645   BytecodeBranchAnalysis analysis(bytecode_array(), local_zone()); | 645   BytecodeBranchAnalysis analysis(bytecode_array(), local_zone()); | 
| 646   BytecodeLoopAnalysis loop_analysis(bytecode_array(), &analysis, local_zone()); | 646   BytecodeLoopAnalysis loop_analysis(bytecode_array(), &analysis, local_zone()); | 
| 647   analysis.Analyze(); | 647   analysis.Analyze(); | 
| 648   loop_analysis.Analyze(); | 648   loop_analysis.Analyze(); | 
| 649   set_branch_analysis(&analysis); | 649   set_branch_analysis(&analysis); | 
| 650   set_loop_analysis(&loop_analysis); | 650   set_loop_analysis(&loop_analysis); | 
| 651 | 651 | 
| 652   interpreter::BytecodeArrayIterator iterator(bytecode_array()); | 652   interpreter::BytecodeArrayIterator iterator(bytecode_array()); | 
| 653   set_bytecode_iterator(&iterator); | 653   set_bytecode_iterator(&iterator); | 
| 654   SourcePositionTableIterator source_position_iterator( | 654   SourcePositionTableIterator source_position_iterator( | 
| 655       bytecode_array()->source_position_table()); | 655       bytecode_array()->source_position_table()); | 
| 656 | 656 | 
| 657   BuildOSRNormalEntryPoint(); | 657   BuildOSRNormalEntryPoint(); | 
| 658   while (!iterator.done()) { | 658   for (; !iterator.done(); iterator.Advance()) { | 
| 659     int current_offset = iterator.current_offset(); | 659     int current_offset = iterator.current_offset(); | 
| 660     UpdateCurrentSourcePosition(&source_position_iterator, current_offset); | 660     UpdateCurrentSourcePosition(&source_position_iterator, current_offset); | 
| 661     EnterAndExitExceptionHandlers(current_offset); | 661     EnterAndExitExceptionHandlers(current_offset); | 
| 662     SwitchToMergeEnvironment(current_offset); | 662     SwitchToMergeEnvironment(current_offset); | 
| 663     if (environment() != nullptr) { | 663     if (environment() != nullptr) { | 
| 664       BuildLoopHeaderEnvironment(current_offset); | 664       BuildLoopHeaderEnvironment(current_offset); | 
| 665       BuildOSRLoopEntryPoint(current_offset); | 665       BuildOSRLoopEntryPoint(current_offset); | 
| 666 | 666 | 
|  | 667       // Skip the first stack check if stack_check is false | 
|  | 668       if (!stack_check && | 
|  | 669           iterator.current_bytecode() == interpreter::Bytecode::kStackCheck) { | 
|  | 670         stack_check = true; | 
|  | 671         continue; | 
|  | 672       } | 
|  | 673 | 
| 667       switch (iterator.current_bytecode()) { | 674       switch (iterator.current_bytecode()) { | 
| 668 #define BYTECODE_CASE(name, ...)       \ | 675 #define BYTECODE_CASE(name, ...)       \ | 
| 669   case interpreter::Bytecode::k##name: \ | 676   case interpreter::Bytecode::k##name: \ | 
| 670     Visit##name();                     \ | 677     Visit##name();                     \ | 
| 671     break; | 678     break; | 
| 672         BYTECODE_LIST(BYTECODE_CASE) | 679         BYTECODE_LIST(BYTECODE_CASE) | 
| 673 #undef BYTECODE_CODE | 680 #undef BYTECODE_CODE | 
| 674       } | 681       } | 
| 675     } | 682     } | 
| 676     iterator.Advance(); |  | 
| 677   } | 683   } | 
| 678 | 684 | 
| 679   set_branch_analysis(nullptr); | 685   set_branch_analysis(nullptr); | 
| 680   set_bytecode_iterator(nullptr); | 686   set_bytecode_iterator(nullptr); | 
| 681   DCHECK(exception_handlers_.empty()); | 687   DCHECK(exception_handlers_.empty()); | 
| 682 } | 688 } | 
| 683 | 689 | 
| 684 void BytecodeGraphBuilder::VisitLdaZero() { | 690 void BytecodeGraphBuilder::VisitLdaZero() { | 
| 685   Node* node = jsgraph()->ZeroConstant(); | 691   Node* node = jsgraph()->ZeroConstant(); | 
| 686   environment()->BindAccumulator(node); | 692   environment()->BindAccumulator(node); | 
| (...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2234     source_positions_->set_current_position(it->source_position()); | 2240     source_positions_->set_current_position(it->source_position()); | 
| 2235     it->Advance(); | 2241     it->Advance(); | 
| 2236   } else { | 2242   } else { | 
| 2237     DCHECK_GT(it->code_offset(), offset); | 2243     DCHECK_GT(it->code_offset(), offset); | 
| 2238   } | 2244   } | 
| 2239 } | 2245 } | 
| 2240 | 2246 | 
| 2241 }  // namespace compiler | 2247 }  // namespace compiler | 
| 2242 }  // namespace internal | 2248 }  // namespace internal | 
| 2243 }  // namespace v8 | 2249 }  // namespace v8 | 
| OLD | NEW | 
|---|