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 2677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // 1. Build all the tests, with dangling true branches. Unconditionally |
| 2694 // deoptimize if we encounter a non-smi comparison. | 2694 // deoptimize if we encounter a non-smi comparison. |
| 2695 for (int i = 0; i < clause_count; ++i) { | 2695 for (int i = 0; i < clause_count; ++i) { |
| 2696 CaseClause* clause = clauses->at(i); | 2696 CaseClause* clause = clauses->at(i); |
| 2697 if (clause->is_default()) continue; | 2697 if (clause->is_default()) continue; |
| 2698 if (!clause->label()->IsSmiLiteral()) { | 2698 if (!clause->label()->IsSmiLiteral() && |
| 2699 !clause->label()->IsStringLiteral()) { | |
| 2699 return Bailout("SwitchStatement: non-literal switch label"); | 2700 return Bailout("SwitchStatement: non-literal switch label"); |
| 2700 } | 2701 } |
| 2701 | 2702 |
| 2702 // Unconditionally deoptimize on the first non-smi compare. | |
| 2703 clause->RecordTypeFeedback(oracle()); | 2703 clause->RecordTypeFeedback(oracle()); |
| 2704 if (!clause->IsSmiCompare()) { | 2704 |
| 2705 // Finish with deoptimize and add uses of enviroment values to | 2705 // Generate a compare and branch. |
| 2706 // account for invisible uses. | 2706 CHECK_ALIVE(VisitForValue(clause->label())); |
| 2707 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); | 2707 HValue* label_value = Pop(); |
| 2708 set_current_block(NULL); | 2708 |
| 2709 break; | 2709 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); |
| 2710 HBasicBlock* body_block = graph()->CreateBasicBlock(); | |
| 2711 | |
| 2712 if (clause->IsSmiCompare()) { | |
| 2713 HCompareIDAndBranch* compare = | |
| 2714 new(zone()) HCompareIDAndBranch(tag_value, | |
| 2715 label_value, | |
| 2716 Token::EQ_STRICT); | |
| 2717 compare->SetInputRepresentation(Representation::Integer32()); | |
| 2718 compare->SetSuccessorAt(0, body_block); | |
| 2719 compare->SetSuccessorAt(1, next_test_block); | |
| 2720 current_block()->Finish(compare); | |
| 2721 } else { | |
| 2722 AddInstruction(new(zone()) HCheckNonSmi(tag_value)); | |
| 2723 AddInstruction(HCheckInstanceType::NewIsSymbol(tag_value)); | |
| 2724 HCompareObjectEqAndBranch* compare = | |
| 2725 new(zone()) HCompareObjectEqAndBranch(tag_value, label_value); | |
| 2726 compare->SetSuccessorAt(0, body_block); | |
|
Vyacheslav Egorov (Chromium)
2011/10/24 09:37:19
Can be moved outside of the if to avoid code dupli
| |
| 2727 compare->SetSuccessorAt(1, next_test_block); | |
| 2728 current_block()->Finish(compare); | |
| 2710 } | 2729 } |
| 2711 | 2730 |
| 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); | |
| 2723 compare->SetSuccessorAt(1, next_test_block); | |
| 2724 current_block()->Finish(compare); | |
| 2725 set_current_block(next_test_block); | 2731 set_current_block(next_test_block); |
| 2726 } | 2732 } |
| 2727 | 2733 |
| 2728 // Save the current block to use for the default or to join with the | 2734 // Save the current block to use for the default or to join with the |
| 2729 // exit. This block is NULL if we deoptimized. | 2735 // exit. This block is NULL if we deoptimized. |
| 2730 HBasicBlock* last_block = current_block(); | 2736 HBasicBlock* last_block = current_block(); |
| 2731 | 2737 |
| 2732 // 2. Loop over the clauses and the linked list of tests in lockstep, | 2738 // 2. Loop over the clauses and the linked list of tests in lockstep, |
| 2733 // translating the clause bodies. | 2739 // translating the clause bodies. |
| 2734 HBasicBlock* curr_test_block = first_test_block; | 2740 HBasicBlock* curr_test_block = first_test_block; |
| (...skipping 4278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7013 } | 7019 } |
| 7014 } | 7020 } |
| 7015 | 7021 |
| 7016 #ifdef DEBUG | 7022 #ifdef DEBUG |
| 7017 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 7023 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 7018 if (allocator_ != NULL) allocator_->Verify(); | 7024 if (allocator_ != NULL) allocator_->Verify(); |
| 7019 #endif | 7025 #endif |
| 7020 } | 7026 } |
| 7021 | 7027 |
| 7022 } } // namespace v8::internal | 7028 } } // namespace v8::internal |
| OLD | NEW |