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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 void HBasicBlock::AddInstruction(HInstruction* instr) { | 106 void HBasicBlock::AddInstruction(HInstruction* instr) { |
107 ASSERT(!IsStartBlock() || !IsFinished()); | 107 ASSERT(!IsStartBlock() || !IsFinished()); |
108 ASSERT(!instr->IsLinked()); | 108 ASSERT(!instr->IsLinked()); |
109 ASSERT(!IsFinished()); | 109 ASSERT(!IsFinished()); |
110 if (first_ == NULL) { | 110 if (first_ == NULL) { |
111 HBlockEntry* entry = new(zone()) HBlockEntry(); | 111 HBlockEntry* entry = new(zone()) HBlockEntry(); |
112 entry->InitializeAsFirst(this); | 112 entry->InitializeAsFirst(this); |
113 first_ = last_ = entry; | 113 first_ = last_ = entry; |
114 } | 114 } |
115 instr->InsertAfter(last_); | 115 instr->InsertAfter(last_); |
116 last_ = instr; | |
117 } | 116 } |
118 | 117 |
119 | 118 |
120 HDeoptimize* HBasicBlock::CreateDeoptimize( | 119 HDeoptimize* HBasicBlock::CreateDeoptimize( |
121 HDeoptimize::UseEnvironment has_uses) { | 120 HDeoptimize::UseEnvironment has_uses) { |
122 ASSERT(HasEnvironment()); | 121 ASSERT(HasEnvironment()); |
123 if (has_uses == HDeoptimize::kNoUses) return new(zone()) HDeoptimize(0); | 122 if (has_uses == HDeoptimize::kNoUses) return new(zone()) HDeoptimize(0); |
124 | 123 |
125 HEnvironment* environment = last_environment(); | 124 HEnvironment* environment = last_environment(); |
126 HDeoptimize* instr = new(zone()) HDeoptimize(environment->length()); | 125 HDeoptimize* instr = new(zone()) HDeoptimize(environment->length()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 void HBasicBlock::Finish(HControlInstruction* end) { | 157 void HBasicBlock::Finish(HControlInstruction* end) { |
159 ASSERT(!IsFinished()); | 158 ASSERT(!IsFinished()); |
160 AddInstruction(end); | 159 AddInstruction(end); |
161 end_ = end; | 160 end_ = end; |
162 for (HSuccessorIterator it(end); !it.Done(); it.Advance()) { | 161 for (HSuccessorIterator it(end); !it.Done(); it.Advance()) { |
163 it.Current()->RegisterPredecessor(this); | 162 it.Current()->RegisterPredecessor(this); |
164 } | 163 } |
165 } | 164 } |
166 | 165 |
167 | 166 |
168 void HBasicBlock::Goto(HBasicBlock* block, bool drop_extra) { | 167 void HBasicBlock::Goto(HBasicBlock* block, FunctionState* state) { |
168 bool drop_extra = state != NULL && state->drop_extra(); | |
169 bool arguments_pushed = state != NULL && state->arguments_pushed(); | |
170 | |
169 if (block->IsInlineReturnTarget()) { | 171 if (block->IsInlineReturnTarget()) { |
170 AddInstruction(new(zone()) HLeaveInlined); | 172 AddInstruction(new(zone()) HLeaveInlined(arguments_pushed)); |
171 last_environment_ = last_environment()->DiscardInlined(drop_extra); | 173 last_environment_ = last_environment()->DiscardInlined(drop_extra); |
172 } | 174 } |
175 | |
173 AddSimulate(AstNode::kNoNumber); | 176 AddSimulate(AstNode::kNoNumber); |
174 HGoto* instr = new(zone()) HGoto(block); | 177 HGoto* instr = new(zone()) HGoto(block); |
175 Finish(instr); | 178 Finish(instr); |
176 } | 179 } |
177 | 180 |
178 | 181 |
179 void HBasicBlock::AddLeaveInlined(HValue* return_value, | 182 void HBasicBlock::AddLeaveInlined(HValue* return_value, |
180 HBasicBlock* target, | 183 HBasicBlock* target, |
181 bool drop_extra) { | 184 FunctionState* state) { |
185 bool drop_extra = state != NULL && state->drop_extra(); | |
186 bool arguments_pushed = state != NULL && state->arguments_pushed(); | |
187 | |
182 ASSERT(target->IsInlineReturnTarget()); | 188 ASSERT(target->IsInlineReturnTarget()); |
183 ASSERT(return_value != NULL); | 189 ASSERT(return_value != NULL); |
184 AddInstruction(new(zone()) HLeaveInlined); | 190 AddInstruction(new(zone()) HLeaveInlined(arguments_pushed)); |
185 last_environment_ = last_environment()->DiscardInlined(drop_extra); | 191 last_environment_ = last_environment()->DiscardInlined(drop_extra); |
186 last_environment()->Push(return_value); | 192 last_environment()->Push(return_value); |
187 AddSimulate(AstNode::kNoNumber); | 193 AddSimulate(AstNode::kNoNumber); |
188 HGoto* instr = new(zone()) HGoto(target); | 194 HGoto* instr = new(zone()) HGoto(target); |
189 Finish(instr); | 195 Finish(instr); |
190 } | 196 } |
191 | 197 |
192 | 198 |
193 void HBasicBlock::SetInitialEnvironment(HEnvironment* env) { | 199 void HBasicBlock::SetInitialEnvironment(HEnvironment* env) { |
194 ASSERT(!HasEnvironment()); | 200 ASSERT(!HasEnvironment()); |
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2171 CompilationInfo* info, | 2177 CompilationInfo* info, |
2172 TypeFeedbackOracle* oracle, | 2178 TypeFeedbackOracle* oracle, |
2173 ReturnHandlingFlag return_handling) | 2179 ReturnHandlingFlag return_handling) |
2174 : owner_(owner), | 2180 : owner_(owner), |
2175 compilation_info_(info), | 2181 compilation_info_(info), |
2176 oracle_(oracle), | 2182 oracle_(oracle), |
2177 call_context_(NULL), | 2183 call_context_(NULL), |
2178 return_handling_(return_handling), | 2184 return_handling_(return_handling), |
2179 function_return_(NULL), | 2185 function_return_(NULL), |
2180 test_context_(NULL), | 2186 test_context_(NULL), |
2187 entry_(NULL), | |
2188 arguments_elements_(NULL), | |
2181 outer_(owner->function_state()) { | 2189 outer_(owner->function_state()) { |
2182 if (outer_ != NULL) { | 2190 if (outer_ != NULL) { |
2183 // State for an inline function. | 2191 // State for an inline function. |
2184 if (owner->ast_context()->IsTest()) { | 2192 if (owner->ast_context()->IsTest()) { |
2185 HBasicBlock* if_true = owner->graph()->CreateBasicBlock(); | 2193 HBasicBlock* if_true = owner->graph()->CreateBasicBlock(); |
2186 HBasicBlock* if_false = owner->graph()->CreateBasicBlock(); | 2194 HBasicBlock* if_false = owner->graph()->CreateBasicBlock(); |
2187 if_true->MarkAsInlineReturnTarget(); | 2195 if_true->MarkAsInlineReturnTarget(); |
2188 if_false->MarkAsInlineReturnTarget(); | 2196 if_false->MarkAsInlineReturnTarget(); |
2189 Expression* cond = TestContext::cast(owner->ast_context())->condition(); | 2197 Expression* cond = TestContext::cast(owner->ast_context())->condition(); |
2190 // The AstContext constructor pushed on the context stack. This newed | 2198 // The AstContext constructor pushed on the context stack. This newed |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2330 } | 2338 } |
2331 | 2339 |
2332 | 2340 |
2333 void TestContext::ReturnControl(HControlInstruction* instr, int ast_id) { | 2341 void TestContext::ReturnControl(HControlInstruction* instr, int ast_id) { |
2334 ASSERT(!instr->HasObservableSideEffects()); | 2342 ASSERT(!instr->HasObservableSideEffects()); |
2335 HBasicBlock* empty_true = owner()->graph()->CreateBasicBlock(); | 2343 HBasicBlock* empty_true = owner()->graph()->CreateBasicBlock(); |
2336 HBasicBlock* empty_false = owner()->graph()->CreateBasicBlock(); | 2344 HBasicBlock* empty_false = owner()->graph()->CreateBasicBlock(); |
2337 instr->SetSuccessorAt(0, empty_true); | 2345 instr->SetSuccessorAt(0, empty_true); |
2338 instr->SetSuccessorAt(1, empty_false); | 2346 instr->SetSuccessorAt(1, empty_false); |
2339 owner()->current_block()->Finish(instr); | 2347 owner()->current_block()->Finish(instr); |
2340 empty_true->Goto(if_true(), owner()->function_state()->drop_extra()); | 2348 empty_true->Goto(if_true(), owner()->function_state()); |
2341 empty_false->Goto(if_false(), owner()->function_state()->drop_extra()); | 2349 empty_false->Goto(if_false(), owner()->function_state()); |
2342 owner()->set_current_block(NULL); | 2350 owner()->set_current_block(NULL); |
2343 } | 2351 } |
2344 | 2352 |
2345 | 2353 |
2346 void TestContext::BuildBranch(HValue* value) { | 2354 void TestContext::BuildBranch(HValue* value) { |
2347 // We expect the graph to be in edge-split form: there is no edge that | 2355 // We expect the graph to be in edge-split form: there is no edge that |
2348 // connects a branch node to a join node. We conservatively ensure that | 2356 // connects a branch node to a join node. We conservatively ensure that |
2349 // property by always adding an empty block on the outgoing edges of this | 2357 // property by always adding an empty block on the outgoing edges of this |
2350 // branch. | 2358 // branch. |
2351 HGraphBuilder* builder = owner(); | 2359 HGraphBuilder* builder = owner(); |
2352 if (value != NULL && value->CheckFlag(HValue::kIsArguments)) { | 2360 if (value != NULL && value->CheckFlag(HValue::kIsArguments)) { |
2353 builder->Bailout("arguments object value in a test context"); | 2361 builder->Bailout("arguments object value in a test context"); |
2354 } | 2362 } |
2355 HBasicBlock* empty_true = builder->graph()->CreateBasicBlock(); | 2363 HBasicBlock* empty_true = builder->graph()->CreateBasicBlock(); |
2356 HBasicBlock* empty_false = builder->graph()->CreateBasicBlock(); | 2364 HBasicBlock* empty_false = builder->graph()->CreateBasicBlock(); |
2357 unsigned test_id = condition()->test_id(); | 2365 unsigned test_id = condition()->test_id(); |
2358 ToBooleanStub::Types expected(builder->oracle()->ToBooleanTypes(test_id)); | 2366 ToBooleanStub::Types expected(builder->oracle()->ToBooleanTypes(test_id)); |
2359 HBranch* test = new(zone()) HBranch(value, empty_true, empty_false, expected); | 2367 HBranch* test = new(zone()) HBranch(value, empty_true, empty_false, expected); |
2360 builder->current_block()->Finish(test); | 2368 builder->current_block()->Finish(test); |
2361 | 2369 |
2362 empty_true->Goto(if_true(), owner()->function_state()->drop_extra()); | 2370 empty_true->Goto(if_true(), owner()->function_state()); |
2363 empty_false->Goto(if_false(), owner()->function_state()->drop_extra()); | 2371 empty_false->Goto(if_false(), owner()->function_state()); |
2364 builder->set_current_block(NULL); | 2372 builder->set_current_block(NULL); |
2365 } | 2373 } |
2366 | 2374 |
2367 | 2375 |
2368 // HGraphBuilder infrastructure for bailing out and checking bailouts. | 2376 // HGraphBuilder infrastructure for bailing out and checking bailouts. |
2369 #define CHECK_BAILOUT(call) \ | 2377 #define CHECK_BAILOUT(call) \ |
2370 do { \ | 2378 do { \ |
2371 call; \ | 2379 call; \ |
2372 if (HasStackOverflow()) return; \ | 2380 if (HasStackOverflow()) return; \ |
2373 } while (false) | 2381 } while (false) |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2848 CHECK_ALIVE(VisitForValue(stmt->expression())); | 2856 CHECK_ALIVE(VisitForValue(stmt->expression())); |
2849 HValue* result = environment()->Pop(); | 2857 HValue* result = environment()->Pop(); |
2850 current_block()->FinishExit(new(zone()) HReturn(result)); | 2858 current_block()->FinishExit(new(zone()) HReturn(result)); |
2851 } else if (function_state()->is_construct()) { | 2859 } else if (function_state()->is_construct()) { |
2852 // Return from an inlined construct call. In a test context the return | 2860 // Return from an inlined construct call. In a test context the return |
2853 // value will always evaluate to true, in a value context the return value | 2861 // value will always evaluate to true, in a value context the return value |
2854 // needs to be a JSObject. | 2862 // needs to be a JSObject. |
2855 if (context->IsTest()) { | 2863 if (context->IsTest()) { |
2856 TestContext* test = TestContext::cast(context); | 2864 TestContext* test = TestContext::cast(context); |
2857 CHECK_ALIVE(VisitForEffect(stmt->expression())); | 2865 CHECK_ALIVE(VisitForEffect(stmt->expression())); |
2858 current_block()->Goto(test->if_true(), function_state()->drop_extra()); | 2866 current_block()->Goto(test->if_true(), function_state()); |
2859 } else if (context->IsEffect()) { | 2867 } else if (context->IsEffect()) { |
2860 CHECK_ALIVE(VisitForEffect(stmt->expression())); | 2868 CHECK_ALIVE(VisitForEffect(stmt->expression())); |
2861 current_block()->Goto(function_return(), function_state()->drop_extra()); | 2869 current_block()->Goto(function_return(), function_state()); |
2862 } else { | 2870 } else { |
2863 ASSERT(context->IsValue()); | 2871 ASSERT(context->IsValue()); |
2864 CHECK_ALIVE(VisitForValue(stmt->expression())); | 2872 CHECK_ALIVE(VisitForValue(stmt->expression())); |
2865 HValue* return_value = Pop(); | 2873 HValue* return_value = Pop(); |
2866 HValue* receiver = environment()->Lookup(0); | 2874 HValue* receiver = environment()->Lookup(0); |
2867 HHasInstanceTypeAndBranch* typecheck = | 2875 HHasInstanceTypeAndBranch* typecheck = |
2868 new(zone()) HHasInstanceTypeAndBranch(return_value, | 2876 new(zone()) HHasInstanceTypeAndBranch(return_value, |
2869 FIRST_SPEC_OBJECT_TYPE, | 2877 FIRST_SPEC_OBJECT_TYPE, |
2870 LAST_SPEC_OBJECT_TYPE); | 2878 LAST_SPEC_OBJECT_TYPE); |
2871 HBasicBlock* if_spec_object = graph()->CreateBasicBlock(); | 2879 HBasicBlock* if_spec_object = graph()->CreateBasicBlock(); |
2872 HBasicBlock* not_spec_object = graph()->CreateBasicBlock(); | 2880 HBasicBlock* not_spec_object = graph()->CreateBasicBlock(); |
2873 typecheck->SetSuccessorAt(0, if_spec_object); | 2881 typecheck->SetSuccessorAt(0, if_spec_object); |
2874 typecheck->SetSuccessorAt(1, not_spec_object); | 2882 typecheck->SetSuccessorAt(1, not_spec_object); |
2875 current_block()->Finish(typecheck); | 2883 current_block()->Finish(typecheck); |
2876 if_spec_object->AddLeaveInlined(return_value, | 2884 if_spec_object->AddLeaveInlined(return_value, |
2877 function_return(), | 2885 function_return(), |
2878 function_state()->drop_extra()); | 2886 function_state()); |
2879 not_spec_object->AddLeaveInlined(receiver, | 2887 not_spec_object->AddLeaveInlined(receiver, |
2880 function_return(), | 2888 function_return(), |
2881 function_state()->drop_extra()); | 2889 function_state()); |
2882 } | 2890 } |
2883 } else { | 2891 } else { |
2884 // Return from an inlined function, visit the subexpression in the | 2892 // Return from an inlined function, visit the subexpression in the |
2885 // expression context of the call. | 2893 // expression context of the call. |
2886 if (context->IsTest()) { | 2894 if (context->IsTest()) { |
2887 TestContext* test = TestContext::cast(context); | 2895 TestContext* test = TestContext::cast(context); |
2888 VisitForControl(stmt->expression(), | 2896 VisitForControl(stmt->expression(), |
2889 test->if_true(), | 2897 test->if_true(), |
2890 test->if_false()); | 2898 test->if_false()); |
2891 } else if (context->IsEffect()) { | 2899 } else if (context->IsEffect()) { |
2892 CHECK_ALIVE(VisitForEffect(stmt->expression())); | 2900 CHECK_ALIVE(VisitForEffect(stmt->expression())); |
2893 current_block()->Goto(function_return(), function_state()->drop_extra()); | 2901 current_block()->Goto(function_return(), function_state()); |
2894 } else { | 2902 } else { |
2895 ASSERT(context->IsValue()); | 2903 ASSERT(context->IsValue()); |
2896 CHECK_ALIVE(VisitForValue(stmt->expression())); | 2904 CHECK_ALIVE(VisitForValue(stmt->expression())); |
2897 HValue* return_value = Pop(); | 2905 HValue* return_value = Pop(); |
2898 current_block()->AddLeaveInlined(return_value, | 2906 current_block()->AddLeaveInlined(return_value, |
2899 function_return(), | 2907 function_return(), |
2900 function_state()->drop_extra()); | 2908 function_state()); |
2901 } | 2909 } |
2902 } | 2910 } |
2903 set_current_block(NULL); | 2911 set_current_block(NULL); |
2904 } | 2912 } |
2905 | 2913 |
2906 | 2914 |
2907 void HGraphBuilder::VisitWithStatement(WithStatement* stmt) { | 2915 void HGraphBuilder::VisitWithStatement(WithStatement* stmt) { |
2908 ASSERT(!HasStackOverflow()); | 2916 ASSERT(!HasStackOverflow()); |
2909 ASSERT(current_block() != NULL); | 2917 ASSERT(current_block() != NULL); |
2910 ASSERT(current_block()->HasPredecessor()); | 2918 ASSERT(current_block()->HasPredecessor()); |
(...skipping 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4985 } | 4993 } |
4986 | 4994 |
4987 bool HGraphBuilder::TryArgumentsAccess(Property* expr) { | 4995 bool HGraphBuilder::TryArgumentsAccess(Property* expr) { |
4988 VariableProxy* proxy = expr->obj()->AsVariableProxy(); | 4996 VariableProxy* proxy = expr->obj()->AsVariableProxy(); |
4989 if (proxy == NULL) return false; | 4997 if (proxy == NULL) return false; |
4990 if (!proxy->var()->IsStackAllocated()) return false; | 4998 if (!proxy->var()->IsStackAllocated()) return false; |
4991 if (!environment()->Lookup(proxy->var())->CheckFlag(HValue::kIsArguments)) { | 4999 if (!environment()->Lookup(proxy->var())->CheckFlag(HValue::kIsArguments)) { |
4992 return false; | 5000 return false; |
4993 } | 5001 } |
4994 | 5002 |
4995 // Our implementation of arguments (based on this stack frame or an | |
4996 // adapter below it) does not work for inlined functions. | |
4997 if (function_state()->outer() != NULL) { | 5003 if (function_state()->outer() != NULL) { |
4998 Bailout("arguments access in inlined function"); | 5004 // Push arguments when entering inlined function. |
4999 return true; | 5005 if (!function_state()->arguments_pushed()) { |
Kevin Millikin (Chromium)
2012/04/11 11:49:18
I'd move this after all possible "return false", s
Vyacheslav Egorov (Chromium)
2012/04/11 12:47:28
Done.
| |
5006 HInstruction* insert_after = function_state()->entry(); | |
5007 ASSERT(insert_after->IsEnterInlined()); | |
5008 | |
5009 ZoneList<HValue*>* arguments_values = | |
5010 HEnterInlined::cast(insert_after)->arguments_values(); | |
5011 | |
5012 for (int i = 0; i < arguments_values->length(); i++) { | |
5013 HValue* argument = arguments_values->at(i); | |
5014 HInstruction* push_argument = new(zone()) HPushArgument(argument); | |
5015 push_argument->InsertAfter(insert_after); | |
5016 insert_after = push_argument; | |
5017 } | |
5018 | |
5019 HInstruction* arguments_elements = new(zone()) HArgumentsElements(); | |
5020 arguments_elements->ClearFlag(HValue::kUseGVN); | |
5021 arguments_elements->InsertAfter(insert_after); | |
5022 function_state()->set_arguments_elements(arguments_elements); | |
5023 } | |
5000 } | 5024 } |
5001 | 5025 |
5002 HInstruction* result = NULL; | 5026 HInstruction* result = NULL; |
5003 if (expr->key()->IsPropertyName()) { | 5027 if (expr->key()->IsPropertyName()) { |
5004 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); | 5028 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); |
5005 if (!name->IsEqualTo(CStrVector("length"))) return false; | 5029 if (!name->IsEqualTo(CStrVector("length"))) return false; |
5006 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 5030 |
5007 result = new(zone()) HArgumentsLength(elements); | 5031 if (function_state()->outer() == NULL) { |
5032 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | |
5033 result = new(zone()) HArgumentsLength(elements); | |
5034 } else { | |
5035 // Number of arguments without receiver. | |
5036 int argument_count = environment()-> | |
5037 arguments_environment()->parameter_count() - 1; | |
5038 result = new(zone()) HConstant( | |
5039 Handle<Object>(Smi::FromInt(argument_count)), | |
5040 Representation::Integer32()); | |
5041 } | |
5008 } else { | 5042 } else { |
5009 Push(graph()->GetArgumentsObject()); | 5043 Push(graph()->GetArgumentsObject()); |
5010 VisitForValue(expr->key()); | 5044 VisitForValue(expr->key()); |
5011 if (HasStackOverflow() || current_block() == NULL) return true; | 5045 if (HasStackOverflow() || current_block() == NULL) return true; |
5012 HValue* key = Pop(); | 5046 HValue* key = Pop(); |
5013 Drop(1); // Arguments object. | 5047 Drop(1); // Arguments object. |
5014 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); | 5048 if (function_state()->outer() == NULL) { |
5015 HInstruction* length = AddInstruction( | 5049 HInstruction* elements = AddInstruction(new(zone()) HArgumentsElements); |
5016 new(zone()) HArgumentsLength(elements)); | 5050 HInstruction* length = AddInstruction( |
5017 HInstruction* checked_key = | 5051 new(zone()) HArgumentsLength(elements)); |
5018 AddInstruction(new(zone()) HBoundsCheck(key, length)); | 5052 HInstruction* checked_key = |
5019 result = new(zone()) HAccessArgumentsAt(elements, length, checked_key); | 5053 AddInstruction(new(zone()) HBoundsCheck(key, length)); |
5054 result = new(zone()) HAccessArgumentsAt(elements, length, checked_key); | |
5055 } else { | |
5056 // Number of arguments without receiver. | |
5057 HInstruction* elements = function_state()->arguments_elements(); | |
5058 int argument_count = environment()-> | |
5059 arguments_environment()->parameter_count() - 1; | |
5060 HInstruction* length = AddInstruction(new(zone()) HConstant( | |
5061 Handle<Object>(Smi::FromInt(argument_count)), | |
5062 Representation::Integer32())); | |
5063 HInstruction* checked_key = | |
5064 AddInstruction(new(zone()) HBoundsCheck(key, length)); | |
5065 result = new(zone()) HAccessArgumentsAt(elements, length, checked_key); | |
5066 } | |
5020 } | 5067 } |
5021 ast_context()->ReturnInstruction(result, expr->id()); | 5068 ast_context()->ReturnInstruction(result, expr->id()); |
5022 return true; | 5069 return true; |
5023 } | 5070 } |
5024 | 5071 |
5025 | 5072 |
5026 void HGraphBuilder::VisitProperty(Property* expr) { | 5073 void HGraphBuilder::VisitProperty(Property* expr) { |
5027 ASSERT(!HasStackOverflow()); | 5074 ASSERT(!HasStackOverflow()); |
5028 ASSERT(current_block() != NULL); | 5075 ASSERT(current_block() != NULL); |
5029 ASSERT(current_block()->HasPredecessor()); | 5076 ASSERT(current_block()->HasPredecessor()); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5416 // IA32 only, overwrite the caller's context in the deoptimization | 5463 // IA32 only, overwrite the caller's context in the deoptimization |
5417 // environment with the correct one. | 5464 // environment with the correct one. |
5418 // | 5465 // |
5419 // TODO(kmillikin): implement the same inlining on other platforms so we | 5466 // TODO(kmillikin): implement the same inlining on other platforms so we |
5420 // can remove the unsightly ifdefs in this function. | 5467 // can remove the unsightly ifdefs in this function. |
5421 HConstant* context = new HConstant(Handle<Context>(target->context()), | 5468 HConstant* context = new HConstant(Handle<Context>(target->context()), |
5422 Representation::Tagged()); | 5469 Representation::Tagged()); |
5423 AddInstruction(context); | 5470 AddInstruction(context); |
5424 inner_env->BindContext(context); | 5471 inner_env->BindContext(context); |
5425 #endif | 5472 #endif |
5473 | |
5426 AddSimulate(return_id); | 5474 AddSimulate(return_id); |
5427 current_block()->UpdateEnvironment(inner_env); | 5475 current_block()->UpdateEnvironment(inner_env); |
5428 AddInstruction(new(zone()) HEnterInlined(target, | 5476 |
5429 arguments->length(), | 5477 ZoneList<HValue*>* arguments_values = NULL; |
5430 function, | 5478 |
5431 call_kind, | 5479 // If the function uses arguments copy current arguments values |
5432 function_state()->is_construct(), | 5480 // to use them for materialization. |
5433 function->scope()->arguments())); | 5481 if (function->scope()->arguments() != NULL) { |
5482 HEnvironment* arguments_env = inner_env->arguments_environment(); | |
5483 int arguments_count = arguments_env->parameter_count(); | |
5484 arguments_values = new(zone()) ZoneList<HValue*>(arguments_count); | |
5485 for (int i = 0; i < arguments_count; i++) { | |
5486 arguments_values->Add(arguments_env->Lookup(i)); | |
5487 } | |
5488 } | |
5489 | |
5490 HInstruction* enter_inlined = | |
5491 AddInstruction(new(zone()) HEnterInlined(target, | |
5492 arguments->length(), | |
5493 function, | |
5494 call_kind, | |
5495 function_state()->is_construct(), | |
5496 function->scope()->arguments(), | |
5497 arguments_values)); | |
5498 function_state()->set_entry(enter_inlined); | |
5499 | |
5434 // If the function uses arguments object create and bind one. | 5500 // If the function uses arguments object create and bind one. |
5435 if (function->scope()->arguments() != NULL) { | 5501 if (function->scope()->arguments() != NULL) { |
5436 ASSERT(function->scope()->arguments()->IsStackAllocated()); | 5502 ASSERT(function->scope()->arguments()->IsStackAllocated()); |
5437 environment()->Bind(function->scope()->arguments(), | 5503 inner_env->Bind(function->scope()->arguments(), |
5438 graph()->GetArgumentsObject()); | 5504 graph()->GetArgumentsObject()); |
5439 } | 5505 } |
5506 | |
5507 | |
5440 VisitDeclarations(target_info.scope()->declarations()); | 5508 VisitDeclarations(target_info.scope()->declarations()); |
5441 VisitStatements(function->body()); | 5509 VisitStatements(function->body()); |
5442 if (HasStackOverflow()) { | 5510 if (HasStackOverflow()) { |
5443 // Bail out if the inline function did, as we cannot residualize a call | 5511 // Bail out if the inline function did, as we cannot residualize a call |
5444 // instead. | 5512 // instead. |
5445 TraceInline(target, caller, "inline graph construction failed"); | 5513 TraceInline(target, caller, "inline graph construction failed"); |
5446 target_shared->DisableOptimization(); | 5514 target_shared->DisableOptimization(); |
5447 inline_bailout_ = true; | 5515 inline_bailout_ = true; |
5448 delete target_state; | 5516 delete target_state; |
5449 return true; | 5517 return true; |
5450 } | 5518 } |
5451 | 5519 |
5452 // Update inlined nodes count. | 5520 // Update inlined nodes count. |
5453 inlined_count_ += nodes_added; | 5521 inlined_count_ += nodes_added; |
5454 | 5522 |
5455 TraceInline(target, caller, NULL); | 5523 TraceInline(target, caller, NULL); |
5456 | 5524 |
5457 if (current_block() != NULL) { | 5525 if (current_block() != NULL) { |
5458 // Add default return value (i.e. undefined for normals calls or the newly | 5526 // Add default return value (i.e. undefined for normals calls or the newly |
5459 // allocated receiver for construct calls) if control can fall off the | 5527 // allocated receiver for construct calls) if control can fall off the |
5460 // body. In a test context, undefined is false and any JSObject is true. | 5528 // body. In a test context, undefined is false and any JSObject is true. |
5461 if (call_context()->IsValue()) { | 5529 if (call_context()->IsValue()) { |
5462 ASSERT(function_return() != NULL); | 5530 ASSERT(function_return() != NULL); |
5463 HValue* return_value = function_state()->is_construct() | 5531 HValue* return_value = function_state()->is_construct() |
5464 ? receiver | 5532 ? receiver |
5465 : undefined; | 5533 : undefined; |
5466 current_block()->AddLeaveInlined(return_value, | 5534 current_block()->AddLeaveInlined(return_value, |
5467 function_return(), | 5535 function_return(), |
5468 function_state()->drop_extra()); | 5536 function_state()); |
5469 } else if (call_context()->IsEffect()) { | 5537 } else if (call_context()->IsEffect()) { |
5470 ASSERT(function_return() != NULL); | 5538 ASSERT(function_return() != NULL); |
5471 current_block()->Goto(function_return(), function_state()->drop_extra()); | 5539 current_block()->Goto(function_return(), function_state()); |
5472 } else { | 5540 } else { |
5473 ASSERT(call_context()->IsTest()); | 5541 ASSERT(call_context()->IsTest()); |
5474 ASSERT(inlined_test_context() != NULL); | 5542 ASSERT(inlined_test_context() != NULL); |
5475 HBasicBlock* target = function_state()->is_construct() | 5543 HBasicBlock* target = function_state()->is_construct() |
5476 ? inlined_test_context()->if_true() | 5544 ? inlined_test_context()->if_true() |
5477 : inlined_test_context()->if_false(); | 5545 : inlined_test_context()->if_false(); |
5478 current_block()->Goto(target, function_state()->drop_extra()); | 5546 current_block()->Goto(target, function_state()); |
5479 } | 5547 } |
5480 } | 5548 } |
5481 | 5549 |
5482 // Fix up the function exits. | 5550 // Fix up the function exits. |
5483 if (inlined_test_context() != NULL) { | 5551 if (inlined_test_context() != NULL) { |
5484 HBasicBlock* if_true = inlined_test_context()->if_true(); | 5552 HBasicBlock* if_true = inlined_test_context()->if_true(); |
5485 HBasicBlock* if_false = inlined_test_context()->if_false(); | 5553 HBasicBlock* if_false = inlined_test_context()->if_false(); |
5486 | 5554 |
5487 // Pop the return test context from the expression context stack. | 5555 // Pop the return test context from the expression context stack. |
5488 ASSERT(ast_context() == inlined_test_context()); | 5556 ASSERT(ast_context() == inlined_test_context()); |
5489 ClearInlinedTestContext(); | 5557 ClearInlinedTestContext(); |
5490 delete target_state; | 5558 delete target_state; |
5491 | 5559 |
5492 // Forward to the real test context. | 5560 // Forward to the real test context. |
5493 if (if_true->HasPredecessor()) { | 5561 if (if_true->HasPredecessor()) { |
5494 if_true->SetJoinId(ast_id); | 5562 if_true->SetJoinId(ast_id); |
5495 HBasicBlock* true_target = TestContext::cast(ast_context())->if_true(); | 5563 HBasicBlock* true_target = TestContext::cast(ast_context())->if_true(); |
5496 if_true->Goto(true_target, function_state()->drop_extra()); | 5564 if_true->Goto(true_target, function_state()); |
5497 } | 5565 } |
5498 if (if_false->HasPredecessor()) { | 5566 if (if_false->HasPredecessor()) { |
5499 if_false->SetJoinId(ast_id); | 5567 if_false->SetJoinId(ast_id); |
5500 HBasicBlock* false_target = TestContext::cast(ast_context())->if_false(); | 5568 HBasicBlock* false_target = TestContext::cast(ast_context())->if_false(); |
5501 if_false->Goto(false_target, function_state()->drop_extra()); | 5569 if_false->Goto(false_target, function_state()); |
5502 } | 5570 } |
5503 set_current_block(NULL); | 5571 set_current_block(NULL); |
5504 return true; | 5572 return true; |
5505 | 5573 |
5506 } else if (function_return()->HasPredecessor()) { | 5574 } else if (function_return()->HasPredecessor()) { |
5507 function_return()->SetJoinId(ast_id); | 5575 function_return()->SetJoinId(ast_id); |
5508 set_current_block(function_return()); | 5576 set_current_block(function_return()); |
5509 } else { | 5577 } else { |
5510 set_current_block(NULL); | 5578 set_current_block(NULL); |
5511 } | 5579 } |
(...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8239 } | 8307 } |
8240 } | 8308 } |
8241 | 8309 |
8242 #ifdef DEBUG | 8310 #ifdef DEBUG |
8243 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 8311 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
8244 if (allocator_ != NULL) allocator_->Verify(); | 8312 if (allocator_ != NULL) allocator_->Verify(); |
8245 #endif | 8313 #endif |
8246 } | 8314 } |
8247 | 8315 |
8248 } } // namespace v8::internal | 8316 } } // namespace v8::internal |
OLD | NEW |