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

Side by Side Diff: src/compiler.cc

Issue 555553003: Minor compiler pipeline refactoring. Inline UpdateSharedFunctionInfo and make Parser::Parse respons… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove more uses of setting the strictness in the compilation info. Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/compiler/js-inlining.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 8
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // so we can afford to adjust the estimate generously. 612 // so we can afford to adjust the estimate generously.
613 estimate += 8; 613 estimate += 8;
614 } else { 614 } else {
615 estimate += 3; 615 estimate += 3;
616 } 616 }
617 617
618 shared->set_expected_nof_properties(estimate); 618 shared->set_expected_nof_properties(estimate);
619 } 619 }
620 620
621 621
622 static void UpdateSharedFunctionInfo(CompilationInfo* info) {
623 // Update the shared function info with the compiled code and the
624 // scope info. Please note, that the order of the shared function
625 // info initialization is important since set_scope_info might
626 // trigger a GC, causing the DCHECK below to be invalid if the code
627 // was flushed. By setting the code object last we avoid this.
628 Handle<SharedFunctionInfo> shared = info->shared_info();
629 Handle<ScopeInfo> scope_info =
630 ScopeInfo::Create(info->scope(), info->zone());
631 shared->set_scope_info(*scope_info);
632
633 Handle<Code> code = info->code();
634 CHECK(code->kind() == Code::FUNCTION);
635 shared->ReplaceCode(*code);
636 if (shared->optimization_disabled()) code->set_optimizable(false);
637
638 shared->set_feedback_vector(*info->feedback_vector());
639
640 // Set the expected number of properties for instances.
641 FunctionLiteral* lit = info->function();
642 int expected = lit->expected_property_count();
643 SetExpectedNofPropertiesFromEstimate(shared, expected);
644
645 // Check the function has compiled code.
646 DCHECK(shared->is_compiled());
647 shared->set_bailout_reason(lit->dont_optimize_reason());
648 shared->set_ast_node_count(lit->ast_node_count());
649 shared->set_strict_mode(lit->strict_mode());
650 }
651
652
653 // Sets the function info on a function. 622 // Sets the function info on a function.
654 // The start_position points to the first '(' character after the function name 623 // The start_position points to the first '(' character after the function name
655 // in the full script source. When counting characters in the script source the 624 // in the full script source. When counting characters in the script source the
656 // the first character is number 0 (not 1). 625 // the first character is number 0 (not 1).
657 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, 626 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
658 FunctionLiteral* lit, 627 FunctionLiteral* lit,
659 bool is_toplevel, 628 bool is_toplevel,
660 Handle<Script> script) { 629 Handle<Script> script) {
661 function_info->set_length(lit->parameter_count()); 630 function_info->set_length(lit->parameter_count());
662 function_info->set_formal_parameter_count(lit->parameter_count()); 631 function_info->set_formal_parameter_count(lit->parameter_count());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 return false; 664 return false;
696 } 665 }
697 return true; 666 return true;
698 } 667 }
699 668
700 669
701 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( 670 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
702 CompilationInfo* info) { 671 CompilationInfo* info) {
703 VMState<COMPILER> state(info->isolate()); 672 VMState<COMPILER> state(info->isolate());
704 PostponeInterruptsScope postpone(info->isolate()); 673 PostponeInterruptsScope postpone(info->isolate());
674
675 // Parse and update CompilationInfo with the results.
705 if (!Parser::Parse(info)) return MaybeHandle<Code>(); 676 if (!Parser::Parse(info)) return MaybeHandle<Code>();
706 info->SetStrictMode(info->function()->strict_mode()); 677 Handle<SharedFunctionInfo> shared = info->shared_info();
678 FunctionLiteral* lit = info->function();
679 shared->set_strict_mode(lit->strict_mode());
680 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
681 shared->set_bailout_reason(lit->dont_optimize_reason());
682 shared->set_ast_node_count(lit->ast_node_count());
707 683
684 // Compile unoptimized code.
708 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); 685 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
686
687 CHECK_EQ(Code::FUNCTION, info->code()->kind());
709 Compiler::RecordFunctionCompilation( 688 Compiler::RecordFunctionCompilation(
710 Logger::LAZY_COMPILE_TAG, info, info->shared_info()); 689 Logger::LAZY_COMPILE_TAG, info, info->shared_info());
711 UpdateSharedFunctionInfo(info); 690
712 DCHECK_EQ(Code::FUNCTION, info->code()->kind()); 691 // Update the shared function info with the scope info. Allocating the
692 // ScopeInfo object may cause a GC.
693 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone());
694 shared->set_scope_info(*scope_info);
695
696 // Update the code and feedback vector for the shared function info.
697 shared->ReplaceCode(*info->code());
698 if (shared->optimization_disabled()) info->code()->set_optimizable(false);
699 shared->set_feedback_vector(*info->feedback_vector());
700
713 return info->code(); 701 return info->code();
714 } 702 }
715 703
716 704
717 MaybeHandle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) { 705 MaybeHandle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) {
718 DCHECK(!function->GetIsolate()->has_pending_exception()); 706 DCHECK(!function->GetIsolate()->has_pending_exception());
719 DCHECK(!function->is_compiled()); 707 DCHECK(!function->is_compiled());
720 if (function->shared()->is_compiled()) { 708 if (function->shared()->is_compiled()) {
721 return Handle<Code>(function->shared()->code()); 709 return Handle<Code>(function->shared()->code());
722 } 710 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 798
811 799
812 void Compiler::CompileForLiveEdit(Handle<Script> script) { 800 void Compiler::CompileForLiveEdit(Handle<Script> script) {
813 // TODO(635): support extensions. 801 // TODO(635): support extensions.
814 CompilationInfoWithZone info(script); 802 CompilationInfoWithZone info(script);
815 PostponeInterruptsScope postpone(info.isolate()); 803 PostponeInterruptsScope postpone(info.isolate());
816 VMState<COMPILER> state(info.isolate()); 804 VMState<COMPILER> state(info.isolate());
817 805
818 info.MarkAsGlobal(); 806 info.MarkAsGlobal();
819 if (!Parser::Parse(&info)) return; 807 if (!Parser::Parse(&info)) return;
820 info.SetStrictMode(info.function()->strict_mode());
821 808
822 LiveEditFunctionTracker tracker(info.isolate(), info.function()); 809 LiveEditFunctionTracker tracker(info.isolate(), info.function());
823 if (!CompileUnoptimizedCode(&info)) return; 810 if (!CompileUnoptimizedCode(&info)) return;
824 if (!info.shared_info().is_null()) { 811 if (!info.shared_info().is_null()) {
825 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), 812 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(),
826 info.zone()); 813 info.zone());
827 info.shared_info()->set_scope_info(*scope_info); 814 info.shared_info()->set_scope_info(*scope_info);
828 } 815 }
829 tracker.RecordRootFunctionInfo(info.code()); 816 tracker.RecordRootFunctionInfo(info.code());
830 } 817 }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 Handle<FixedArray> literals(function->literals()); 1172 Handle<FixedArray> literals(function->literals());
1186 Handle<Context> native_context(function->context()->native_context()); 1173 Handle<Context> native_context(function->context()->native_context());
1187 SharedFunctionInfo::AddToOptimizedCodeMap( 1174 SharedFunctionInfo::AddToOptimizedCodeMap(
1188 shared, native_context, code, literals, info->osr_ast_id()); 1175 shared, native_context, code, literals, info->osr_ast_id());
1189 } 1176 }
1190 } 1177 }
1191 1178
1192 1179
1193 static bool CompileOptimizedPrologue(CompilationInfo* info) { 1180 static bool CompileOptimizedPrologue(CompilationInfo* info) {
1194 if (!Parser::Parse(info)) return false; 1181 if (!Parser::Parse(info)) return false;
1195 info->SetStrictMode(info->function()->strict_mode());
1196
1197 if (!Rewriter::Rewrite(info)) return false; 1182 if (!Rewriter::Rewrite(info)) return false;
1198 if (!Scope::Analyze(info)) return false; 1183 if (!Scope::Analyze(info)) return false;
1199 DCHECK(info->scope() != NULL); 1184 DCHECK(info->scope() != NULL);
1200 return true; 1185 return true;
1201 } 1186 }
1202 1187
1203 1188
1204 static bool GetOptimizedCodeNow(CompilationInfo* info) { 1189 static bool GetOptimizedCodeNow(CompilationInfo* info) {
1205 if (!CompileOptimizedPrologue(info)) return false; 1190 if (!CompileOptimizedPrologue(info)) return false;
1206 1191
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 AllowHandleDereference allow_deref; 1407 AllowHandleDereference allow_deref;
1423 bool tracing_on = info()->IsStub() 1408 bool tracing_on = info()->IsStub()
1424 ? FLAG_trace_hydrogen_stubs 1409 ? FLAG_trace_hydrogen_stubs
1425 : (FLAG_trace_hydrogen && 1410 : (FLAG_trace_hydrogen &&
1426 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1411 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1427 return (tracing_on && 1412 return (tracing_on &&
1428 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1413 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1429 } 1414 }
1430 1415
1431 } } // namespace v8::internal 1416 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/compiler/js-inlining.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698