| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 if (lit->dont_optimize_reason() != kNoReason) { | 592 if (lit->dont_optimize_reason() != kNoReason) { |
| 593 shared_info->DisableOptimization(lit->dont_optimize_reason()); | 593 shared_info->DisableOptimization(lit->dont_optimize_reason()); |
| 594 } | 594 } |
| 595 shared_info->set_dont_crankshaft( | 595 shared_info->set_dont_crankshaft( |
| 596 shared_info->dont_crankshaft() || | 596 shared_info->dont_crankshaft() || |
| 597 (lit->flags() & AstProperties::kDontCrankshaft)); | 597 (lit->flags() & AstProperties::kDontCrankshaft)); |
| 598 } | 598 } |
| 599 return true; | 599 return true; |
| 600 } | 600 } |
| 601 | 601 |
| 602 bool UseTurboFan(Handle<SharedFunctionInfo> shared, BailoutId osr_ast_id) { | 602 bool UseTurboFan(Handle<SharedFunctionInfo> shared) { |
| 603 bool optimization_disabled = shared->optimization_disabled(); | 603 bool optimization_disabled = shared->optimization_disabled(); |
| 604 bool dont_crankshaft = shared->dont_crankshaft(); | 604 bool dont_crankshaft = shared->dont_crankshaft(); |
| 605 | 605 |
| 606 // Check the enabling conditions for Turbofan. | 606 // Check the enabling conditions for Turbofan. |
| 607 // 1. "use asm" code. | 607 // 1. "use asm" code. |
| 608 bool is_turbofanable_asm = | 608 bool is_turbofanable_asm = |
| 609 FLAG_turbo_asm && shared->asm_function() && !optimization_disabled; | 609 FLAG_turbo_asm && shared->asm_function() && !optimization_disabled; |
| 610 | 610 |
| 611 // 2. Fallback for features unsupported by Crankshaft. | 611 // 2. Fallback for features unsupported by Crankshaft. |
| 612 bool is_unsupported_by_crankshaft_but_turbofanable = | 612 bool is_unsupported_by_crankshaft_but_turbofanable = |
| 613 dont_crankshaft && strcmp(FLAG_turbo_filter, "~~") == 0 && | 613 dont_crankshaft && strcmp(FLAG_turbo_filter, "~~") == 0 && |
| 614 !optimization_disabled; | 614 !optimization_disabled; |
| 615 | 615 |
| 616 // 3. Explicitly enabled by the command-line filter. | 616 // 3. Explicitly enabled by the command-line filter. |
| 617 bool passes_turbo_filter = shared->PassesFilter(FLAG_turbo_filter); | 617 bool passes_turbo_filter = shared->PassesFilter(FLAG_turbo_filter); |
| 618 | 618 |
| 619 // If this is OSR request, OSR must be enabled by Turbofan. | 619 return is_turbofanable_asm || is_unsupported_by_crankshaft_but_turbofanable || |
| 620 bool passes_osr_test = FLAG_turbo_osr || osr_ast_id.IsNone(); | 620 passes_turbo_filter; |
| 621 | |
| 622 return (is_turbofanable_asm || | |
| 623 is_unsupported_by_crankshaft_but_turbofanable || | |
| 624 passes_turbo_filter) && | |
| 625 passes_osr_test; | |
| 626 } | 621 } |
| 627 | 622 |
| 628 bool GetOptimizedCodeNow(CompilationJob* job) { | 623 bool GetOptimizedCodeNow(CompilationJob* job) { |
| 629 CompilationInfo* info = job->info(); | 624 CompilationInfo* info = job->info(); |
| 630 Isolate* isolate = info->isolate(); | 625 Isolate* isolate = info->isolate(); |
| 631 | 626 |
| 632 // Parsing is not required when optimizing from existing bytecode. | 627 // Parsing is not required when optimizing from existing bytecode. |
| 633 if (!info->is_optimizing_from_bytecode()) { | 628 if (!info->is_optimizing_from_bytecode()) { |
| 634 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; | 629 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
| 635 } | 630 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 } | 713 } |
| 719 | 714 |
| 720 // Reset profiler ticks, function is no longer considered hot. | 715 // Reset profiler ticks, function is no longer considered hot. |
| 721 if (shared->is_compiled()) { | 716 if (shared->is_compiled()) { |
| 722 shared->code()->set_profiler_ticks(0); | 717 shared->code()->set_profiler_ticks(0); |
| 723 } | 718 } |
| 724 | 719 |
| 725 VMState<COMPILER> state(isolate); | 720 VMState<COMPILER> state(isolate); |
| 726 DCHECK(!isolate->has_pending_exception()); | 721 DCHECK(!isolate->has_pending_exception()); |
| 727 PostponeInterruptsScope postpone(isolate); | 722 PostponeInterruptsScope postpone(isolate); |
| 728 bool use_turbofan = UseTurboFan(shared, osr_ast_id); | 723 bool use_turbofan = UseTurboFan(shared); |
| 729 base::SmartPointer<CompilationJob> job( | 724 base::SmartPointer<CompilationJob> job( |
| 730 use_turbofan ? compiler::Pipeline::NewCompilationJob(function) | 725 use_turbofan ? compiler::Pipeline::NewCompilationJob(function) |
| 731 : new HCompilationJob(function)); | 726 : new HCompilationJob(function)); |
| 732 CompilationInfo* info = job->info(); | 727 CompilationInfo* info = job->info(); |
| 733 ParseInfo* parse_info = info->parse_info(); | 728 ParseInfo* parse_info = info->parse_info(); |
| 734 | 729 |
| 735 info->SetOptimizingForOsr(osr_ast_id); | 730 info->SetOptimizingForOsr(osr_ast_id); |
| 736 | 731 |
| 737 // Do not use Crankshaft/TurboFan if we need to be able to set break points. | 732 // Do not use Crankshaft/TurboFan if we need to be able to set break points. |
| 738 if (info->shared_info()->HasDebugInfo()) { | 733 if (info->shared_info()->HasDebugInfo()) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 if (FLAG_trace_opt) { | 915 if (FLAG_trace_opt) { |
| 921 PrintF("[found optimized code for "); | 916 PrintF("[found optimized code for "); |
| 922 function->ShortPrint(); | 917 function->ShortPrint(); |
| 923 PrintF(" during unoptimized compile]\n"); | 918 PrintF(" during unoptimized compile]\n"); |
| 924 } | 919 } |
| 925 DCHECK(function->shared()->is_compiled()); | 920 DCHECK(function->shared()->is_compiled()); |
| 926 return cached_code; | 921 return cached_code; |
| 927 } | 922 } |
| 928 } | 923 } |
| 929 | 924 |
| 930 // If the debugger is active, do not compile with turbofan unless we can | |
| 931 // deopt from turbofan code. | |
| 932 if (FLAG_turbo_asm && function->shared()->asm_function() && | |
| 933 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) && | |
| 934 !FLAG_turbo_osr) { | |
| 935 Handle<Code> code; | |
| 936 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT).ToHandle(&code)) { | |
| 937 DCHECK(function->shared()->is_compiled()); | |
| 938 return code; | |
| 939 } | |
| 940 } | |
| 941 | |
| 942 if (function->shared()->is_compiled()) { | 925 if (function->shared()->is_compiled()) { |
| 943 return Handle<Code>(function->shared()->code()); | 926 return Handle<Code>(function->shared()->code()); |
| 944 } | 927 } |
| 945 | 928 |
| 946 Zone zone(isolate->allocator()); | 929 Zone zone(isolate->allocator()); |
| 947 ParseInfo parse_info(&zone, function); | 930 ParseInfo parse_info(&zone, function); |
| 948 CompilationInfo info(&parse_info, function); | 931 CompilationInfo info(&parse_info, function); |
| 949 Handle<Code> result; | 932 Handle<Code> result; |
| 950 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); | 933 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); |
| 951 | 934 |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 MaybeHandle<Code> code; | 1743 MaybeHandle<Code> code; |
| 1761 if (cached.code != nullptr) code = handle(cached.code); | 1744 if (cached.code != nullptr) code = handle(cached.code); |
| 1762 Handle<Context> native_context(function->context()->native_context()); | 1745 Handle<Context> native_context(function->context()->native_context()); |
| 1763 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1746 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 1764 literals, BailoutId::None()); | 1747 literals, BailoutId::None()); |
| 1765 } | 1748 } |
| 1766 } | 1749 } |
| 1767 | 1750 |
| 1768 } // namespace internal | 1751 } // namespace internal |
| 1769 } // namespace v8 | 1752 } // namespace v8 |
| OLD | NEW |