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

Side by Side Diff: src/hydrogen.cc

Issue 8551006: Version 3.7.9. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 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
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 HBasicBlock* loop_header) { 727 HBasicBlock* loop_header) {
728 if (block == NULL || visited->Contains(block->block_id())) return; 728 if (block == NULL || visited->Contains(block->block_id())) return;
729 if (block->parent_loop_header() != loop_header) return; 729 if (block->parent_loop_header() != loop_header) return;
730 visited->Add(block->block_id()); 730 visited->Add(block->block_id());
731 if (block->IsLoopHeader()) { 731 if (block->IsLoopHeader()) {
732 PostorderLoopBlocks(block->loop_information(), visited, order, loop_header); 732 PostorderLoopBlocks(block->loop_information(), visited, order, loop_header);
733 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) { 733 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) {
734 Postorder(it.Current(), visited, order, block); 734 Postorder(it.Current(), visited, order, block);
735 } 735 }
736 } else { 736 } else {
737 ASSERT(block->IsFinished());
737 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) { 738 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) {
738 Postorder(it.Current(), visited, order, loop_header); 739 Postorder(it.Current(), visited, order, loop_header);
739 } 740 }
740 } 741 }
741 ASSERT(block->end()->FirstSuccessor() == NULL || 742 ASSERT(block->end()->FirstSuccessor() == NULL ||
742 order->Contains(block->end()->FirstSuccessor()) || 743 order->Contains(block->end()->FirstSuccessor()) ||
743 block->end()->FirstSuccessor()->IsLoopHeader()); 744 block->end()->FirstSuccessor()->IsLoopHeader());
744 ASSERT(block->end()->SecondSuccessor() == NULL || 745 ASSERT(block->end()->SecondSuccessor() == NULL ||
745 order->Contains(block->end()->SecondSuccessor()) || 746 order->Contains(block->end()->SecondSuccessor()) ||
746 block->end()->SecondSuccessor()->IsLoopHeader()); 747 block->end()->SecondSuccessor()->IsLoopHeader());
(...skipping 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after
2701 ASSERT(current_block()->HasPredecessor()); 2702 ASSERT(current_block()->HasPredecessor());
2702 // We only optimize switch statements with smi-literal smi comparisons, 2703 // We only optimize switch statements with smi-literal smi comparisons,
2703 // with a bounded number of clauses. 2704 // with a bounded number of clauses.
2704 const int kCaseClauseLimit = 128; 2705 const int kCaseClauseLimit = 128;
2705 ZoneList<CaseClause*>* clauses = stmt->cases(); 2706 ZoneList<CaseClause*>* clauses = stmt->cases();
2706 int clause_count = clauses->length(); 2707 int clause_count = clauses->length();
2707 if (clause_count > kCaseClauseLimit) { 2708 if (clause_count > kCaseClauseLimit) {
2708 return Bailout("SwitchStatement: too many clauses"); 2709 return Bailout("SwitchStatement: too many clauses");
2709 } 2710 }
2710 2711
2712 HValue* context = environment()->LookupContext();
2713
2711 CHECK_ALIVE(VisitForValue(stmt->tag())); 2714 CHECK_ALIVE(VisitForValue(stmt->tag()));
2712 AddSimulate(stmt->EntryId()); 2715 AddSimulate(stmt->EntryId());
2713 HValue* tag_value = Pop(); 2716 HValue* tag_value = Pop();
2714 HBasicBlock* first_test_block = current_block(); 2717 HBasicBlock* first_test_block = current_block();
2715 2718
2716 // 1. Build all the tests, with dangling true branches. Unconditionally 2719 SwitchType switch_type = UNKNOWN_SWITCH;
2717 // deoptimize if we encounter a non-smi comparison. 2720
2721 // 1. Extract clause type
2718 for (int i = 0; i < clause_count; ++i) { 2722 for (int i = 0; i < clause_count; ++i) {
2719 CaseClause* clause = clauses->at(i); 2723 CaseClause* clause = clauses->at(i);
2720 if (clause->is_default()) continue; 2724 if (clause->is_default()) continue;
2721 if (!clause->label()->IsSmiLiteral()) { 2725
2722 return Bailout("SwitchStatement: non-literal switch label"); 2726 if (switch_type == UNKNOWN_SWITCH) {
2727 if (clause->label()->IsSmiLiteral()) {
2728 switch_type = SMI_SWITCH;
2729 } else if (clause->label()->IsStringLiteral()) {
2730 switch_type = STRING_SWITCH;
2731 } else {
2732 return Bailout("SwitchStatement: non-literal switch label");
2733 }
2734 } else if ((switch_type == STRING_SWITCH &&
2735 !clause->label()->IsStringLiteral()) ||
2736 (switch_type == SMI_SWITCH &&
2737 !clause->label()->IsSmiLiteral())) {
2738 return Bailout("SwitchStatemnt: mixed label types are not supported");
2739 }
2740 }
2741
2742 HUnaryControlInstruction* string_check = NULL;
2743 HBasicBlock* not_string_block = NULL;
2744
2745 // Test switch's tag value if all clauses are string literals
2746 if (switch_type == STRING_SWITCH) {
2747 string_check = new(zone()) HIsStringAndBranch(tag_value);
2748 first_test_block = graph()->CreateBasicBlock();
2749 not_string_block = graph()->CreateBasicBlock();
2750
2751 string_check->SetSuccessorAt(0, first_test_block);
2752 string_check->SetSuccessorAt(1, not_string_block);
2753 current_block()->Finish(string_check);
2754
2755 set_current_block(first_test_block);
2756 }
2757
2758 // 2. Build all the tests, with dangling true branches
2759 for (int i = 0; i < clause_count; ++i) {
2760 CaseClause* clause = clauses->at(i);
2761 if (clause->is_default()) continue;
2762
2763 if (switch_type == SMI_SWITCH) {
2764 clause->RecordTypeFeedback(oracle());
2723 } 2765 }
2724 2766
2725 // Unconditionally deoptimize on the first non-smi compare. 2767 // Generate a compare and branch.
2726 clause->RecordTypeFeedback(oracle()); 2768 CHECK_ALIVE(VisitForValue(clause->label()));
2727 if (!clause->IsSmiCompare()) { 2769 HValue* label_value = Pop();
2728 // Finish with deoptimize and add uses of enviroment values to 2770
2729 // account for invisible uses. 2771 HBasicBlock* next_test_block = graph()->CreateBasicBlock();
2730 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); 2772 HBasicBlock* body_block = graph()->CreateBasicBlock();
2731 set_current_block(NULL); 2773
2732 break; 2774 HControlInstruction* compare;
2775
2776 if (switch_type == SMI_SWITCH) {
2777 if (!clause->IsSmiCompare()) {
2778 // Finish with deoptimize and add uses of enviroment values to
2779 // account for invisible uses.
2780 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll);
2781 set_current_block(NULL);
2782 break;
2783 }
2784
2785 HCompareIDAndBranch* compare_ =
2786 new(zone()) HCompareIDAndBranch(tag_value,
2787 label_value,
2788 Token::EQ_STRICT);
2789 compare_->SetInputRepresentation(Representation::Integer32());
2790 compare = compare_;
2791 } else {
2792 compare = new(zone()) HStringCompareAndBranch(context, tag_value,
2793 label_value,
2794 Token::EQ_STRICT);
2733 } 2795 }
2734 2796
2735 // Otherwise generate a compare and branch.
2736 CHECK_ALIVE(VisitForValue(clause->label()));
2737 HValue* label_value = Pop();
2738 HCompareIDAndBranch* compare =
2739 new(zone()) HCompareIDAndBranch(tag_value,
2740 label_value,
2741 Token::EQ_STRICT);
2742 compare->SetInputRepresentation(Representation::Integer32());
2743 HBasicBlock* body_block = graph()->CreateBasicBlock();
2744 HBasicBlock* next_test_block = graph()->CreateBasicBlock();
2745 compare->SetSuccessorAt(0, body_block); 2797 compare->SetSuccessorAt(0, body_block);
2746 compare->SetSuccessorAt(1, next_test_block); 2798 compare->SetSuccessorAt(1, next_test_block);
2747 current_block()->Finish(compare); 2799 current_block()->Finish(compare);
2800
2748 set_current_block(next_test_block); 2801 set_current_block(next_test_block);
2749 } 2802 }
2750 2803
2751 // Save the current block to use for the default or to join with the 2804 // Save the current block to use for the default or to join with the
2752 // exit. This block is NULL if we deoptimized. 2805 // exit. This block is NULL if we deoptimized.
2753 HBasicBlock* last_block = current_block(); 2806 HBasicBlock* last_block = current_block();
2754 2807
2755 // 2. Loop over the clauses and the linked list of tests in lockstep, 2808 if (not_string_block != NULL) {
2809 last_block = CreateJoin(last_block, not_string_block, stmt->ExitId());
2810 }
2811
2812 // 3. Loop over the clauses and the linked list of tests in lockstep,
2756 // translating the clause bodies. 2813 // translating the clause bodies.
2757 HBasicBlock* curr_test_block = first_test_block; 2814 HBasicBlock* curr_test_block = first_test_block;
2758 HBasicBlock* fall_through_block = NULL; 2815 HBasicBlock* fall_through_block = NULL;
2816
2759 BreakAndContinueInfo break_info(stmt); 2817 BreakAndContinueInfo break_info(stmt);
2760 { BreakAndContinueScope push(&break_info, this); 2818 { BreakAndContinueScope push(&break_info, this);
2761 for (int i = 0; i < clause_count; ++i) { 2819 for (int i = 0; i < clause_count; ++i) {
2762 CaseClause* clause = clauses->at(i); 2820 CaseClause* clause = clauses->at(i);
2763 2821
2764 // Identify the block where normal (non-fall-through) control flow 2822 // Identify the block where normal (non-fall-through) control flow
2765 // goes to. 2823 // goes to.
2766 HBasicBlock* normal_block = NULL; 2824 HBasicBlock* normal_block = NULL;
2767 if (clause->is_default()) { 2825 if (clause->is_default()) {
2768 if (last_block != NULL) { 2826 if (last_block != NULL) {
(...skipping 2844 matching lines...) Expand 10 before | Expand all | Expand 10 after
5613 HInstruction* instr = NULL; 5671 HInstruction* instr = NULL;
5614 switch (expr->op()) { 5672 switch (expr->op()) {
5615 case Token::ADD: 5673 case Token::ADD:
5616 if (info.IsString()) { 5674 if (info.IsString()) {
5617 AddInstruction(new(zone()) HCheckNonSmi(left)); 5675 AddInstruction(new(zone()) HCheckNonSmi(left));
5618 AddInstruction(HCheckInstanceType::NewIsString(left)); 5676 AddInstruction(HCheckInstanceType::NewIsString(left));
5619 AddInstruction(new(zone()) HCheckNonSmi(right)); 5677 AddInstruction(new(zone()) HCheckNonSmi(right));
5620 AddInstruction(HCheckInstanceType::NewIsString(right)); 5678 AddInstruction(HCheckInstanceType::NewIsString(right));
5621 instr = new(zone()) HStringAdd(context, left, right); 5679 instr = new(zone()) HStringAdd(context, left, right);
5622 } else { 5680 } else {
5623 instr = new(zone()) HAdd(context, left, right); 5681 instr = HAdd::NewHAdd(zone(), context, left, right);
5624 } 5682 }
5625 break; 5683 break;
5626 case Token::SUB: 5684 case Token::SUB:
5627 instr = new(zone()) HSub(context, left, right); 5685 instr = HSub::NewHSub(zone(), context, left, right);
5628 break; 5686 break;
5629 case Token::MUL: 5687 case Token::MUL:
5630 instr = new(zone()) HMul(context, left, right); 5688 instr = HMul::NewHMul(zone(), context, left, right);
5631 break; 5689 break;
5632 case Token::MOD: 5690 case Token::MOD:
5633 instr = new(zone()) HMod(context, left, right); 5691 instr = HMod::NewHMod(zone(), context, left, right);
5634 break; 5692 break;
5635 case Token::DIV: 5693 case Token::DIV:
5636 instr = new(zone()) HDiv(context, left, right); 5694 instr = HDiv::NewHDiv(zone(), context, left, right);
5637 break; 5695 break;
5638 case Token::BIT_XOR: 5696 case Token::BIT_XOR:
5639 case Token::BIT_AND: 5697 case Token::BIT_AND:
5640 case Token::BIT_OR: 5698 case Token::BIT_OR:
5641 instr = new(zone()) HBitwise(expr->op(), context, left, right); 5699 instr = HBitwise::NewHBitwise(zone(), expr->op(), context, left, right);
5642 break; 5700 break;
5643 case Token::SAR: 5701 case Token::SAR:
5644 instr = new(zone()) HSar(context, left, right); 5702 instr = HSar::NewHSar(zone(), context, left, right);
5645 break; 5703 break;
5646 case Token::SHR: 5704 case Token::SHR:
5647 instr = new(zone()) HShr(context, left, right); 5705 instr = HShr::NewHShr(zone(), context, left, right);
5648 break; 5706 break;
5649 case Token::SHL: 5707 case Token::SHL:
5650 instr = new(zone()) HShl(context, left, right); 5708 instr = HShl::NewHShl(zone(), context, left, right);
5651 break; 5709 break;
5652 default: 5710 default:
5653 UNREACHABLE(); 5711 UNREACHABLE();
5654 } 5712 }
5655 5713
5656 // If we hit an uninitialized binary op stub we will get type info 5714 // If we hit an uninitialized binary op stub we will get type info
5657 // for a smi operation. If one of the operands is a constant string 5715 // for a smi operation. If one of the operands is a constant string
5658 // do not generate code assuming it is a smi operation. 5716 // do not generate code assuming it is a smi operation.
5659 if (info.IsSmi() && 5717 if (info.IsSmi() &&
5660 ((left->IsConstant() && HConstant::cast(left)->HasStringValue()) || 5718 ((left->IsConstant() && HConstant::cast(left)->HasStringValue()) ||
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
7094 } 7152 }
7095 } 7153 }
7096 7154
7097 #ifdef DEBUG 7155 #ifdef DEBUG
7098 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7156 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7099 if (allocator_ != NULL) allocator_->Verify(); 7157 if (allocator_ != NULL) allocator_->Verify();
7100 #endif 7158 #endif
7101 } 7159 }
7102 7160
7103 } } // namespace v8::internal 7161 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698