| OLD | NEW |
| 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 3776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3787 | 3787 |
| 3788 | 3788 |
| 3789 bool HGraphBuilder::TryArgumentsAccess(Property* expr) { | 3789 bool HGraphBuilder::TryArgumentsAccess(Property* expr) { |
| 3790 VariableProxy* proxy = expr->obj()->AsVariableProxy(); | 3790 VariableProxy* proxy = expr->obj()->AsVariableProxy(); |
| 3791 if (proxy == NULL) return false; | 3791 if (proxy == NULL) return false; |
| 3792 if (!proxy->var()->IsStackAllocated()) return false; | 3792 if (!proxy->var()->IsStackAllocated()) return false; |
| 3793 if (!environment()->Lookup(proxy->var())->CheckFlag(HValue::kIsArguments)) { | 3793 if (!environment()->Lookup(proxy->var())->CheckFlag(HValue::kIsArguments)) { |
| 3794 return false; | 3794 return false; |
| 3795 } | 3795 } |
| 3796 | 3796 |
| 3797 // Our implementation of arguments (based on this stack frame or an |
| 3798 // adapter below it) does not work for inlined functions. |
| 3799 if (function_state()->outer() != NULL) { |
| 3800 Bailout("arguments access in inlined function"); |
| 3801 return true; |
| 3802 } |
| 3803 |
| 3797 HInstruction* result = NULL; | 3804 HInstruction* result = NULL; |
| 3798 if (expr->key()->IsPropertyName()) { | 3805 if (expr->key()->IsPropertyName()) { |
| 3799 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); | 3806 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); |
| 3800 if (!name->IsEqualTo(CStrVector("length"))) return false; | 3807 if (!name->IsEqualTo(CStrVector("length"))) return false; |
| 3801 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 3808 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); |
| 3802 result = new(zone()) HArgumentsLength(elements); | 3809 result = new(zone()) HArgumentsLength(elements); |
| 3803 } else { | 3810 } else { |
| 3804 Push(graph()->GetArgumentsObject()); | 3811 Push(graph()->GetArgumentsObject()); |
| 3805 VisitForValue(expr->key()); | 3812 VisitForValue(expr->key()); |
| 3806 if (HasStackOverflow()) return false; | 3813 if (HasStackOverflow()) return false; |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4308 } | 4315 } |
| 4309 return false; | 4316 return false; |
| 4310 } | 4317 } |
| 4311 | 4318 |
| 4312 | 4319 |
| 4313 bool HGraphBuilder::TryCallApply(Call* expr) { | 4320 bool HGraphBuilder::TryCallApply(Call* expr) { |
| 4314 Expression* callee = expr->expression(); | 4321 Expression* callee = expr->expression(); |
| 4315 Property* prop = callee->AsProperty(); | 4322 Property* prop = callee->AsProperty(); |
| 4316 ASSERT(prop != NULL); | 4323 ASSERT(prop != NULL); |
| 4317 | 4324 |
| 4325 if (!expr->IsMonomorphic() || expr->check_type() != RECEIVER_MAP_CHECK) { |
| 4326 return false; |
| 4327 } |
| 4328 Handle<Map> function_map = expr->GetReceiverTypes()->first(); |
| 4329 if (function_map->instance_type() != JS_FUNCTION_TYPE || |
| 4330 !expr->target()->shared()->HasBuiltinFunctionId() || |
| 4331 expr->target()->shared()->builtin_function_id() != kFunctionApply) { |
| 4332 return false; |
| 4333 } |
| 4334 |
| 4318 if (info()->scope()->arguments() == NULL) return false; | 4335 if (info()->scope()->arguments() == NULL) return false; |
| 4319 | 4336 |
| 4320 Handle<String> name = prop->key()->AsLiteral()->AsPropertyName(); | |
| 4321 if (!name->IsEqualTo(CStrVector("apply"))) return false; | |
| 4322 | |
| 4323 ZoneList<Expression*>* args = expr->arguments(); | 4337 ZoneList<Expression*>* args = expr->arguments(); |
| 4324 if (args->length() != 2) return false; | 4338 if (args->length() != 2) return false; |
| 4325 | 4339 |
| 4326 VariableProxy* arg_two = args->at(1)->AsVariableProxy(); | 4340 VariableProxy* arg_two = args->at(1)->AsVariableProxy(); |
| 4327 if (arg_two == NULL || !arg_two->var()->IsStackAllocated()) return false; | 4341 if (arg_two == NULL || !arg_two->var()->IsStackAllocated()) return false; |
| 4328 HValue* arg_two_value = environment()->Lookup(arg_two->var()); | 4342 HValue* arg_two_value = environment()->Lookup(arg_two->var()); |
| 4329 if (!arg_two_value->CheckFlag(HValue::kIsArguments)) return false; | 4343 if (!arg_two_value->CheckFlag(HValue::kIsArguments)) return false; |
| 4330 | 4344 |
| 4331 if (!expr->IsMonomorphic() || | 4345 // Our implementation of arguments (based on this stack frame or an |
| 4332 expr->check_type() != RECEIVER_MAP_CHECK) return false; | 4346 // adapter below it) does not work for inlined functions. |
| 4347 if (function_state()->outer() != NULL) { |
| 4348 Bailout("Function.prototype.apply optimization in inlined function"); |
| 4349 return true; |
| 4350 } |
| 4333 | 4351 |
| 4334 // Found pattern f.apply(receiver, arguments). | 4352 // Found pattern f.apply(receiver, arguments). |
| 4335 VisitForValue(prop->obj()); | 4353 VisitForValue(prop->obj()); |
| 4336 if (HasStackOverflow()) return false; | 4354 if (HasStackOverflow()) return false; |
| 4337 HValue* function = Pop(); | 4355 HValue* function = Pop(); |
| 4338 VisitForValue(args->at(0)); | 4356 VisitForValue(args->at(0)); |
| 4339 if (HasStackOverflow()) return false; | 4357 if (HasStackOverflow()) return false; |
| 4340 HValue* receiver = Pop(); | 4358 HValue* receiver = Pop(); |
| 4341 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 4359 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); |
| 4342 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); | 4360 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); |
| 4343 AddCheckConstantFunction(expr, | 4361 AddCheckConstantFunction(expr, function, function_map, true); |
| 4344 function, | |
| 4345 expr->GetReceiverTypes()->first(), | |
| 4346 true); | |
| 4347 HInstruction* result = | 4362 HInstruction* result = |
| 4348 new(zone()) HApplyArguments(function, receiver, length, elements); | 4363 new(zone()) HApplyArguments(function, receiver, length, elements); |
| 4349 result->set_position(expr->position()); | 4364 result->set_position(expr->position()); |
| 4350 ast_context()->ReturnInstruction(result, expr->id()); | 4365 ast_context()->ReturnInstruction(result, expr->id()); |
| 4351 return true; | 4366 return true; |
| 4352 } | 4367 } |
| 4353 | 4368 |
| 4354 | 4369 |
| 4355 void HGraphBuilder::VisitCall(Call* expr) { | 4370 void HGraphBuilder::VisitCall(Call* expr) { |
| 4356 Expression* callee = expr->expression(); | 4371 Expression* callee = expr->expression(); |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5267 // false from %_IsConstructCall(). | 5282 // false from %_IsConstructCall(). |
| 5268 ast_context()->ReturnValue(graph()->GetConstantFalse()); | 5283 ast_context()->ReturnValue(graph()->GetConstantFalse()); |
| 5269 } else { | 5284 } else { |
| 5270 ast_context()->ReturnInstruction(new(zone()) HIsConstructCall, call->id()); | 5285 ast_context()->ReturnInstruction(new(zone()) HIsConstructCall, call->id()); |
| 5271 } | 5286 } |
| 5272 } | 5287 } |
| 5273 | 5288 |
| 5274 | 5289 |
| 5275 // Support for arguments.length and arguments[?]. | 5290 // Support for arguments.length and arguments[?]. |
| 5276 void HGraphBuilder::GenerateArgumentsLength(CallRuntime* call) { | 5291 void HGraphBuilder::GenerateArgumentsLength(CallRuntime* call) { |
| 5292 // Our implementation of arguments (based on this stack frame or an |
| 5293 // adapter below it) does not work for inlined functions. This runtime |
| 5294 // function is blacklisted by AstNode::IsInlineable. |
| 5295 ASSERT(function_state()->outer() == NULL); |
| 5277 ASSERT(call->arguments()->length() == 0); | 5296 ASSERT(call->arguments()->length() == 0); |
| 5278 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 5297 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); |
| 5279 HArgumentsLength* result = new(zone()) HArgumentsLength(elements); | 5298 HArgumentsLength* result = new(zone()) HArgumentsLength(elements); |
| 5280 ast_context()->ReturnInstruction(result, call->id()); | 5299 ast_context()->ReturnInstruction(result, call->id()); |
| 5281 } | 5300 } |
| 5282 | 5301 |
| 5283 | 5302 |
| 5284 void HGraphBuilder::GenerateArguments(CallRuntime* call) { | 5303 void HGraphBuilder::GenerateArguments(CallRuntime* call) { |
| 5304 // Our implementation of arguments (based on this stack frame or an |
| 5305 // adapter below it) does not work for inlined functions. This runtime |
| 5306 // function is blacklisted by AstNode::IsInlineable. |
| 5307 ASSERT(function_state()->outer() == NULL); |
| 5285 ASSERT(call->arguments()->length() == 1); | 5308 ASSERT(call->arguments()->length() == 1); |
| 5286 VISIT_FOR_VALUE(call->arguments()->at(0)); | 5309 VISIT_FOR_VALUE(call->arguments()->at(0)); |
| 5287 HValue* index = Pop(); | 5310 HValue* index = Pop(); |
| 5288 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 5311 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); |
| 5289 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); | 5312 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); |
| 5290 HAccessArgumentsAt* result = | 5313 HAccessArgumentsAt* result = |
| 5291 new(zone()) HAccessArgumentsAt(elements, length, index); | 5314 new(zone()) HAccessArgumentsAt(elements, length, index); |
| 5292 ast_context()->ReturnInstruction(result, call->id()); | 5315 ast_context()->ReturnInstruction(result, call->id()); |
| 5293 } | 5316 } |
| 5294 | 5317 |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6074 } | 6097 } |
| 6075 } | 6098 } |
| 6076 | 6099 |
| 6077 #ifdef DEBUG | 6100 #ifdef DEBUG |
| 6078 if (graph_ != NULL) graph_->Verify(); | 6101 if (graph_ != NULL) graph_->Verify(); |
| 6079 if (allocator_ != NULL) allocator_->Verify(); | 6102 if (allocator_ != NULL) allocator_->Verify(); |
| 6080 #endif | 6103 #endif |
| 6081 } | 6104 } |
| 6082 | 6105 |
| 6083 } } // namespace v8::internal | 6106 } } // namespace v8::internal |
| OLD | NEW |