OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/compiler.h" | 5 #include "vm/compiler.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 | 8 |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 "Print the IR flow graph when optimizing."); | 52 "Print the IR flow graph when optimizing."); |
53 DEFINE_FLAG(bool, range_analysis, true, "Enable range analysis"); | 53 DEFINE_FLAG(bool, range_analysis, true, "Enable range analysis"); |
54 DEFINE_FLAG(bool, reorder_basic_blocks, true, "Enable basic-block reordering."); | 54 DEFINE_FLAG(bool, reorder_basic_blocks, true, "Enable basic-block reordering."); |
55 DEFINE_FLAG(bool, trace_compiler, false, "Trace compiler operations."); | 55 DEFINE_FLAG(bool, trace_compiler, false, "Trace compiler operations."); |
56 DEFINE_FLAG(bool, trace_bailout, false, "Print bailout from ssa compiler."); | 56 DEFINE_FLAG(bool, trace_bailout, false, "Print bailout from ssa compiler."); |
57 DEFINE_FLAG(bool, use_inlining, true, "Enable call-site inlining"); | 57 DEFINE_FLAG(bool, use_inlining, true, "Enable call-site inlining"); |
58 DEFINE_FLAG(bool, verify_compiler, false, | 58 DEFINE_FLAG(bool, verify_compiler, false, |
59 "Enable compiler verification assertions"); | 59 "Enable compiler verification assertions"); |
60 | 60 |
61 DECLARE_FLAG(bool, trace_failed_optimization_attempts); | 61 DECLARE_FLAG(bool, trace_failed_optimization_attempts); |
| 62 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 63 DECLARE_FLAG(bool, warning_as_error); |
62 | 64 |
63 // Compile a function. Should call only if the function has not been compiled. | 65 // Compile a function. Should call only if the function has not been compiled. |
64 // Arg0: function object. | 66 // Arg0: function object. |
65 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { | 67 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { |
66 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); | 68 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); |
67 ASSERT(!function.HasCode()); | 69 ASSERT(!function.HasCode()); |
68 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 70 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
69 if (!error.IsNull()) { | 71 if (!error.IsNull()) { |
70 Exceptions::PropagateError(error); | 72 Exceptions::PropagateError(error); |
71 } | 73 } |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 LibraryPrefix& prefix = LibraryPrefix::Handle(); | 591 LibraryPrefix& prefix = LibraryPrefix::Handle(); |
590 for (intptr_t i = 0; i < prefixes->Length(); i++) { | 592 for (intptr_t i = 0; i < prefixes->Length(); i++) { |
591 prefix ^= prefixes->At(i); | 593 prefix ^= prefixes->At(i); |
592 prefix.RegisterDependentCode(code); | 594 prefix.RegisterDependentCode(code); |
593 } | 595 } |
594 } | 596 } |
595 } | 597 } |
596 is_compiled = true; | 598 is_compiled = true; |
597 done = true; | 599 done = true; |
598 } else { | 600 } else { |
599 // We bailed out. | 601 // We bailed out or we encountered an error. |
| 602 const Error& error = Error::Handle( |
| 603 isolate->object_store()->sticky_error()); |
600 | 604 |
601 if (isolate->object_store()->sticky_error() == | 605 if (error.raw() == Object::branch_offset_error().raw()) { |
602 Object::branch_offset_error().raw()) { | |
603 // Compilation failed due to an out of range branch offset in the | 606 // Compilation failed due to an out of range branch offset in the |
604 // assembler. We try again (done = false) with far branches enabled. | 607 // assembler. We try again (done = false) with far branches enabled. |
605 done = false; | 608 done = false; |
606 ASSERT(!use_far_branches); | 609 ASSERT(!use_far_branches); |
607 use_far_branches = true; | 610 use_far_branches = true; |
608 } else { | 611 } else { |
609 // If the error isn't due to an out of range branch offset, we don't | 612 // If the error isn't due to an out of range branch offset, we don't |
610 // try again (done = true), and indicate that we did not finish | 613 // try again (done = true), and indicate that we did not finish |
611 // compiling (is_compiled = false). | 614 // compiling (is_compiled = false). |
612 if (FLAG_trace_bailout) { | 615 if (FLAG_trace_bailout) { |
613 const Error& bailout_error = Error::Handle( | 616 OS::Print("%s\n", error.ToErrorCString()); |
614 isolate->object_store()->sticky_error()); | |
615 OS::Print("%s\n", bailout_error.ToErrorCString()); | |
616 } | 617 } |
617 done = true; | 618 done = true; |
618 ASSERT(optimized); | 619 ASSERT(optimized || |
| 620 (FLAG_warn_on_javascript_compatibility && |
| 621 FLAG_warning_as_error)); |
619 } | 622 } |
620 | 623 |
621 isolate->object_store()->clear_sticky_error(); | 624 // Clear the error if it was not a real error, but just a bailout. |
| 625 if (error.IsLanguageError() && |
| 626 (LanguageError::Cast(error).kind() == LanguageError::kBailout)) { |
| 627 isolate->object_store()->clear_sticky_error(); |
| 628 } |
622 is_compiled = false; | 629 is_compiled = false; |
623 } | 630 } |
624 // Reset global isolate state. | 631 // Reset global isolate state. |
625 isolate->set_deopt_id(prev_deopt_id); | 632 isolate->set_deopt_id(prev_deopt_id); |
626 } | 633 } |
627 return is_compiled; | 634 return is_compiled; |
628 } | 635 } |
629 | 636 |
630 | 637 |
631 static void DisassembleCode(const Function& function, bool optimized) { | 638 static void DisassembleCode(const Function& function, bool optimized) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 (function.end_token_pos() - function.token_pos())); | 791 (function.end_token_pos() - function.token_pos())); |
785 } | 792 } |
786 { | 793 { |
787 HANDLESCOPE(isolate); | 794 HANDLESCOPE(isolate); |
788 Parser::ParseFunction(parsed_function); | 795 Parser::ParseFunction(parsed_function); |
789 parsed_function->AllocateVariables(); | 796 parsed_function->AllocateVariables(); |
790 } | 797 } |
791 | 798 |
792 const bool success = | 799 const bool success = |
793 CompileParsedFunctionHelper(parsed_function, optimized, osr_id); | 800 CompileParsedFunctionHelper(parsed_function, optimized, osr_id); |
794 if (optimized && !success) { | 801 if (!success) { |
795 // Optimizer bailed out. Disable optimizations and to never try again. | 802 if (optimized) { |
796 if (FLAG_trace_compiler) { | 803 // Optimizer bailed out. Disable optimizations and to never try again. |
797 OS::Print("--> disabling optimizations for '%s'\n", | 804 if (FLAG_trace_compiler) { |
798 function.ToFullyQualifiedCString()); | 805 OS::Print("--> disabling optimizations for '%s'\n", |
799 } else if (FLAG_trace_failed_optimization_attempts) { | 806 function.ToFullyQualifiedCString()); |
800 OS::Print("Cannot optimize: %s\n", function.ToFullyQualifiedCString()); | 807 } else if (FLAG_trace_failed_optimization_attempts) { |
| 808 OS::Print("Cannot optimize: %s\n", |
| 809 function.ToFullyQualifiedCString()); |
| 810 } |
| 811 function.SetIsOptimizable(false); |
| 812 return Error::null(); |
801 } | 813 } |
802 function.SetIsOptimizable(false); | 814 // So far, the only possible real error is a JS warning reported as error. |
803 return Error::null(); | 815 ASSERT(FLAG_warn_on_javascript_compatibility && FLAG_warning_as_error); |
| 816 Error& error = Error::Handle(); |
| 817 // We got an error during compilation. |
| 818 error = isolate->object_store()->sticky_error(); |
| 819 ASSERT(!error.IsNull()); |
| 820 isolate->object_store()->clear_sticky_error(); |
| 821 return error.raw(); |
804 } | 822 } |
805 | 823 |
806 ASSERT(success); | |
807 per_compile_timer.Stop(); | 824 per_compile_timer.Stop(); |
808 | 825 |
809 if (FLAG_trace_compiler) { | 826 if (FLAG_trace_compiler) { |
810 OS::Print("--> '%s' entry: %#" Px " size: %" Pd " time: %" Pd64 " us\n", | 827 OS::Print("--> '%s' entry: %#" Px " size: %" Pd " time: %" Pd64 " us\n", |
811 function.ToFullyQualifiedCString(), | 828 function.ToFullyQualifiedCString(), |
812 Code::Handle(function.CurrentCode()).EntryPoint(), | 829 Code::Handle(function.CurrentCode()).EntryPoint(), |
813 Code::Handle(function.CurrentCode()).Size(), | 830 Code::Handle(function.CurrentCode()).Size(), |
814 per_compile_timer.TotalElapsedTime()); | 831 per_compile_timer.TotalElapsedTime()); |
815 } | 832 } |
816 | 833 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 const Object& result = | 984 const Object& result = |
968 Object::Handle(isolate->object_store()->sticky_error()); | 985 Object::Handle(isolate->object_store()->sticky_error()); |
969 isolate->object_store()->clear_sticky_error(); | 986 isolate->object_store()->clear_sticky_error(); |
970 return result.raw(); | 987 return result.raw(); |
971 } | 988 } |
972 UNREACHABLE(); | 989 UNREACHABLE(); |
973 return Object::null(); | 990 return Object::null(); |
974 } | 991 } |
975 | 992 |
976 } // namespace dart | 993 } // namespace dart |
OLD | NEW |