Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/full-codegen/arm64/full-codegen-arm64.cc

Issue 2201193004: Use Variable::binding_needs_init() to determine hole initialization (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove one more comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/full-codegen/arm/full-codegen-arm.cc ('k') | src/full-codegen/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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_ARM64 5 #if V8_TARGET_ARCH_ARM64
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 __ CompareRoot(x1, Heap::kWithContextMapRootIndex); 749 __ CompareRoot(x1, Heap::kWithContextMapRootIndex);
750 __ Check(ne, kDeclarationInWithContext); 750 __ Check(ne, kDeclarationInWithContext);
751 __ CompareRoot(x1, Heap::kCatchContextMapRootIndex); 751 __ CompareRoot(x1, Heap::kCatchContextMapRootIndex);
752 __ Check(ne, kDeclarationInCatchContext); 752 __ Check(ne, kDeclarationInCatchContext);
753 } 753 }
754 } 754 }
755 755
756 756
757 void FullCodeGenerator::VisitVariableDeclaration( 757 void FullCodeGenerator::VisitVariableDeclaration(
758 VariableDeclaration* declaration) { 758 VariableDeclaration* declaration) {
759 // If it was not possible to allocate the variable at compile time, we
760 // need to "declare" it at runtime to make sure it actually exists in the
761 // local context.
762 VariableProxy* proxy = declaration->proxy(); 759 VariableProxy* proxy = declaration->proxy();
763 VariableMode mode = declaration->mode();
764 Variable* variable = proxy->var(); 760 Variable* variable = proxy->var();
765 bool hole_init = mode == LET || mode == CONST;
766
767 switch (variable->location()) { 761 switch (variable->location()) {
768 case VariableLocation::GLOBAL: 762 case VariableLocation::GLOBAL:
769 case VariableLocation::UNALLOCATED: { 763 case VariableLocation::UNALLOCATED: {
770 DCHECK(!variable->binding_needs_init()); 764 DCHECK(!variable->binding_needs_init());
771 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); 765 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot();
772 DCHECK(!slot.IsInvalid()); 766 DCHECK(!slot.IsInvalid());
773 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); 767 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
774 globals_->Add(isolate()->factory()->undefined_value(), zone()); 768 globals_->Add(isolate()->factory()->undefined_value(), zone());
775 break; 769 break;
776 } 770 }
777 case VariableLocation::PARAMETER: 771 case VariableLocation::PARAMETER:
778 case VariableLocation::LOCAL: 772 case VariableLocation::LOCAL:
779 if (hole_init) { 773 if (variable->binding_needs_init()) {
780 Comment cmnt(masm_, "[ VariableDeclaration"); 774 Comment cmnt(masm_, "[ VariableDeclaration");
781 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex); 775 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
782 __ Str(x10, StackOperand(variable)); 776 __ Str(x10, StackOperand(variable));
783 } 777 }
784 break; 778 break;
785 779
786 case VariableLocation::CONTEXT: 780 case VariableLocation::CONTEXT:
787 if (hole_init) { 781 if (variable->binding_needs_init()) {
788 Comment cmnt(masm_, "[ VariableDeclaration"); 782 Comment cmnt(masm_, "[ VariableDeclaration");
789 EmitDebugCheckDeclarationContext(variable); 783 EmitDebugCheckDeclarationContext(variable);
790 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex); 784 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
791 __ Str(x10, ContextMemOperand(cp, variable->index())); 785 __ Str(x10, ContextMemOperand(cp, variable->index()));
792 // No write barrier since the_hole_value is in old space. 786 // No write barrier since the_hole_value is in old space.
793 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); 787 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
794 } 788 }
795 break; 789 break;
796 790
797 case VariableLocation::LOOKUP: { 791 case VariableLocation::LOOKUP: {
798 Comment cmnt(masm_, "[ VariableDeclaration"); 792 Comment cmnt(masm_, "[ VariableDeclaration");
799 DCHECK_EQ(VAR, mode); 793 DCHECK_EQ(VAR, variable->mode());
800 DCHECK(!hole_init); 794 DCHECK(!variable->binding_needs_init());
801 __ Mov(x2, Operand(variable->name())); 795 __ Mov(x2, Operand(variable->name()));
802 __ Push(x2); 796 __ Push(x2);
803 __ CallRuntime(Runtime::kDeclareEvalVar); 797 __ CallRuntime(Runtime::kDeclareEvalVar);
804 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); 798 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
805 break; 799 break;
806 } 800 }
807 } 801 }
808 } 802 }
809 803
810 804
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 // introducing variables. In those cases, we do not want to 1244 // introducing variables. In those cases, we do not want to
1251 // perform a runtime call for all variables in the scope 1245 // perform a runtime call for all variables in the scope
1252 // containing the eval. 1246 // containing the eval.
1253 Variable* var = proxy->var(); 1247 Variable* var = proxy->var();
1254 if (var->mode() == DYNAMIC_GLOBAL) { 1248 if (var->mode() == DYNAMIC_GLOBAL) {
1255 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); 1249 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow);
1256 __ B(done); 1250 __ B(done);
1257 } else if (var->mode() == DYNAMIC_LOCAL) { 1251 } else if (var->mode() == DYNAMIC_LOCAL) {
1258 Variable* local = var->local_if_not_shadowed(); 1252 Variable* local = var->local_if_not_shadowed();
1259 __ Ldr(x0, ContextSlotOperandCheckExtensions(local, slow)); 1253 __ Ldr(x0, ContextSlotOperandCheckExtensions(local, slow));
1260 if (local->mode() == LET || local->mode() == CONST) { 1254 if (local->binding_needs_init()) {
1261 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, done); 1255 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, done);
1262 __ Mov(x0, Operand(var->name())); 1256 __ Mov(x0, Operand(var->name()));
1263 __ Push(x0); 1257 __ Push(x0);
1264 __ CallRuntime(Runtime::kThrowReferenceError); 1258 __ CallRuntime(Runtime::kThrowReferenceError);
1259 } else {
1260 __ B(done);
1265 } 1261 }
1266 __ B(done);
1267 } 1262 }
1268 } 1263 }
1269 1264
1270 1265
1271 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, 1266 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy,
1272 TypeofMode typeof_mode) { 1267 TypeofMode typeof_mode) {
1273 #ifdef DEBUG 1268 #ifdef DEBUG
1274 Variable* var = proxy->var(); 1269 Variable* var = proxy->var();
1275 DCHECK(var->IsUnallocatedOrGlobalSlot() || 1270 DCHECK(var->IsUnallocatedOrGlobalSlot() ||
1276 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL)); 1271 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL));
(...skipping 23 matching lines...) Expand all
1300 } 1295 }
1301 1296
1302 case VariableLocation::PARAMETER: 1297 case VariableLocation::PARAMETER:
1303 case VariableLocation::LOCAL: 1298 case VariableLocation::LOCAL:
1304 case VariableLocation::CONTEXT: { 1299 case VariableLocation::CONTEXT: {
1305 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); 1300 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
1306 Comment cmnt(masm_, var->IsContextSlot() 1301 Comment cmnt(masm_, var->IsContextSlot()
1307 ? "Context variable" 1302 ? "Context variable"
1308 : "Stack variable"); 1303 : "Stack variable");
1309 if (NeedsHoleCheckForLoad(proxy)) { 1304 if (NeedsHoleCheckForLoad(proxy)) {
1310 // Let and const need a read barrier. 1305 // Throw a reference error when using an uninitialized let/const
1306 // binding in harmony mode.
1307 Label done;
1311 GetVar(x0, var); 1308 GetVar(x0, var);
1312 Label done;
1313 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, &done); 1309 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, &done);
1314 if (var->mode() == LET || var->mode() == CONST) { 1310 __ Mov(x0, Operand(var->name()));
1315 // Throw a reference error when using an uninitialized let/const 1311 __ Push(x0);
1316 // binding in harmony mode. 1312 __ CallRuntime(Runtime::kThrowReferenceError);
1317 __ Mov(x0, Operand(var->name())); 1313 __ Bind(&done);
1318 __ Push(x0);
1319 __ CallRuntime(Runtime::kThrowReferenceError);
1320 __ Bind(&done);
1321 }
1322 context()->Plug(x0); 1314 context()->Plug(x0);
1323 break; 1315 break;
1324 } 1316 }
1325 context()->Plug(var); 1317 context()->Plug(var);
1326 break; 1318 break;
1327 } 1319 }
1328 1320
1329 case VariableLocation::LOOKUP: { 1321 case VariableLocation::LOOKUP: {
1330 Label done, slow; 1322 Label done, slow;
1331 // Generate code for loading from variables potentially shadowed by 1323 // Generate code for loading from variables potentially shadowed by
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, 2043 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
2052 FeedbackVectorSlot slot) { 2044 FeedbackVectorSlot slot) {
2053 ASM_LOCATION("FullCodeGenerator::EmitVariableAssignment"); 2045 ASM_LOCATION("FullCodeGenerator::EmitVariableAssignment");
2054 if (var->IsUnallocated()) { 2046 if (var->IsUnallocated()) {
2055 // Global var, const, or let. 2047 // Global var, const, or let.
2056 __ Mov(StoreDescriptor::NameRegister(), Operand(var->name())); 2048 __ Mov(StoreDescriptor::NameRegister(), Operand(var->name()));
2057 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); 2049 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister());
2058 EmitLoadStoreICSlot(slot); 2050 EmitLoadStoreICSlot(slot);
2059 CallStoreIC(); 2051 CallStoreIC();
2060 2052
2061 } else if (var->mode() == LET && op != Token::INIT) { 2053 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) {
2062 // Non-initializing assignment to let variable needs a write barrier.
2063 DCHECK(!var->IsLookupSlot()); 2054 DCHECK(!var->IsLookupSlot());
2064 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2055 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2065 Label assign;
2066 MemOperand location = VarOperand(var, x1); 2056 MemOperand location = VarOperand(var, x1);
2067 __ Ldr(x10, location); 2057 // Perform an initialization check for lexically declared variables.
2068 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &assign); 2058 if (var->binding_needs_init()) {
2069 __ Mov(x10, Operand(var->name())); 2059 Label assign;
2070 __ Push(x10); 2060 __ Ldr(x10, location);
2071 __ CallRuntime(Runtime::kThrowReferenceError); 2061 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &assign);
2072 // Perform the assignment. 2062 __ Mov(x10, Operand(var->name()));
2073 __ Bind(&assign); 2063 __ Push(x10);
2074 EmitStoreToStackLocalOrContextSlot(var, location); 2064 __ CallRuntime(Runtime::kThrowReferenceError);
2075 2065 __ Bind(&assign);
2076 } else if (var->mode() == CONST && op != Token::INIT) { 2066 }
2077 // Assignment to const variable needs a write barrier. 2067 if (var->mode() == CONST) {
2078 DCHECK(!var->IsLookupSlot()); 2068 __ CallRuntime(Runtime::kThrowConstAssignError);
2079 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2069 } else {
2080 Label const_error; 2070 EmitStoreToStackLocalOrContextSlot(var, location);
2081 MemOperand location = VarOperand(var, x1); 2071 }
2082 __ Ldr(x10, location);
2083 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &const_error);
2084 __ Mov(x10, Operand(var->name()));
2085 __ Push(x10);
2086 __ CallRuntime(Runtime::kThrowReferenceError);
2087 __ Bind(&const_error);
2088 __ CallRuntime(Runtime::kThrowConstAssignError);
2089
2090 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { 2072 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) {
2091 // Initializing assignment to const {this} needs a write barrier. 2073 // Initializing assignment to const {this} needs a write barrier.
2092 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2074 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2093 Label uninitialized_this; 2075 Label uninitialized_this;
2094 MemOperand location = VarOperand(var, x1); 2076 MemOperand location = VarOperand(var, x1);
2095 __ Ldr(x10, location); 2077 __ Ldr(x10, location);
2096 __ JumpIfRoot(x10, Heap::kTheHoleValueRootIndex, &uninitialized_this); 2078 __ JumpIfRoot(x10, Heap::kTheHoleValueRootIndex, &uninitialized_this);
2097 __ Mov(x0, Operand(var->name())); 2079 __ Mov(x0, Operand(var->name()));
2098 __ Push(x0); 2080 __ Push(x0);
2099 __ CallRuntime(Runtime::kThrowReferenceError); 2081 __ CallRuntime(Runtime::kThrowReferenceError);
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
3848 } 3830 }
3849 3831
3850 return INTERRUPT; 3832 return INTERRUPT;
3851 } 3833 }
3852 3834
3853 3835
3854 } // namespace internal 3836 } // namespace internal
3855 } // namespace v8 3837 } // namespace v8
3856 3838
3857 #endif // V8_TARGET_ARCH_ARM64 3839 #endif // V8_TARGET_ARCH_ARM64
OLDNEW
« no previous file with comments | « src/full-codegen/arm/full-codegen-arm.cc ('k') | src/full-codegen/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698