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

Side by Side Diff: src/hydrogen.cc

Issue 8373029: [hydrogen] optimize switch with string clauses (Closed) Base URL: gh:v8/v8@master
Patch Set: separate type extraction and code generation Created 9 years, 2 months 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
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | 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 2672 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = UNSUPPORTED_SWITCH;
Vyacheslav Egorov (Chromium) 2011/10/24 12:12:00 UNSUPPORTED -> UNKNOWN?
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 == UNSUPPORTED_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 (clause->label()->IsSmiLiteral() &&
Vyacheslav Egorov (Chromium) 2011/10/24 12:12:00 labels can be neither smi nor strings. Correct con
2709 switch_type == STRING_SWITCH ||
2710 clause->label()->IsStringLiteral() &&
2711 switch_type == SMI_SWITCH) {
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));
Vyacheslav Egorov (Chromium) 2011/10/24 12:12:00 You also need HCheckNonSmi(tag_value) otherwise it
2719 }
2720
2721 // 2. Build all the tests, with dangling true branches
2722 for (int i = 0; i < clause_count; ++i) {
2723 CaseClause* clause = clauses->at(i);
2724 if (clause->is_default()) continue;
2725
2726 clause->RecordTypeFeedback(oracle());
2727
2728 // Generate a compare and branch.
2729 CHECK_ALIVE(VisitForValue(clause->label()));
2730 HValue* label_value = Pop();
2731
2732 HBasicBlock* next_test_block = graph()->CreateBasicBlock();
2733 HBasicBlock* body_block = graph()->CreateBasicBlock();
2734
2735 HControlInstruction* compare;
2736
2737 if (switch_type == SMI_SWITCH) {
2738 if (!clause->IsSmiCompare()) {
2739 // Finish with deoptimize and add uses of enviroment values to
2740 // account for invisible uses.
2741 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll);
2742 set_current_block(NULL);
2743 break;
2744 }
2745
2746 HCompareIDAndBranch* compare_ =
2747 new(zone()) HCompareIDAndBranch(tag_value,
2748 label_value,
2749 Token::EQ_STRICT);
2750 compare_->SetInputRepresentation(Representation::Integer32());
2751 compare = compare_;
2752 } else {
2753 compare = new(zone()) HCompareObjectEqAndBranch(tag_value, label_value);
2700 } 2754 }
2701 2755
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); 2756 compare->SetSuccessorAt(0, body_block);
2723 compare->SetSuccessorAt(1, next_test_block); 2757 compare->SetSuccessorAt(1, next_test_block);
2724 current_block()->Finish(compare); 2758 current_block()->Finish(compare);
2759
2725 set_current_block(next_test_block); 2760 set_current_block(next_test_block);
2726 } 2761 }
2727 2762
2728 // Save the current block to use for the default or to join with the 2763 // Save the current block to use for the default or to join with the
2729 // exit. This block is NULL if we deoptimized. 2764 // exit. This block is NULL if we deoptimized.
2730 HBasicBlock* last_block = current_block(); 2765 HBasicBlock* last_block = current_block();
2731 2766
2732 // 2. Loop over the clauses and the linked list of tests in lockstep, 2767 // 3. Loop over the clauses and the linked list of tests in lockstep,
2733 // translating the clause bodies. 2768 // translating the clause bodies.
2734 HBasicBlock* curr_test_block = first_test_block; 2769 HBasicBlock* curr_test_block = first_test_block;
2735 HBasicBlock* fall_through_block = NULL; 2770 HBasicBlock* fall_through_block = NULL;
2736 BreakAndContinueInfo break_info(stmt); 2771 BreakAndContinueInfo break_info(stmt);
2737 { BreakAndContinueScope push(&break_info, this); 2772 { BreakAndContinueScope push(&break_info, this);
2738 for (int i = 0; i < clause_count; ++i) { 2773 for (int i = 0; i < clause_count; ++i) {
2739 CaseClause* clause = clauses->at(i); 2774 CaseClause* clause = clauses->at(i);
2740 2775
2741 // Identify the block where normal (non-fall-through) control flow 2776 // Identify the block where normal (non-fall-through) control flow
2742 // goes to. 2777 // goes to.
(...skipping 4270 matching lines...) Expand 10 before | Expand all | Expand 10 after
7013 } 7048 }
7014 } 7049 }
7015 7050
7016 #ifdef DEBUG 7051 #ifdef DEBUG
7017 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7052 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7018 if (allocator_ != NULL) allocator_->Verify(); 7053 if (allocator_ != NULL) allocator_->Verify();
7019 #endif 7054 #endif
7020 } 7055 }
7021 7056
7022 } } // namespace v8::internal 7057 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698