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

Side by Side Diff: src/hydrogen.cc

Issue 7497067: Fix fun.apply(receiver, arguments) optimization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 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') | src/objects.h » ('j') | 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 4744 matching lines...) Expand 10 before | Expand all | Expand 10 after
4755 } 4755 }
4756 return false; 4756 return false;
4757 } 4757 }
4758 4758
4759 4759
4760 bool HGraphBuilder::TryCallApply(Call* expr) { 4760 bool HGraphBuilder::TryCallApply(Call* expr) {
4761 Expression* callee = expr->expression(); 4761 Expression* callee = expr->expression();
4762 Property* prop = callee->AsProperty(); 4762 Property* prop = callee->AsProperty();
4763 ASSERT(prop != NULL); 4763 ASSERT(prop != NULL);
4764 4764
4765 if (!expr->IsMonomorphic() || expr->check_type() != RECEIVER_MAP_CHECK) {
4766 return false;
4767 }
4768 Handle<Map> function_map = expr->GetReceiverTypes()->first();
4769 if (function_map->instance_type() != JS_FUNCTION_TYPE ||
4770 !expr->target()->shared()->HasBuiltinFunctionId() ||
4771 expr->target()->shared()->builtin_function_id() != kFunctionApply) {
4772 return false;
4773 }
4774
4765 if (info()->scope()->arguments() == NULL) return false; 4775 if (info()->scope()->arguments() == NULL) return false;
4766 4776
4767 Handle<String> name = prop->key()->AsLiteral()->AsPropertyName();
4768 if (!name->IsEqualTo(CStrVector("apply"))) return false;
4769
4770 ZoneList<Expression*>* args = expr->arguments(); 4777 ZoneList<Expression*>* args = expr->arguments();
4771 if (args->length() != 2) return false; 4778 if (args->length() != 2) return false;
4772 4779
4773 VariableProxy* arg_two = args->at(1)->AsVariableProxy(); 4780 VariableProxy* arg_two = args->at(1)->AsVariableProxy();
4774 if (arg_two == NULL || !arg_two->var()->IsStackAllocated()) return false; 4781 if (arg_two == NULL || !arg_two->var()->IsStackAllocated()) return false;
4775 HValue* arg_two_value = environment()->Lookup(arg_two->var()); 4782 HValue* arg_two_value = environment()->Lookup(arg_two->var());
4776 if (!arg_two_value->CheckFlag(HValue::kIsArguments)) return false; 4783 if (!arg_two_value->CheckFlag(HValue::kIsArguments)) return false;
4777 4784
4778 if (!expr->IsMonomorphic() ||
4779 expr->check_type() != RECEIVER_MAP_CHECK) return false;
4780
4781 // Our implementation of arguments (based on this stack frame or an 4785 // Our implementation of arguments (based on this stack frame or an
4782 // adapter below it) does not work for inlined functions. 4786 // adapter below it) does not work for inlined functions.
4783 if (function_state()->outer() != NULL) { 4787 if (function_state()->outer() != NULL) {
4784 Bailout("Function.prototype.apply optimization in inlined function"); 4788 Bailout("Function.prototype.apply optimization in inlined function");
4785 return true; 4789 return true;
4786 } 4790 }
4787 4791
4788 // Found pattern f.apply(receiver, arguments). 4792 // Found pattern f.apply(receiver, arguments).
4789 VisitForValue(prop->obj()); 4793 VisitForValue(prop->obj());
4790 if (HasStackOverflow() || current_block() == NULL) return true; 4794 if (HasStackOverflow() || current_block() == NULL) return true;
4791 HValue* function = Pop(); 4795 HValue* function = Pop();
4792 VisitForValue(args->at(0)); 4796 VisitForValue(args->at(0));
4793 if (HasStackOverflow() || current_block() == NULL) return true; 4797 if (HasStackOverflow() || current_block() == NULL) return true;
4794 HValue* receiver = Pop(); 4798 HValue* receiver = Pop();
4795 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); 4799 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements);
4796 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); 4800 HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements));
4797 AddCheckConstantFunction(expr, 4801 AddCheckConstantFunction(expr, function, function_map, true);
4798 function,
4799 expr->GetReceiverTypes()->first(),
4800 true);
4801 HInstruction* result = 4802 HInstruction* result =
4802 new(zone()) HApplyArguments(function, receiver, length, elements); 4803 new(zone()) HApplyArguments(function, receiver, length, elements);
4803 result->set_position(expr->position()); 4804 result->set_position(expr->position());
4804 ast_context()->ReturnInstruction(result, expr->id()); 4805 ast_context()->ReturnInstruction(result, expr->id());
4805 return true; 4806 return true;
4806 } 4807 }
4807 4808
4808 4809
4809 void HGraphBuilder::VisitCall(Call* expr) { 4810 void HGraphBuilder::VisitCall(Call* expr) {
4810 ASSERT(!HasStackOverflow()); 4811 ASSERT(!HasStackOverflow());
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after
6746 } 6747 }
6747 } 6748 }
6748 6749
6749 #ifdef DEBUG 6750 #ifdef DEBUG
6750 if (graph_ != NULL) graph_->Verify(); 6751 if (graph_ != NULL) graph_->Verify();
6751 if (allocator_ != NULL) allocator_->Verify(); 6752 if (allocator_ != NULL) allocator_->Verify();
6752 #endif 6753 #endif
6753 } 6754 }
6754 6755
6755 } } // namespace v8::internal 6756 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698