OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4791 : CALL_AS_METHOD; | 4791 : CALL_AS_METHOD; |
4792 | 4792 |
4793 // Precondition: call is monomorphic and we have found a target with the | 4793 // Precondition: call is monomorphic and we have found a target with the |
4794 // appropriate arity. | 4794 // appropriate arity. |
4795 Handle<JSFunction> caller = info()->closure(); | 4795 Handle<JSFunction> caller = info()->closure(); |
4796 Handle<JSFunction> target = expr->target(); | 4796 Handle<JSFunction> target = expr->target(); |
4797 Handle<SharedFunctionInfo> target_shared(target->shared()); | 4797 Handle<SharedFunctionInfo> target_shared(target->shared()); |
4798 | 4798 |
4799 // Do a quick check on source code length to avoid parsing large | 4799 // Do a quick check on source code length to avoid parsing large |
4800 // inlining candidates. | 4800 // inlining candidates. |
4801 if ((FLAG_limit_inlining && target->shared()->SourceSize() > kMaxSourceSize) | 4801 if ((FLAG_limit_inlining && target_shared->SourceSize() > kMaxSourceSize) |
4802 || target->shared()->SourceSize() > kUnlimitedMaxSourceSize) { | 4802 || target_shared->SourceSize() > kUnlimitedMaxSourceSize) { |
4803 TraceInline(target, caller, "target text too big"); | 4803 TraceInline(target, caller, "target text too big"); |
4804 return false; | 4804 return false; |
4805 } | 4805 } |
4806 | 4806 |
4807 // Target must be inlineable. | 4807 // Target must be inlineable. |
4808 if (!target->IsInlineable()) { | 4808 if (!target->IsInlineable()) { |
4809 TraceInline(target, caller, "target not inlineable"); | 4809 TraceInline(target, caller, "target not inlineable"); |
4810 return false; | 4810 return false; |
4811 } | 4811 } |
| 4812 if (target_shared->dont_inline() || target_shared->dont_crankshaft()) { |
| 4813 TraceInline(target, caller, "target contains unsupported syntax [early]"); |
| 4814 return false; |
| 4815 } |
| 4816 |
| 4817 int nodes_added = target_shared->ast_node_count(); |
| 4818 if ((FLAG_limit_inlining && nodes_added > kMaxInlinedSize) || |
| 4819 nodes_added > kUnlimitedMaxInlinedSize) { |
| 4820 TraceInline(target, caller, "target AST is too large [early]"); |
| 4821 return false; |
| 4822 } |
4812 | 4823 |
4813 #if !defined(V8_TARGET_ARCH_IA32) | 4824 #if !defined(V8_TARGET_ARCH_IA32) |
4814 // Target must be able to use caller's context. | 4825 // Target must be able to use caller's context. |
4815 CompilationInfo* outer_info = info(); | 4826 CompilationInfo* outer_info = info(); |
4816 if (target->context() != outer_info->closure()->context() || | 4827 if (target->context() != outer_info->closure()->context() || |
4817 outer_info->scope()->contains_with() || | 4828 outer_info->scope()->contains_with() || |
4818 outer_info->scope()->num_heap_slots() > 0) { | 4829 outer_info->scope()->num_heap_slots() > 0) { |
4819 TraceInline(target, caller, "target requires context change"); | 4830 TraceInline(target, caller, "target requires context change"); |
4820 return false; | 4831 return false; |
4821 } | 4832 } |
(...skipping 24 matching lines...) Expand all Loading... |
4846 } | 4857 } |
4847 } | 4858 } |
4848 | 4859 |
4849 // We don't want to add more than a certain number of nodes from inlining. | 4860 // We don't want to add more than a certain number of nodes from inlining. |
4850 if ((FLAG_limit_inlining && inlined_count_ > kMaxInlinedNodes) || | 4861 if ((FLAG_limit_inlining && inlined_count_ > kMaxInlinedNodes) || |
4851 inlined_count_ > kUnlimitedMaxInlinedNodes) { | 4862 inlined_count_ > kUnlimitedMaxInlinedNodes) { |
4852 TraceInline(target, caller, "cumulative AST node limit reached"); | 4863 TraceInline(target, caller, "cumulative AST node limit reached"); |
4853 return false; | 4864 return false; |
4854 } | 4865 } |
4855 | 4866 |
4856 int count_before = AstNode::Count(); | |
4857 | |
4858 // Parse and allocate variables. | 4867 // Parse and allocate variables. |
4859 CompilationInfo target_info(target); | 4868 CompilationInfo target_info(target); |
4860 if (!ParserApi::Parse(&target_info, kNoParsingFlags) || | 4869 if (!ParserApi::Parse(&target_info, kNoParsingFlags) || |
4861 !Scope::Analyze(&target_info)) { | 4870 !Scope::Analyze(&target_info)) { |
4862 if (target_info.isolate()->has_pending_exception()) { | 4871 if (target_info.isolate()->has_pending_exception()) { |
4863 // Parse or scope error, never optimize this function. | 4872 // Parse or scope error, never optimize this function. |
4864 SetStackOverflow(); | 4873 SetStackOverflow(); |
4865 target_shared->DisableOptimization(*target); | 4874 target_shared->DisableOptimization(*target); |
4866 } | 4875 } |
4867 TraceInline(target, caller, "parse failure"); | 4876 TraceInline(target, caller, "parse failure"); |
4868 return false; | 4877 return false; |
4869 } | 4878 } |
4870 | 4879 |
4871 if (target_info.scope()->num_heap_slots() > 0) { | 4880 if (target_info.scope()->num_heap_slots() > 0) { |
4872 TraceInline(target, caller, "target has context-allocated variables"); | 4881 TraceInline(target, caller, "target has context-allocated variables"); |
4873 return false; | 4882 return false; |
4874 } | 4883 } |
4875 FunctionLiteral* function = target_info.function(); | 4884 FunctionLiteral* function = target_info.function(); |
4876 | 4885 |
4877 // Count the number of AST nodes added by inlining this call. | 4886 // The following conditions must be checked again after re-parsing, because |
4878 int nodes_added = AstNode::Count() - count_before; | 4887 // earlier the information might not have been complete due to lazy parsing. |
| 4888 nodes_added = function->AstNodeCount(); |
4879 if ((FLAG_limit_inlining && nodes_added > kMaxInlinedSize) || | 4889 if ((FLAG_limit_inlining && nodes_added > kMaxInlinedSize) || |
4880 nodes_added > kUnlimitedMaxInlinedSize) { | 4890 nodes_added > kUnlimitedMaxInlinedSize) { |
4881 TraceInline(target, caller, "target AST is too large"); | 4891 TraceInline(target, caller, "target AST is too large [late]"); |
| 4892 return false; |
| 4893 } |
| 4894 AstProperties::Flags* flags(function->ast_properties()->flags()); |
| 4895 if (flags->Contains(kDontInline) || flags->Contains(kDontCrankshaft)) { |
| 4896 TraceInline(target, caller, "target contains unsupported syntax [late]"); |
4882 return false; | 4897 return false; |
4883 } | 4898 } |
4884 | 4899 |
4885 // Don't inline functions that uses the arguments object. | 4900 // Don't inline functions that uses the arguments object. |
4886 if (function->scope()->arguments() != NULL) { | 4901 if (function->scope()->arguments() != NULL) { |
4887 TraceInline(target, caller, "target requires special argument handling"); | 4902 TraceInline(target, caller, "target requires special argument handling"); |
4888 return false; | 4903 return false; |
4889 } | 4904 } |
4890 | 4905 |
4891 // All declarations must be inlineable. | 4906 // All declarations must be inlineable. |
4892 ZoneList<Declaration*>* decls = target_info.scope()->declarations(); | 4907 ZoneList<Declaration*>* decls = target_info.scope()->declarations(); |
4893 int decl_count = decls->length(); | 4908 int decl_count = decls->length(); |
4894 for (int i = 0; i < decl_count; ++i) { | 4909 for (int i = 0; i < decl_count; ++i) { |
4895 if (!decls->at(i)->IsInlineable()) { | 4910 if (!decls->at(i)->IsInlineable()) { |
4896 TraceInline(target, caller, "target has non-trivial declaration"); | 4911 TraceInline(target, caller, "target has non-trivial declaration"); |
4897 return false; | 4912 return false; |
4898 } | 4913 } |
4899 } | 4914 } |
4900 // All statements in the body must be inlineable. | |
4901 for (int i = 0, count = function->body()->length(); i < count; ++i) { | |
4902 if (!function->body()->at(i)->IsInlineable()) { | |
4903 TraceInline(target, caller, "target contains unsupported syntax"); | |
4904 return false; | |
4905 } | |
4906 } | |
4907 | 4915 |
4908 // Generate the deoptimization data for the unoptimized version of | 4916 // Generate the deoptimization data for the unoptimized version of |
4909 // the target function if we don't already have it. | 4917 // the target function if we don't already have it. |
4910 if (!target_shared->has_deoptimization_support()) { | 4918 if (!target_shared->has_deoptimization_support()) { |
4911 // Note that we compile here using the same AST that we will use for | 4919 // Note that we compile here using the same AST that we will use for |
4912 // generating the optimized inline code. | 4920 // generating the optimized inline code. |
4913 target_info.EnableDeoptimizationSupport(); | 4921 target_info.EnableDeoptimizationSupport(); |
4914 if (!FullCodeGenerator::MakeCode(&target_info)) { | 4922 if (!FullCodeGenerator::MakeCode(&target_info)) { |
4915 TraceInline(target, caller, "could not generate deoptimization info"); | 4923 TraceInline(target, caller, "could not generate deoptimization info"); |
4916 return false; | 4924 return false; |
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7453 } | 7461 } |
7454 } | 7462 } |
7455 | 7463 |
7456 #ifdef DEBUG | 7464 #ifdef DEBUG |
7457 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 7465 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
7458 if (allocator_ != NULL) allocator_->Verify(); | 7466 if (allocator_ != NULL) allocator_->Verify(); |
7459 #endif | 7467 #endif |
7460 } | 7468 } |
7461 | 7469 |
7462 } } // namespace v8::internal | 7470 } } // namespace v8::internal |
OLD | NEW |