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 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 // Transform both the class literal and the prototype to fast properties. | 1694 // Transform both the class literal and the prototype to fast properties. |
1695 const Operator* op = javascript()->CallRuntime(Runtime::kToFastProperties, 1); | 1695 const Operator* op = javascript()->CallRuntime(Runtime::kToFastProperties, 1); |
1696 NewNode(op, environment()->Pop()); // prototype | 1696 NewNode(op, environment()->Pop()); // prototype |
1697 NewNode(op, environment()->Pop()); // literal | 1697 NewNode(op, environment()->Pop()); // literal |
1698 | 1698 |
1699 // Assign to class variable. | 1699 // Assign to class variable. |
1700 if (expr->scope() != NULL) { | 1700 if (expr->scope() != NULL) { |
1701 DCHECK_NOT_NULL(expr->class_variable_proxy()); | 1701 DCHECK_NOT_NULL(expr->class_variable_proxy()); |
1702 Variable* var = expr->class_variable_proxy()->var(); | 1702 Variable* var = expr->class_variable_proxy()->var(); |
1703 FrameStateBeforeAndAfter states(this, BailoutId::None()); | 1703 FrameStateBeforeAndAfter states(this, BailoutId::None()); |
1704 BuildVariableAssignment(states, var, literal, Token::INIT_CONST, | 1704 BuildVariableAssignment(var, literal, Token::INIT_CONST, BailoutId::None(), |
1705 BailoutId::None()); | 1705 states); |
1706 } | 1706 } |
1707 | 1707 |
1708 ast_context()->ProduceValue(literal); | 1708 ast_context()->ProduceValue(literal); |
1709 } | 1709 } |
1710 | 1710 |
1711 | 1711 |
1712 void AstGraphBuilder::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { | 1712 void AstGraphBuilder::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { |
1713 UNREACHABLE(); | 1713 UNREACHABLE(); |
1714 } | 1714 } |
1715 | 1715 |
1716 | 1716 |
1717 void AstGraphBuilder::VisitConditional(Conditional* expr) { | 1717 void AstGraphBuilder::VisitConditional(Conditional* expr) { |
1718 IfBuilder compare_if(this); | 1718 IfBuilder compare_if(this); |
1719 VisitForTest(expr->condition()); | 1719 VisitForTest(expr->condition()); |
1720 Node* condition = environment()->Pop(); | 1720 Node* condition = environment()->Pop(); |
1721 compare_if.If(condition); | 1721 compare_if.If(condition); |
1722 compare_if.Then(); | 1722 compare_if.Then(); |
1723 Visit(expr->then_expression()); | 1723 Visit(expr->then_expression()); |
1724 compare_if.Else(); | 1724 compare_if.Else(); |
1725 Visit(expr->else_expression()); | 1725 Visit(expr->else_expression()); |
1726 compare_if.End(); | 1726 compare_if.End(); |
1727 ast_context()->ReplaceValue(); | 1727 ast_context()->ReplaceValue(); |
1728 } | 1728 } |
1729 | 1729 |
1730 | 1730 |
1731 void AstGraphBuilder::VisitVariableProxy(VariableProxy* expr) { | 1731 void AstGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
1732 VectorSlotPair pair = CreateVectorSlotPair(expr->VariableFeedbackSlot()); | 1732 VectorSlotPair pair = CreateVectorSlotPair(expr->VariableFeedbackSlot()); |
1733 FrameStateBeforeAndAfter states(this, BeforeId(expr)); | 1733 FrameStateBeforeAndAfter states(this, BeforeId(expr)); |
1734 Node* value = BuildVariableLoad(states, expr->var(), expr->id(), pair, | 1734 Node* value = BuildVariableLoad(expr->var(), expr->id(), states, pair, |
1735 ast_context()->GetStateCombine()); | 1735 ast_context()->GetStateCombine()); |
1736 ast_context()->ProduceValue(value); | 1736 ast_context()->ProduceValue(value); |
1737 } | 1737 } |
1738 | 1738 |
1739 | 1739 |
1740 void AstGraphBuilder::VisitLiteral(Literal* expr) { | 1740 void AstGraphBuilder::VisitLiteral(Literal* expr) { |
1741 Node* value = jsgraph()->Constant(expr->value()); | 1741 Node* value = jsgraph()->Constant(expr->value()); |
1742 ast_context()->ProduceValue(value); | 1742 ast_context()->ProduceValue(value); |
1743 } | 1743 } |
1744 | 1744 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2036 | 2036 |
2037 // Left-hand side can only be a property, a global or a variable slot. | 2037 // Left-hand side can only be a property, a global or a variable slot. |
2038 Property* property = expr->AsProperty(); | 2038 Property* property = expr->AsProperty(); |
2039 LhsKind assign_type = DetermineLhsKind(expr); | 2039 LhsKind assign_type = DetermineLhsKind(expr); |
2040 | 2040 |
2041 // Evaluate LHS expression and store the value. | 2041 // Evaluate LHS expression and store the value. |
2042 switch (assign_type) { | 2042 switch (assign_type) { |
2043 case VARIABLE: { | 2043 case VARIABLE: { |
2044 Variable* var = expr->AsVariableProxy()->var(); | 2044 Variable* var = expr->AsVariableProxy()->var(); |
2045 FrameStateBeforeAndAfter states(this, BailoutId::None()); | 2045 FrameStateBeforeAndAfter states(this, BailoutId::None()); |
2046 BuildVariableAssignment(states, var, value, Token::ASSIGN, bailout_id); | 2046 BuildVariableAssignment(var, value, Token::ASSIGN, bailout_id, states); |
2047 break; | 2047 break; |
2048 } | 2048 } |
2049 case NAMED_PROPERTY: { | 2049 case NAMED_PROPERTY: { |
2050 environment()->Push(value); | 2050 environment()->Push(value); |
2051 VisitForValue(property->obj()); | 2051 VisitForValue(property->obj()); |
2052 FrameStateBeforeAndAfter states(this, property->obj()->id()); | 2052 FrameStateBeforeAndAfter states(this, property->obj()->id()); |
2053 Node* object = environment()->Pop(); | 2053 Node* object = environment()->Pop(); |
2054 value = environment()->Pop(); | 2054 value = environment()->Pop(); |
2055 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); | 2055 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); |
2056 Node* store = | 2056 Node* store = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 // the left-hand side value and performing a binary operation. | 2108 // the left-hand side value and performing a binary operation. |
2109 if (expr->is_compound()) { | 2109 if (expr->is_compound()) { |
2110 Node* old_value = NULL; | 2110 Node* old_value = NULL; |
2111 switch (assign_type) { | 2111 switch (assign_type) { |
2112 case VARIABLE: { | 2112 case VARIABLE: { |
2113 VariableProxy* proxy = expr->target()->AsVariableProxy(); | 2113 VariableProxy* proxy = expr->target()->AsVariableProxy(); |
2114 VectorSlotPair pair = | 2114 VectorSlotPair pair = |
2115 CreateVectorSlotPair(proxy->VariableFeedbackSlot()); | 2115 CreateVectorSlotPair(proxy->VariableFeedbackSlot()); |
2116 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); | 2116 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); |
2117 old_value = | 2117 old_value = |
2118 BuildVariableLoad(states, proxy->var(), expr->target()->id(), pair, | 2118 BuildVariableLoad(proxy->var(), expr->target()->id(), states, pair, |
2119 OutputFrameStateCombine::Push()); | 2119 OutputFrameStateCombine::Push()); |
2120 break; | 2120 break; |
2121 } | 2121 } |
2122 case NAMED_PROPERTY: { | 2122 case NAMED_PROPERTY: { |
2123 Node* object = environment()->Top(); | 2123 Node* object = environment()->Top(); |
2124 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); | 2124 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); |
2125 VectorSlotPair pair = | 2125 VectorSlotPair pair = |
2126 CreateVectorSlotPair(property->PropertyFeedbackSlot()); | 2126 CreateVectorSlotPair(property->PropertyFeedbackSlot()); |
2127 FrameStateBeforeAndAfter states(this, property->obj()->id()); | 2127 FrameStateBeforeAndAfter states(this, property->obj()->id()); |
2128 old_value = BuildNamedLoad(object, name, pair); | 2128 old_value = BuildNamedLoad(object, name, pair); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2163 before_store_id = expr->value()->id(); | 2163 before_store_id = expr->value()->id(); |
2164 } | 2164 } |
2165 } | 2165 } |
2166 | 2166 |
2167 FrameStateBeforeAndAfter store_states(this, before_store_id); | 2167 FrameStateBeforeAndAfter store_states(this, before_store_id); |
2168 // Store the value. | 2168 // Store the value. |
2169 Node* value = environment()->Pop(); | 2169 Node* value = environment()->Pop(); |
2170 switch (assign_type) { | 2170 switch (assign_type) { |
2171 case VARIABLE: { | 2171 case VARIABLE: { |
2172 Variable* variable = expr->target()->AsVariableProxy()->var(); | 2172 Variable* variable = expr->target()->AsVariableProxy()->var(); |
2173 BuildVariableAssignment(store_states, variable, value, expr->op(), | 2173 BuildVariableAssignment(variable, value, expr->op(), expr->id(), |
2174 expr->id(), ast_context()->GetStateCombine()); | 2174 store_states, ast_context()->GetStateCombine()); |
2175 break; | 2175 break; |
2176 } | 2176 } |
2177 case NAMED_PROPERTY: { | 2177 case NAMED_PROPERTY: { |
2178 Node* object = environment()->Pop(); | 2178 Node* object = environment()->Pop(); |
2179 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); | 2179 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); |
2180 Node* store = | 2180 Node* store = |
2181 BuildNamedStore(object, name, value, expr->AssignmentFeedbackId()); | 2181 BuildNamedStore(object, name, value, expr->AssignmentFeedbackId()); |
2182 store_states.AddToNode(store, expr->id(), | 2182 store_states.AddToNode(store, expr->id(), |
2183 ast_context()->GetStateCombine()); | 2183 ast_context()->GetStateCombine()); |
2184 break; | 2184 break; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 CallFunctionFlags flags = NO_CALL_FUNCTION_FLAGS; | 2245 CallFunctionFlags flags = NO_CALL_FUNCTION_FLAGS; |
2246 Node* receiver_value = NULL; | 2246 Node* receiver_value = NULL; |
2247 Node* callee_value = NULL; | 2247 Node* callee_value = NULL; |
2248 bool possibly_eval = false; | 2248 bool possibly_eval = false; |
2249 switch (call_type) { | 2249 switch (call_type) { |
2250 case Call::GLOBAL_CALL: { | 2250 case Call::GLOBAL_CALL: { |
2251 VariableProxy* proxy = callee->AsVariableProxy(); | 2251 VariableProxy* proxy = callee->AsVariableProxy(); |
2252 VectorSlotPair pair = CreateVectorSlotPair(proxy->VariableFeedbackSlot()); | 2252 VectorSlotPair pair = CreateVectorSlotPair(proxy->VariableFeedbackSlot()); |
2253 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); | 2253 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); |
2254 callee_value = | 2254 callee_value = |
2255 BuildVariableLoad(states, proxy->var(), expr->expression()->id(), | 2255 BuildVariableLoad(proxy->var(), expr->expression()->id(), states, |
2256 pair, OutputFrameStateCombine::Push()); | 2256 pair, OutputFrameStateCombine::Push()); |
2257 receiver_value = jsgraph()->UndefinedConstant(); | 2257 receiver_value = jsgraph()->UndefinedConstant(); |
2258 break; | 2258 break; |
2259 } | 2259 } |
2260 case Call::LOOKUP_SLOT_CALL: { | 2260 case Call::LOOKUP_SLOT_CALL: { |
2261 Variable* variable = callee->AsVariableProxy()->var(); | 2261 Variable* variable = callee->AsVariableProxy()->var(); |
2262 DCHECK(variable->location() == Variable::LOOKUP); | 2262 DCHECK(variable->location() == Variable::LOOKUP); |
2263 Node* name = jsgraph()->Constant(variable->name()); | 2263 Node* name = jsgraph()->Constant(variable->name()); |
2264 const Operator* op = | 2264 const Operator* op = |
2265 javascript()->CallRuntime(Runtime::kLoadLookupSlot, 2); | 2265 javascript()->CallRuntime(Runtime::kLoadLookupSlot, 2); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 | 2473 |
2474 // Evaluate LHS expression and get old value. | 2474 // Evaluate LHS expression and get old value. |
2475 Node* old_value = NULL; | 2475 Node* old_value = NULL; |
2476 int stack_depth = -1; | 2476 int stack_depth = -1; |
2477 switch (assign_type) { | 2477 switch (assign_type) { |
2478 case VARIABLE: { | 2478 case VARIABLE: { |
2479 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 2479 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
2480 VectorSlotPair pair = CreateVectorSlotPair(proxy->VariableFeedbackSlot()); | 2480 VectorSlotPair pair = CreateVectorSlotPair(proxy->VariableFeedbackSlot()); |
2481 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); | 2481 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); |
2482 old_value = | 2482 old_value = |
2483 BuildVariableLoad(states, proxy->var(), expr->expression()->id(), | 2483 BuildVariableLoad(proxy->var(), expr->expression()->id(), states, |
2484 pair, OutputFrameStateCombine::Push()); | 2484 pair, OutputFrameStateCombine::Push()); |
2485 stack_depth = 0; | 2485 stack_depth = 0; |
2486 break; | 2486 break; |
2487 } | 2487 } |
2488 case NAMED_PROPERTY: { | 2488 case NAMED_PROPERTY: { |
2489 VisitForValue(property->obj()); | 2489 VisitForValue(property->obj()); |
2490 FrameStateBeforeAndAfter states(this, property->obj()->id()); | 2490 FrameStateBeforeAndAfter states(this, property->obj()->id()); |
2491 Node* object = environment()->Top(); | 2491 Node* object = environment()->Top(); |
2492 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); | 2492 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); |
2493 VectorSlotPair pair = | 2493 VectorSlotPair pair = |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2537 // before. | 2537 // before. |
2538 states.AddToNode(value, BailoutId::None(), | 2538 states.AddToNode(value, BailoutId::None(), |
2539 OutputFrameStateCombine::Ignore()); | 2539 OutputFrameStateCombine::Ignore()); |
2540 } | 2540 } |
2541 | 2541 |
2542 // Store the value. | 2542 // Store the value. |
2543 switch (assign_type) { | 2543 switch (assign_type) { |
2544 case VARIABLE: { | 2544 case VARIABLE: { |
2545 Variable* variable = expr->expression()->AsVariableProxy()->var(); | 2545 Variable* variable = expr->expression()->AsVariableProxy()->var(); |
2546 environment()->Push(value); | 2546 environment()->Push(value); |
2547 BuildVariableAssignment(store_states, variable, value, expr->op(), | 2547 BuildVariableAssignment(variable, value, expr->op(), expr->AssignmentId(), |
2548 expr->AssignmentId()); | 2548 store_states); |
2549 environment()->Pop(); | 2549 environment()->Pop(); |
2550 break; | 2550 break; |
2551 } | 2551 } |
2552 case NAMED_PROPERTY: { | 2552 case NAMED_PROPERTY: { |
2553 Node* object = environment()->Pop(); | 2553 Node* object = environment()->Pop(); |
2554 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); | 2554 Handle<Name> name = property->key()->AsLiteral()->AsPropertyName(); |
2555 Node* store = | 2555 Node* store = |
2556 BuildNamedStore(object, name, value, expr->CountStoreFeedbackId()); | 2556 BuildNamedStore(object, name, value, expr->CountStoreFeedbackId()); |
2557 environment()->Push(value); | 2557 environment()->Push(value); |
2558 store_states.AddToNode(store, expr->AssignmentId(), | 2558 store_states.AddToNode(store, expr->AssignmentId(), |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2741 | 2741 |
2742 void AstGraphBuilder::VisitTypeof(UnaryOperation* expr) { | 2742 void AstGraphBuilder::VisitTypeof(UnaryOperation* expr) { |
2743 Node* operand; | 2743 Node* operand; |
2744 if (expr->expression()->IsVariableProxy()) { | 2744 if (expr->expression()->IsVariableProxy()) { |
2745 // Typeof does not throw a reference error on global variables, hence we | 2745 // Typeof does not throw a reference error on global variables, hence we |
2746 // perform a non-contextual load in case the operand is a variable proxy. | 2746 // perform a non-contextual load in case the operand is a variable proxy. |
2747 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 2747 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
2748 VectorSlotPair pair = CreateVectorSlotPair(proxy->VariableFeedbackSlot()); | 2748 VectorSlotPair pair = CreateVectorSlotPair(proxy->VariableFeedbackSlot()); |
2749 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); | 2749 FrameStateBeforeAndAfter states(this, BeforeId(proxy)); |
2750 operand = | 2750 operand = |
2751 BuildVariableLoad(states, proxy->var(), expr->expression()->id(), pair, | 2751 BuildVariableLoad(proxy->var(), expr->expression()->id(), states, pair, |
2752 OutputFrameStateCombine::Push(), NOT_CONTEXTUAL); | 2752 OutputFrameStateCombine::Push(), NOT_CONTEXTUAL); |
2753 } else { | 2753 } else { |
2754 VisitForValue(expr->expression()); | 2754 VisitForValue(expr->expression()); |
2755 operand = environment()->Pop(); | 2755 operand = environment()->Pop(); |
2756 } | 2756 } |
2757 Node* value = NewNode(javascript()->TypeOf(), operand); | 2757 Node* value = NewNode(javascript()->TypeOf(), operand); |
2758 ast_context()->ProduceValue(value); | 2758 ast_context()->ProduceValue(value); |
2759 } | 2759 } |
2760 | 2760 |
2761 | 2761 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2808 return info()->language_mode(); | 2808 return info()->language_mode(); |
2809 } | 2809 } |
2810 | 2810 |
2811 | 2811 |
2812 VectorSlotPair AstGraphBuilder::CreateVectorSlotPair( | 2812 VectorSlotPair AstGraphBuilder::CreateVectorSlotPair( |
2813 FeedbackVectorICSlot slot) const { | 2813 FeedbackVectorICSlot slot) const { |
2814 return VectorSlotPair(handle(info()->shared_info()->feedback_vector()), slot); | 2814 return VectorSlotPair(handle(info()->shared_info()->feedback_vector()), slot); |
2815 } | 2815 } |
2816 | 2816 |
2817 | 2817 |
| 2818 uint32_t AstGraphBuilder::ComputeBitsetForDynamicGlobal(Variable* variable) { |
| 2819 DCHECK_EQ(DYNAMIC_GLOBAL, variable->mode()); |
| 2820 EnumSet<int, uint32_t> check_depths; |
| 2821 for (Scope* s = current_scope(); s != nullptr; s = s->outer_scope()) { |
| 2822 if (s->num_heap_slots() <= 0) continue; |
| 2823 // TODO(mstarzinger): Be smarter about which checks to require! |
| 2824 int depth = current_scope()->ContextChainLength(s); |
| 2825 if (depth > DynamicGlobalAccess::kMaxCheckDepth) { |
| 2826 return DynamicGlobalAccess::kFullCheckRequired; |
| 2827 } |
| 2828 check_depths.Add(depth); |
| 2829 } |
| 2830 return check_depths.ToIntegral(); |
| 2831 } |
| 2832 |
| 2833 |
| 2834 uint32_t AstGraphBuilder::ComputeBitsetForDynamicContext(Variable* variable) { |
| 2835 DCHECK_EQ(DYNAMIC_LOCAL, variable->mode()); |
| 2836 EnumSet<int, uint32_t> check_depths; |
| 2837 for (Scope* s = current_scope(); s != nullptr; s = s->outer_scope()) { |
| 2838 if (s->num_heap_slots() <= 0) continue; |
| 2839 if (!s->calls_sloppy_eval()) continue; |
| 2840 int depth = current_scope()->ContextChainLength(s); |
| 2841 if (depth > DynamicContextAccess::kMaxCheckDepth) { |
| 2842 return DynamicContextAccess::kFullCheckRequired; |
| 2843 } |
| 2844 check_depths.Add(depth); |
| 2845 if (s == variable->scope()) break; |
| 2846 } |
| 2847 return check_depths.ToIntegral(); |
| 2848 } |
| 2849 |
| 2850 |
2818 Node* AstGraphBuilder::ProcessArguments(const Operator* op, int arity) { | 2851 Node* AstGraphBuilder::ProcessArguments(const Operator* op, int arity) { |
2819 DCHECK(environment()->stack_height() >= arity); | 2852 DCHECK(environment()->stack_height() >= arity); |
2820 Node** all = info()->zone()->NewArray<Node*>(arity); | 2853 Node** all = info()->zone()->NewArray<Node*>(arity); |
2821 for (int i = arity - 1; i >= 0; --i) { | 2854 for (int i = arity - 1; i >= 0; --i) { |
2822 all[i] = environment()->Pop(); | 2855 all[i] = environment()->Pop(); |
2823 } | 2856 } |
2824 Node* value = NewNode(op, arity, all); | 2857 Node* value = NewNode(op, arity, all); |
2825 return value; | 2858 return value; |
2826 } | 2859 } |
2827 | 2860 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2917 | 2950 |
2918 // Allocate and initialize a new arguments object. | 2951 // Allocate and initialize a new arguments object. |
2919 Node* callee = GetFunctionClosure(); | 2952 Node* callee = GetFunctionClosure(); |
2920 const Operator* op = javascript()->CallRuntime(Runtime::kNewArguments, 1); | 2953 const Operator* op = javascript()->CallRuntime(Runtime::kNewArguments, 1); |
2921 Node* object = NewNode(op, callee); | 2954 Node* object = NewNode(op, callee); |
2922 | 2955 |
2923 // Assign the object to the arguments variable. | 2956 // Assign the object to the arguments variable. |
2924 DCHECK(arguments->IsContextSlot() || arguments->IsStackAllocated()); | 2957 DCHECK(arguments->IsContextSlot() || arguments->IsStackAllocated()); |
2925 // This should never lazy deopt, so it is fine to send invalid bailout id. | 2958 // This should never lazy deopt, so it is fine to send invalid bailout id. |
2926 FrameStateBeforeAndAfter states(this, BailoutId::None()); | 2959 FrameStateBeforeAndAfter states(this, BailoutId::None()); |
2927 BuildVariableAssignment(states, arguments, object, Token::ASSIGN, | 2960 BuildVariableAssignment(arguments, object, Token::ASSIGN, BailoutId::None(), |
2928 BailoutId::None()); | 2961 states); |
2929 | 2962 |
2930 return object; | 2963 return object; |
2931 } | 2964 } |
2932 | 2965 |
2933 | 2966 |
2934 Node* AstGraphBuilder::BuildRestArgumentsArray(Variable* rest, int index) { | 2967 Node* AstGraphBuilder::BuildRestArgumentsArray(Variable* rest, int index) { |
2935 if (rest == NULL) return NULL; | 2968 if (rest == NULL) return NULL; |
2936 | 2969 |
2937 DCHECK(index >= 0); | 2970 DCHECK(index >= 0); |
2938 const Operator* op = javascript()->CallRuntime(Runtime::kNewRestParamSlow, 1); | 2971 const Operator* op = javascript()->CallRuntime(Runtime::kNewRestParamSlow, 1); |
2939 Node* object = NewNode(op, jsgraph()->SmiConstant(index)); | 2972 Node* object = NewNode(op, jsgraph()->SmiConstant(index)); |
2940 | 2973 |
2941 // Assign the object to the rest array | 2974 // Assign the object to the rest array |
2942 DCHECK(rest->IsContextSlot() || rest->IsStackAllocated()); | 2975 DCHECK(rest->IsContextSlot() || rest->IsStackAllocated()); |
2943 // This should never lazy deopt, so it is fine to send invalid bailout id. | 2976 // This should never lazy deopt, so it is fine to send invalid bailout id. |
2944 FrameStateBeforeAndAfter states(this, BailoutId::None()); | 2977 FrameStateBeforeAndAfter states(this, BailoutId::None()); |
2945 BuildVariableAssignment(states, rest, object, Token::ASSIGN, | 2978 BuildVariableAssignment(rest, object, Token::ASSIGN, BailoutId::None(), |
2946 BailoutId::None()); | 2979 states); |
2947 | 2980 |
2948 return object; | 2981 return object; |
2949 } | 2982 } |
2950 | 2983 |
2951 | 2984 |
2952 Node* AstGraphBuilder::BuildHoleCheckSilent(Node* value, Node* for_hole, | 2985 Node* AstGraphBuilder::BuildHoleCheckSilent(Node* value, Node* for_hole, |
2953 Node* not_hole) { | 2986 Node* not_hole) { |
2954 Node* the_hole = jsgraph()->TheHoleConstant(); | 2987 Node* the_hole = jsgraph()->TheHoleConstant(); |
2955 Node* check = NewNode(javascript()->StrictEqual(), value, the_hole); | 2988 Node* check = NewNode(javascript()->StrictEqual(), value, the_hole); |
2956 return NewNode(common()->Select(kMachAnyTagged, BranchHint::kFalse), check, | 2989 return NewNode(common()->Select(kMachAnyTagged, BranchHint::kFalse), check, |
(...skipping 28 matching lines...) Expand all Loading... |
2985 prototype_check.Then(); | 3018 prototype_check.Then(); |
2986 Node* error = BuildThrowStaticPrototypeError(bailout_id); | 3019 Node* error = BuildThrowStaticPrototypeError(bailout_id); |
2987 environment()->Push(error); | 3020 environment()->Push(error); |
2988 prototype_check.Else(); | 3021 prototype_check.Else(); |
2989 environment()->Push(name); | 3022 environment()->Push(name); |
2990 prototype_check.End(); | 3023 prototype_check.End(); |
2991 return environment()->Pop(); | 3024 return environment()->Pop(); |
2992 } | 3025 } |
2993 | 3026 |
2994 | 3027 |
2995 Node* AstGraphBuilder::BuildVariableLoad(FrameStateBeforeAndAfter& states, | 3028 Node* AstGraphBuilder::BuildVariableLoad(Variable* variable, |
2996 Variable* variable, | |
2997 BailoutId bailout_id, | 3029 BailoutId bailout_id, |
| 3030 FrameStateBeforeAndAfter& states, |
2998 const VectorSlotPair& feedback, | 3031 const VectorSlotPair& feedback, |
2999 OutputFrameStateCombine combine, | 3032 OutputFrameStateCombine combine, |
3000 ContextualMode contextual_mode) { | 3033 ContextualMode contextual_mode) { |
3001 Node* the_hole = jsgraph()->TheHoleConstant(); | 3034 Node* the_hole = jsgraph()->TheHoleConstant(); |
3002 VariableMode mode = variable->mode(); | 3035 VariableMode mode = variable->mode(); |
3003 switch (variable->location()) { | 3036 switch (variable->location()) { |
3004 case Variable::UNALLOCATED: { | 3037 case Variable::UNALLOCATED: { |
3005 // Global var, const, or let variable. | 3038 // Global var, const, or let variable. |
3006 Node* global = BuildLoadGlobalObject(); | 3039 Node* global = BuildLoadGlobalObject(); |
3007 Handle<Name> name = variable->name(); | 3040 Handle<Name> name = variable->name(); |
3008 Node* node = BuildNamedLoad(global, name, feedback, contextual_mode); | 3041 Node* value = BuildNamedLoad(global, name, feedback, contextual_mode); |
3009 states.AddToNode(node, bailout_id, combine); | 3042 states.AddToNode(value, bailout_id, combine); |
3010 return node; | 3043 return value; |
3011 } | 3044 } |
3012 case Variable::PARAMETER: | 3045 case Variable::PARAMETER: |
3013 case Variable::LOCAL: { | 3046 case Variable::LOCAL: { |
3014 // Local var, const, or let variable. | 3047 // Local var, const, or let variable. |
3015 Node* value = environment()->Lookup(variable); | 3048 Node* value = environment()->Lookup(variable); |
3016 if (mode == CONST_LEGACY) { | 3049 if (mode == CONST_LEGACY) { |
3017 // Perform check for uninitialized legacy const variables. | 3050 // Perform check for uninitialized legacy const variables. |
3018 if (value->op() == the_hole->op()) { | 3051 if (value->op() == the_hole->op()) { |
3019 value = jsgraph()->UndefinedConstant(); | 3052 value = jsgraph()->UndefinedConstant(); |
3020 } else if (value->opcode() == IrOpcode::kPhi) { | 3053 } else if (value->opcode() == IrOpcode::kPhi) { |
(...skipping 25 matching lines...) Expand all Loading... |
3046 Node* undefined = jsgraph()->UndefinedConstant(); | 3079 Node* undefined = jsgraph()->UndefinedConstant(); |
3047 value = BuildHoleCheckSilent(value, undefined, value); | 3080 value = BuildHoleCheckSilent(value, undefined, value); |
3048 } else if (mode == LET || mode == CONST) { | 3081 } else if (mode == LET || mode == CONST) { |
3049 // Perform check for uninitialized let/const variables. | 3082 // Perform check for uninitialized let/const variables. |
3050 value = BuildHoleCheckThrow(value, variable, value, bailout_id); | 3083 value = BuildHoleCheckThrow(value, variable, value, bailout_id); |
3051 } | 3084 } |
3052 return value; | 3085 return value; |
3053 } | 3086 } |
3054 case Variable::LOOKUP: { | 3087 case Variable::LOOKUP: { |
3055 // Dynamic lookup of context variable (anywhere in the chain). | 3088 // Dynamic lookup of context variable (anywhere in the chain). |
3056 Node* name = jsgraph()->Constant(variable->name()); | 3089 Node* value = jsgraph()->TheHoleConstant(); |
3057 Runtime::FunctionId function_id = | 3090 Handle<String> name = variable->name(); |
3058 (contextual_mode == CONTEXTUAL) | 3091 if (mode == DYNAMIC_GLOBAL) { |
3059 ? Runtime::kLoadLookupSlot | 3092 uint32_t check_bitset = ComputeBitsetForDynamicGlobal(variable); |
3060 : Runtime::kLoadLookupSlotNoReferenceError; | 3093 const Operator* op = javascript()->LoadDynamicGlobal(name, check_bitset, |
3061 const Operator* op = javascript()->CallRuntime(function_id, 2); | 3094 contextual_mode); |
3062 Node* pair = NewNode(op, current_context(), name); | 3095 value = NewNode(op, current_context()); |
3063 PrepareFrameState(pair, bailout_id, OutputFrameStateCombine::Push(1)); | 3096 } else if (mode == DYNAMIC_LOCAL) { |
3064 return NewNode(common()->Projection(0), pair); | 3097 Variable* local = variable->local_if_not_shadowed(); |
| 3098 DCHECK(local->location() == Variable::CONTEXT); // Must be context. |
| 3099 int depth = current_scope()->ContextChainLength(local->scope()); |
| 3100 uint32_t check_bitset = ComputeBitsetForDynamicContext(variable); |
| 3101 const Operator* op = javascript()->LoadDynamicContext( |
| 3102 name, check_bitset, depth, local->index()); |
| 3103 value = NewNode(op, current_context()); |
| 3104 // TODO(mstarzinger): Hole checks are missing here when optimized. |
| 3105 } else if (mode == DYNAMIC) { |
| 3106 uint32_t check_bitset = DynamicGlobalAccess::kFullCheckRequired; |
| 3107 const Operator* op = javascript()->LoadDynamicGlobal(name, check_bitset, |
| 3108 contextual_mode); |
| 3109 value = NewNode(op, current_context()); |
| 3110 } |
| 3111 PrepareFrameState(value, bailout_id, combine); |
| 3112 return value; |
3065 } | 3113 } |
3066 } | 3114 } |
3067 UNREACHABLE(); | 3115 UNREACHABLE(); |
3068 return NULL; | 3116 return NULL; |
3069 } | 3117 } |
3070 | 3118 |
3071 | 3119 |
3072 Node* AstGraphBuilder::BuildVariableDelete(Variable* variable, | 3120 Node* AstGraphBuilder::BuildVariableDelete(Variable* variable, |
3073 BailoutId bailout_id, | 3121 BailoutId bailout_id, |
3074 OutputFrameStateCombine combine) { | 3122 OutputFrameStateCombine combine) { |
(...skipping 21 matching lines...) Expand all Loading... |
3096 PrepareFrameState(result, bailout_id, combine); | 3144 PrepareFrameState(result, bailout_id, combine); |
3097 return result; | 3145 return result; |
3098 } | 3146 } |
3099 } | 3147 } |
3100 UNREACHABLE(); | 3148 UNREACHABLE(); |
3101 return NULL; | 3149 return NULL; |
3102 } | 3150 } |
3103 | 3151 |
3104 | 3152 |
3105 Node* AstGraphBuilder::BuildVariableAssignment( | 3153 Node* AstGraphBuilder::BuildVariableAssignment( |
3106 FrameStateBeforeAndAfter& states, Variable* variable, Node* value, | 3154 Variable* variable, Node* value, Token::Value op, BailoutId bailout_id, |
3107 Token::Value op, BailoutId bailout_id, OutputFrameStateCombine combine) { | 3155 FrameStateBeforeAndAfter& states, OutputFrameStateCombine combine) { |
3108 Node* the_hole = jsgraph()->TheHoleConstant(); | 3156 Node* the_hole = jsgraph()->TheHoleConstant(); |
3109 VariableMode mode = variable->mode(); | 3157 VariableMode mode = variable->mode(); |
3110 switch (variable->location()) { | 3158 switch (variable->location()) { |
3111 case Variable::UNALLOCATED: { | 3159 case Variable::UNALLOCATED: { |
3112 // Global var, const, or let variable. | 3160 // Global var, const, or let variable. |
3113 Node* global = BuildLoadGlobalObject(); | 3161 Node* global = BuildLoadGlobalObject(); |
3114 Handle<Name> name = variable->name(); | 3162 Handle<Name> name = variable->name(); |
3115 Node* store = | 3163 Node* store = |
3116 BuildNamedStore(global, name, value, TypeFeedbackId::None()); | 3164 BuildNamedStore(global, name, value, TypeFeedbackId::None()); |
3117 states.AddToNode(store, bailout_id, combine); | 3165 states.AddToNode(store, bailout_id, combine); |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3785 // Phi does not exist yet, introduce one. | 3833 // Phi does not exist yet, introduce one. |
3786 value = NewPhi(inputs, value, control); | 3834 value = NewPhi(inputs, value, control); |
3787 value->ReplaceInput(inputs - 1, other); | 3835 value->ReplaceInput(inputs - 1, other); |
3788 } | 3836 } |
3789 return value; | 3837 return value; |
3790 } | 3838 } |
3791 | 3839 |
3792 } // namespace compiler | 3840 } // namespace compiler |
3793 } // namespace internal | 3841 } // namespace internal |
3794 } // namespace v8 | 3842 } // namespace v8 |
OLD | NEW |