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

Side by Side Diff: src/compiler.cc

Issue 549158: Refactor the selection of code generator (toplevel or optimizing) and... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 11 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 | « src/ast.h ('k') | src/fast-codegen.h » ('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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "bootstrapper.h" 30 #include "bootstrapper.h"
31 #include "codegen-inl.h" 31 #include "codegen-inl.h"
32 #include "compilation-cache.h" 32 #include "compilation-cache.h"
33 #include "compiler.h" 33 #include "compiler.h"
34 #include "debug.h" 34 #include "debug.h"
35 #include "fast-codegen.h"
35 #include "full-codegen.h" 36 #include "full-codegen.h"
36 #include "oprofile-agent.h" 37 #include "oprofile-agent.h"
37 #include "rewriter.h" 38 #include "rewriter.h"
38 #include "scopes.h" 39 #include "scopes.h"
39 #include "usage-analyzer.h" 40 #include "usage-analyzer.h"
40 41
41 namespace v8 { 42 namespace v8 {
42 namespace internal { 43 namespace internal {
43 44
44 45
(...skipping 29 matching lines...) Expand all
74 } 75 }
75 #endif 76 #endif
76 77
77 // Optimize the AST. 78 // Optimize the AST.
78 if (!Rewriter::Optimize(literal)) { 79 if (!Rewriter::Optimize(literal)) {
79 // Signal a stack overflow by returning a null handle. The stack 80 // Signal a stack overflow by returning a null handle. The stack
80 // overflow exception will be thrown by the caller. 81 // overflow exception will be thrown by the caller.
81 return Handle<Code>::null(); 82 return Handle<Code>::null();
82 } 83 }
83 84
84 // Generate code and return it. 85 // Generate code and return it. Code generator selection is governed by
85 if (FLAG_fast_compiler) { 86 // which backends are enabled and whether the function is considered
86 // If there is no shared function info, try the fast code 87 // run-once code or not:
87 // generator for code in the global scope. Otherwise obey the 88 //
88 // explicit hint in the shared function info. 89 // --full-compiler enables the dedicated backend for code we expect to be
89 // If always_fast_compiler is true, always try the fast compiler. 90 // run once
90 if (shared.is_null() && !literal->scope()->is_global_scope() && 91 // --fast-compiler enables a speculative optimizing backend (for
91 !FLAG_always_fast_compiler) { 92 // non-run-once code)
92 if (FLAG_trace_bailout) PrintF("Non-global scope\n"); 93 //
93 } else if (!shared.is_null() && !shared->try_fast_codegen() && 94 // The normal choice of backend can be overridden with the flags
94 !FLAG_always_fast_compiler) { 95 // --always-full-compiler and --always-fast-compiler, which are mutually
95 if (FLAG_trace_bailout) PrintF("No hint to try fast\n"); 96 // incompatible.
96 } else { 97 CHECK(!FLAG_always_full_compiler || !FLAG_always_fast_compiler);
97 FullCodeGenSyntaxChecker checker; 98
98 checker.Check(literal); 99 bool is_run_once = (shared.is_null())
99 if (checker.has_supported_syntax()) { 100 ? literal->scope()->is_global_scope()
100 return FullCodeGenerator::MakeCode(literal, script, is_eval); 101 : (shared->is_toplevel() || shared->try_full_codegen());
101 } 102
103 if (FLAG_always_full_compiler || (FLAG_full_compiler && is_run_once)) {
104 FullCodeGenSyntaxChecker checker;
105 checker.Check(literal);
106 if (checker.has_supported_syntax()) {
107 return FullCodeGenerator::MakeCode(literal, script, is_eval);
102 } 108 }
109 } else if (FLAG_always_fast_compiler ||
110 (FLAG_fast_compiler && !is_run_once)) {
111 FastCodeGenSyntaxChecker checker;
112 checker.Check(literal);
113 // Does not yet generate code.
103 } 114 }
115
104 return CodeGenerator::MakeCode(literal, script, is_eval); 116 return CodeGenerator::MakeCode(literal, script, is_eval);
105 } 117 }
106 118
107 119
108 static bool IsValidJSON(FunctionLiteral* lit) { 120 static bool IsValidJSON(FunctionLiteral* lit) {
109 if (lit->body()->length() != 1) 121 if (lit->body()->length() != 1)
110 return false; 122 return false;
111 Statement* stmt = lit->body()->at(0); 123 Statement* stmt = lit->body()->at(0);
112 if (stmt->AsExpressionStatement() == NULL) 124 if (stmt->AsExpressionStatement() == NULL)
113 return false; 125 return false;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 Handle<Code> code; 472 Handle<Code> code;
461 if (FLAG_lazy && allow_lazy) { 473 if (FLAG_lazy && allow_lazy) {
462 code = ComputeLazyCompile(literal->num_parameters()); 474 code = ComputeLazyCompile(literal->num_parameters());
463 } else { 475 } else {
464 // The bodies of function literals have not yet been visited by 476 // The bodies of function literals have not yet been visited by
465 // the AST optimizer/analyzer. 477 // the AST optimizer/analyzer.
466 if (!Rewriter::Optimize(literal)) { 478 if (!Rewriter::Optimize(literal)) {
467 return Handle<JSFunction>::null(); 479 return Handle<JSFunction>::null();
468 } 480 }
469 481
470 // Generate code and return it. 482 // Generate code and return it. The way that the compilation mode
483 // is controlled by the command-line flags is described in
484 // the static helper function MakeCode.
485 CHECK(!FLAG_always_full_compiler || !FLAG_always_fast_compiler);
486 bool is_run_once = literal->try_full_codegen();
471 bool is_compiled = false; 487 bool is_compiled = false;
472 if (FLAG_always_fast_compiler || 488 if (FLAG_always_full_compiler || (FLAG_full_compiler && is_run_once)) {
473 (FLAG_fast_compiler && literal->try_fast_codegen())) {
474 FullCodeGenSyntaxChecker checker; 489 FullCodeGenSyntaxChecker checker;
475 checker.Check(literal); 490 checker.Check(literal);
476 if (checker.has_supported_syntax()) { 491 if (checker.has_supported_syntax()) {
477 code = FullCodeGenerator::MakeCode(literal, 492 code = FullCodeGenerator::MakeCode(literal,
478 script, 493 script,
479 false); // Not eval. 494 false); // Not eval.
480 is_compiled = true; 495 is_compiled = true;
481 } 496 }
497 } else if (FLAG_always_fast_compiler ||
498 (FLAG_fast_compiler && !is_run_once)) {
499 FastCodeGenSyntaxChecker checker;
500 checker.Check(literal);
501 // Generate no code.
482 } 502 }
483 503
484 if (!is_compiled) { 504 if (!is_compiled) {
485 // We didn't try the fast compiler, or we failed to select it. 505 // We fall back to the classic V8 code generator.
486 code = CodeGenerator::MakeCode(literal, 506 code = CodeGenerator::MakeCode(literal,
487 script, 507 script,
488 false); // Not eval. 508 false); // Not eval.
489 } 509 }
490 510
491 // Check for stack-overflow exception. 511 // Check for stack-overflow exception.
492 if (code.is_null()) { 512 if (code.is_null()) {
493 caller->SetStackOverflow(); 513 caller->SetStackOverflow();
494 return Handle<JSFunction>::null(); 514 return Handle<JSFunction>::null();
495 } 515 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 fun->shared()->set_script(*script); 557 fun->shared()->set_script(*script);
538 fun->shared()->set_function_token_position(lit->function_token_position()); 558 fun->shared()->set_function_token_position(lit->function_token_position());
539 fun->shared()->set_start_position(lit->start_position()); 559 fun->shared()->set_start_position(lit->start_position());
540 fun->shared()->set_end_position(lit->end_position()); 560 fun->shared()->set_end_position(lit->end_position());
541 fun->shared()->set_is_expression(lit->is_expression()); 561 fun->shared()->set_is_expression(lit->is_expression());
542 fun->shared()->set_is_toplevel(is_toplevel); 562 fun->shared()->set_is_toplevel(is_toplevel);
543 fun->shared()->set_inferred_name(*lit->inferred_name()); 563 fun->shared()->set_inferred_name(*lit->inferred_name());
544 fun->shared()->SetThisPropertyAssignmentsInfo( 564 fun->shared()->SetThisPropertyAssignmentsInfo(
545 lit->has_only_simple_this_property_assignments(), 565 lit->has_only_simple_this_property_assignments(),
546 *lit->this_property_assignments()); 566 *lit->this_property_assignments());
547 fun->shared()->set_try_fast_codegen(lit->try_fast_codegen()); 567 fun->shared()->set_try_full_codegen(lit->try_full_codegen());
548 } 568 }
549 569
550 570
551 } } // namespace v8::internal 571 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/fast-codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698