OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 | 70 |
71 int HValue::LoopWeight() const { | 71 int HValue::LoopWeight() const { |
72 const int w = FLAG_loop_weight; | 72 const int w = FLAG_loop_weight; |
73 static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w }; | 73 static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w }; |
74 return weights[Min(block()->LoopNestingDepth(), | 74 return weights[Min(block()->LoopNestingDepth(), |
75 static_cast<int>(ARRAY_SIZE(weights)-1))]; | 75 static_cast<int>(ARRAY_SIZE(weights)-1))]; |
76 } | 76 } |
77 | 77 |
78 | 78 |
| 79 Isolate* HValue::isolate() const { |
| 80 ASSERT(block() != NULL); |
| 81 return block()->graph()->isolate(); |
| 82 } |
| 83 |
| 84 |
79 void HValue::AssumeRepresentation(Representation r) { | 85 void HValue::AssumeRepresentation(Representation r) { |
80 if (CheckFlag(kFlexibleRepresentation)) { | 86 if (CheckFlag(kFlexibleRepresentation)) { |
81 ChangeRepresentation(r); | 87 ChangeRepresentation(r); |
82 // The representation of the value is dictated by type feedback and | 88 // The representation of the value is dictated by type feedback and |
83 // will not be changed later. | 89 // will not be changed later. |
84 ClearFlag(kFlexibleRepresentation); | 90 ClearFlag(kFlexibleRepresentation); |
85 } | 91 } |
86 } | 92 } |
87 | 93 |
88 | 94 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 case kNonPrimitive: return "non-primitive"; | 341 case kNonPrimitive: return "non-primitive"; |
336 case kJSArray: return "array"; | 342 case kJSArray: return "array"; |
337 case kJSObject: return "object"; | 343 case kJSObject: return "object"; |
338 case kUninitialized: return "uninitialized"; | 344 case kUninitialized: return "uninitialized"; |
339 } | 345 } |
340 UNREACHABLE(); | 346 UNREACHABLE(); |
341 return "Unreachable code"; | 347 return "Unreachable code"; |
342 } | 348 } |
343 | 349 |
344 | 350 |
345 HType HType::TypeFromValue(Handle<Object> value) { | 351 HType HType::TypeFromValue(Isolate* isolate, Handle<Object> value) { |
346 // Handle dereferencing is safe here: an object's type as checked below | 352 // Handle dereferencing is safe here: an object's type as checked below |
347 // never changes. | 353 // never changes. |
348 AllowHandleDereference allow_handle_deref; | 354 AllowHandleDereference allow_handle_deref(isolate); |
349 | 355 |
350 HType result = HType::Tagged(); | 356 HType result = HType::Tagged(); |
351 if (value->IsSmi()) { | 357 if (value->IsSmi()) { |
352 result = HType::Smi(); | 358 result = HType::Smi(); |
353 } else if (value->IsHeapNumber()) { | 359 } else if (value->IsHeapNumber()) { |
354 result = HType::HeapNumber(); | 360 result = HType::HeapNumber(); |
355 } else if (value->IsString()) { | 361 } else if (value->IsString()) { |
356 result = HType::String(); | 362 result = HType::String(); |
357 } else if (value->IsBoolean()) { | 363 } else if (value->IsBoolean()) { |
358 result = HType::Boolean(); | 364 result = HType::Boolean(); |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 | 1298 |
1293 HValue* HCheckInstanceType::Canonicalize() { | 1299 HValue* HCheckInstanceType::Canonicalize() { |
1294 if (check_ == IS_STRING && | 1300 if (check_ == IS_STRING && |
1295 !value()->type().IsUninitialized() && | 1301 !value()->type().IsUninitialized() && |
1296 value()->type().IsString()) { | 1302 value()->type().IsString()) { |
1297 return NULL; | 1303 return NULL; |
1298 } | 1304 } |
1299 | 1305 |
1300 if (check_ == IS_SYMBOL && value()->IsConstant()) { | 1306 if (check_ == IS_SYMBOL && value()->IsConstant()) { |
1301 // Dereferencing is safe here: a symbol cannot become a non-symbol. | 1307 // Dereferencing is safe here: a symbol cannot become a non-symbol. |
1302 AllowHandleDereference allow_handle_deref; | 1308 AllowHandleDereference allow_handle_deref(isolate()); |
1303 if (HConstant::cast(value())->handle()->IsSymbol()) return NULL; | 1309 if (HConstant::cast(value())->handle()->IsSymbol()) return NULL; |
1304 } | 1310 } |
1305 return this; | 1311 return this; |
1306 } | 1312 } |
1307 | 1313 |
1308 | 1314 |
1309 void HCheckInstanceType::GetCheckInterval(InstanceType* first, | 1315 void HCheckInstanceType::GetCheckInterval(InstanceType* first, |
1310 InstanceType* last) { | 1316 InstanceType* last) { |
1311 ASSERT(is_interval_check()); | 1317 ASSERT(is_interval_check()); |
1312 switch (check_) { | 1318 switch (check_) { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value)); | 1804 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value)); |
1799 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value); | 1805 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value); |
1800 } | 1806 } |
1801 | 1807 |
1802 | 1808 |
1803 HConstant::HConstant(Handle<Object> handle, Representation r) | 1809 HConstant::HConstant(Handle<Object> handle, Representation r) |
1804 : handle_(handle), | 1810 : handle_(handle), |
1805 has_int32_value_(false), | 1811 has_int32_value_(false), |
1806 has_double_value_(false) { | 1812 has_double_value_(false) { |
1807 // Dereferencing here is safe: the value of a number object does not change. | 1813 // Dereferencing here is safe: the value of a number object does not change. |
1808 AllowHandleDereference allow_handle_deref; | 1814 AllowHandleDereference allow_handle_deref(Isolate::Current()); |
1809 SetFlag(kUseGVN); | 1815 SetFlag(kUseGVN); |
1810 if (handle_->IsNumber()) { | 1816 if (handle_->IsNumber()) { |
1811 double n = handle_->Number(); | 1817 double n = handle_->Number(); |
1812 has_int32_value_ = IsInteger32(n); | 1818 has_int32_value_ = IsInteger32(n); |
1813 int32_value_ = DoubleToInt32(n); | 1819 int32_value_ = DoubleToInt32(n); |
1814 double_value_ = n; | 1820 double_value_ = n; |
1815 has_double_value_ = true; | 1821 has_double_value_ = true; |
1816 } | 1822 } |
1817 if (r.IsNone()) { | 1823 if (r.IsNone()) { |
1818 if (has_int32_value_) { | 1824 if (has_int32_value_) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 bool HConstant::ToBoolean() { | 1885 bool HConstant::ToBoolean() { |
1880 // Converts the constant's boolean value according to | 1886 // Converts the constant's boolean value according to |
1881 // ECMAScript section 9.2 ToBoolean conversion. | 1887 // ECMAScript section 9.2 ToBoolean conversion. |
1882 if (HasInteger32Value()) return Integer32Value() != 0; | 1888 if (HasInteger32Value()) return Integer32Value() != 0; |
1883 if (HasDoubleValue()) { | 1889 if (HasDoubleValue()) { |
1884 double v = DoubleValue(); | 1890 double v = DoubleValue(); |
1885 return v != 0 && !isnan(v); | 1891 return v != 0 && !isnan(v); |
1886 } | 1892 } |
1887 // Dereferencing is safe: singletons do not change and strings are | 1893 // Dereferencing is safe: singletons do not change and strings are |
1888 // immutable. | 1894 // immutable. |
1889 AllowHandleDereference allow_handle_deref; | 1895 AllowHandleDereference allow_handle_deref(isolate()); |
1890 if (handle_->IsTrue()) return true; | 1896 if (handle_->IsTrue()) return true; |
1891 if (handle_->IsFalse()) return false; | 1897 if (handle_->IsFalse()) return false; |
1892 if (handle_->IsUndefined()) return false; | 1898 if (handle_->IsUndefined()) return false; |
1893 if (handle_->IsNull()) return false; | 1899 if (handle_->IsNull()) return false; |
1894 if (handle_->IsString() && String::cast(*handle_)->length() == 0) { | 1900 if (handle_->IsString() && String::cast(*handle_)->length() == 0) { |
1895 return false; | 1901 return false; |
1896 } | 1902 } |
1897 return true; | 1903 return true; |
1898 } | 1904 } |
1899 | 1905 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 } | 2573 } |
2568 return result; | 2574 return result; |
2569 } | 2575 } |
2570 | 2576 |
2571 | 2577 |
2572 HType HConstant::CalculateInferredType() { | 2578 HType HConstant::CalculateInferredType() { |
2573 if (has_int32_value_) { | 2579 if (has_int32_value_) { |
2574 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber(); | 2580 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber(); |
2575 } | 2581 } |
2576 if (has_double_value_) return HType::HeapNumber(); | 2582 if (has_double_value_) return HType::HeapNumber(); |
2577 return HType::TypeFromValue(handle_); | 2583 return HType::TypeFromValue(isolate(), handle_); |
2578 } | 2584 } |
2579 | 2585 |
2580 | 2586 |
2581 HType HCompareGeneric::CalculateInferredType() { | 2587 HType HCompareGeneric::CalculateInferredType() { |
2582 return HType::Boolean(); | 2588 return HType::Boolean(); |
2583 } | 2589 } |
2584 | 2590 |
2585 | 2591 |
2586 HType HInstanceOf::CalculateInferredType() { | 2592 HType HInstanceOf::CalculateInferredType() { |
2587 return HType::Boolean(); | 2593 return HType::Boolean(); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2826 } | 2832 } |
2827 } | 2833 } |
2828 return new(zone) HStringAdd(context, left, right); | 2834 return new(zone) HStringAdd(context, left, right); |
2829 } | 2835 } |
2830 | 2836 |
2831 | 2837 |
2832 HInstruction* HStringCharFromCode::New( | 2838 HInstruction* HStringCharFromCode::New( |
2833 Zone* zone, HValue* context, HValue* char_code) { | 2839 Zone* zone, HValue* context, HValue* char_code) { |
2834 if (FLAG_fold_constants && char_code->IsConstant()) { | 2840 if (FLAG_fold_constants && char_code->IsConstant()) { |
2835 HConstant* c_code = HConstant::cast(char_code); | 2841 HConstant* c_code = HConstant::cast(char_code); |
| 2842 Isolate* isolate = Isolate::Current(); |
2836 if (c_code->HasNumberValue()) { | 2843 if (c_code->HasNumberValue()) { |
2837 if (isfinite(c_code->DoubleValue())) { | 2844 if (isfinite(c_code->DoubleValue())) { |
2838 uint32_t code = c_code->NumberValueAsInteger32() & 0xffff; | 2845 uint32_t code = c_code->NumberValueAsInteger32() & 0xffff; |
2839 return new(zone) HConstant(LookupSingleCharacterStringFromCode(code), | 2846 return new(zone) HConstant(LookupSingleCharacterStringFromCode(isolate, |
| 2847 code), |
2840 Representation::Tagged()); | 2848 Representation::Tagged()); |
2841 } | 2849 } |
2842 return new(zone) HConstant(FACTORY->empty_string(), | 2850 return new(zone) HConstant(isolate->factory()->empty_string(), |
2843 Representation::Tagged()); | 2851 Representation::Tagged()); |
2844 } | 2852 } |
2845 } | 2853 } |
2846 return new(zone) HStringCharFromCode(context, char_code); | 2854 return new(zone) HStringCharFromCode(context, char_code); |
2847 } | 2855 } |
2848 | 2856 |
2849 | 2857 |
2850 HInstruction* HStringLength::New(Zone* zone, HValue* string) { | 2858 HInstruction* HStringLength::New(Zone* zone, HValue* string) { |
2851 if (FLAG_fold_constants && string->IsConstant()) { | 2859 if (FLAG_fold_constants && string->IsConstant()) { |
2852 HConstant* c_string = HConstant::cast(string); | 2860 HConstant* c_string = HConstant::cast(string); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3248 | 3256 |
3249 | 3257 |
3250 void HCheckFunction::Verify() { | 3258 void HCheckFunction::Verify() { |
3251 HInstruction::Verify(); | 3259 HInstruction::Verify(); |
3252 ASSERT(HasNoUses()); | 3260 ASSERT(HasNoUses()); |
3253 } | 3261 } |
3254 | 3262 |
3255 #endif | 3263 #endif |
3256 | 3264 |
3257 } } // namespace v8::internal | 3265 } } // namespace v8::internal |
OLD | NEW |