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 2156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 | 2167 |
2168 | 2168 |
2169 HConstant::HConstant(Handle<Object> handle, Representation r) | 2169 HConstant::HConstant(Handle<Object> handle, Representation r) |
2170 : handle_(handle), | 2170 : handle_(handle), |
2171 unique_id_(), | 2171 unique_id_(), |
2172 has_smi_value_(false), | 2172 has_smi_value_(false), |
2173 has_int32_value_(false), | 2173 has_int32_value_(false), |
2174 has_double_value_(false), | 2174 has_double_value_(false), |
2175 is_internalized_string_(false), | 2175 is_internalized_string_(false), |
2176 is_not_in_new_space_(true), | 2176 is_not_in_new_space_(true), |
2177 is_cell_(false), | |
2178 boolean_value_(handle->BooleanValue()) { | 2177 boolean_value_(handle->BooleanValue()) { |
2179 if (handle_->IsHeapObject()) { | 2178 if (handle_->IsHeapObject()) { |
2180 Heap* heap = Handle<HeapObject>::cast(handle)->GetHeap(); | 2179 Heap* heap = Handle<HeapObject>::cast(handle)->GetHeap(); |
2181 is_not_in_new_space_ = !heap->InNewSpace(*handle); | 2180 is_not_in_new_space_ = !heap->InNewSpace(*handle); |
2182 } | 2181 } |
2183 if (handle_->IsNumber()) { | 2182 if (handle_->IsNumber()) { |
2184 double n = handle_->Number(); | 2183 double n = handle_->Number(); |
2185 has_int32_value_ = IsInteger32(n); | 2184 has_int32_value_ = IsInteger32(n); |
2186 int32_value_ = DoubleToInt32(n); | 2185 int32_value_ = DoubleToInt32(n); |
2187 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); | 2186 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); |
2188 double_value_ = n; | 2187 double_value_ = n; |
2189 has_double_value_ = true; | 2188 has_double_value_ = true; |
2190 } else { | 2189 } else { |
2191 type_from_value_ = HType::TypeFromValue(handle_); | 2190 type_from_value_ = HType::TypeFromValue(handle_); |
2192 is_internalized_string_ = handle_->IsInternalizedString(); | 2191 is_internalized_string_ = handle_->IsInternalizedString(); |
2193 } | 2192 } |
2194 | |
2195 is_cell_ = !handle_.is_null() && | |
2196 (handle_->IsCell() || handle_->IsPropertyCell()); | |
2197 Initialize(r); | 2193 Initialize(r); |
2198 } | 2194 } |
2199 | 2195 |
2200 | 2196 |
2201 HConstant::HConstant(Handle<Object> handle, | 2197 HConstant::HConstant(Handle<Object> handle, |
2202 UniqueValueId unique_id, | 2198 UniqueValueId unique_id, |
2203 Representation r, | 2199 Representation r, |
2204 HType type, | 2200 HType type, |
2205 bool is_internalize_string, | 2201 bool is_internalize_string, |
2206 bool is_not_in_new_space, | 2202 bool is_not_in_new_space, |
2207 bool is_cell, | |
2208 bool boolean_value) | 2203 bool boolean_value) |
2209 : handle_(handle), | 2204 : handle_(handle), |
2210 unique_id_(unique_id), | 2205 unique_id_(unique_id), |
2211 has_smi_value_(false), | 2206 has_smi_value_(false), |
2212 has_int32_value_(false), | 2207 has_int32_value_(false), |
2213 has_double_value_(false), | 2208 has_double_value_(false), |
2214 is_internalized_string_(is_internalize_string), | 2209 is_internalized_string_(is_internalize_string), |
2215 is_not_in_new_space_(is_not_in_new_space), | 2210 is_not_in_new_space_(is_not_in_new_space), |
2216 is_cell_(is_cell), | |
2217 boolean_value_(boolean_value), | 2211 boolean_value_(boolean_value), |
2218 type_from_value_(type) { | 2212 type_from_value_(type) { |
2219 ASSERT(!handle.is_null()); | 2213 ASSERT(!handle.is_null()); |
2220 ASSERT(!type.IsUninitialized()); | 2214 ASSERT(!type.IsUninitialized()); |
2221 ASSERT(!type.IsTaggedNumber()); | 2215 ASSERT(!type.IsTaggedNumber()); |
2222 Initialize(r); | 2216 Initialize(r); |
2223 } | 2217 } |
2224 | 2218 |
2225 | 2219 |
2226 HConstant::HConstant(int32_t integer_value, | 2220 HConstant::HConstant(int32_t integer_value, |
2227 Representation r, | 2221 Representation r, |
2228 bool is_not_in_new_space, | 2222 bool is_not_in_new_space, |
2229 Handle<Object> optional_handle) | 2223 Handle<Object> optional_handle) |
2230 : handle_(optional_handle), | 2224 : handle_(optional_handle), |
2231 unique_id_(), | 2225 unique_id_(), |
2232 has_int32_value_(true), | 2226 has_int32_value_(true), |
2233 has_double_value_(true), | 2227 has_double_value_(true), |
2234 is_internalized_string_(false), | 2228 is_internalized_string_(false), |
2235 is_not_in_new_space_(is_not_in_new_space), | 2229 is_not_in_new_space_(is_not_in_new_space), |
2236 is_cell_(false), | |
2237 boolean_value_(integer_value != 0), | 2230 boolean_value_(integer_value != 0), |
2238 int32_value_(integer_value), | 2231 int32_value_(integer_value), |
2239 double_value_(FastI2D(integer_value)) { | 2232 double_value_(FastI2D(integer_value)) { |
2240 has_smi_value_ = Smi::IsValid(int32_value_); | 2233 has_smi_value_ = Smi::IsValid(int32_value_); |
2241 Initialize(r); | 2234 Initialize(r); |
2242 } | 2235 } |
2243 | 2236 |
2244 | 2237 |
2245 HConstant::HConstant(double double_value, | 2238 HConstant::HConstant(double double_value, |
2246 Representation r, | 2239 Representation r, |
2247 bool is_not_in_new_space, | 2240 bool is_not_in_new_space, |
2248 Handle<Object> optional_handle) | 2241 Handle<Object> optional_handle) |
2249 : handle_(optional_handle), | 2242 : handle_(optional_handle), |
2250 unique_id_(), | 2243 unique_id_(), |
2251 has_int32_value_(IsInteger32(double_value)), | 2244 has_int32_value_(IsInteger32(double_value)), |
2252 has_double_value_(true), | 2245 has_double_value_(true), |
2253 is_internalized_string_(false), | 2246 is_internalized_string_(false), |
2254 is_not_in_new_space_(is_not_in_new_space), | 2247 is_not_in_new_space_(is_not_in_new_space), |
2255 is_cell_(false), | |
2256 boolean_value_(double_value != 0 && !std::isnan(double_value)), | 2248 boolean_value_(double_value != 0 && !std::isnan(double_value)), |
2257 int32_value_(DoubleToInt32(double_value)), | 2249 int32_value_(DoubleToInt32(double_value)), |
2258 double_value_(double_value) { | 2250 double_value_(double_value) { |
2259 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); | 2251 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); |
2260 Initialize(r); | 2252 Initialize(r); |
2261 } | 2253 } |
2262 | 2254 |
2263 | 2255 |
2264 void HConstant::Initialize(Representation r) { | 2256 void HConstant::Initialize(Representation r) { |
2265 if (r.IsNone()) { | 2257 if (r.IsNone()) { |
2266 if (has_smi_value_) { | 2258 if (has_smi_value_) { |
2267 r = Representation::Smi(); | 2259 r = Representation::Smi(); |
2268 } else if (has_int32_value_) { | 2260 } else if (has_int32_value_) { |
2269 r = Representation::Integer32(); | 2261 r = Representation::Integer32(); |
2270 } else if (has_double_value_) { | 2262 } else if (has_double_value_) { |
2271 r = Representation::Double(); | 2263 r = Representation::Double(); |
2272 } else { | 2264 } else { |
2273 r = Representation::Tagged(); | 2265 r = Representation::Tagged(); |
2274 } | 2266 } |
2275 } | 2267 } |
2276 set_representation(r); | 2268 set_representation(r); |
2277 SetFlag(kUseGVN); | 2269 SetFlag(kUseGVN); |
| 2270 if (representation().IsInteger32()) { |
| 2271 ClearGVNFlag(kDependsOnOsrEntries); |
| 2272 } |
2278 } | 2273 } |
2279 | 2274 |
2280 | 2275 |
2281 bool HConstant::EmitAtUses() { | |
2282 ASSERT(IsLinked()); | |
2283 if (block()->graph()->has_osr_loop_entry()) { | |
2284 return block()->graph()->IsStandardConstant(this); | |
2285 } | |
2286 if (IsCell()) return false; | |
2287 if (representation().IsDouble()) return false; | |
2288 return true; | |
2289 } | |
2290 | |
2291 | |
2292 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { | 2276 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { |
2293 if (r.IsSmi() && !has_smi_value_) return NULL; | 2277 if (r.IsSmi() && !has_smi_value_) return NULL; |
2294 if (r.IsInteger32() && !has_int32_value_) return NULL; | 2278 if (r.IsInteger32() && !has_int32_value_) return NULL; |
2295 if (r.IsDouble() && !has_double_value_) return NULL; | 2279 if (r.IsDouble() && !has_double_value_) return NULL; |
2296 if (has_int32_value_) { | 2280 if (has_int32_value_) { |
2297 return new(zone) HConstant(int32_value_, r, is_not_in_new_space_, handle_); | 2281 return new(zone) HConstant(int32_value_, r, is_not_in_new_space_, handle_); |
2298 } | 2282 } |
2299 if (has_double_value_) { | 2283 if (has_double_value_) { |
2300 return new(zone) HConstant(double_value_, r, is_not_in_new_space_, handle_); | 2284 return new(zone) HConstant(double_value_, r, is_not_in_new_space_, handle_); |
2301 } | 2285 } |
2302 ASSERT(!handle_.is_null()); | 2286 ASSERT(!handle_.is_null()); |
2303 return new(zone) HConstant(handle_, | 2287 return new(zone) HConstant(handle_, |
2304 unique_id_, | 2288 unique_id_, |
2305 r, | 2289 r, |
2306 type_from_value_, | 2290 type_from_value_, |
2307 is_internalized_string_, | 2291 is_internalized_string_, |
2308 is_not_in_new_space_, | 2292 is_not_in_new_space_, |
2309 is_cell_, | |
2310 boolean_value_); | 2293 boolean_value_); |
2311 } | 2294 } |
2312 | 2295 |
2313 | 2296 |
2314 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const { | 2297 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const { |
2315 if (has_int32_value_) { | 2298 if (has_int32_value_) { |
2316 return new(zone) HConstant(int32_value_, | 2299 return new(zone) HConstant(int32_value_, |
2317 Representation::Integer32(), | 2300 Representation::Integer32(), |
2318 is_not_in_new_space_, | 2301 is_not_in_new_space_, |
2319 handle_); | 2302 handle_); |
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3834 int offset = (index * kPointerSize) + map->instance_size(); | 3817 int offset = (index * kPointerSize) + map->instance_size(); |
3835 return HObjectAccess(kInobject, offset); | 3818 return HObjectAccess(kInobject, offset); |
3836 } else { | 3819 } else { |
3837 // Non-negative property indices are in the properties array. | 3820 // Non-negative property indices are in the properties array. |
3838 int offset = (index * kPointerSize) + FixedArray::kHeaderSize; | 3821 int offset = (index * kPointerSize) + FixedArray::kHeaderSize; |
3839 return HObjectAccess(kBackingStore, offset, name); | 3822 return HObjectAccess(kBackingStore, offset, name); |
3840 } | 3823 } |
3841 } | 3824 } |
3842 | 3825 |
3843 | 3826 |
3844 HObjectAccess HObjectAccess::ForCellPayload(Isolate* isolate) { | |
3845 return HObjectAccess( | |
3846 kInobject, Cell::kValueOffset, | |
3847 Handle<String>(isolate->heap()->cell_value_string())); | |
3848 } | |
3849 | |
3850 | |
3851 void HObjectAccess::SetGVNFlags(HValue *instr, bool is_store) { | 3827 void HObjectAccess::SetGVNFlags(HValue *instr, bool is_store) { |
3852 // set the appropriate GVN flags for a given load or store instruction | 3828 // set the appropriate GVN flags for a given load or store instruction |
3853 if (is_store) { | 3829 if (is_store) { |
3854 // track dominating allocations in order to eliminate write barriers | 3830 // track dominating allocations in order to eliminate write barriers |
3855 instr->SetGVNFlag(kDependsOnNewSpacePromotion); | 3831 instr->SetGVNFlag(kDependsOnNewSpacePromotion); |
3856 instr->SetFlag(HValue::kTrackSideEffectDominators); | 3832 instr->SetFlag(HValue::kTrackSideEffectDominators); |
3857 } else { | 3833 } else { |
3858 // try to GVN loads, but don't hoist above map changes | 3834 // try to GVN loads, but don't hoist above map changes |
3859 instr->SetFlag(HValue::kUseGVN); | 3835 instr->SetFlag(HValue::kUseGVN); |
3860 instr->SetGVNFlag(kDependsOnMaps); | 3836 instr->SetGVNFlag(kDependsOnMaps); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3910 case kBackingStore: | 3886 case kBackingStore: |
3911 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); | 3887 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); |
3912 stream->Add("[backing-store]"); | 3888 stream->Add("[backing-store]"); |
3913 break; | 3889 break; |
3914 } | 3890 } |
3915 | 3891 |
3916 stream->Add("@%d", offset()); | 3892 stream->Add("@%d", offset()); |
3917 } | 3893 } |
3918 | 3894 |
3919 } } // namespace v8::internal | 3895 } } // namespace v8::internal |
OLD | NEW |