| 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" | |
| 11 #include "src/compiler/compiler-source-position-table.h" | 10 #include "src/compiler/compiler-source-position-table.h" |
| 12 #include "src/compiler/linkage.h" | 11 #include "src/compiler/linkage.h" |
| 13 #include "src/compiler/operator-properties.h" | 12 #include "src/compiler/operator-properties.h" |
| 14 #include "src/interpreter/bytecodes.h" | 13 #include "src/interpreter/bytecodes.h" |
| 15 #include "src/objects-inl.h" | 14 #include "src/objects-inl.h" |
| 16 | 15 |
| 17 namespace v8 { | 16 namespace v8 { |
| 18 namespace internal { | 17 namespace internal { |
| 19 namespace compiler { | 18 namespace compiler { |
| 20 | 19 |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 &state_values_cache_, jsgraph()->OptimizedOutConstant(), | 630 &state_values_cache_, jsgraph()->OptimizedOutConstant(), |
| 632 liveness_analyzer()->local_count(), true, local_zone()); | 631 liveness_analyzer()->local_count(), true, local_zone()); |
| 633 liveness_analyzer()->Run(&replacer); | 632 liveness_analyzer()->Run(&replacer); |
| 634 if (FLAG_trace_environment_liveness) { | 633 if (FLAG_trace_environment_liveness) { |
| 635 OFStream os(stdout); | 634 OFStream os(stdout); |
| 636 liveness_analyzer()->Print(os); | 635 liveness_analyzer()->Print(os); |
| 637 } | 636 } |
| 638 } | 637 } |
| 639 | 638 |
| 640 void BytecodeGraphBuilder::VisitBytecodes(bool stack_check) { | 639 void BytecodeGraphBuilder::VisitBytecodes(bool stack_check) { |
| 641 BytecodeBranchAnalysis analysis(bytecode_array(), local_zone()); | 640 BytecodeAnalysis bytecode_analysis(bytecode_array(), local_zone()); |
| 642 BytecodeLoopAnalysis loop_analysis(bytecode_array(), &analysis, local_zone()); | 641 bytecode_analysis.Analyze(); |
| 643 analysis.Analyze(); | 642 set_bytecode_analysis(&bytecode_analysis); |
| 644 loop_analysis.Analyze(); | |
| 645 set_branch_analysis(&analysis); | |
| 646 set_loop_analysis(&loop_analysis); | |
| 647 | 643 |
| 648 interpreter::BytecodeArrayIterator iterator(bytecode_array()); | 644 interpreter::BytecodeArrayIterator iterator(bytecode_array()); |
| 649 set_bytecode_iterator(&iterator); | 645 set_bytecode_iterator(&iterator); |
| 650 SourcePositionTableIterator source_position_iterator( | 646 SourcePositionTableIterator source_position_iterator( |
| 651 bytecode_array()->source_position_table()); | 647 bytecode_array()->source_position_table()); |
| 652 | 648 |
| 653 BuildOSRNormalEntryPoint(); | 649 BuildOSRNormalEntryPoint(); |
| 654 for (; !iterator.done(); iterator.Advance()) { | 650 for (; !iterator.done(); iterator.Advance()) { |
| 655 int current_offset = iterator.current_offset(); | 651 int current_offset = iterator.current_offset(); |
| 656 UpdateCurrentSourcePosition(&source_position_iterator, current_offset); | 652 UpdateCurrentSourcePosition(&source_position_iterator, current_offset); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 670 switch (iterator.current_bytecode()) { | 666 switch (iterator.current_bytecode()) { |
| 671 #define BYTECODE_CASE(name, ...) \ | 667 #define BYTECODE_CASE(name, ...) \ |
| 672 case interpreter::Bytecode::k##name: \ | 668 case interpreter::Bytecode::k##name: \ |
| 673 Visit##name(); \ | 669 Visit##name(); \ |
| 674 break; | 670 break; |
| 675 BYTECODE_LIST(BYTECODE_CASE) | 671 BYTECODE_LIST(BYTECODE_CASE) |
| 676 #undef BYTECODE_CODE | 672 #undef BYTECODE_CODE |
| 677 } | 673 } |
| 678 } | 674 } |
| 679 } | 675 } |
| 680 | 676 set_bytecode_analysis(nullptr); |
| 681 set_branch_analysis(nullptr); | |
| 682 set_bytecode_iterator(nullptr); | 677 set_bytecode_iterator(nullptr); |
| 683 DCHECK(exception_handlers_.empty()); | 678 DCHECK(exception_handlers_.empty()); |
| 684 } | 679 } |
| 685 | 680 |
| 686 void BytecodeGraphBuilder::VisitLdaZero() { | 681 void BytecodeGraphBuilder::VisitLdaZero() { |
| 687 Node* node = jsgraph()->ZeroConstant(); | 682 Node* node = jsgraph()->ZeroConstant(); |
| 688 environment()->BindAccumulator(node); | 683 environment()->BindAccumulator(node); |
| 689 } | 684 } |
| 690 | 685 |
| 691 void BytecodeGraphBuilder::VisitLdaSmi() { | 686 void BytecodeGraphBuilder::VisitLdaSmi() { |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 void BytecodeGraphBuilder::SwitchToMergeEnvironment(int current_offset) { | 1893 void BytecodeGraphBuilder::SwitchToMergeEnvironment(int current_offset) { |
| 1899 if (merge_environments_[current_offset] != nullptr) { | 1894 if (merge_environments_[current_offset] != nullptr) { |
| 1900 if (environment() != nullptr) { | 1895 if (environment() != nullptr) { |
| 1901 merge_environments_[current_offset]->Merge(environment()); | 1896 merge_environments_[current_offset]->Merge(environment()); |
| 1902 } | 1897 } |
| 1903 set_environment(merge_environments_[current_offset]); | 1898 set_environment(merge_environments_[current_offset]); |
| 1904 } | 1899 } |
| 1905 } | 1900 } |
| 1906 | 1901 |
| 1907 void BytecodeGraphBuilder::BuildLoopHeaderEnvironment(int current_offset) { | 1902 void BytecodeGraphBuilder::BuildLoopHeaderEnvironment(int current_offset) { |
| 1908 if (branch_analysis()->backward_branches_target(current_offset)) { | 1903 if (bytecode_analysis()->IsLoopHeader(current_offset)) { |
| 1909 // Add loop header and store a copy so we can connect merged back | 1904 // Add loop header and store a copy so we can connect merged back |
| 1910 // edge inputs to the loop header. | 1905 // edge inputs to the loop header. |
| 1911 merge_environments_[current_offset] = environment()->CopyForLoop(); | 1906 merge_environments_[current_offset] = environment()->CopyForLoop(); |
| 1912 } | 1907 } |
| 1913 } | 1908 } |
| 1914 | 1909 |
| 1915 void BytecodeGraphBuilder::MergeIntoSuccessorEnvironment(int target_offset) { | 1910 void BytecodeGraphBuilder::MergeIntoSuccessorEnvironment(int target_offset) { |
| 1916 BuildLoopExitsForBranch(target_offset); | 1911 BuildLoopExitsForBranch(target_offset); |
| 1917 if (merge_environments_[target_offset] == nullptr) { | 1912 if (merge_environments_[target_offset] == nullptr) { |
| 1918 // Append merge nodes to the environment. We may merge here with another | 1913 // Append merge nodes to the environment. We may merge here with another |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1941 osr_env->PrepareForOsrEntry(); | 1936 osr_env->PrepareForOsrEntry(); |
| 1942 loop_env->Merge(osr_env); | 1937 loop_env->Merge(osr_env); |
| 1943 } | 1938 } |
| 1944 } | 1939 } |
| 1945 | 1940 |
| 1946 void BytecodeGraphBuilder::BuildOSRNormalEntryPoint() { | 1941 void BytecodeGraphBuilder::BuildOSRNormalEntryPoint() { |
| 1947 if (!osr_ast_id_.IsNone()) { | 1942 if (!osr_ast_id_.IsNone()) { |
| 1948 // For OSR add an {OsrNormalEntry} as the the top-level environment start. | 1943 // For OSR add an {OsrNormalEntry} as the the top-level environment start. |
| 1949 // It will be replaced with {Dead} by the OSR deconstruction. | 1944 // It will be replaced with {Dead} by the OSR deconstruction. |
| 1950 NewNode(common()->OsrNormalEntry()); | 1945 NewNode(common()->OsrNormalEntry()); |
| 1951 // Note that the requested OSR entry point must be the target of a backward | 1946 // Note that the requested OSR entry point must be the header of a loop. |
| 1952 // branch, otherwise there will not be a proper loop header available. | 1947 DCHECK(bytecode_analysis()->IsLoopHeader(osr_ast_id_.ToInt())); |
| 1953 DCHECK(branch_analysis()->backward_branches_target(osr_ast_id_.ToInt())); | |
| 1954 } | 1948 } |
| 1955 } | 1949 } |
| 1956 | 1950 |
| 1957 void BytecodeGraphBuilder::BuildLoopExitsForBranch(int target_offset) { | 1951 void BytecodeGraphBuilder::BuildLoopExitsForBranch(int target_offset) { |
| 1958 int origin_offset = bytecode_iterator().current_offset(); | 1952 int origin_offset = bytecode_iterator().current_offset(); |
| 1959 // Only build loop exits for forward edges. | 1953 // Only build loop exits for forward edges. |
| 1960 if (target_offset > origin_offset) { | 1954 if (target_offset > origin_offset) { |
| 1961 BuildLoopExitsUntilLoop(loop_analysis()->GetLoopOffsetFor(target_offset)); | 1955 BuildLoopExitsUntilLoop( |
| 1956 bytecode_analysis()->GetLoopOffsetFor(target_offset)); |
| 1962 } | 1957 } |
| 1963 } | 1958 } |
| 1964 | 1959 |
| 1965 void BytecodeGraphBuilder::BuildLoopExitsUntilLoop(int loop_offset) { | 1960 void BytecodeGraphBuilder::BuildLoopExitsUntilLoop(int loop_offset) { |
| 1966 int origin_offset = bytecode_iterator().current_offset(); | 1961 int origin_offset = bytecode_iterator().current_offset(); |
| 1967 int current_loop = loop_analysis()->GetLoopOffsetFor(origin_offset); | 1962 int current_loop = bytecode_analysis()->GetLoopOffsetFor(origin_offset); |
| 1968 while (loop_offset < current_loop) { | 1963 while (loop_offset < current_loop) { |
| 1969 Node* loop_node = merge_environments_[current_loop]->GetControlDependency(); | 1964 Node* loop_node = merge_environments_[current_loop]->GetControlDependency(); |
| 1970 environment()->PrepareForLoopExit(loop_node); | 1965 environment()->PrepareForLoopExit(loop_node); |
| 1971 current_loop = loop_analysis()->GetParentLoopFor(current_loop); | 1966 current_loop = bytecode_analysis()->GetParentLoopFor(current_loop); |
| 1972 } | 1967 } |
| 1973 } | 1968 } |
| 1974 | 1969 |
| 1975 void BytecodeGraphBuilder::BuildLoopExitsForFunctionExit() { | 1970 void BytecodeGraphBuilder::BuildLoopExitsForFunctionExit() { |
| 1976 BuildLoopExitsUntilLoop(-1); | 1971 BuildLoopExitsUntilLoop(-1); |
| 1977 } | 1972 } |
| 1978 | 1973 |
| 1979 void BytecodeGraphBuilder::BuildJump() { | 1974 void BytecodeGraphBuilder::BuildJump() { |
| 1980 MergeIntoSuccessorEnvironment(bytecode_iterator().GetJumpTargetOffset()); | 1975 MergeIntoSuccessorEnvironment(bytecode_iterator().GetJumpTargetOffset()); |
| 1981 } | 1976 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2231 it->source_position().ScriptOffset(), start_position_.InliningId())); | 2226 it->source_position().ScriptOffset(), start_position_.InliningId())); |
| 2232 it->Advance(); | 2227 it->Advance(); |
| 2233 } else { | 2228 } else { |
| 2234 DCHECK_GT(it->code_offset(), offset); | 2229 DCHECK_GT(it->code_offset(), offset); |
| 2235 } | 2230 } |
| 2236 } | 2231 } |
| 2237 | 2232 |
| 2238 } // namespace compiler | 2233 } // namespace compiler |
| 2239 } // namespace internal | 2234 } // namespace internal |
| 2240 } // namespace v8 | 2235 } // namespace v8 |
| OLD | NEW |