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

Side by Side Diff: src/hydrogen.cc

Issue 8373029: [hydrogen] optimize switch with string clauses (Closed) Base URL: gh:v8/v8@master
Patch Set: split string and smi cases 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 | « no previous file | 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 enum {
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 We don't use anonymous enums
2694 none, smi, string
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 use either kSmiSwitch or SMI_SWITCH naming f
2695 } clause_type = none;
2696
2693 // 1. Build all the tests, with dangling true branches. Unconditionally 2697 // 1. Build all the tests, with dangling true branches. Unconditionally
2694 // deoptimize if we encounter a non-smi comparison. 2698 // deoptimize if we encounter a non-smi comparison.
2695 for (int i = 0; i < clause_count; ++i) { 2699 for (int i = 0; i < clause_count; ++i) {
2696 CaseClause* clause = clauses->at(i); 2700 CaseClause* clause = clauses->at(i);
2697 if (clause->is_default()) continue; 2701 if (clause->is_default()) continue;
2698 if (!clause->label()->IsSmiLiteral()) { 2702
2699 return Bailout("SwitchStatement: non-literal switch label"); 2703 if (clause_type == none) {
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 I would suggest extracting loop part that computes
2704 if (clause->label()->IsSmiLiteral()) {
2705 clause_type = smi;
2706 } else if (clause->label()->IsStringLiteral()) {
2707 clause_type = string;
2708 } else {
2709 return Bailout("SwitchStatement: non-literal switch label");
2710 }
2711 } else if (clause->label()->IsSmiLiteral() && clause_type == string ||
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 clause can be neither smi nor string literal. I t
2712 clause->label()->IsStringLiteral() && clause_type == smi) {
2713 return Bailout("SwitchStatemnt: mixed label types are not supported");
2700 } 2714 }
2701 2715
2702 // Unconditionally deoptimize on the first non-smi compare.
2703 clause->RecordTypeFeedback(oracle()); 2716 clause->RecordTypeFeedback(oracle());
2704 if (!clause->IsSmiCompare()) { 2717
2705 // Finish with deoptimize and add uses of enviroment values to 2718 // Generate a compare and branch.
2706 // account for invisible uses. 2719 CHECK_ALIVE(VisitForValue(clause->label()));
2707 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); 2720 HValue* label_value = Pop();
2708 set_current_block(NULL); 2721
2709 break; 2722 HBasicBlock* next_test_block = graph()->CreateBasicBlock();
2723 HBasicBlock* body_block = graph()->CreateBasicBlock();
2724
2725 HControlInstruction* compare;
2726
2727 if (clause_type == smi) {
2728 if (!clause->IsSmiCompare()) {
2729 // Finish with deoptimize and add uses of enviroment values to
2730 // account for invisible uses.
2731 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll);
2732 set_current_block(NULL);
2733 break;
2734 }
2735
2736 HCompareIDAndBranch* compare_ =
2737 new(zone()) HCompareIDAndBranch(tag_value,
2738 label_value,
2739 Token::EQ_STRICT);
2740 compare_->SetInputRepresentation(Representation::Integer32());
2741 compare = reinterpret_cast<HControlInstruction*>(compare_);
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 I don't think you need reinterpret_cast here. HCo
2742 } else {
2743 HCompareObjectEqAndBranch* compare_ =
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 I think you don't need this temp variable
2744 new(zone()) HCompareObjectEqAndBranch(tag_value, label_value);
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 Why not CompareIDAndBranch? Once loop that compute
2745 compare = reinterpret_cast<HControlInstruction*>(compare_);
Vyacheslav Egorov (Chromium) 2011/10/24 10:56:26 I don't think you need reinterpret_cast here. HCo
2710 } 2746 }
2711 2747
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); 2748 compare->SetSuccessorAt(0, body_block);
2723 compare->SetSuccessorAt(1, next_test_block); 2749 compare->SetSuccessorAt(1, next_test_block);
2724 current_block()->Finish(compare); 2750 current_block()->Finish(compare);
2751
2725 set_current_block(next_test_block); 2752 set_current_block(next_test_block);
2726 } 2753 }
2727 2754
2728 // Save the current block to use for the default or to join with the 2755 // Save the current block to use for the default or to join with the
2729 // exit. This block is NULL if we deoptimized. 2756 // exit. This block is NULL if we deoptimized.
2730 HBasicBlock* last_block = current_block(); 2757 HBasicBlock* last_block = current_block();
2731 2758
2732 // 2. Loop over the clauses and the linked list of tests in lockstep, 2759 // 2. Loop over the clauses and the linked list of tests in lockstep,
2733 // translating the clause bodies. 2760 // translating the clause bodies.
2734 HBasicBlock* curr_test_block = first_test_block; 2761 HBasicBlock* curr_test_block = first_test_block;
(...skipping 4278 matching lines...) Expand 10 before | Expand all | Expand 10 after
7013 } 7040 }
7014 } 7041 }
7015 7042
7016 #ifdef DEBUG 7043 #ifdef DEBUG
7017 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7044 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7018 if (allocator_ != NULL) allocator_->Verify(); 7045 if (allocator_ != NULL) allocator_->Verify();
7019 #endif 7046 #endif
7020 } 7047 }
7021 7048
7022 } } // namespace v8::internal 7049 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698