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

Side by Side Diff: src/hydrogen.cc

Issue 7049005: Refactor TraceInlining method of hydrogen so it works correctly. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: adopt Kevin's suggestion that makes it less bad. Created 9 years, 7 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/hydrogen.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 4001 matching lines...) Expand 10 before | Expand all | Expand 10 after
4012 if (join->HasPredecessor()) { 4012 if (join->HasPredecessor()) {
4013 set_current_block(join); 4013 set_current_block(join);
4014 join->SetJoinId(expr->id()); 4014 join->SetJoinId(expr->id());
4015 if (!ast_context()->IsEffect()) ast_context()->ReturnValue(Pop()); 4015 if (!ast_context()->IsEffect()) ast_context()->ReturnValue(Pop());
4016 } else { 4016 } else {
4017 set_current_block(NULL); 4017 set_current_block(NULL);
4018 } 4018 }
4019 } 4019 }
4020 4020
4021 4021
4022 void HGraphBuilder::TraceInline(Handle<JSFunction> target, const char* reason) { 4022 void HGraphBuilder::TraceInline(Handle<JSFunction> target,
4023 Handle<JSFunction> caller,
4024 const char* reason) {
4023 if (FLAG_trace_inlining) { 4025 if (FLAG_trace_inlining) {
4026 SmartPointer<char> target_name = target->shared()->DebugName()->ToCString();
4027 SmartPointer<char> caller_name = caller->shared()->DebugName()->ToCString();
4024 if (reason == NULL) { 4028 if (reason == NULL) {
4025 // We are currently in the context of inlined function thus we have 4029 PrintF("Inlined %s called from %s.\n", *target_name, *caller_name);
4026 // to go to an outer FunctionState to get caller.
4027 SmartPointer<char> callee = target->shared()->DebugName()->ToCString();
4028 SmartPointer<char> caller =
4029 function_state()->outer()->compilation_info()->function()->
4030 debug_name()->ToCString();
4031 PrintF("Inlined %s called from %s.\n", *callee, *caller);
4032 } else { 4030 } else {
4033 SmartPointer<char> callee = target->shared()->DebugName()->ToCString();
4034 SmartPointer<char> caller =
4035 info()->function()->debug_name()->ToCString();
4036 PrintF("Did not inline %s called from %s (%s).\n", 4031 PrintF("Did not inline %s called from %s (%s).\n",
4037 *callee, *caller, reason); 4032 *target_name, *caller_name, reason);
4038 } 4033 }
4039 } 4034 }
4040 } 4035 }
4041 4036
4042 4037
4043 bool HGraphBuilder::TryInline(Call* expr) { 4038 bool HGraphBuilder::TryInline(Call* expr) {
4044 if (!FLAG_use_inlining) return false; 4039 if (!FLAG_use_inlining) return false;
4045 4040
4046 // Precondition: call is monomorphic and we have found a target with the 4041 // Precondition: call is monomorphic and we have found a target with the
4047 // appropriate arity. 4042 // appropriate arity.
4048 Handle<JSFunction> target = expr->target(); 4043 Handle<JSFunction> target = expr->target();
4044 Handle<JSFunction> caller = info()->closure();
4049 4045
4050 // Do a quick check on source code length to avoid parsing large 4046 // Do a quick check on source code length to avoid parsing large
4051 // inlining candidates. 4047 // inlining candidates.
4052 if (FLAG_limit_inlining && target->shared()->SourceSize() > kMaxSourceSize) { 4048 if (FLAG_limit_inlining && target->shared()->SourceSize() > kMaxSourceSize) {
4053 TraceInline(target, "target text too big"); 4049 TraceInline(target, caller, "target text too big");
4054 return false; 4050 return false;
4055 } 4051 }
4056 4052
4057 // Target must be inlineable. 4053 // Target must be inlineable.
4058 if (!target->IsInlineable()) { 4054 if (!target->IsInlineable()) {
4059 TraceInline(target, "target not inlineable"); 4055 TraceInline(target, caller, "target not inlineable");
4060 return false; 4056 return false;
4061 } 4057 }
4062 4058
4063 // No context change required. 4059 // No context change required.
4064 CompilationInfo* outer_info = info(); 4060 CompilationInfo* outer_info = info();
4065 if (target->context() != outer_info->closure()->context() || 4061 if (target->context() != outer_info->closure()->context() ||
4066 outer_info->scope()->contains_with() || 4062 outer_info->scope()->contains_with() ||
4067 outer_info->scope()->num_heap_slots() > 0) { 4063 outer_info->scope()->num_heap_slots() > 0) {
4068 TraceInline(target, "target requires context change"); 4064 TraceInline(target, caller, "target requires context change");
4069 return false; 4065 return false;
4070 } 4066 }
4071 4067
4072 // Don't inline deeper than kMaxInliningLevels calls. 4068 // Don't inline deeper than kMaxInliningLevels calls.
4073 HEnvironment* env = environment(); 4069 HEnvironment* env = environment();
4074 int current_level = 1; 4070 int current_level = 1;
4075 while (env->outer() != NULL) { 4071 while (env->outer() != NULL) {
4076 if (current_level == Compiler::kMaxInliningLevels) { 4072 if (current_level == Compiler::kMaxInliningLevels) {
4077 TraceInline(target, "inline depth limit reached"); 4073 TraceInline(target, caller, "inline depth limit reached");
4078 return false; 4074 return false;
4079 } 4075 }
4080 current_level++; 4076 current_level++;
4081 env = env->outer(); 4077 env = env->outer();
4082 } 4078 }
4083 4079
4084 // Don't inline recursive functions. 4080 // Don't inline recursive functions.
4085 if (target->shared() == outer_info->closure()->shared()) { 4081 if (target->shared() == outer_info->closure()->shared()) {
4086 TraceInline(target, "target is recursive"); 4082 TraceInline(target, caller, "target is recursive");
4087 return false; 4083 return false;
4088 } 4084 }
4089 4085
4090 // We don't want to add more than a certain number of nodes from inlining. 4086 // We don't want to add more than a certain number of nodes from inlining.
4091 if (FLAG_limit_inlining && inlined_count_ > kMaxInlinedNodes) { 4087 if (FLAG_limit_inlining && inlined_count_ > kMaxInlinedNodes) {
4092 TraceInline(target, "cumulative AST node limit reached"); 4088 TraceInline(target, caller, "cumulative AST node limit reached");
4093 return false; 4089 return false;
4094 } 4090 }
4095 4091
4096 int count_before = AstNode::Count(); 4092 int count_before = AstNode::Count();
4097 4093
4098 // Parse and allocate variables. 4094 // Parse and allocate variables.
4099 CompilationInfo target_info(target); 4095 CompilationInfo target_info(target);
4100 if (!ParserApi::Parse(&target_info) || 4096 if (!ParserApi::Parse(&target_info) ||
4101 !Scope::Analyze(&target_info)) { 4097 !Scope::Analyze(&target_info)) {
4102 if (target_info.isolate()->has_pending_exception()) { 4098 if (target_info.isolate()->has_pending_exception()) {
4103 // Parse or scope error, never optimize this function. 4099 // Parse or scope error, never optimize this function.
4104 SetStackOverflow(); 4100 SetStackOverflow();
4105 target->shared()->set_optimization_disabled(true); 4101 target->shared()->set_optimization_disabled(true);
4106 } 4102 }
4107 TraceInline(target, "parse failure"); 4103 TraceInline(target, caller, "parse failure");
4108 return false; 4104 return false;
4109 } 4105 }
4110 4106
4111 if (target_info.scope()->num_heap_slots() > 0) { 4107 if (target_info.scope()->num_heap_slots() > 0) {
4112 TraceInline(target, "target has context-allocated variables"); 4108 TraceInline(target, caller, "target has context-allocated variables");
4113 return false; 4109 return false;
4114 } 4110 }
4115 FunctionLiteral* function = target_info.function(); 4111 FunctionLiteral* function = target_info.function();
4116 4112
4117 // Count the number of AST nodes added by inlining this call. 4113 // Count the number of AST nodes added by inlining this call.
4118 int nodes_added = AstNode::Count() - count_before; 4114 int nodes_added = AstNode::Count() - count_before;
4119 if (FLAG_limit_inlining && nodes_added > kMaxInlinedSize) { 4115 if (FLAG_limit_inlining && nodes_added > kMaxInlinedSize) {
4120 TraceInline(target, "target AST is too large"); 4116 TraceInline(target, caller, "target AST is too large");
4121 return false; 4117 return false;
4122 } 4118 }
4123 4119
4124 // Check if we can handle all declarations in the inlined functions. 4120 // Check if we can handle all declarations in the inlined functions.
4125 VisitDeclarations(target_info.scope()->declarations()); 4121 VisitDeclarations(target_info.scope()->declarations());
4126 if (HasStackOverflow()) { 4122 if (HasStackOverflow()) {
4127 TraceInline(target, "target has non-trivial declaration"); 4123 TraceInline(target, caller, "target has non-trivial declaration");
4128 ClearStackOverflow(); 4124 ClearStackOverflow();
4129 return false; 4125 return false;
4130 } 4126 }
4131 4127
4132 // Don't inline functions that uses the arguments object or that 4128 // Don't inline functions that uses the arguments object or that
4133 // have a mismatching number of parameters. 4129 // have a mismatching number of parameters.
4134 Handle<SharedFunctionInfo> target_shared(target->shared()); 4130 Handle<SharedFunctionInfo> target_shared(target->shared());
4135 int arity = expr->arguments()->length(); 4131 int arity = expr->arguments()->length();
4136 if (function->scope()->arguments() != NULL || 4132 if (function->scope()->arguments() != NULL ||
4137 arity != target_shared->formal_parameter_count()) { 4133 arity != target_shared->formal_parameter_count()) {
4138 TraceInline(target, "target requires special argument handling"); 4134 TraceInline(target, caller, "target requires special argument handling");
4139 return false; 4135 return false;
4140 } 4136 }
4141 4137
4142 // All statements in the body must be inlineable. 4138 // All statements in the body must be inlineable.
4143 for (int i = 0, count = function->body()->length(); i < count; ++i) { 4139 for (int i = 0, count = function->body()->length(); i < count; ++i) {
4144 if (!function->body()->at(i)->IsInlineable()) { 4140 if (!function->body()->at(i)->IsInlineable()) {
4145 TraceInline(target, "target contains unsupported syntax"); 4141 TraceInline(target, caller, "target contains unsupported syntax");
4146 return false; 4142 return false;
4147 } 4143 }
4148 } 4144 }
4149 4145
4150 // Generate the deoptimization data for the unoptimized version of 4146 // Generate the deoptimization data for the unoptimized version of
4151 // the target function if we don't already have it. 4147 // the target function if we don't already have it.
4152 if (!target_shared->has_deoptimization_support()) { 4148 if (!target_shared->has_deoptimization_support()) {
4153 // Note that we compile here using the same AST that we will use for 4149 // Note that we compile here using the same AST that we will use for
4154 // generating the optimized inline code. 4150 // generating the optimized inline code.
4155 target_info.EnableDeoptimizationSupport(); 4151 target_info.EnableDeoptimizationSupport();
4156 if (!FullCodeGenerator::MakeCode(&target_info)) { 4152 if (!FullCodeGenerator::MakeCode(&target_info)) {
4157 TraceInline(target, "could not generate deoptimization info"); 4153 TraceInline(target, caller, "could not generate deoptimization info");
4158 return false; 4154 return false;
4159 } 4155 }
4160 target_shared->EnableDeoptimizationSupport(*target_info.code()); 4156 target_shared->EnableDeoptimizationSupport(*target_info.code());
4161 Compiler::RecordFunctionCompilation(Logger::FUNCTION_TAG, 4157 Compiler::RecordFunctionCompilation(Logger::FUNCTION_TAG,
4162 &target_info, 4158 &target_info,
4163 target_shared); 4159 target_shared);
4164 } 4160 }
4165 4161
4166 // ---------------------------------------------------------------- 4162 // ----------------------------------------------------------------
4167 // Save the pending call context and type feedback oracle. Set up new ones 4163 // Save the pending call context and type feedback oracle. Set up new ones
(...skipping 13 matching lines...) Expand all
4181 HBasicBlock* body_entry = CreateBasicBlock(inner_env); 4177 HBasicBlock* body_entry = CreateBasicBlock(inner_env);
4182 current_block()->Goto(body_entry); 4178 current_block()->Goto(body_entry);
4183 4179
4184 body_entry->SetJoinId(expr->ReturnId()); 4180 body_entry->SetJoinId(expr->ReturnId());
4185 set_current_block(body_entry); 4181 set_current_block(body_entry);
4186 AddInstruction(new(zone()) HEnterInlined(target, function)); 4182 AddInstruction(new(zone()) HEnterInlined(target, function));
4187 VisitStatements(function->body()); 4183 VisitStatements(function->body());
4188 if (HasStackOverflow()) { 4184 if (HasStackOverflow()) {
4189 // Bail out if the inline function did, as we cannot residualize a call 4185 // Bail out if the inline function did, as we cannot residualize a call
4190 // instead. 4186 // instead.
4191 TraceInline(target, "inline graph construction failed"); 4187 TraceInline(target, caller, "inline graph construction failed");
4192 return true; 4188 return true;
4193 } 4189 }
4194 4190
4195 // Update inlined nodes count. 4191 // Update inlined nodes count.
4196 inlined_count_ += nodes_added; 4192 inlined_count_ += nodes_added;
4197 4193
4198 TraceInline(target, NULL); 4194 TraceInline(target, caller, NULL);
4199 4195
4200 if (current_block() != NULL) { 4196 if (current_block() != NULL) {
4201 // Add a return of undefined if control can fall off the body. In a 4197 // Add a return of undefined if control can fall off the body. In a
4202 // test context, undefined is false. 4198 // test context, undefined is false.
4203 if (inlined_test_context() == NULL) { 4199 if (inlined_test_context() == NULL) {
4204 ASSERT(function_return() != NULL); 4200 ASSERT(function_return() != NULL);
4205 ASSERT(call_context()->IsEffect() || call_context()->IsValue()); 4201 ASSERT(call_context()->IsEffect() || call_context()->IsValue());
4206 if (call_context()->IsEffect()) { 4202 if (call_context()->IsEffect()) {
4207 current_block()->Goto(function_return(), false); 4203 current_block()->Goto(function_return(), false);
4208 } else { 4204 } else {
(...skipping 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after
6200 } 6196 }
6201 } 6197 }
6202 6198
6203 #ifdef DEBUG 6199 #ifdef DEBUG
6204 if (graph_ != NULL) graph_->Verify(); 6200 if (graph_ != NULL) graph_->Verify();
6205 if (allocator_ != NULL) allocator_->Verify(); 6201 if (allocator_ != NULL) allocator_->Verify();
6206 #endif 6202 #endif
6207 } 6203 }
6208 6204
6209 } } // namespace v8::internal 6205 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698