Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: src/hydrogen-instructions.cc

Issue 61463005: Supported folding of constant size allocation followed by dynamic size allocation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebasing Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (block->last() == previous) { 779 if (block->last() == previous) {
780 block->set_last(this); 780 block->set_last(this);
781 } 781 }
782 if (position() == RelocInfo::kNoPosition && 782 if (position() == RelocInfo::kNoPosition &&
783 previous->position() != RelocInfo::kNoPosition) { 783 previous->position() != RelocInfo::kNoPosition) {
784 set_position(previous->position()); 784 set_position(previous->position());
785 } 785 }
786 } 786 }
787 787
788 788
789 bool HInstruction::Dominates(HInstruction* other) {
790 if (block() != other->block()) {
791 return block()->Dominates(other->block());
792 }
793 // Both instructions are in the same basic block. This instruction
794 // should precede the other one in order to dominate it.
795 for (HInstruction* instr = next(); instr != NULL; instr = instr->next()) {
796 if (instr == other) {
797 return true;
798 }
799 }
800 return false;
801 }
802
803
789 #ifdef DEBUG 804 #ifdef DEBUG
790 void HInstruction::Verify() { 805 void HInstruction::Verify() {
791 // Verify that input operands are defined before use. 806 // Verify that input operands are defined before use.
792 HBasicBlock* cur_block = block(); 807 HBasicBlock* cur_block = block();
793 for (int i = 0; i < OperandCount(); ++i) { 808 for (int i = 0; i < OperandCount(); ++i) {
794 HValue* other_operand = OperandAt(i); 809 HValue* other_operand = OperandAt(i);
795 if (other_operand == NULL) continue; 810 if (other_operand == NULL) continue;
796 HBasicBlock* other_block = other_operand->block(); 811 HBasicBlock* other_block = other_operand->block();
797 if (cur_block == other_block) { 812 if (cur_block == other_block) {
798 if (!other_operand->IsPhi()) { 813 if (!other_operand->IsPhi()) {
(...skipping 2582 matching lines...) Expand 10 before | Expand all | Expand 10 after
3381 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); 3396 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3382 } 3397 }
3383 return; 3398 return;
3384 } 3399 }
3385 3400
3386 HAllocate* dominator_allocate = HAllocate::cast(dominator); 3401 HAllocate* dominator_allocate = HAllocate::cast(dominator);
3387 HValue* dominator_size = dominator_allocate->size(); 3402 HValue* dominator_size = dominator_allocate->size();
3388 HValue* current_size = size(); 3403 HValue* current_size = size();
3389 3404
3390 // TODO(hpayer): Add support for non-constant allocation in dominator. 3405 // TODO(hpayer): Add support for non-constant allocation in dominator.
3391 if (!current_size->IsInteger32Constant() || 3406 if (!dominator_size->IsInteger32Constant()) {
3392 !dominator_size->IsInteger32Constant()) {
3393 if (FLAG_trace_allocation_folding) { 3407 if (FLAG_trace_allocation_folding) {
3394 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", 3408 PrintF("#%d (%s) cannot fold into #%d (%s), "
3409 "dynamic allocation size in dominator\n",
3395 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); 3410 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3396 } 3411 }
3397 return; 3412 return;
3398 } 3413 }
3399 3414
3400 dominator_allocate = GetFoldableDominator(dominator_allocate); 3415 dominator_allocate = GetFoldableDominator(dominator_allocate);
3401 if (dominator_allocate == NULL) { 3416 if (dominator_allocate == NULL) {
3402 return; 3417 return;
3403 } 3418 }
3404 3419
3420 if (!current_size->IsInteger32Constant()) {
3421 if (!current_size->HasRange()) {
3422 if (FLAG_trace_allocation_folding) {
3423 PrintF("#%d (%s) cannot fold into #%d (%s), "
3424 "can't estimate total allocation size\n",
3425 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3426 }
3427 return;
3428 }
3429
3430 // If it's not constant then it is a size_in_bytes calculation graph
3431 // like this: (const_header_size + const_element_size * size).
3432 ASSERT(current_size->IsInstruction());
3433
3434 HInstruction* current_instr = HInstruction::cast(current_size);
3435 if (!current_instr->Dominates(dominator_allocate)) {
3436 if (FLAG_trace_allocation_folding) {
3437 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic size "
3438 "value does not dominate target allocation\n",
3439 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3440 }
3441 return;
3442 }
3443 }
3444
3405 ASSERT((IsNewSpaceAllocation() && 3445 ASSERT((IsNewSpaceAllocation() &&
3406 dominator_allocate->IsNewSpaceAllocation()) || 3446 dominator_allocate->IsNewSpaceAllocation()) ||
3407 (IsOldDataSpaceAllocation() && 3447 (IsOldDataSpaceAllocation() &&
3408 dominator_allocate->IsOldDataSpaceAllocation()) || 3448 dominator_allocate->IsOldDataSpaceAllocation()) ||
3409 (IsOldPointerSpaceAllocation() && 3449 (IsOldPointerSpaceAllocation() &&
3410 dominator_allocate->IsOldPointerSpaceAllocation())); 3450 dominator_allocate->IsOldPointerSpaceAllocation()));
3411 3451
3412 // First update the size of the dominator allocate instruction. 3452 // First update the size of the dominator allocate instruction.
3413 dominator_size = dominator_allocate->size(); 3453 dominator_size = dominator_allocate->size();
3414 int32_t original_object_size = 3454 int32_t original_object_size =
3415 HConstant::cast(dominator_size)->GetInteger32Constant(); 3455 HConstant::cast(dominator_size)->GetInteger32Constant();
3416 int32_t dominator_size_constant = original_object_size; 3456 int32_t dominator_size_constant = original_object_size;
3417 int32_t current_size_constant = 3457
3418 HConstant::cast(current_size)->GetInteger32Constant(); 3458 if (MustAllocateDoubleAligned()) {
3419 int32_t new_dominator_size = dominator_size_constant + current_size_constant; 3459 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) {
3460 dominator_size_constant += kDoubleSize / 2;
3461 }
3462 }
3463
3464 if (current_size->IsInteger32Constant()) {
Hannes Payer (out of office) 2013/11/21 12:07:19 The size check code with tracing output is almost
3465 int32_t current_size_constant =
3466 HConstant::cast(current_size)->GetInteger32Constant();
3467 int32_t new_dominator_size =
3468 dominator_size_constant + current_size_constant;
3469
3470 if (new_dominator_size >
3471 isolate()->heap()->MaxRegularSpaceAllocationSize()) {
3472 if (FLAG_trace_allocation_folding) {
3473 PrintF("#%d (%s) cannot fold into #%d (%s), "
3474 "resulting allocation size is too big\n",
3475 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3476 }
3477 return;
3478 }
3479
3480 HInstruction* new_dominator_size_constant =
3481 HConstant::CreateAndInsertBefore(zone,
3482 context(),
3483 new_dominator_size,
3484 Representation::None(),
3485 dominator_allocate);
3486 dominator_allocate->UpdateSize(new_dominator_size_constant);
3487
3488 } else {
3489 int32_t current_size_upper_bound = current_size->range()->upper();
3490 int32_t new_dominator_size_upper_bound =
3491 dominator_size_constant + current_size_upper_bound;
3492
3493 if (new_dominator_size_upper_bound >
3494 isolate()->heap()->MaxRegularSpaceAllocationSize()) {
3495 if (FLAG_trace_allocation_folding) {
3496 PrintF("#%d (%s) cannot fold into #%d (%s), "
3497 "resulting allocation size upper bound is too big\n",
3498 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3499 }
3500 return;
3501 }
3502
3503 HValue* new_dominator_size_constant =
3504 HConstant::CreateAndInsertBefore(zone,
3505 context(),
3506 dominator_size_constant,
3507 Representation::Integer32(),
3508 dominator_allocate);
3509
3510 // Add old and new size together and insert
3511 current_size->ChangeRepresentation(Representation::Integer32());
3512
3513 HInstruction* new_dominator_size = HAdd::New(zone, context(),
3514 new_dominator_size_constant, current_size);
3515 new_dominator_size->ClearFlag(HValue::kCanOverflow);
3516 new_dominator_size->ChangeRepresentation(Representation::Integer32());
3517
3518 new_dominator_size->InsertBefore(dominator_allocate);
3519
3520 dominator_allocate->UpdateSize(new_dominator_size);
3521 }
3420 3522
3421 if (MustAllocateDoubleAligned()) { 3523 if (MustAllocateDoubleAligned()) {
3422 if (!dominator_allocate->MustAllocateDoubleAligned()) { 3524 if (!dominator_allocate->MustAllocateDoubleAligned()) {
3423 dominator_allocate->MakeDoubleAligned(); 3525 dominator_allocate->MakeDoubleAligned();
3424 } 3526 }
3425 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) {
3426 dominator_size_constant += kDoubleSize / 2;
3427 new_dominator_size += kDoubleSize / 2;
3428 }
3429 } 3527 }
3430 3528
3431 if (new_dominator_size > isolate()->heap()->MaxRegularSpaceAllocationSize()) {
3432 if (FLAG_trace_allocation_folding) {
3433 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n",
3434 id(), Mnemonic(), dominator_allocate->id(),
3435 dominator_allocate->Mnemonic(), new_dominator_size);
3436 }
3437 return;
3438 }
3439
3440 HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore(
3441 zone,
3442 context(),
3443 new_dominator_size,
3444 Representation::None(),
3445 dominator_allocate);
3446 dominator_allocate->UpdateSize(new_dominator_size_constant);
3447
3448 #ifdef VERIFY_HEAP 3529 #ifdef VERIFY_HEAP
3449 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { 3530 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) {
3450 dominator_allocate->MakePrefillWithFiller(); 3531 dominator_allocate->MakePrefillWithFiller();
3451 } else { 3532 } else {
3452 // TODO(hpayer): This is a short-term hack to make allocation mementos 3533 // TODO(hpayer): This is a short-term hack to make allocation mementos
3453 // work again in new space. 3534 // work again in new space.
3454 dominator_allocate->ClearNextMapWord(original_object_size); 3535 dominator_allocate->ClearNextMapWord(original_object_size);
3455 } 3536 }
3456 #else 3537 #else
3457 // TODO(hpayer): This is a short-term hack to make allocation mementos 3538 // TODO(hpayer): This is a short-term hack to make allocation mementos
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
4374 break; 4455 break;
4375 case kExternalMemory: 4456 case kExternalMemory:
4376 stream->Add("[external-memory]"); 4457 stream->Add("[external-memory]");
4377 break; 4458 break;
4378 } 4459 }
4379 4460
4380 stream->Add("@%d", offset()); 4461 stream->Add("@%d", offset());
4381 } 4462 }
4382 4463
4383 } } // namespace v8::internal 4464 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698