Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2683 int clause_count = clauses->length(); | 2683 int clause_count = clauses->length(); |
| 2684 if (clause_count > kCaseClauseLimit) { | 2684 if (clause_count > kCaseClauseLimit) { |
| 2685 return Bailout("SwitchStatement: too many clauses"); | 2685 return Bailout("SwitchStatement: too many clauses"); |
| 2686 } | 2686 } |
| 2687 | 2687 |
| 2688 CHECK_ALIVE(VisitForValue(stmt->tag())); | 2688 CHECK_ALIVE(VisitForValue(stmt->tag())); |
| 2689 AddSimulate(stmt->EntryId()); | 2689 AddSimulate(stmt->EntryId()); |
| 2690 HValue* tag_value = Pop(); | 2690 HValue* tag_value = Pop(); |
| 2691 HBasicBlock* first_test_block = current_block(); | 2691 HBasicBlock* first_test_block = current_block(); |
| 2692 | 2692 |
| 2693 // 1. Build all the tests, with dangling true branches. Unconditionally | 2693 SwitchType switch_type = UNKNOWN_SWITCH; |
| 2694 // deoptimize if we encounter a non-smi comparison. | 2694 |
| 2695 // 1. Extract clause type | |
| 2695 for (int i = 0; i < clause_count; ++i) { | 2696 for (int i = 0; i < clause_count; ++i) { |
| 2696 CaseClause* clause = clauses->at(i); | 2697 CaseClause* clause = clauses->at(i); |
| 2697 if (clause->is_default()) continue; | 2698 if (clause->is_default()) continue; |
| 2698 if (!clause->label()->IsSmiLiteral()) { | 2699 |
| 2699 return Bailout("SwitchStatement: non-literal switch label"); | 2700 if (switch_type == UNKNOWN_SWITCH) { |
| 2701 if (clause->label()->IsSmiLiteral()) { | |
| 2702 switch_type = SMI_SWITCH; | |
| 2703 } else if (clause->label()->IsStringLiteral()) { | |
| 2704 switch_type = STRING_SWITCH; | |
| 2705 } else { | |
| 2706 return Bailout("SwitchStatement: non-literal switch label"); | |
| 2707 } | |
| 2708 } else if ((switch_type == STRING_SWITCH && | |
| 2709 !clause->label()->IsStringLiteral()) || | |
| 2710 (switch_type == SMI_SWITCH && | |
| 2711 !clause->label()->IsSmiLiteral())) { | |
| 2712 return Bailout("SwitchStatemnt: mixed label types are not supported"); | |
| 2713 } | |
| 2714 } | |
| 2715 | |
| 2716 // Test switch's tag value if all clauses are string literals | |
| 2717 if (switch_type == STRING_SWITCH) { | |
| 2718 AddInstruction(HCheckInstanceType::NewIsSymbol(tag_value)); | |
| 2719 AddInstruction(new(zone()) HCheckNonSmi(tag_value)); | |
|
Vyacheslav Egorov (Chromium)
2011/10/24 12:27:29
Checking that tag_value is non-smi after is-symbol
| |
| 2720 } | |
| 2721 | |
| 2722 // 2. Build all the tests, with dangling true branches | |
| 2723 for (int i = 0; i < clause_count; ++i) { | |
| 2724 CaseClause* clause = clauses->at(i); | |
| 2725 if (clause->is_default()) continue; | |
| 2726 | |
| 2727 clause->RecordTypeFeedback(oracle()); | |
| 2728 | |
| 2729 // Generate a compare and branch. | |
| 2730 CHECK_ALIVE(VisitForValue(clause->label())); | |
| 2731 HValue* label_value = Pop(); | |
| 2732 | |
| 2733 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); | |
| 2734 HBasicBlock* body_block = graph()->CreateBasicBlock(); | |
| 2735 | |
| 2736 HControlInstruction* compare; | |
| 2737 | |
| 2738 if (switch_type == SMI_SWITCH) { | |
| 2739 if (!clause->IsSmiCompare()) { | |
| 2740 // Finish with deoptimize and add uses of enviroment values to | |
| 2741 // account for invisible uses. | |
| 2742 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); | |
| 2743 set_current_block(NULL); | |
| 2744 break; | |
| 2745 } | |
| 2746 | |
| 2747 HCompareIDAndBranch* compare_ = | |
| 2748 new(zone()) HCompareIDAndBranch(tag_value, | |
| 2749 label_value, | |
| 2750 Token::EQ_STRICT); | |
| 2751 compare_->SetInputRepresentation(Representation::Integer32()); | |
| 2752 compare = compare_; | |
| 2753 } else { | |
| 2754 compare = new(zone()) HCompareObjectEqAndBranch(tag_value, label_value); | |
| 2700 } | 2755 } |
| 2701 | 2756 |
| 2702 // Unconditionally deoptimize on the first non-smi compare. | |
| 2703 clause->RecordTypeFeedback(oracle()); | |
| 2704 if (!clause->IsSmiCompare()) { | |
| 2705 // Finish with deoptimize and add uses of enviroment values to | |
| 2706 // account for invisible uses. | |
| 2707 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); | |
| 2708 set_current_block(NULL); | |
| 2709 break; | |
| 2710 } | |
| 2711 | |
| 2712 // Otherwise generate a compare and branch. | |
| 2713 CHECK_ALIVE(VisitForValue(clause->label())); | |
| 2714 HValue* label_value = Pop(); | |
| 2715 HCompareIDAndBranch* compare = | |
| 2716 new(zone()) HCompareIDAndBranch(tag_value, | |
| 2717 label_value, | |
| 2718 Token::EQ_STRICT); | |
| 2719 compare->SetInputRepresentation(Representation::Integer32()); | |
| 2720 HBasicBlock* body_block = graph()->CreateBasicBlock(); | |
| 2721 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); | |
| 2722 compare->SetSuccessorAt(0, body_block); | 2757 compare->SetSuccessorAt(0, body_block); |
| 2723 compare->SetSuccessorAt(1, next_test_block); | 2758 compare->SetSuccessorAt(1, next_test_block); |
| 2724 current_block()->Finish(compare); | 2759 current_block()->Finish(compare); |
| 2760 | |
| 2725 set_current_block(next_test_block); | 2761 set_current_block(next_test_block); |
| 2726 } | 2762 } |
| 2727 | 2763 |
| 2728 // Save the current block to use for the default or to join with the | 2764 // Save the current block to use for the default or to join with the |
| 2729 // exit. This block is NULL if we deoptimized. | 2765 // exit. This block is NULL if we deoptimized. |
| 2730 HBasicBlock* last_block = current_block(); | 2766 HBasicBlock* last_block = current_block(); |
| 2731 | 2767 |
| 2732 // 2. Loop over the clauses and the linked list of tests in lockstep, | 2768 // 3. Loop over the clauses and the linked list of tests in lockstep, |
| 2733 // translating the clause bodies. | 2769 // translating the clause bodies. |
| 2734 HBasicBlock* curr_test_block = first_test_block; | 2770 HBasicBlock* curr_test_block = first_test_block; |
| 2735 HBasicBlock* fall_through_block = NULL; | 2771 HBasicBlock* fall_through_block = NULL; |
| 2736 BreakAndContinueInfo break_info(stmt); | 2772 BreakAndContinueInfo break_info(stmt); |
| 2737 { BreakAndContinueScope push(&break_info, this); | 2773 { BreakAndContinueScope push(&break_info, this); |
| 2738 for (int i = 0; i < clause_count; ++i) { | 2774 for (int i = 0; i < clause_count; ++i) { |
| 2739 CaseClause* clause = clauses->at(i); | 2775 CaseClause* clause = clauses->at(i); |
| 2740 | 2776 |
| 2741 // Identify the block where normal (non-fall-through) control flow | 2777 // Identify the block where normal (non-fall-through) control flow |
| 2742 // goes to. | 2778 // goes to. |
| (...skipping 4270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7013 } | 7049 } |
| 7014 } | 7050 } |
| 7015 | 7051 |
| 7016 #ifdef DEBUG | 7052 #ifdef DEBUG |
| 7017 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 7053 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 7018 if (allocator_ != NULL) allocator_->Verify(); | 7054 if (allocator_ != NULL) allocator_->Verify(); |
| 7019 #endif | 7055 #endif |
| 7020 } | 7056 } |
| 7021 | 7057 |
| 7022 } } // namespace v8::internal | 7058 } } // namespace v8::internal |
| OLD | NEW |