OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/ast-loop-assignment-analyzer.h" | 8 #include "src/compiler/ast-loop-assignment-analyzer.h" |
9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
10 #include "src/compiler/js-type-feedback.h" | 10 #include "src/compiler/js-type-feedback.h" |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Build receiver check for sloppy mode if necessary. | 469 // Build receiver check for sloppy mode if necessary. |
470 // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC? | 470 // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC? |
471 Node* original_receiver = env.Lookup(scope->receiver()); | 471 Node* original_receiver = env.Lookup(scope->receiver()); |
472 Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver); | 472 Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver); |
473 env.Bind(scope->receiver(), patched_receiver); | 473 env.Bind(scope->receiver(), patched_receiver); |
474 | 474 |
475 // Build function context only if there are context allocated variables. | 475 // Build function context only if there are context allocated variables. |
476 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 476 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
477 if (heap_slots > 0) { | 477 if (heap_slots > 0) { |
478 // Push a new inner context scope for the function. | 478 // Push a new inner context scope for the function. |
479 Node* closure = GetFunctionClosure(); | 479 Node* inner_context = BuildLocalFunctionContext(function_context_.get()); |
480 Node* inner_context = | |
481 BuildLocalFunctionContext(function_context_.get(), closure); | |
482 ContextScope top_context(this, scope, inner_context); | 480 ContextScope top_context(this, scope, inner_context); |
483 CreateGraphBody(stack_check); | 481 CreateGraphBody(stack_check); |
484 } else { | 482 } else { |
485 // Simply use the outer function context in building the graph. | 483 // Simply use the outer function context in building the graph. |
486 CreateGraphBody(stack_check); | 484 CreateGraphBody(stack_check); |
487 } | 485 } |
488 | 486 |
489 // Finish the basic structure of the graph. | 487 // Finish the basic structure of the graph. |
490 graph()->SetEnd(graph()->NewNode(common()->End(), exit_control())); | 488 graph()->SetEnd(graph()->NewNode(common()->End(), exit_control())); |
491 | 489 |
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2467 int array_index = 0; | 2465 int array_index = 0; |
2468 Handle<FixedArray> data = isolate()->factory()->NewFixedArray( | 2466 Handle<FixedArray> data = isolate()->factory()->NewFixedArray( |
2469 static_cast<int>(globals()->size()), TENURED); | 2467 static_cast<int>(globals()->size()), TENURED); |
2470 for (Handle<Object> obj : *globals()) data->set(array_index++, *obj); | 2468 for (Handle<Object> obj : *globals()) data->set(array_index++, *obj); |
2471 int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | | 2469 int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | |
2472 DeclareGlobalsNativeFlag::encode(info()->is_native()) | | 2470 DeclareGlobalsNativeFlag::encode(info()->is_native()) | |
2473 DeclareGlobalsLanguageMode::encode(language_mode()); | 2471 DeclareGlobalsLanguageMode::encode(language_mode()); |
2474 Node* flags = jsgraph()->Constant(encoded_flags); | 2472 Node* flags = jsgraph()->Constant(encoded_flags); |
2475 Node* pairs = jsgraph()->Constant(data); | 2473 Node* pairs = jsgraph()->Constant(data); |
2476 const Operator* op = javascript()->CallRuntime(Runtime::kDeclareGlobals, 3); | 2474 const Operator* op = javascript()->CallRuntime(Runtime::kDeclareGlobals, 3); |
2477 NewNode(op, current_context(), pairs, flags); | 2475 Node* call = NewNode(op, current_context(), pairs, flags); |
| 2476 PrepareFrameState(call, BailoutId::Declarations()); |
2478 globals()->clear(); | 2477 globals()->clear(); |
2479 } | 2478 } |
2480 | 2479 |
2481 | 2480 |
2482 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { | 2481 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { |
2483 if (stmt == NULL) return; | 2482 if (stmt == NULL) return; |
2484 Visit(stmt); | 2483 Visit(stmt); |
2485 } | 2484 } |
2486 | 2485 |
2487 | 2486 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2626 receiver_check.Then(); | 2625 receiver_check.Then(); |
2627 Node* proxy = BuildLoadGlobalProxy(); | 2626 Node* proxy = BuildLoadGlobalProxy(); |
2628 environment()->Push(proxy); | 2627 environment()->Push(proxy); |
2629 receiver_check.Else(); | 2628 receiver_check.Else(); |
2630 environment()->Push(receiver); | 2629 environment()->Push(receiver); |
2631 receiver_check.End(); | 2630 receiver_check.End(); |
2632 return environment()->Pop(); | 2631 return environment()->Pop(); |
2633 } | 2632 } |
2634 | 2633 |
2635 | 2634 |
2636 Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context, Node* closure) { | 2635 Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context) { |
| 2636 Node* closure = GetFunctionClosure(); |
| 2637 |
2637 // Allocate a new local context. | 2638 // Allocate a new local context. |
2638 const Operator* op = javascript()->CreateFunctionContext(); | 2639 Node* local_context = |
2639 Node* local_context = NewNode(op, closure); | 2640 info()->scope()->is_script_scope() |
| 2641 ? BuildLocalScriptContext(info()->scope()) |
| 2642 : NewNode(javascript()->CreateFunctionContext(), closure); |
2640 | 2643 |
2641 // Copy parameters into context if necessary. | 2644 // Copy parameters into context if necessary. |
2642 int num_parameters = info()->scope()->num_parameters(); | 2645 int num_parameters = info()->scope()->num_parameters(); |
2643 for (int i = 0; i < num_parameters; i++) { | 2646 for (int i = 0; i < num_parameters; i++) { |
2644 Variable* variable = info()->scope()->parameter(i); | 2647 Variable* variable = info()->scope()->parameter(i); |
2645 if (!variable->IsContextSlot()) continue; | 2648 if (!variable->IsContextSlot()) continue; |
2646 // Temporary parameter node. The parameter indices are shifted by 1 | 2649 // Temporary parameter node. The parameter indices are shifted by 1 |
2647 // (receiver is parameter index -1 but environment index 0). | 2650 // (receiver is parameter index -1 but environment index 0). |
2648 Node* parameter = NewNode(common()->Parameter(i + 1), graph()->start()); | 2651 Node* parameter = NewNode(common()->Parameter(i + 1), graph()->start()); |
2649 // Context variable (at bottom of the context chain). | 2652 // Context variable (at bottom of the context chain). |
2650 DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope())); | 2653 DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope())); |
2651 const Operator* op = javascript()->StoreContext(0, variable->index()); | 2654 const Operator* op = javascript()->StoreContext(0, variable->index()); |
2652 NewNode(op, local_context, parameter); | 2655 NewNode(op, local_context, parameter); |
2653 } | 2656 } |
2654 | 2657 |
2655 return local_context; | 2658 return local_context; |
2656 } | 2659 } |
2657 | 2660 |
2658 | 2661 |
| 2662 Node* AstGraphBuilder::BuildLocalScriptContext(Scope* scope) { |
| 2663 Node* closure = GetFunctionClosure(); |
| 2664 |
| 2665 // Allocate a new local context. |
| 2666 const Operator* op = javascript()->CreateScriptContext(); |
| 2667 Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(isolate())); |
| 2668 Node* local_context = NewNode(op, closure, scope_info); |
| 2669 PrepareFrameState(local_context, BailoutId::FunctionEntry()); |
| 2670 |
| 2671 return local_context; |
| 2672 } |
| 2673 |
| 2674 |
2659 Node* AstGraphBuilder::BuildLocalBlockContext(Scope* scope) { | 2675 Node* AstGraphBuilder::BuildLocalBlockContext(Scope* scope) { |
2660 Node* closure = GetFunctionClosure(); | 2676 Node* closure = GetFunctionClosure(); |
2661 | 2677 |
2662 // Allocate a new local context. | 2678 // Allocate a new local context. |
2663 const Operator* op = javascript()->CreateBlockContext(); | 2679 const Operator* op = javascript()->CreateBlockContext(); |
2664 Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(info_->isolate())); | 2680 Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(isolate())); |
2665 Node* local_context = NewNode(op, scope_info, closure); | 2681 Node* local_context = NewNode(op, scope_info, closure); |
2666 | 2682 |
2667 return local_context; | 2683 return local_context; |
2668 } | 2684 } |
2669 | 2685 |
2670 | 2686 |
2671 Node* AstGraphBuilder::BuildArgumentsObject(Variable* arguments) { | 2687 Node* AstGraphBuilder::BuildArgumentsObject(Variable* arguments) { |
2672 if (arguments == NULL) return NULL; | 2688 if (arguments == NULL) return NULL; |
2673 | 2689 |
2674 // Allocate and initialize a new arguments object. | 2690 // Allocate and initialize a new arguments object. |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3532 // Phi does not exist yet, introduce one. | 3548 // Phi does not exist yet, introduce one. |
3533 value = NewPhi(inputs, value, control); | 3549 value = NewPhi(inputs, value, control); |
3534 value->ReplaceInput(inputs - 1, other); | 3550 value->ReplaceInput(inputs - 1, other); |
3535 } | 3551 } |
3536 return value; | 3552 return value; |
3537 } | 3553 } |
3538 | 3554 |
3539 } // namespace compiler | 3555 } // namespace compiler |
3540 } // namespace internal | 3556 } // namespace internal |
3541 } // namespace v8 | 3557 } // namespace v8 |
OLD | NEW |