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

Side by Side Diff: src/compiler.cc

Issue 675493002: Move AST node counting to post-pass (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove duplicate Renumber() call Created 6 years, 2 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
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/ast-numbering.h" 9 #include "src/ast-numbering.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 } 640 }
641 641
642 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 642 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
643 Handle<Script>(info->script()), Handle<Code>(info->code()), 643 Handle<Script>(info->script()), Handle<Code>(info->code()),
644 info)); 644 info));
645 } 645 }
646 646
647 647
648 static bool CompileUnoptimizedCode(CompilationInfo* info) { 648 static bool CompileUnoptimizedCode(CompilationInfo* info) {
649 DCHECK(AllowCompilation::IsAllowed(info->isolate())); 649 DCHECK(AllowCompilation::IsAllowed(info->isolate()));
650 DCHECK(info->function() != NULL); 650 if (!Compiler::Analyze(info)) return false;
651 if (!Rewriter::Rewrite(info)) return false;
652 if (!Scope::Analyze(info)) return false;
653 DCHECK(info->scope() != NULL);
654
655 if (!FullCodeGenerator::MakeCode(info)) { 651 if (!FullCodeGenerator::MakeCode(info)) {
656 Isolate* isolate = info->isolate(); 652 Isolate* isolate = info->isolate();
657 if (!isolate->has_pending_exception()) isolate->StackOverflow(); 653 if (!isolate->has_pending_exception()) isolate->StackOverflow();
658 return false; 654 return false;
659 } 655 }
660 return true; 656 return true;
661 } 657 }
662 658
663 659
664 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( 660 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
665 CompilationInfo* info) { 661 CompilationInfo* info) {
666 VMState<COMPILER> state(info->isolate()); 662 VMState<COMPILER> state(info->isolate());
667 PostponeInterruptsScope postpone(info->isolate()); 663 PostponeInterruptsScope postpone(info->isolate());
668 664
669 // Parse and update CompilationInfo with the results. 665 // Parse and update CompilationInfo with the results.
670 if (!Parser::Parse(info)) return MaybeHandle<Code>(); 666 if (!Parser::Parse(info)) return MaybeHandle<Code>();
671 Handle<SharedFunctionInfo> shared = info->shared_info(); 667 Handle<SharedFunctionInfo> shared = info->shared_info();
672 FunctionLiteral* lit = info->function(); 668 FunctionLiteral* lit = info->function();
673 shared->set_strict_mode(lit->strict_mode()); 669 shared->set_strict_mode(lit->strict_mode());
674 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); 670 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
675 shared->set_bailout_reason(lit->dont_optimize_reason()); 671 shared->set_bailout_reason(lit->dont_optimize_reason());
676 shared->set_ast_node_count(lit->ast_node_count());
677 672
678 // Compile unoptimized code. 673 // Compile unoptimized code.
679 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); 674 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
680 675
681 CHECK_EQ(Code::FUNCTION, info->code()->kind()); 676 CHECK_EQ(Code::FUNCTION, info->code()->kind());
682 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); 677 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
683 678
684 // Update the shared function info with the scope info. Allocating the 679 // Update the shared function info with the scope info. Allocating the
685 // ScopeInfo object may cause a GC. 680 // ScopeInfo object may cause a GC.
686 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); 681 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 // Do not cache bound functions. 731 // Do not cache bound functions.
737 if (shared->bound()) return; 732 if (shared->bound()) return;
738 Handle<FixedArray> literals(function->literals()); 733 Handle<FixedArray> literals(function->literals());
739 Handle<Context> native_context(function->context()->native_context()); 734 Handle<Context> native_context(function->context()->native_context());
740 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, 735 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
741 literals, info->osr_ast_id()); 736 literals, info->osr_ast_id());
742 } 737 }
743 } 738 }
744 739
745 740
746 static bool CompileOptimizedPrologue(CompilationInfo* info) { 741 static bool Renumber(CompilationInfo* info) {
747 if (!Parser::Parse(info)) return false; 742 if (!AstNumbering::Renumber(info->function(), info->zone())) return false;
743 if (!info->shared_info().is_null()) {
744 info->shared_info()->set_ast_node_count(info->function()->ast_node_count());
745 }
746 return true;
747 }
748
749
750 bool Compiler::Analyze(CompilationInfo* info) {
751 DCHECK(info->function() != NULL);
748 if (!Rewriter::Rewrite(info)) return false; 752 if (!Rewriter::Rewrite(info)) return false;
749 if (!Scope::Analyze(info)) return false; 753 if (!Scope::Analyze(info)) return false;
750 if (!AstNumbering::Renumber(info->function(), info->zone())) return false; 754 if (!Renumber(info)) return false;
751 DCHECK(info->scope() != NULL); 755 DCHECK(info->scope() != NULL);
752 return true; 756 return true;
753 } 757 }
754 758
755 759
760 bool Compiler::ParseAndAnalyze(CompilationInfo* info) {
761 if (!Parser::Parse(info)) return false;
762 return Compiler::Analyze(info);
763 }
764
765
756 static bool GetOptimizedCodeNow(CompilationInfo* info) { 766 static bool GetOptimizedCodeNow(CompilationInfo* info) {
757 if (!CompileOptimizedPrologue(info)) return false; 767 if (!Compiler::ParseAndAnalyze(info)) return false;
758 768
759 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); 769 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
760 770
761 OptimizedCompileJob job(info); 771 OptimizedCompileJob job(info);
762 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || 772 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED ||
763 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || 773 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED ||
764 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { 774 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) {
765 if (FLAG_trace_opt) { 775 if (FLAG_trace_opt) {
766 PrintF("[aborted optimizing "); 776 PrintF("[aborted optimizing ");
767 info->closure()->ShortPrint(); 777 info->closure()->ShortPrint();
(...skipping 21 matching lines...) Expand all
789 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { 799 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) {
790 if (FLAG_trace_concurrent_recompilation) { 800 if (FLAG_trace_concurrent_recompilation) {
791 PrintF(" ** Compilation queue full, will retry optimizing "); 801 PrintF(" ** Compilation queue full, will retry optimizing ");
792 info->closure()->ShortPrint(); 802 info->closure()->ShortPrint();
793 PrintF(" later.\n"); 803 PrintF(" later.\n");
794 } 804 }
795 return false; 805 return false;
796 } 806 }
797 807
798 CompilationHandleScope handle_scope(info); 808 CompilationHandleScope handle_scope(info);
799 if (!CompileOptimizedPrologue(info)) return false; 809 if (!Compiler::ParseAndAnalyze(info)) return false;
800 info->SaveHandles(); // Copy handles to the compilation handle scope. 810 info->SaveHandles(); // Copy handles to the compilation handle scope.
801 811
802 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); 812 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
803 813
804 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); 814 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info);
805 OptimizedCompileJob::Status status = job->CreateGraph(); 815 OptimizedCompileJob::Status status = job->CreateGraph();
806 if (status != OptimizedCompileJob::SUCCEEDED) return false; 816 if (status != OptimizedCompileJob::SUCCEEDED) return false;
807 isolate->optimizing_compiler_thread()->QueueForOptimization(job); 817 isolate->optimizing_compiler_thread()->QueueForOptimization(job);
808 818
809 if (FLAG_trace_concurrent_recompilation) { 819 if (FLAG_trace_concurrent_recompilation) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 return false; 912 return false;
903 } 913 }
904 function->ReplaceCode(*code); 914 function->ReplaceCode(*code);
905 DCHECK(function->is_compiled()); 915 DCHECK(function->is_compiled());
906 return true; 916 return true;
907 } 917 }
908 918
909 919
910 // TODO(turbofan): In the future, unoptimized code with deopt support could 920 // TODO(turbofan): In the future, unoptimized code with deopt support could
911 // be generated lazily once deopt is triggered. 921 // be generated lazily once deopt is triggered.
912 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { 922 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
Michael Starzinger 2014/10/27 11:41:54 nit: We might even want to add a two assertions he
wingo 2014/10/27 14:58:09 Done.
913 if (!info->shared_info()->has_deoptimization_support()) { 923 if (!info->shared_info()->has_deoptimization_support()) {
914 CompilationInfoWithZone unoptimized(info->shared_info()); 924 CompilationInfoWithZone unoptimized(info->shared_info());
915 // Note that we use the same AST that we will use for generating the 925 // Note that we use the same AST that we will use for generating the
916 // optimized code. 926 // optimized code.
917 unoptimized.SetFunction(info->function()); 927 unoptimized.SetFunction(info->function());
918 unoptimized.PrepareForCompilation(info->scope()); 928 unoptimized.PrepareForCompilation(info->scope());
919 unoptimized.SetContext(info->context()); 929 unoptimized.SetContext(info->context());
920 unoptimized.EnableDeoptimizationSupport(); 930 unoptimized.EnableDeoptimizationSupport();
921 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; 931 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
922 932
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 // the inner unction must be allowed to be compiled lazily. 1307 // the inner unction must be allowed to be compiled lazily.
1298 DCHECK(allow_lazy); 1308 DCHECK(allow_lazy);
1299 } 1309 }
1300 1310
1301 // Generate code 1311 // Generate code
1302 Handle<ScopeInfo> scope_info; 1312 Handle<ScopeInfo> scope_info;
1303 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { 1313 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) {
1304 Handle<Code> code = isolate->builtins()->CompileLazy(); 1314 Handle<Code> code = isolate->builtins()->CompileLazy();
1305 info.SetCode(code); 1315 info.SetCode(code);
1306 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); 1316 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate));
1307 } else if (FullCodeGenerator::MakeCode(&info)) { 1317 } else if (Renumber(&info) && FullCodeGenerator::MakeCode(&info)) {
1308 DCHECK(!info.code().is_null()); 1318 DCHECK(!info.code().is_null());
1309 scope_info = ScopeInfo::Create(info.scope(), info.zone()); 1319 scope_info = ScopeInfo::Create(info.scope(), info.zone());
1310 } else { 1320 } else {
1311 return Handle<SharedFunctionInfo>::null(); 1321 return Handle<SharedFunctionInfo>::null();
1312 } 1322 }
1313 1323
1314 // Create a shared function info object. 1324 // Create a shared function info object.
1315 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( 1325 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo(
1316 literal->name(), literal->materialized_literal_count(), literal->kind(), 1326 literal->name(), literal->materialized_literal_count(), literal->kind(),
1317 info.code(), scope_info, info.feedback_vector()); 1327 info.code(), scope_info, info.feedback_vector());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 AllowHandleDereference allow_deref; 1467 AllowHandleDereference allow_deref;
1458 bool tracing_on = info()->IsStub() 1468 bool tracing_on = info()->IsStub()
1459 ? FLAG_trace_hydrogen_stubs 1469 ? FLAG_trace_hydrogen_stubs
1460 : (FLAG_trace_hydrogen && 1470 : (FLAG_trace_hydrogen &&
1461 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1471 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1462 return (tracing_on && 1472 return (tracing_on &&
1463 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1473 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1464 } 1474 }
1465 1475
1466 } } // namespace v8::internal 1476 } } // namespace v8::internal
OLDNEW
« src/compiler.h ('K') | « src/compiler.h ('k') | src/compiler/js-inlining.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698