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

Side by Side Diff: src/typing.cc

Issue 111573003: Hydrogen: Re-use regular comparisons infrastructure for switch statements (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added comment Created 7 years 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/type-info.cc ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 void AstTyper::VisitWithStatement(WithStatement* stmt) { 144 void AstTyper::VisitWithStatement(WithStatement* stmt) {
145 RECURSE(stmt->expression()); 145 RECURSE(stmt->expression());
146 RECURSE(stmt->statement()); 146 RECURSE(stmt->statement());
147 } 147 }
148 148
149 149
150 void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) { 150 void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) {
151 RECURSE(Visit(stmt->tag())); 151 RECURSE(Visit(stmt->tag()));
152 152
153 ZoneList<CaseClause*>* clauses = stmt->cases(); 153 ZoneList<CaseClause*>* clauses = stmt->cases();
154 SwitchStatement::SwitchType switch_type = stmt->switch_type();
155 Effects local_effects(zone()); 154 Effects local_effects(zone());
156 bool complex_effects = false; // True for label effects or fall-through. 155 bool complex_effects = false; // True for label effects or fall-through.
157 156
158 for (int i = 0; i < clauses->length(); ++i) { 157 for (int i = 0; i < clauses->length(); ++i) {
159 CaseClause* clause = clauses->at(i); 158 CaseClause* clause = clauses->at(i);
159
160 Effects clause_effects = EnterEffects(); 160 Effects clause_effects = EnterEffects();
161 161
162 if (!clause->is_default()) { 162 if (!clause->is_default()) {
163 Expression* label = clause->label(); 163 Expression* label = clause->label();
164 SwitchStatement::SwitchType label_switch_type = 164 // Collect type feedback.
165 label->IsSmiLiteral() ? SwitchStatement::SMI_SWITCH : 165 Handle<Type> tag_type, label_type, combined_type;
166 label->IsStringLiteral() ? SwitchStatement::STRING_SWITCH : 166 oracle()->CompareType(clause->CompareId(),
167 SwitchStatement::GENERIC_SWITCH; 167 &tag_type, &label_type, &combined_type);
168 if (switch_type == SwitchStatement::UNKNOWN_SWITCH) 168 NarrowLowerType(stmt->tag(), tag_type);
169 switch_type = label_switch_type; 169 NarrowLowerType(label, label_type);
170 else if (switch_type != label_switch_type) 170 clause->set_compare_type(combined_type);
171 switch_type = SwitchStatement::GENERIC_SWITCH;
172 171
173 RECURSE(Visit(label)); 172 RECURSE(Visit(label));
174 if (!clause_effects.IsEmpty()) complex_effects = true; 173 if (!clause_effects.IsEmpty()) complex_effects = true;
175 } 174 }
176 175
177 ZoneList<Statement*>* stmts = clause->statements(); 176 ZoneList<Statement*>* stmts = clause->statements();
178 RECURSE(VisitStatements(stmts)); 177 RECURSE(VisitStatements(stmts));
179 ExitEffects(); 178 ExitEffects();
180 if (stmts->is_empty() || stmts->last()->IsJump()) { 179 if (stmts->is_empty() || stmts->last()->IsJump()) {
181 local_effects.Alt(clause_effects); 180 local_effects.Alt(clause_effects);
182 } else { 181 } else {
183 complex_effects = true; 182 complex_effects = true;
184 } 183 }
185 } 184 }
186 185
187 if (complex_effects) { 186 if (complex_effects) {
188 store_.Forget(); // Reached this in unknown state. 187 store_.Forget(); // Reached this in unknown state.
189 } else { 188 } else {
190 store_.Seq(local_effects); 189 store_.Seq(local_effects);
191 } 190 }
192
193 if (switch_type == SwitchStatement::UNKNOWN_SWITCH)
194 switch_type = SwitchStatement::GENERIC_SWITCH;
195 stmt->set_switch_type(switch_type);
196
197 // Collect type feedback.
198 // TODO(rossberg): can we eliminate this special case and extra loop?
199 if (switch_type == SwitchStatement::SMI_SWITCH) {
200 for (int i = 0; i < clauses->length(); ++i) {
201 CaseClause* clause = clauses->at(i);
202 if (!clause->is_default())
203 clause->set_compare_type(oracle()->ClauseType(clause->CompareId()));
204 }
205 }
206 } 191 }
207 192
208 193
209 void AstTyper::VisitCaseClause(CaseClause* clause) { 194 void AstTyper::VisitCaseClause(CaseClause* clause) {
210 UNREACHABLE(); 195 UNREACHABLE();
211 } 196 }
212 197
213 198
214 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { 199 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) {
215 // Collect type feedback. 200 // Collect type feedback.
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 void AstTyper::VisitModuleUrl(ModuleUrl* module) { 720 void AstTyper::VisitModuleUrl(ModuleUrl* module) {
736 } 721 }
737 722
738 723
739 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { 724 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) {
740 RECURSE(Visit(stmt->body())); 725 RECURSE(Visit(stmt->body()));
741 } 726 }
742 727
743 728
744 } } // namespace v8::internal 729 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/type-info.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698