| 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 #include "src/ast.h" | 5 #include "src/ast.h" |
| 6 | 6 |
| 7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
| 8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return IsLiteral() && AsLiteral()->value()->IsNull(); | 47 return IsLiteral() && AsLiteral()->value()->IsNull(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const { | 51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const { |
| 52 const VariableProxy* var_proxy = AsVariableProxy(); | 52 const VariableProxy* var_proxy = AsVariableProxy(); |
| 53 if (var_proxy == NULL) return false; | 53 if (var_proxy == NULL) return false; |
| 54 Variable* var = var_proxy->var(); | 54 Variable* var = var_proxy->var(); |
| 55 // The global identifier "undefined" is immutable. Everything | 55 // The global identifier "undefined" is immutable. Everything |
| 56 // else could be reassigned. | 56 // else could be reassigned. |
| 57 return var != NULL && var->location() == Variable::UNALLOCATED && | 57 return var != NULL && var->IsUnallocatedOrGlobalSlot() && |
| 58 var_proxy->raw_name()->IsOneByteEqualTo("undefined"); | 58 var_proxy->raw_name()->IsOneByteEqualTo("undefined"); |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position, | 62 VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position, |
| 63 int end_position) | 63 int end_position) |
| 64 : Expression(zone, start_position), | 64 : Expression(zone, start_position), |
| 65 bit_field_(IsThisField::encode(var->is_this()) | | 65 bit_field_(IsThisField::encode(var->is_this()) | |
| 66 IsAssignedField::encode(false) | | 66 IsAssignedField::encode(false) | |
| 67 IsResolvedField::encode(false)), | 67 IsResolvedField::encode(false)), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 88 DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name()); | 88 DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name()); |
| 89 set_var(var); | 89 set_var(var); |
| 90 set_is_resolved(); | 90 set_is_resolved(); |
| 91 var->set_is_used(); | 91 var->set_is_used(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 void VariableProxy::SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, | 95 void VariableProxy::SetFirstFeedbackICSlot(FeedbackVectorICSlot slot, |
| 96 ICSlotCache* cache) { | 96 ICSlotCache* cache) { |
| 97 variable_feedback_slot_ = slot; | 97 variable_feedback_slot_ = slot; |
| 98 if (var()->IsUnallocated()) { | 98 if (var()->IsUnallocatedOrGlobalSlot()) { |
| 99 cache->Add(VariableICSlotPair(var(), slot)); | 99 cache->Add(VariableICSlotPair(var(), slot)); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 FeedbackVectorRequirements VariableProxy::ComputeFeedbackRequirements( | 104 FeedbackVectorRequirements VariableProxy::ComputeFeedbackRequirements( |
| 105 Isolate* isolate, const ICSlotCache* cache) { | 105 Isolate* isolate, const ICSlotCache* cache) { |
| 106 if (UsesVariableFeedbackSlot()) { | 106 if (UsesVariableFeedbackSlot()) { |
| 107 // VariableProxies that point to the same Variable within a function can | 107 // VariableProxies that point to the same Variable within a function can |
| 108 // make their loads from the same IC slot. | 108 // make their loads from the same IC slot. |
| 109 if (var()->IsUnallocated()) { | 109 if (var()->IsUnallocatedOrGlobalSlot()) { |
| 110 for (int i = 0; i < cache->length(); i++) { | 110 for (int i = 0; i < cache->length(); i++) { |
| 111 VariableICSlotPair& pair = cache->at(i); | 111 VariableICSlotPair& pair = cache->at(i); |
| 112 if (pair.variable() == var()) { | 112 if (pair.variable() == var()) { |
| 113 variable_feedback_slot_ = pair.slot(); | 113 variable_feedback_slot_ = pair.slot(); |
| 114 return FeedbackVectorRequirements(0, 0); | 114 return FeedbackVectorRequirements(0, 0); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 return FeedbackVectorRequirements(0, 1); | 118 return FeedbackVectorRequirements(0, 1); |
| 119 } | 119 } |
| 120 return FeedbackVectorRequirements(0, 0); | 120 return FeedbackVectorRequirements(0, 0); |
| 121 } | 121 } |
| 122 | 122 |
| 123 | 123 |
| 124 static int GetStoreICSlots(Expression* expr) { | 124 static int GetStoreICSlots(Expression* expr) { |
| 125 int ic_slots = 0; | 125 int ic_slots = 0; |
| 126 if (FLAG_vector_stores) { | 126 if (FLAG_vector_stores) { |
| 127 Property* property = expr->AsProperty(); | 127 Property* property = expr->AsProperty(); |
| 128 LhsKind assign_type = Property::GetAssignType(property); | 128 LhsKind assign_type = Property::GetAssignType(property); |
| 129 if ((assign_type == VARIABLE && | 129 if ((assign_type == VARIABLE && |
| 130 expr->AsVariableProxy()->var()->IsUnallocated()) || | 130 expr->AsVariableProxy()->var()->IsUnallocatedOrGlobalSlot()) || |
| 131 assign_type == NAMED_PROPERTY || assign_type == KEYED_PROPERTY) { | 131 assign_type == NAMED_PROPERTY || assign_type == KEYED_PROPERTY) { |
| 132 ic_slots++; | 132 ic_slots++; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 return ic_slots; | 135 return ic_slots; |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 static Code::Kind GetStoreICKind(Expression* expr) { | 139 static Code::Kind GetStoreICKind(Expression* expr) { |
| 140 LhsKind assign_type = Property::GetAssignType(expr->AsProperty()); | 140 LhsKind assign_type = Property::GetAssignType(expr->AsProperty()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // This logic that computes the number of slots needed for vector store | 282 // This logic that computes the number of slots needed for vector store |
| 283 // ICs must mirror FullCodeGenerator::VisitClassLiteral. | 283 // ICs must mirror FullCodeGenerator::VisitClassLiteral. |
| 284 int ic_slots = 0; | 284 int ic_slots = 0; |
| 285 for (int i = 0; i < properties()->length(); i++) { | 285 for (int i = 0; i < properties()->length(); i++) { |
| 286 ObjectLiteral::Property* property = properties()->at(i); | 286 ObjectLiteral::Property* property = properties()->at(i); |
| 287 | 287 |
| 288 Expression* value = property->value(); | 288 Expression* value = property->value(); |
| 289 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 289 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; |
| 290 } | 290 } |
| 291 | 291 |
| 292 if (scope() != NULL && class_variable_proxy()->var()->IsUnallocated()) { | 292 if (scope() != NULL && |
| 293 class_variable_proxy()->var()->IsUnallocatedOrGlobalSlot()) { |
| 293 ic_slots++; | 294 ic_slots++; |
| 294 } | 295 } |
| 295 | 296 |
| 296 #ifdef DEBUG | 297 #ifdef DEBUG |
| 297 // FullCodeGenerator::VisitClassLiteral verifies that it consumes slot_count_ | 298 // FullCodeGenerator::VisitClassLiteral verifies that it consumes slot_count_ |
| 298 // slots. | 299 // slots. |
| 299 slot_count_ = ic_slots; | 300 slot_count_ = ic_slots; |
| 300 #endif | 301 #endif |
| 301 return FeedbackVectorRequirements(0, ic_slots); | 302 return FeedbackVectorRequirements(0, ic_slots); |
| 302 } | 303 } |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 int slots = IsUsingCallFeedbackSlot(isolate) ? 1 : 0; | 746 int slots = IsUsingCallFeedbackSlot(isolate) ? 1 : 0; |
| 746 return FeedbackVectorRequirements(slots, ic_slots); | 747 return FeedbackVectorRequirements(slots, ic_slots); |
| 747 } | 748 } |
| 748 | 749 |
| 749 | 750 |
| 750 Call::CallType Call::GetCallType(Isolate* isolate) const { | 751 Call::CallType Call::GetCallType(Isolate* isolate) const { |
| 751 VariableProxy* proxy = expression()->AsVariableProxy(); | 752 VariableProxy* proxy = expression()->AsVariableProxy(); |
| 752 if (proxy != NULL) { | 753 if (proxy != NULL) { |
| 753 if (proxy->var()->is_possibly_eval(isolate)) { | 754 if (proxy->var()->is_possibly_eval(isolate)) { |
| 754 return POSSIBLY_EVAL_CALL; | 755 return POSSIBLY_EVAL_CALL; |
| 755 } else if (proxy->var()->IsUnallocated()) { | 756 } else if (proxy->var()->IsUnallocatedOrGlobalSlot()) { |
| 756 return GLOBAL_CALL; | 757 return GLOBAL_CALL; |
| 757 } else if (proxy->var()->IsLookupSlot()) { | 758 } else if (proxy->var()->IsLookupSlot()) { |
| 758 return LOOKUP_SLOT_CALL; | 759 return LOOKUP_SLOT_CALL; |
| 759 } | 760 } |
| 760 } | 761 } |
| 761 | 762 |
| 762 if (expression()->IsSuperCallReference()) return SUPER_CALL; | 763 if (expression()->IsSuperCallReference()) return SUPER_CALL; |
| 763 | 764 |
| 764 Property* property = expression()->AsProperty(); | 765 Property* property = expression()->AsProperty(); |
| 765 return property != NULL ? PROPERTY_CALL : OTHER_CALL; | 766 return property != NULL ? PROPERTY_CALL : OTHER_CALL; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 bool Literal::Match(void* literal1, void* literal2) { | 1146 bool Literal::Match(void* literal1, void* literal2) { |
| 1146 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1147 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
| 1147 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1148 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
| 1148 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 1149 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
| 1149 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1150 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
| 1150 } | 1151 } |
| 1151 | 1152 |
| 1152 | 1153 |
| 1153 } // namespace internal | 1154 } // namespace internal |
| 1154 } // namespace v8 | 1155 } // namespace v8 |
| OLD | NEW |