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 3246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3257 FrameStateBeforeAndAfter& states, | 3257 FrameStateBeforeAndAfter& states, |
3258 const VectorSlotPair& feedback, | 3258 const VectorSlotPair& feedback, |
3259 OutputFrameStateCombine combine, | 3259 OutputFrameStateCombine combine, |
3260 ContextualMode contextual_mode) { | 3260 ContextualMode contextual_mode) { |
3261 Node* the_hole = jsgraph()->TheHoleConstant(); | 3261 Node* the_hole = jsgraph()->TheHoleConstant(); |
3262 VariableMode mode = variable->mode(); | 3262 VariableMode mode = variable->mode(); |
3263 switch (variable->location()) { | 3263 switch (variable->location()) { |
3264 case VariableLocation::GLOBAL: | 3264 case VariableLocation::GLOBAL: |
3265 case VariableLocation::UNALLOCATED: { | 3265 case VariableLocation::UNALLOCATED: { |
3266 // Global var, const, or let variable. | 3266 // Global var, const, or let variable. |
| 3267 Node* script_context = current_context(); |
| 3268 int slot_index = -1; |
| 3269 if (variable->index() > 0) { |
| 3270 DCHECK(variable->IsStaticGlobalObjectProperty()); |
| 3271 // Each var occupies two slots in the context: for reads and writes. |
| 3272 slot_index = variable->index(); |
| 3273 int depth = current_scope()->ContextChainLength(variable->scope()); |
| 3274 if (depth > 0) { |
| 3275 const Operator* op = javascript()->LoadContext( |
| 3276 depth - 1, Context::PREVIOUS_INDEX, true); |
| 3277 script_context = NewNode(op, current_context()); |
| 3278 } |
| 3279 } |
3267 Node* global = BuildLoadGlobalObject(); | 3280 Node* global = BuildLoadGlobalObject(); |
3268 Handle<Name> name = variable->name(); | 3281 Handle<Name> name = variable->name(); |
3269 Node* value = BuildGlobalLoad(global, name, feedback, contextual_mode); | 3282 Node* value = BuildGlobalLoad(script_context, global, name, feedback, |
| 3283 contextual_mode, slot_index); |
3270 states.AddToNode(value, bailout_id, combine); | 3284 states.AddToNode(value, bailout_id, combine); |
3271 return value; | 3285 return value; |
3272 } | 3286 } |
3273 case VariableLocation::PARAMETER: | 3287 case VariableLocation::PARAMETER: |
3274 case VariableLocation::LOCAL: { | 3288 case VariableLocation::LOCAL: { |
3275 // Local var, const, or let variable. | 3289 // Local var, const, or let variable. |
3276 Node* value = environment()->Lookup(variable); | 3290 Node* value = environment()->Lookup(variable); |
3277 if (mode == CONST_LEGACY) { | 3291 if (mode == CONST_LEGACY) { |
3278 // Perform check for uninitialized legacy const variables. | 3292 // Perform check for uninitialized legacy const variables. |
3279 if (value->op() == the_hole->op()) { | 3293 if (value->op() == the_hole->op()) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3397 Node* AstGraphBuilder::BuildVariableAssignment( | 3411 Node* AstGraphBuilder::BuildVariableAssignment( |
3398 Variable* variable, Node* value, Token::Value op, | 3412 Variable* variable, Node* value, Token::Value op, |
3399 const VectorSlotPair& feedback, BailoutId bailout_id, | 3413 const VectorSlotPair& feedback, BailoutId bailout_id, |
3400 FrameStateBeforeAndAfter& states, OutputFrameStateCombine combine) { | 3414 FrameStateBeforeAndAfter& states, OutputFrameStateCombine combine) { |
3401 Node* the_hole = jsgraph()->TheHoleConstant(); | 3415 Node* the_hole = jsgraph()->TheHoleConstant(); |
3402 VariableMode mode = variable->mode(); | 3416 VariableMode mode = variable->mode(); |
3403 switch (variable->location()) { | 3417 switch (variable->location()) { |
3404 case VariableLocation::GLOBAL: | 3418 case VariableLocation::GLOBAL: |
3405 case VariableLocation::UNALLOCATED: { | 3419 case VariableLocation::UNALLOCATED: { |
3406 // Global var, const, or let variable. | 3420 // Global var, const, or let variable. |
| 3421 Node* script_context = current_context(); |
| 3422 int slot_index = -1; |
| 3423 if (variable->index() > 0) { |
| 3424 DCHECK(variable->IsStaticGlobalObjectProperty()); |
| 3425 // Each var occupies two slots in the context: for reads and writes. |
| 3426 slot_index = variable->index(); |
| 3427 int depth = current_scope()->ContextChainLength(variable->scope()); |
| 3428 if (depth > 0) { |
| 3429 const Operator* op = javascript()->LoadContext( |
| 3430 depth - 1, Context::PREVIOUS_INDEX, true); |
| 3431 script_context = NewNode(op, current_context()); |
| 3432 } |
| 3433 } |
3407 Node* global = BuildLoadGlobalObject(); | 3434 Node* global = BuildLoadGlobalObject(); |
3408 Handle<Name> name = variable->name(); | 3435 Handle<Name> name = variable->name(); |
3409 Node* store = BuildGlobalStore(global, name, value, feedback, | 3436 Node* store = |
3410 TypeFeedbackId::None()); | 3437 BuildGlobalStore(script_context, global, name, value, feedback, |
| 3438 TypeFeedbackId::None(), slot_index); |
3411 states.AddToNode(store, bailout_id, combine); | 3439 states.AddToNode(store, bailout_id, combine); |
3412 return store; | 3440 return store; |
3413 } | 3441 } |
3414 case VariableLocation::PARAMETER: | 3442 case VariableLocation::PARAMETER: |
3415 case VariableLocation::LOCAL: | 3443 case VariableLocation::LOCAL: |
3416 // Local var, const, or let variable. | 3444 // Local var, const, or let variable. |
3417 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { | 3445 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { |
3418 // Perform an initialization check for legacy const variables. | 3446 // Perform an initialization check for legacy const variables. |
3419 Node* current = environment()->Lookup(variable); | 3447 Node* current = environment()->Lookup(variable); |
3420 if (current->op() != the_hole->op()) { | 3448 if (current->op() != the_hole->op()) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3604 Node* name_node = jsgraph()->Constant(name); | 3632 Node* name_node = jsgraph()->Constant(name); |
3605 Runtime::FunctionId function_id = is_strict(language_mode()) | 3633 Runtime::FunctionId function_id = is_strict(language_mode()) |
3606 ? Runtime::kStoreToSuper_Strict | 3634 ? Runtime::kStoreToSuper_Strict |
3607 : Runtime::kStoreToSuper_Sloppy; | 3635 : Runtime::kStoreToSuper_Sloppy; |
3608 const Operator* op = javascript()->CallRuntime(function_id, 4); | 3636 const Operator* op = javascript()->CallRuntime(function_id, 4); |
3609 Node* node = NewNode(op, receiver, home_object, name_node, value); | 3637 Node* node = NewNode(op, receiver, home_object, name_node, value); |
3610 return Record(js_type_feedback_, node, id); | 3638 return Record(js_type_feedback_, node, id); |
3611 } | 3639 } |
3612 | 3640 |
3613 | 3641 |
3614 Node* AstGraphBuilder::BuildGlobalLoad(Node* object, Handle<Name> name, | 3642 Node* AstGraphBuilder::BuildGlobalLoad(Node* script_context, Node* global, |
| 3643 Handle<Name> name, |
3615 const VectorSlotPair& feedback, | 3644 const VectorSlotPair& feedback, |
3616 ContextualMode mode) { | 3645 ContextualMode mode, int slot_index) { |
3617 const Operator* op = | 3646 const Operator* op = |
3618 javascript()->LoadGlobal(MakeUnique(name), feedback, mode); | 3647 javascript()->LoadGlobal(MakeUnique(name), feedback, mode, slot_index); |
3619 Node* node = NewNode(op, object, BuildLoadFeedbackVector()); | 3648 Node* node = NewNode(op, script_context, global, BuildLoadFeedbackVector()); |
3620 return Record(js_type_feedback_, node, feedback.slot()); | 3649 return Record(js_type_feedback_, node, feedback.slot()); |
3621 } | 3650 } |
3622 | 3651 |
3623 | 3652 |
3624 Node* AstGraphBuilder::BuildGlobalStore(Node* object, Handle<Name> name, | 3653 Node* AstGraphBuilder::BuildGlobalStore(Node* script_context, Node* global, |
3625 Node* value, | 3654 Handle<Name> name, Node* value, |
3626 const VectorSlotPair& feedback, | 3655 const VectorSlotPair& feedback, |
3627 TypeFeedbackId id) { | 3656 TypeFeedbackId id, int slot_index) { |
3628 const Operator* op = | 3657 const Operator* op = javascript()->StoreGlobal( |
3629 javascript()->StoreGlobal(language_mode(), MakeUnique(name), feedback); | 3658 language_mode(), MakeUnique(name), feedback, slot_index); |
3630 Node* node = NewNode(op, object, value, BuildLoadFeedbackVector()); | 3659 Node* node = |
| 3660 NewNode(op, script_context, global, value, BuildLoadFeedbackVector()); |
3631 if (FLAG_vector_stores) { | 3661 if (FLAG_vector_stores) { |
3632 return Record(js_type_feedback_, node, feedback.slot()); | 3662 return Record(js_type_feedback_, node, feedback.slot()); |
3633 } | 3663 } |
3634 return Record(js_type_feedback_, node, id); | 3664 return Record(js_type_feedback_, node, id); |
3635 } | 3665 } |
3636 | 3666 |
3637 | 3667 |
3638 Node* AstGraphBuilder::BuildLoadObjectField(Node* object, int offset) { | 3668 Node* AstGraphBuilder::BuildLoadObjectField(Node* object, int offset) { |
3639 return NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object, | 3669 return NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object, |
3640 jsgraph()->IntPtrConstant(offset - kHeapObjectTag)); | 3670 jsgraph()->IntPtrConstant(offset - kHeapObjectTag)); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3914 size = size + kInputBufferSizeIncrement + input_buffer_size_; | 3944 size = size + kInputBufferSizeIncrement + input_buffer_size_; |
3915 input_buffer_ = local_zone()->NewArray<Node*>(size); | 3945 input_buffer_ = local_zone()->NewArray<Node*>(size); |
3916 input_buffer_size_ = size; | 3946 input_buffer_size_ = size; |
3917 } | 3947 } |
3918 return input_buffer_; | 3948 return input_buffer_; |
3919 } | 3949 } |
3920 | 3950 |
3921 | 3951 |
3922 Node* AstGraphBuilder::MakeNode(const Operator* op, int value_input_count, | 3952 Node* AstGraphBuilder::MakeNode(const Operator* op, int value_input_count, |
3923 Node** value_inputs, bool incomplete) { | 3953 Node** value_inputs, bool incomplete) { |
3924 DCHECK(op->ValueInputCount() == value_input_count); | 3954 DCHECK_EQ(op->ValueInputCount(), value_input_count); |
3925 | 3955 |
3926 bool has_context = OperatorProperties::HasContextInput(op); | 3956 bool has_context = OperatorProperties::HasContextInput(op); |
3927 int frame_state_count = OperatorProperties::GetFrameStateInputCount(op); | 3957 int frame_state_count = OperatorProperties::GetFrameStateInputCount(op); |
3928 bool has_control = op->ControlInputCount() == 1; | 3958 bool has_control = op->ControlInputCount() == 1; |
3929 bool has_effect = op->EffectInputCount() == 1; | 3959 bool has_effect = op->EffectInputCount() == 1; |
3930 | 3960 |
3931 DCHECK(op->ControlInputCount() < 2); | 3961 DCHECK(op->ControlInputCount() < 2); |
3932 DCHECK(op->EffectInputCount() < 2); | 3962 DCHECK(op->EffectInputCount() < 2); |
3933 | 3963 |
3934 Node* result = NULL; | 3964 Node* result = NULL; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4205 // Phi does not exist yet, introduce one. | 4235 // Phi does not exist yet, introduce one. |
4206 value = NewPhi(inputs, value, control); | 4236 value = NewPhi(inputs, value, control); |
4207 value->ReplaceInput(inputs - 1, other); | 4237 value->ReplaceInput(inputs - 1, other); |
4208 } | 4238 } |
4209 return value; | 4239 return value; |
4210 } | 4240 } |
4211 | 4241 |
4212 } // namespace compiler | 4242 } // namespace compiler |
4213 } // namespace internal | 4243 } // namespace internal |
4214 } // namespace v8 | 4244 } // namespace v8 |
OLD | NEW |