| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 // Optimize the AST. | 75 // Optimize the AST. |
| 76 if (!Rewriter::Optimize(function)) { | 76 if (!Rewriter::Optimize(function)) { |
| 77 // Signal a stack overflow by returning a null handle. The stack | 77 // Signal a stack overflow by returning a null handle. The stack |
| 78 // overflow exception will be thrown by the caller. | 78 // overflow exception will be thrown by the caller. |
| 79 return Handle<Code>::null(); | 79 return Handle<Code>::null(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 if (function->scope()->num_parameters() > 0 || |
| 83 function->scope()->num_stack_slots()) { |
| 84 AssignedVariablesAnalyzer ava(function); |
| 85 ava.Analyze(); |
| 86 if (ava.HasStackOverflow()) { |
| 87 return Handle<Code>::null(); |
| 88 } |
| 89 } |
| 90 |
| 82 if (FLAG_use_flow_graph) { | 91 if (FLAG_use_flow_graph) { |
| 83 FlowGraphBuilder builder; | 92 FlowGraphBuilder builder; |
| 84 builder.Build(function); | 93 builder.Build(function); |
| 85 | 94 |
| 95 if (!builder.HasStackOverflow()) { |
| 96 int variable_count = |
| 97 function->num_parameters() + function->scope()->num_stack_slots(); |
| 98 if (variable_count > 0 && builder.definitions()->length() > 0) { |
| 99 ReachingDefinitions rd(builder.postorder(), |
| 100 builder.definitions(), |
| 101 variable_count); |
| 102 rd.Compute(); |
| 103 } |
| 104 } |
| 105 |
| 86 #ifdef DEBUG | 106 #ifdef DEBUG |
| 87 if (FLAG_print_graph_text) { | 107 if (FLAG_print_graph_text && !builder.HasStackOverflow()) { |
| 88 builder.graph()->PrintText(builder.postorder()); | 108 builder.graph()->PrintText(function, builder.postorder()); |
| 89 } | 109 } |
| 90 #endif | 110 #endif |
| 91 } | 111 } |
| 92 | 112 |
| 93 // Generate code and return it. Code generator selection is governed by | 113 // Generate code and return it. Code generator selection is governed by |
| 94 // which backends are enabled and whether the function is considered | 114 // which backends are enabled and whether the function is considered |
| 95 // run-once code or not: | 115 // run-once code or not: |
| 96 // | 116 // |
| 97 // --full-compiler enables the dedicated backend for code we expect to be | 117 // --full-compiler enables the dedicated backend for code we expect to be |
| 98 // run once | 118 // run once |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 Handle<Code> code; | 480 Handle<Code> code; |
| 461 if (FLAG_lazy && allow_lazy) { | 481 if (FLAG_lazy && allow_lazy) { |
| 462 code = ComputeLazyCompile(literal->num_parameters()); | 482 code = ComputeLazyCompile(literal->num_parameters()); |
| 463 } else { | 483 } else { |
| 464 // The bodies of function literals have not yet been visited by | 484 // The bodies of function literals have not yet been visited by |
| 465 // the AST optimizer/analyzer. | 485 // the AST optimizer/analyzer. |
| 466 if (!Rewriter::Optimize(literal)) { | 486 if (!Rewriter::Optimize(literal)) { |
| 467 return Handle<JSFunction>::null(); | 487 return Handle<JSFunction>::null(); |
| 468 } | 488 } |
| 469 | 489 |
| 490 if (literal->scope()->num_parameters() > 0 || |
| 491 literal->scope()->num_stack_slots()) { |
| 492 AssignedVariablesAnalyzer ava(literal); |
| 493 ava.Analyze(); |
| 494 if (ava.HasStackOverflow()) { |
| 495 return Handle<JSFunction>::null(); |
| 496 } |
| 497 } |
| 498 |
| 470 if (FLAG_use_flow_graph) { | 499 if (FLAG_use_flow_graph) { |
| 471 FlowGraphBuilder builder; | 500 FlowGraphBuilder builder; |
| 472 builder.Build(literal); | 501 builder.Build(literal); |
| 473 | 502 |
| 503 if (!builder.HasStackOverflow()) { |
| 504 int variable_count = |
| 505 literal->num_parameters() + literal->scope()->num_stack_slots(); |
| 506 if (variable_count > 0 && builder.definitions()->length() > 0) { |
| 507 ReachingDefinitions rd(builder.postorder(), |
| 508 builder.definitions(), |
| 509 variable_count); |
| 510 rd.Compute(); |
| 511 } |
| 512 } |
| 513 |
| 474 #ifdef DEBUG | 514 #ifdef DEBUG |
| 475 if (FLAG_print_graph_text) { | 515 if (FLAG_print_graph_text && !builder.HasStackOverflow()) { |
| 476 builder.graph()->PrintText(builder.postorder()); | 516 builder.graph()->PrintText(literal, builder.postorder()); |
| 477 } | 517 } |
| 478 #endif | 518 #endif |
| 479 } | 519 } |
| 480 | 520 |
| 481 // Generate code and return it. The way that the compilation mode | 521 // Generate code and return it. The way that the compilation mode |
| 482 // is controlled by the command-line flags is described in | 522 // is controlled by the command-line flags is described in |
| 483 // the static helper function MakeCode. | 523 // the static helper function MakeCode. |
| 484 CompilationInfo info(literal, script, false); | 524 CompilationInfo info(literal, script, false); |
| 485 | 525 |
| 486 CHECK(!FLAG_always_full_compiler || !FLAG_always_fast_compiler); | 526 CHECK(!FLAG_always_full_compiler || !FLAG_always_fast_compiler); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 LOG(CodeCreateEvent(tag, *code, *func_name)); | 637 LOG(CodeCreateEvent(tag, *code, *func_name)); |
| 598 OProfileAgent::CreateNativeCodeRegion(*func_name, | 638 OProfileAgent::CreateNativeCodeRegion(*func_name, |
| 599 code->instruction_start(), | 639 code->instruction_start(), |
| 600 code->instruction_size()); | 640 code->instruction_size()); |
| 601 } | 641 } |
| 602 } | 642 } |
| 603 } | 643 } |
| 604 #endif | 644 #endif |
| 605 | 645 |
| 606 } } // namespace v8::internal | 646 } } // namespace v8::internal |
| OLD | NEW |