OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/full-codegen/full-codegen.h" | 7 #include "src/full-codegen/full-codegen.h" |
8 #include "src/ast/compile-time-value.h" | 8 #include "src/ast/compile-time-value.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 PrepareForBailoutForId(stmt->ExitId(), BailoutState::NO_REGISTERS); | 1112 PrepareForBailoutForId(stmt->ExitId(), BailoutState::NO_REGISTERS); |
1113 __ bind(&exit); | 1113 __ bind(&exit); |
1114 decrement_loop_depth(); | 1114 decrement_loop_depth(); |
1115 } | 1115 } |
1116 | 1116 |
1117 | 1117 |
1118 void FullCodeGenerator::EmitSetHomeObject(Expression* initializer, int offset, | 1118 void FullCodeGenerator::EmitSetHomeObject(Expression* initializer, int offset, |
1119 FeedbackVectorSlot slot) { | 1119 FeedbackVectorSlot slot) { |
1120 DCHECK(NeedsHomeObject(initializer)); | 1120 DCHECK(NeedsHomeObject(initializer)); |
1121 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); | 1121 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 1122 __ Move(StoreDescriptor::NameRegister(), |
| 1123 isolate()->factory()->home_object_symbol()); |
1122 __ movp(StoreDescriptor::ValueRegister(), | 1124 __ movp(StoreDescriptor::ValueRegister(), |
1123 Operand(rsp, offset * kPointerSize)); | 1125 Operand(rsp, offset * kPointerSize)); |
1124 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); | 1126 EmitLoadStoreICSlot(slot); |
| 1127 CallStoreIC(); |
1125 } | 1128 } |
1126 | 1129 |
1127 | 1130 |
1128 void FullCodeGenerator::EmitSetHomeObjectAccumulator(Expression* initializer, | 1131 void FullCodeGenerator::EmitSetHomeObjectAccumulator(Expression* initializer, |
1129 int offset, | 1132 int offset, |
1130 FeedbackVectorSlot slot) { | 1133 FeedbackVectorSlot slot) { |
1131 DCHECK(NeedsHomeObject(initializer)); | 1134 DCHECK(NeedsHomeObject(initializer)); |
1132 __ movp(StoreDescriptor::ReceiverRegister(), rax); | 1135 __ movp(StoreDescriptor::ReceiverRegister(), rax); |
| 1136 __ Move(StoreDescriptor::NameRegister(), |
| 1137 isolate()->factory()->home_object_symbol()); |
1133 __ movp(StoreDescriptor::ValueRegister(), | 1138 __ movp(StoreDescriptor::ValueRegister(), |
1134 Operand(rsp, offset * kPointerSize)); | 1139 Operand(rsp, offset * kPointerSize)); |
1135 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); | 1140 EmitLoadStoreICSlot(slot); |
| 1141 CallStoreIC(); |
1136 } | 1142 } |
1137 | 1143 |
1138 | 1144 |
1139 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, | 1145 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, |
1140 TypeofMode typeof_mode, | 1146 TypeofMode typeof_mode, |
1141 Label* slow) { | 1147 Label* slow) { |
1142 Register context = rsi; | 1148 Register context = rsi; |
1143 Register temp = rdx; | 1149 Register temp = rdx; |
1144 | 1150 |
1145 int to_check = scope()->ContextChainLengthUntilOutermostSloppyEval(); | 1151 int to_check = scope()->ContextChainLengthUntilOutermostSloppyEval(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); | 1366 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); |
1361 // Fall through. | 1367 // Fall through. |
1362 case ObjectLiteral::Property::COMPUTED: | 1368 case ObjectLiteral::Property::COMPUTED: |
1363 // It is safe to use [[Put]] here because the boilerplate already | 1369 // It is safe to use [[Put]] here because the boilerplate already |
1364 // contains computed properties with an uninitialized value. | 1370 // contains computed properties with an uninitialized value. |
1365 if (key->IsStringLiteral()) { | 1371 if (key->IsStringLiteral()) { |
1366 DCHECK(key->IsPropertyName()); | 1372 DCHECK(key->IsPropertyName()); |
1367 if (property->emit_store()) { | 1373 if (property->emit_store()) { |
1368 VisitForAccumulatorValue(value); | 1374 VisitForAccumulatorValue(value); |
1369 DCHECK(StoreDescriptor::ValueRegister().is(rax)); | 1375 DCHECK(StoreDescriptor::ValueRegister().is(rax)); |
| 1376 __ Move(StoreDescriptor::NameRegister(), key->value()); |
1370 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); | 1377 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
1371 CallStoreIC(property->GetSlot(0), key->value()); | 1378 EmitLoadStoreICSlot(property->GetSlot(0)); |
| 1379 CallStoreIC(); |
1372 PrepareForBailoutForId(key->id(), BailoutState::NO_REGISTERS); | 1380 PrepareForBailoutForId(key->id(), BailoutState::NO_REGISTERS); |
1373 | 1381 |
1374 if (NeedsHomeObject(value)) { | 1382 if (NeedsHomeObject(value)) { |
1375 EmitSetHomeObjectAccumulator(value, 0, property->GetSlot(1)); | 1383 EmitSetHomeObjectAccumulator(value, 0, property->GetSlot(1)); |
1376 } | 1384 } |
1377 } else { | 1385 } else { |
1378 VisitForEffect(value); | 1386 VisitForEffect(value); |
1379 } | 1387 } |
1380 break; | 1388 break; |
1381 } | 1389 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 1558 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
1551 | 1559 |
1552 if (!result_saved) { | 1560 if (!result_saved) { |
1553 PushOperand(rax); // array literal | 1561 PushOperand(rax); // array literal |
1554 result_saved = true; | 1562 result_saved = true; |
1555 } | 1563 } |
1556 VisitForAccumulatorValue(subexpr); | 1564 VisitForAccumulatorValue(subexpr); |
1557 | 1565 |
1558 __ Move(StoreDescriptor::NameRegister(), Smi::FromInt(array_index)); | 1566 __ Move(StoreDescriptor::NameRegister(), Smi::FromInt(array_index)); |
1559 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); | 1567 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
1560 CallKeyedStoreIC(expr->LiteralFeedbackSlot()); | 1568 EmitLoadStoreICSlot(expr->LiteralFeedbackSlot()); |
| 1569 CallKeyedStoreIC(); |
1561 | 1570 |
1562 PrepareForBailoutForId(expr->GetIdForElement(array_index), | 1571 PrepareForBailoutForId(expr->GetIdForElement(array_index), |
1563 BailoutState::NO_REGISTERS); | 1572 BailoutState::NO_REGISTERS); |
1564 } | 1573 } |
1565 | 1574 |
1566 if (result_saved) { | 1575 if (result_saved) { |
1567 context()->PlugTOS(); | 1576 context()->PlugTOS(); |
1568 } else { | 1577 } else { |
1569 context()->Plug(rax); | 1578 context()->Plug(rax); |
1570 } | 1579 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 Variable* var = expr->AsVariableProxy()->var(); | 1947 Variable* var = expr->AsVariableProxy()->var(); |
1939 EffectContext context(this); | 1948 EffectContext context(this); |
1940 EmitVariableAssignment(var, Token::ASSIGN, slot); | 1949 EmitVariableAssignment(var, Token::ASSIGN, slot); |
1941 break; | 1950 break; |
1942 } | 1951 } |
1943 case NAMED_PROPERTY: { | 1952 case NAMED_PROPERTY: { |
1944 PushOperand(rax); // Preserve value. | 1953 PushOperand(rax); // Preserve value. |
1945 VisitForAccumulatorValue(prop->obj()); | 1954 VisitForAccumulatorValue(prop->obj()); |
1946 __ Move(StoreDescriptor::ReceiverRegister(), rax); | 1955 __ Move(StoreDescriptor::ReceiverRegister(), rax); |
1947 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. | 1956 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. |
1948 CallStoreIC(slot, prop->key()->AsLiteral()->value()); | 1957 __ Move(StoreDescriptor::NameRegister(), |
| 1958 prop->key()->AsLiteral()->value()); |
| 1959 EmitLoadStoreICSlot(slot); |
| 1960 CallStoreIC(); |
1949 break; | 1961 break; |
1950 } | 1962 } |
1951 case NAMED_SUPER_PROPERTY: { | 1963 case NAMED_SUPER_PROPERTY: { |
1952 PushOperand(rax); | 1964 PushOperand(rax); |
1953 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var()); | 1965 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var()); |
1954 VisitForAccumulatorValue( | 1966 VisitForAccumulatorValue( |
1955 prop->obj()->AsSuperPropertyReference()->home_object()); | 1967 prop->obj()->AsSuperPropertyReference()->home_object()); |
1956 // stack: value, this; rax: home_object | 1968 // stack: value, this; rax: home_object |
1957 Register scratch = rcx; | 1969 Register scratch = rcx; |
1958 Register scratch2 = rdx; | 1970 Register scratch2 = rdx; |
(...skipping 26 matching lines...) Expand all Loading... |
1985 EmitKeyedSuperPropertyStore(prop); | 1997 EmitKeyedSuperPropertyStore(prop); |
1986 break; | 1998 break; |
1987 } | 1999 } |
1988 case KEYED_PROPERTY: { | 2000 case KEYED_PROPERTY: { |
1989 PushOperand(rax); // Preserve value. | 2001 PushOperand(rax); // Preserve value. |
1990 VisitForStackValue(prop->obj()); | 2002 VisitForStackValue(prop->obj()); |
1991 VisitForAccumulatorValue(prop->key()); | 2003 VisitForAccumulatorValue(prop->key()); |
1992 __ Move(StoreDescriptor::NameRegister(), rax); | 2004 __ Move(StoreDescriptor::NameRegister(), rax); |
1993 PopOperand(StoreDescriptor::ReceiverRegister()); | 2005 PopOperand(StoreDescriptor::ReceiverRegister()); |
1994 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. | 2006 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. |
1995 CallKeyedStoreIC(slot); | 2007 EmitLoadStoreICSlot(slot); |
| 2008 CallKeyedStoreIC(); |
1996 break; | 2009 break; |
1997 } | 2010 } |
1998 } | 2011 } |
1999 context()->Plug(rax); | 2012 context()->Plug(rax); |
2000 } | 2013 } |
2001 | 2014 |
2002 | 2015 |
2003 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( | 2016 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( |
2004 Variable* var, MemOperand location) { | 2017 Variable* var, MemOperand location) { |
2005 __ movp(location, rax); | 2018 __ movp(location, rax); |
2006 if (var->IsContextSlot()) { | 2019 if (var->IsContextSlot()) { |
2007 __ movp(rdx, rax); | 2020 __ movp(rdx, rax); |
2008 __ RecordWriteContextSlot( | 2021 __ RecordWriteContextSlot( |
2009 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); | 2022 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); |
2010 } | 2023 } |
2011 } | 2024 } |
2012 | 2025 |
2013 | 2026 |
2014 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, | 2027 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, |
2015 FeedbackVectorSlot slot) { | 2028 FeedbackVectorSlot slot) { |
2016 if (var->IsUnallocated()) { | 2029 if (var->IsUnallocated()) { |
2017 // Global var, const, or let. | 2030 // Global var, const, or let. |
| 2031 __ Move(StoreDescriptor::NameRegister(), var->name()); |
2018 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); | 2032 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); |
2019 CallStoreIC(slot, var->name()); | 2033 EmitLoadStoreICSlot(slot); |
| 2034 CallStoreIC(); |
2020 | 2035 |
2021 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) { | 2036 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) { |
2022 DCHECK(!var->IsLookupSlot()); | 2037 DCHECK(!var->IsLookupSlot()); |
2023 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 2038 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
2024 MemOperand location = VarOperand(var, rcx); | 2039 MemOperand location = VarOperand(var, rcx); |
2025 // Perform an initialization check for lexically declared variables. | 2040 // Perform an initialization check for lexically declared variables. |
2026 if (var->binding_needs_init()) { | 2041 if (var->binding_needs_init()) { |
2027 Label assign; | 2042 Label assign; |
2028 __ movp(rdx, location); | 2043 __ movp(rdx, location); |
2029 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); | 2044 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2076 } | 2091 } |
2077 } | 2092 } |
2078 | 2093 |
2079 | 2094 |
2080 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { | 2095 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
2081 // Assignment to a property, using a named store IC. | 2096 // Assignment to a property, using a named store IC. |
2082 Property* prop = expr->target()->AsProperty(); | 2097 Property* prop = expr->target()->AsProperty(); |
2083 DCHECK(prop != NULL); | 2098 DCHECK(prop != NULL); |
2084 DCHECK(prop->key()->IsLiteral()); | 2099 DCHECK(prop->key()->IsLiteral()); |
2085 | 2100 |
| 2101 __ Move(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); |
2086 PopOperand(StoreDescriptor::ReceiverRegister()); | 2102 PopOperand(StoreDescriptor::ReceiverRegister()); |
2087 CallStoreIC(expr->AssignmentSlot(), prop->key()->AsLiteral()->value()); | 2103 EmitLoadStoreICSlot(expr->AssignmentSlot()); |
| 2104 CallStoreIC(); |
2088 | 2105 |
2089 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 2106 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
2090 context()->Plug(rax); | 2107 context()->Plug(rax); |
2091 } | 2108 } |
2092 | 2109 |
2093 | 2110 |
2094 void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { | 2111 void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { |
2095 // Assignment to named property of super. | 2112 // Assignment to named property of super. |
2096 // rax : value | 2113 // rax : value |
2097 // stack : receiver ('this'), home_object | 2114 // stack : receiver ('this'), home_object |
(...skipping 20 matching lines...) Expand all Loading... |
2118 ? Runtime::kStoreKeyedToSuper_Strict | 2135 ? Runtime::kStoreKeyedToSuper_Strict |
2119 : Runtime::kStoreKeyedToSuper_Sloppy); | 2136 : Runtime::kStoreKeyedToSuper_Sloppy); |
2120 } | 2137 } |
2121 | 2138 |
2122 | 2139 |
2123 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { | 2140 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
2124 // Assignment to a property, using a keyed store IC. | 2141 // Assignment to a property, using a keyed store IC. |
2125 PopOperand(StoreDescriptor::NameRegister()); // Key. | 2142 PopOperand(StoreDescriptor::NameRegister()); // Key. |
2126 PopOperand(StoreDescriptor::ReceiverRegister()); | 2143 PopOperand(StoreDescriptor::ReceiverRegister()); |
2127 DCHECK(StoreDescriptor::ValueRegister().is(rax)); | 2144 DCHECK(StoreDescriptor::ValueRegister().is(rax)); |
2128 CallKeyedStoreIC(expr->AssignmentSlot()); | 2145 EmitLoadStoreICSlot(expr->AssignmentSlot()); |
| 2146 CallKeyedStoreIC(); |
2129 | 2147 |
2130 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 2148 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
2131 context()->Plug(rax); | 2149 context()->Plug(rax); |
2132 } | 2150 } |
2133 | 2151 |
2134 | 2152 |
2135 void FullCodeGenerator::CallIC(Handle<Code> code, | 2153 void FullCodeGenerator::CallIC(Handle<Code> code, |
2136 TypeFeedbackId ast_id) { | 2154 TypeFeedbackId ast_id) { |
2137 ic_total_count_++; | 2155 ic_total_count_++; |
2138 __ call(code, RelocInfo::CODE_TARGET, ast_id); | 2156 __ call(code, RelocInfo::CODE_TARGET, ast_id); |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3166 } else { | 3184 } else { |
3167 // Perform the assignment as if via '='. | 3185 // Perform the assignment as if via '='. |
3168 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), | 3186 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
3169 Token::ASSIGN, expr->CountSlot()); | 3187 Token::ASSIGN, expr->CountSlot()); |
3170 PrepareForBailoutForId(expr->AssignmentId(), | 3188 PrepareForBailoutForId(expr->AssignmentId(), |
3171 BailoutState::TOS_REGISTER); | 3189 BailoutState::TOS_REGISTER); |
3172 context()->Plug(rax); | 3190 context()->Plug(rax); |
3173 } | 3191 } |
3174 break; | 3192 break; |
3175 case NAMED_PROPERTY: { | 3193 case NAMED_PROPERTY: { |
| 3194 __ Move(StoreDescriptor::NameRegister(), |
| 3195 prop->key()->AsLiteral()->value()); |
3176 PopOperand(StoreDescriptor::ReceiverRegister()); | 3196 PopOperand(StoreDescriptor::ReceiverRegister()); |
3177 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); | 3197 EmitLoadStoreICSlot(expr->CountSlot()); |
| 3198 CallStoreIC(); |
3178 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 3199 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
3179 if (expr->is_postfix()) { | 3200 if (expr->is_postfix()) { |
3180 if (!context()->IsEffect()) { | 3201 if (!context()->IsEffect()) { |
3181 context()->PlugTOS(); | 3202 context()->PlugTOS(); |
3182 } | 3203 } |
3183 } else { | 3204 } else { |
3184 context()->Plug(rax); | 3205 context()->Plug(rax); |
3185 } | 3206 } |
3186 break; | 3207 break; |
3187 } | 3208 } |
(...skipping 17 matching lines...) Expand all Loading... |
3205 context()->PlugTOS(); | 3226 context()->PlugTOS(); |
3206 } | 3227 } |
3207 } else { | 3228 } else { |
3208 context()->Plug(rax); | 3229 context()->Plug(rax); |
3209 } | 3230 } |
3210 break; | 3231 break; |
3211 } | 3232 } |
3212 case KEYED_PROPERTY: { | 3233 case KEYED_PROPERTY: { |
3213 PopOperand(StoreDescriptor::NameRegister()); | 3234 PopOperand(StoreDescriptor::NameRegister()); |
3214 PopOperand(StoreDescriptor::ReceiverRegister()); | 3235 PopOperand(StoreDescriptor::ReceiverRegister()); |
3215 CallKeyedStoreIC(expr->CountSlot()); | 3236 EmitLoadStoreICSlot(expr->CountSlot()); |
| 3237 CallKeyedStoreIC(); |
3216 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 3238 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
3217 if (expr->is_postfix()) { | 3239 if (expr->is_postfix()) { |
3218 if (!context()->IsEffect()) { | 3240 if (!context()->IsEffect()) { |
3219 context()->PlugTOS(); | 3241 context()->PlugTOS(); |
3220 } | 3242 } |
3221 } else { | 3243 } else { |
3222 context()->Plug(rax); | 3244 context()->Plug(rax); |
3223 } | 3245 } |
3224 break; | 3246 break; |
3225 } | 3247 } |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3587 DCHECK_EQ( | 3609 DCHECK_EQ( |
3588 isolate->builtins()->OnStackReplacement()->entry(), | 3610 isolate->builtins()->OnStackReplacement()->entry(), |
3589 Assembler::target_address_at(call_target_address, unoptimized_code)); | 3611 Assembler::target_address_at(call_target_address, unoptimized_code)); |
3590 return ON_STACK_REPLACEMENT; | 3612 return ON_STACK_REPLACEMENT; |
3591 } | 3613 } |
3592 | 3614 |
3593 } // namespace internal | 3615 } // namespace internal |
3594 } // namespace v8 | 3616 } // namespace v8 |
3595 | 3617 |
3596 #endif // V8_TARGET_ARCH_X64 | 3618 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |