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 3288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3299 // have so far but not Tagged, use that representation instead. | 3299 // have so far but not Tagged, use that representation instead. |
3300 Representation input_rep = value()->representation(); | 3300 Representation input_rep = value()->representation(); |
3301 if (!input_rep.IsTagged()) rep = rep.generalize(input_rep); | 3301 if (!input_rep.IsTagged()) rep = rep.generalize(input_rep); |
3302 return rep; | 3302 return rep; |
3303 } | 3303 } |
3304 | 3304 |
3305 | 3305 |
3306 void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, | 3306 void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
3307 HValue* dominator) { | 3307 HValue* dominator) { |
3308 ASSERT(side_effect == kChangesNewSpacePromotion); | 3308 ASSERT(side_effect == kChangesNewSpacePromotion); |
3309 Zone* zone = dominator->block()->zone(); | |
3309 if (!FLAG_use_allocation_folding) return; | 3310 if (!FLAG_use_allocation_folding) return; |
3310 | 3311 |
3311 // Try to fold allocations together with their dominating allocations. | 3312 // Try to fold allocations together with their dominating allocations. |
3312 if (!dominator->IsAllocate()) { | 3313 if (!dominator->IsAllocate()) { |
3313 if (FLAG_trace_allocation_folding) { | 3314 if (FLAG_trace_allocation_folding) { |
3314 PrintF("#%d (%s) cannot fold into #%d (%s)\n", | 3315 PrintF("#%d (%s) cannot fold into #%d (%s)\n", |
3315 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3316 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
3316 } | 3317 } |
3317 return; | 3318 return; |
3318 } | 3319 } |
3319 | 3320 |
3320 HAllocate* dominator_allocate_instr = HAllocate::cast(dominator); | 3321 HAllocate* dominator_allocate = HAllocate::cast(dominator); |
3321 HValue* dominator_size = dominator_allocate_instr->size(); | 3322 HValue* dominator_size = dominator_allocate->size(); |
3322 HValue* current_size = size(); | 3323 HValue* current_size = size(); |
3323 // We can just fold allocations that are guaranteed in new space. | 3324 |
3324 // TODO(hpayer): Add support for non-constant allocation in dominator. | 3325 // TODO(hpayer): Add support for non-constant allocation in dominator. |
3325 if (!IsNewSpaceAllocation() || !current_size->IsInteger32Constant() || | 3326 if (!current_size->IsInteger32Constant() || |
3326 !dominator_allocate_instr->IsNewSpaceAllocation() || | |
3327 !dominator_size->IsInteger32Constant()) { | 3327 !dominator_size->IsInteger32Constant()) { |
3328 if (FLAG_trace_allocation_folding) { | 3328 if (FLAG_trace_allocation_folding) { |
3329 PrintF("#%d (%s) cannot fold into #%d (%s)\n", | 3329 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", |
3330 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3330 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
3331 } | 3331 } |
3332 return; | 3332 return; |
3333 } | 3333 } |
3334 | 3334 |
3335 // First update the size of the dominator allocate instruction. | |
3336 int32_t dominator_size_constant = | 3335 int32_t dominator_size_constant = |
3337 HConstant::cast(dominator_size)->GetInteger32Constant(); | 3336 HConstant::cast(dominator_size)->GetInteger32Constant(); |
3338 int32_t current_size_constant = | 3337 int32_t current_size_constant = |
3339 HConstant::cast(current_size)->GetInteger32Constant(); | 3338 HConstant::cast(current_size)->GetInteger32Constant(); |
3339 | |
titzer
2013/08/06 12:24:12
This method is getting pretty big; suggest pulling
Hannes Payer (out of office)
2013/08/07 07:48:01
Done.
| |
3340 if (!IsFoldable(dominator_allocate)) { | |
3341 // We cannot hoist old space allocations over new space allocations. | |
3342 if (IsNewSpaceAllocation() || dominator_allocate->IsNewSpaceAllocation()) { | |
3343 if (FLAG_trace_allocation_folding) { | |
3344 PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n", | |
3345 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | |
3346 } | |
3347 return; | |
3348 } | |
3349 | |
3350 // We can hoist old data space allocations over an old pointer space | |
3351 // allocation and vice versa. For that we have to check the dominator | |
3352 // of the dominator allocate instruction. | |
3353 HAllocate* previous_dominator = dominator_allocate->dominating_allocate(); | |
3354 if (previous_dominator == NULL) { | |
3355 set_dominating_allocate(dominator_allocate); | |
3356 if (FLAG_trace_allocation_folding) { | |
3357 PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n", | |
3358 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | |
3359 } | |
3360 return; | |
3361 } | |
3362 | |
3363 // If we stored a dominator in our actual dominator, then it must be in | |
3364 // the space of the dominated allocation operation. We can hoist the old | |
3365 // space allocation over the actual dominator. | |
3366 dominator_allocate = previous_dominator; | |
3367 | |
3368 // We can just fold old space allocations that are in the same basic block, | |
3369 // since it is not guaranteed that we fill up the whole allocated old | |
3370 // space memory. | |
3371 // TODO(hpayer): Remove this limitation and add filler maps for each each | |
3372 // allocation as soon as we have store elimination. | |
3373 if (block()->block_id() != dominator_allocate->block()->block_id()) { | |
3374 if (FLAG_trace_allocation_folding) { | |
3375 PrintF("#%d (%s) cannot fold into #%d (%s), different basic blocks\n", | |
3376 id(), Mnemonic(), dominator_allocate->id(), | |
3377 dominator_allocate->Mnemonic()); | |
3378 } | |
3379 return; | |
3380 } | |
3381 | |
3382 ASSERT((IsOldDataSpaceAllocation() && | |
3383 dominator_allocate->IsOldDataSpaceAllocation()) || | |
3384 (IsOldPointerSpaceAllocation() && | |
3385 dominator_allocate->IsOldPointerSpaceAllocation())); | |
3386 | |
3387 HConstant* dominator_free_space_size = | |
3388 dominator_allocate->filler_free_space_size(); | |
3389 | |
3390 // We already hoisted one old space allocation, i.e., we already installed | |
3391 // a filler map. Hence, we just have to update the free space size. | |
3392 if (dominator_free_space_size != NULL) { | |
3393 int32_t current_free_space_size_constant = | |
3394 HConstant::cast(dominator_free_space_size)->GetInteger32Constant(); | |
titzer
2013/08/06 12:24:12
I think this cast is redundant.
Hannes Payer (out of office)
2013/08/07 07:48:01
Done.
| |
3395 int32_t new_free_space_size_constant = current_free_space_size_constant + | |
3396 current_size_constant; | |
3397 HConstant* new_free_space_size = | |
3398 HConstant::New(zone, context(), new_free_space_size_constant); | |
3399 new_free_space_size->InsertBefore(dominator_free_space_size); | |
3400 dominator_free_space_size->DeleteAndReplaceWith(new_free_space_size); | |
3401 } else { | |
3402 // This is the first old space allocation that gets hoisted. We have to | |
3403 // install a filler map since the follwing allocation may cause a GC. | |
3404 HInstruction* free_space_instr = | |
3405 HInnerAllocatedObject::New(zone, context(), dominator_allocate, | |
3406 dominator_size_constant, type()); | |
3407 free_space_instr->InsertAfter(dominator_allocate); | |
3408 HConstant* filler_map = HConstant::New( | |
3409 zone, | |
3410 context(), | |
3411 isolate()->factory()->free_space_map(), | |
3412 UniqueValueId(isolate()->heap()->free_space_map())); | |
3413 filler_map->InsertAfter(free_space_instr); | |
3414 HInstruction* store_map = HStoreNamedField::New(zone, context(), | |
3415 free_space_instr, HObjectAccess::ForMap(), filler_map); | |
3416 store_map->SetFlag(HValue::kHasNoObservableSideEffects); | |
3417 store_map->InsertAfter(filler_map); | |
3418 | |
3419 HConstant* free_space_size = | |
3420 HConstant::New(zone, context(), current_size_constant); | |
3421 free_space_size->InsertAfter(store_map); | |
3422 dominator_allocate->set_filler_free_space_size(free_space_size); | |
3423 HObjectAccess access = | |
3424 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset); | |
3425 HInstruction* store_size = HStoreNamedField::New(zone, context(), | |
3426 free_space_instr, access, free_space_size); | |
3427 store_size->SetFlag(HValue::kHasNoObservableSideEffects); | |
3428 store_size->InsertAfter(free_space_size); | |
3429 } | |
3430 } | |
3431 | |
3432 ASSERT((IsNewSpaceAllocation() && | |
3433 dominator_allocate->IsNewSpaceAllocation()) || | |
3434 (IsOldDataSpaceAllocation() && | |
3435 dominator_allocate->IsOldDataSpaceAllocation()) || | |
3436 (IsOldPointerSpaceAllocation() && | |
3437 dominator_allocate->IsOldPointerSpaceAllocation())); | |
3438 | |
3439 // First update the size of the dominator allocate instruction. | |
3340 int32_t new_dominator_size = dominator_size_constant + current_size_constant; | 3440 int32_t new_dominator_size = dominator_size_constant + current_size_constant; |
3341 | 3441 |
3342 if (MustAllocateDoubleAligned()) { | 3442 if (MustAllocateDoubleAligned()) { |
3343 if (!dominator_allocate_instr->MustAllocateDoubleAligned()) { | 3443 if (!dominator_allocate->MustAllocateDoubleAligned()) { |
3344 dominator_allocate_instr->MakeDoubleAligned(); | 3444 dominator_allocate->MakeDoubleAligned(); |
3345 } | 3445 } |
3346 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { | 3446 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
3347 dominator_size_constant += kDoubleSize / 2; | 3447 dominator_size_constant += kDoubleSize / 2; |
3348 new_dominator_size += kDoubleSize / 2; | 3448 new_dominator_size += kDoubleSize / 2; |
3349 } | 3449 } |
3350 } | 3450 } |
3351 | 3451 |
3352 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { | 3452 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { |
3353 if (FLAG_trace_allocation_folding) { | 3453 if (FLAG_trace_allocation_folding) { |
3354 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", | 3454 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", |
3355 id(), Mnemonic(), dominator->id(), dominator->Mnemonic(), | 3455 id(), Mnemonic(), dominator_allocate->id(), |
3356 new_dominator_size); | 3456 dominator_allocate->Mnemonic(), new_dominator_size); |
3357 } | 3457 } |
3358 return; | 3458 return; |
3359 } | 3459 } |
3360 HBasicBlock* block = dominator->block(); | |
3361 Zone* zone = block->zone(); | |
3362 HInstruction* new_dominator_size_constant = | 3460 HInstruction* new_dominator_size_constant = |
3363 HConstant::New(zone, context(), new_dominator_size); | 3461 HConstant::New(zone, context(), new_dominator_size); |
3364 new_dominator_size_constant->InsertBefore(dominator_allocate_instr); | 3462 new_dominator_size_constant->InsertBefore(dominator_allocate); |
3365 dominator_allocate_instr->UpdateSize(new_dominator_size_constant); | 3463 dominator_allocate->UpdateSize(new_dominator_size_constant); |
3366 | 3464 |
3367 #ifdef VERIFY_HEAP | 3465 #ifdef VERIFY_HEAP |
3368 if (FLAG_verify_heap) { | 3466 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |
3369 dominator_allocate_instr->MakePrefillWithFiller(); | 3467 dominator_allocate->MakePrefillWithFiller(); |
3370 } | 3468 } |
3371 #endif | 3469 #endif |
3372 | 3470 |
3373 // After that replace the dominated allocate instruction. | 3471 // After that replace the dominated allocate instruction. |
3374 HInstruction* dominated_allocate_instr = | 3472 HInstruction* dominated_allocate_instr = |
3375 HInnerAllocatedObject::New(zone, | 3473 HInnerAllocatedObject::New(zone, |
3376 context(), | 3474 context(), |
3377 dominator_allocate_instr, | 3475 dominator_allocate, |
3378 dominator_size_constant, | 3476 dominator_size_constant, |
3379 type()); | 3477 type()); |
3380 dominated_allocate_instr->InsertBefore(this); | 3478 dominated_allocate_instr->InsertBefore(this); |
3381 DeleteAndReplaceWith(dominated_allocate_instr); | 3479 DeleteAndReplaceWith(dominated_allocate_instr); |
3382 if (FLAG_trace_allocation_folding) { | 3480 if (FLAG_trace_allocation_folding) { |
3383 PrintF("#%d (%s) folded into #%d (%s)\n", | 3481 PrintF("#%d (%s) folded into #%d (%s)\n", |
3384 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3482 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
3385 } | 3483 } |
3386 } | 3484 } |
3387 | 3485 |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4120 break; | 4218 break; |
4121 case kExternalMemory: | 4219 case kExternalMemory: |
4122 stream->Add("[external-memory]"); | 4220 stream->Add("[external-memory]"); |
4123 break; | 4221 break; |
4124 } | 4222 } |
4125 | 4223 |
4126 stream->Add("@%d", offset()); | 4224 stream->Add("@%d", offset()); |
4127 } | 4225 } |
4128 | 4226 |
4129 } } // namespace v8::internal | 4227 } } // namespace v8::internal |
OLD | NEW |