Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/compiler.cc

Issue 1884143003: [compiler] Allow optimization of top-level eval code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-compiler-simplify-13
Patch Set: Fix comment typo. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 time_taken_to_optimize_, 412 time_taken_to_optimize_,
413 time_taken_to_codegen_); 413 time_taken_to_codegen_);
414 } 414 }
415 } 415 }
416 416
417 // ---------------------------------------------------------------------------- 417 // ----------------------------------------------------------------------------
418 // Local helper methods that make up the compilation pipeline. 418 // Local helper methods that make up the compilation pipeline.
419 419
420 namespace { 420 namespace {
421 421
422 bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
423 return shared->is_toplevel() && shared->script()->IsScript() &&
424 Script::cast(shared->script())->compilation_type() ==
425 Script::COMPILATION_TYPE_EVAL;
426 }
427
422 void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 428 void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
423 CompilationInfo* info) { 429 CompilationInfo* info) {
424 // Log the code generation. If source information is available include 430 // Log the code generation. If source information is available include
425 // script name and line number. Check explicitly whether logging is 431 // script name and line number. Check explicitly whether logging is
426 // enabled as finding the line number is not free. 432 // enabled as finding the line number is not free.
427 if (info->isolate()->logger()->is_logging_code_events() || 433 if (info->isolate()->logger()->is_logging_code_events() ||
428 info->isolate()->cpu_profiler()->is_profiling()) { 434 info->isolate()->cpu_profiler()->is_profiling()) {
429 Handle<SharedFunctionInfo> shared = info->shared_info(); 435 Handle<SharedFunctionInfo> shared = info->shared_info();
430 Handle<Script> script = info->parse_info()->script(); 436 Handle<Script> script = info->parse_info()->script();
431 Handle<AbstractCode> abstract_code = 437 Handle<AbstractCode> abstract_code =
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 PrintF("]\n"); 765 PrintF("]\n");
760 } 766 }
761 return cached_code; 767 return cached_code;
762 } 768 }
763 769
764 // Reset profiler ticks, function is no longer considered hot. 770 // Reset profiler ticks, function is no longer considered hot.
765 if (shared->is_compiled()) { 771 if (shared->is_compiled()) {
766 shared->code()->set_profiler_ticks(0); 772 shared->code()->set_profiler_ticks(0);
767 } 773 }
768 774
769 // TODO(mstarzinger): We cannot properly deserialize a scope chain containing
770 // an eval scope and hence would fail at parsing the eval source again.
771 if (shared->disable_optimization_reason() == kEval) {
772 return MaybeHandle<Code>();
773 }
774
775 VMState<COMPILER> state(isolate); 775 VMState<COMPILER> state(isolate);
776 DCHECK(!isolate->has_pending_exception()); 776 DCHECK(!isolate->has_pending_exception());
777 PostponeInterruptsScope postpone(isolate); 777 PostponeInterruptsScope postpone(isolate);
778 bool use_turbofan = UseTurboFan(shared, osr_ast_id); 778 bool use_turbofan = UseTurboFan(shared, osr_ast_id);
779 base::SmartPointer<CompilationJob> job( 779 base::SmartPointer<CompilationJob> job(
780 use_turbofan ? compiler::Pipeline::NewCompilationJob(function) 780 use_turbofan ? compiler::Pipeline::NewCompilationJob(function)
781 : new HCompilationJob(function)); 781 : new HCompilationJob(function));
782 CompilationInfo* info = job->info(); 782 CompilationInfo* info = job->info();
783 ParseInfo* parse_info = info->parse_info();
783 784
784 info->SetOptimizingForOsr(osr_ast_id); 785 info->SetOptimizingForOsr(osr_ast_id);
785 786
786 // Do not use Crankshaft/TurboFan if we need to be able to set break points. 787 // Do not use Crankshaft/TurboFan if we need to be able to set break points.
787 if (info->shared_info()->HasDebugInfo()) { 788 if (info->shared_info()->HasDebugInfo()) {
788 info->AbortOptimization(kFunctionBeingDebugged); 789 info->AbortOptimization(kFunctionBeingDebugged);
789 return MaybeHandle<Code>(); 790 return MaybeHandle<Code>();
790 } 791 }
791 792
792 // Do not use Crankshaft/TurboFan on a generator function. 793 // Do not use Crankshaft/TurboFan on a generator function.
(...skipping 14 matching lines...) Expand all
807 CanonicalHandleScope canonical(isolate); 808 CanonicalHandleScope canonical(isolate);
808 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); 809 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate);
809 TRACE_EVENT0("v8", "V8.OptimizeCode"); 810 TRACE_EVENT0("v8", "V8.OptimizeCode");
810 811
811 // TurboFan can optimize directly from existing bytecode. 812 // TurboFan can optimize directly from existing bytecode.
812 if (FLAG_turbo_from_bytecode && use_turbofan && 813 if (FLAG_turbo_from_bytecode && use_turbofan &&
813 info->shared_info()->HasBytecodeArray()) { 814 info->shared_info()->HasBytecodeArray()) {
814 info->MarkAsOptimizeFromBytecode(); 815 info->MarkAsOptimizeFromBytecode();
815 } 816 }
816 817
818 if (IsEvalToplevel(shared)) {
819 parse_info->set_eval();
820 if (function->context()->IsNativeContext()) parse_info->set_global();
821 parse_info->set_toplevel();
822 parse_info->set_allow_lazy_parsing(false);
823 parse_info->set_lazy(false);
824 }
825
817 if (mode == Compiler::CONCURRENT) { 826 if (mode == Compiler::CONCURRENT) {
818 if (GetOptimizedCodeLater(job.get())) { 827 if (GetOptimizedCodeLater(job.get())) {
819 job.Detach(); // The background recompile job owns this now. 828 job.Detach(); // The background recompile job owns this now.
820 return isolate->builtins()->InOptimizationQueue(); 829 return isolate->builtins()->InOptimizationQueue();
821 } 830 }
822 } else { 831 } else {
823 info->set_osr_frame(osr_frame); 832 info->set_osr_frame(osr_frame);
824 if (GetOptimizedCodeNow(job.get())) return info->code(); 833 if (GetOptimizedCodeNow(job.get())) return info->code();
825 } 834 }
826 835
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) 1004 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
996 .ToHandle(&opt_code)) { 1005 .ToHandle(&opt_code)) {
997 result = opt_code; 1006 result = opt_code;
998 } 1007 }
999 } 1008 }
1000 1009
1001 return result; 1010 return result;
1002 } 1011 }
1003 1012
1004 1013
1005 inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
1006 return shared->is_toplevel() && shared->script()->IsScript() &&
1007 Script::cast(shared->script())->compilation_type() ==
1008 Script::COMPILATION_TYPE_EVAL;
1009 }
1010
1011 Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral( 1014 Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
1012 Isolate* isolate, FunctionLiteral* literal, Handle<Script> script) { 1015 Isolate* isolate, FunctionLiteral* literal, Handle<Script> script) {
1013 Handle<Code> code = isolate->builtins()->CompileLazy(); 1016 Handle<Code> code = isolate->builtins()->CompileLazy();
1014 Handle<ScopeInfo> scope_info = handle(ScopeInfo::Empty(isolate)); 1017 Handle<ScopeInfo> scope_info = handle(ScopeInfo::Empty(isolate));
1015 Handle<SharedFunctionInfo> result = isolate->factory()->NewSharedFunctionInfo( 1018 Handle<SharedFunctionInfo> result = isolate->factory()->NewSharedFunctionInfo(
1016 literal->name(), literal->materialized_literal_count(), literal->kind(), 1019 literal->name(), literal->materialized_literal_count(), literal->kind(),
1017 code, scope_info); 1020 code, scope_info);
1018 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); 1021 SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
1019 SharedFunctionInfo::SetScript(result, script); 1022 SharedFunctionInfo::SetScript(result, script);
1020 return result; 1023 return result;
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 MaybeHandle<Code> code; 1809 MaybeHandle<Code> code;
1807 if (cached.code != nullptr) code = handle(cached.code); 1810 if (cached.code != nullptr) code = handle(cached.code);
1808 Handle<Context> native_context(function->context()->native_context()); 1811 Handle<Context> native_context(function->context()->native_context());
1809 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, 1812 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
1810 literals, BailoutId::None()); 1813 literals, BailoutId::None());
1811 } 1814 }
1812 } 1815 }
1813 1816
1814 } // namespace internal 1817 } // namespace internal
1815 } // namespace v8 1818 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698