| OLD | NEW |
| 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 #include "src/crankshaft/hydrogen.h" | 5 #include "src/crankshaft/hydrogen.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "src/allocation-site-scopes.h" | 10 #include "src/allocation-site-scopes.h" |
| (...skipping 3208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3219 store->SetFlag(HValue::kAllowUndefinedAsNaN); | 3219 store->SetFlag(HValue::kAllowUndefinedAsNaN); |
| 3220 } | 3220 } |
| 3221 | 3221 |
| 3222 builder.EndBody(); | 3222 builder.EndBody(); |
| 3223 } | 3223 } |
| 3224 | 3224 |
| 3225 Counters* counters = isolate()->counters(); | 3225 Counters* counters = isolate()->counters(); |
| 3226 AddIncrementCounter(counters->inlined_copied_elements()); | 3226 AddIncrementCounter(counters->inlined_copied_elements()); |
| 3227 } | 3227 } |
| 3228 | 3228 |
| 3229 | |
| 3230 HValue* HGraphBuilder::BuildCloneShallowArrayCow(HValue* boilerplate, | |
| 3231 HValue* allocation_site, | |
| 3232 AllocationSiteMode mode, | |
| 3233 ElementsKind kind) { | |
| 3234 HAllocate* array = AllocateJSArrayObject(mode); | |
| 3235 | |
| 3236 HValue* map = AddLoadMap(boilerplate); | |
| 3237 HValue* elements = AddLoadElements(boilerplate); | |
| 3238 HValue* length = AddLoadArrayLength(boilerplate, kind); | |
| 3239 | |
| 3240 BuildJSArrayHeader(array, | |
| 3241 map, | |
| 3242 elements, | |
| 3243 mode, | |
| 3244 FAST_ELEMENTS, | |
| 3245 allocation_site, | |
| 3246 length); | |
| 3247 return array; | |
| 3248 } | |
| 3249 | |
| 3250 | |
| 3251 HValue* HGraphBuilder::BuildCloneShallowArrayEmpty(HValue* boilerplate, | |
| 3252 HValue* allocation_site, | |
| 3253 AllocationSiteMode mode) { | |
| 3254 HAllocate* array = AllocateJSArrayObject(mode); | |
| 3255 | |
| 3256 HValue* map = AddLoadMap(boilerplate); | |
| 3257 | |
| 3258 BuildJSArrayHeader(array, | |
| 3259 map, | |
| 3260 NULL, // set elements to empty fixed array | |
| 3261 mode, | |
| 3262 FAST_ELEMENTS, | |
| 3263 allocation_site, | |
| 3264 graph()->GetConstant0()); | |
| 3265 return array; | |
| 3266 } | |
| 3267 | |
| 3268 | |
| 3269 HValue* HGraphBuilder::BuildCloneShallowArrayNonEmpty(HValue* boilerplate, | |
| 3270 HValue* allocation_site, | |
| 3271 AllocationSiteMode mode, | |
| 3272 ElementsKind kind) { | |
| 3273 HValue* boilerplate_elements = AddLoadElements(boilerplate); | |
| 3274 HValue* capacity = AddLoadFixedArrayLength(boilerplate_elements); | |
| 3275 | |
| 3276 // Generate size calculation code here in order to make it dominate | |
| 3277 // the JSArray allocation. | |
| 3278 HValue* elements_size = BuildCalculateElementsSize(kind, capacity); | |
| 3279 | |
| 3280 // Create empty JSArray object for now, store elimination should remove | |
| 3281 // redundant initialization of elements and length fields and at the same | |
| 3282 // time the object will be fully prepared for GC if it happens during | |
| 3283 // elements allocation. | |
| 3284 HValue* result = BuildCloneShallowArrayEmpty( | |
| 3285 boilerplate, allocation_site, mode); | |
| 3286 | |
| 3287 HAllocate* elements = BuildAllocateElements(kind, elements_size); | |
| 3288 | |
| 3289 Add<HStoreNamedField>(result, HObjectAccess::ForElementsPointer(), elements); | |
| 3290 | |
| 3291 // The allocation for the cloned array above causes register pressure on | |
| 3292 // machines with low register counts. Force a reload of the boilerplate | |
| 3293 // elements here to free up a register for the allocation to avoid unnecessary | |
| 3294 // spillage. | |
| 3295 boilerplate_elements = AddLoadElements(boilerplate); | |
| 3296 boilerplate_elements->SetFlag(HValue::kCantBeReplaced); | |
| 3297 | |
| 3298 // Copy the elements array header. | |
| 3299 for (int i = 0; i < FixedArrayBase::kHeaderSize; i += kPointerSize) { | |
| 3300 HObjectAccess access = HObjectAccess::ForFixedArrayHeader(i); | |
| 3301 Add<HStoreNamedField>( | |
| 3302 elements, access, | |
| 3303 Add<HLoadNamedField>(boilerplate_elements, nullptr, access)); | |
| 3304 } | |
| 3305 | |
| 3306 // And the result of the length | |
| 3307 HValue* length = AddLoadArrayLength(boilerplate, kind); | |
| 3308 Add<HStoreNamedField>(result, HObjectAccess::ForArrayLength(kind), length); | |
| 3309 | |
| 3310 BuildCopyElements(boilerplate_elements, kind, elements, | |
| 3311 kind, length, NULL); | |
| 3312 return result; | |
| 3313 } | |
| 3314 | |
| 3315 | |
| 3316 void HGraphBuilder::BuildCreateAllocationMemento( | 3229 void HGraphBuilder::BuildCreateAllocationMemento( |
| 3317 HValue* previous_object, | 3230 HValue* previous_object, |
| 3318 HValue* previous_object_size, | 3231 HValue* previous_object_size, |
| 3319 HValue* allocation_site) { | 3232 HValue* allocation_site) { |
| 3320 DCHECK(allocation_site != NULL); | 3233 DCHECK(allocation_site != NULL); |
| 3321 HInnerAllocatedObject* allocation_memento = Add<HInnerAllocatedObject>( | 3234 HInnerAllocatedObject* allocation_memento = Add<HInnerAllocatedObject>( |
| 3322 previous_object, previous_object_size, HType::HeapObject()); | 3235 previous_object, previous_object_size, HType::HeapObject()); |
| 3323 AddStoreMapConstant( | 3236 AddStoreMapConstant( |
| 3324 allocation_memento, isolate()->factory()->allocation_memento_map()); | 3237 allocation_memento, isolate()->factory()->allocation_memento_map()); |
| 3325 Add<HStoreNamedField>( | 3238 Add<HStoreNamedField>( |
| (...skipping 10017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13343 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 13256 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 13344 } | 13257 } |
| 13345 | 13258 |
| 13346 #ifdef DEBUG | 13259 #ifdef DEBUG |
| 13347 graph_->Verify(false); // No full verify. | 13260 graph_->Verify(false); // No full verify. |
| 13348 #endif | 13261 #endif |
| 13349 } | 13262 } |
| 13350 | 13263 |
| 13351 } // namespace internal | 13264 } // namespace internal |
| 13352 } // namespace v8 | 13265 } // namespace v8 |
| OLD | NEW |