OLD | NEW |
---|---|
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 Loading... | |
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 Handle<Type> tag_type, label_type, combined_type; |
rossberg
2013/12/11 09:41:34
Nit: please add the // Collect type feedback com
Jakob Kummerow
2013/12/11 10:00:01
Done.
| |
165 label->IsSmiLiteral() ? SwitchStatement::SMI_SWITCH : | 165 oracle()->CompareType(clause->CompareId(), |
166 label->IsStringLiteral() ? SwitchStatement::STRING_SWITCH : | 166 &tag_type, &label_type, &combined_type); |
167 SwitchStatement::GENERIC_SWITCH; | 167 NarrowLowerType(stmt->tag(), tag_type); |
168 if (switch_type == SwitchStatement::UNKNOWN_SWITCH) | 168 NarrowLowerType(label, label_type); |
169 switch_type = label_switch_type; | 169 clause->set_compare_type(combined_type); |
170 else if (switch_type != label_switch_type) | |
171 switch_type = SwitchStatement::GENERIC_SWITCH; | |
172 | 170 |
173 RECURSE(Visit(label)); | 171 RECURSE(Visit(label)); |
174 if (!clause_effects.IsEmpty()) complex_effects = true; | 172 if (!clause_effects.IsEmpty()) complex_effects = true; |
175 } | 173 } |
176 | 174 |
177 ZoneList<Statement*>* stmts = clause->statements(); | 175 ZoneList<Statement*>* stmts = clause->statements(); |
178 RECURSE(VisitStatements(stmts)); | 176 RECURSE(VisitStatements(stmts)); |
179 ExitEffects(); | 177 ExitEffects(); |
180 if (stmts->is_empty() || stmts->last()->IsJump()) { | 178 if (stmts->is_empty() || stmts->last()->IsJump()) { |
181 local_effects.Alt(clause_effects); | 179 local_effects.Alt(clause_effects); |
182 } else { | 180 } else { |
183 complex_effects = true; | 181 complex_effects = true; |
184 } | 182 } |
185 } | 183 } |
186 | 184 |
187 if (complex_effects) { | 185 if (complex_effects) { |
188 store_.Forget(); // Reached this in unknown state. | 186 store_.Forget(); // Reached this in unknown state. |
189 } else { | 187 } else { |
190 store_.Seq(local_effects); | 188 store_.Seq(local_effects); |
191 } | 189 } |
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 } | 190 } |
207 | 191 |
208 | 192 |
209 void AstTyper::VisitCaseClause(CaseClause* clause) { | 193 void AstTyper::VisitCaseClause(CaseClause* clause) { |
210 UNREACHABLE(); | 194 UNREACHABLE(); |
211 } | 195 } |
212 | 196 |
213 | 197 |
214 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { | 198 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { |
215 // Collect type feedback. | 199 // Collect type feedback. |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 void AstTyper::VisitModuleUrl(ModuleUrl* module) { | 719 void AstTyper::VisitModuleUrl(ModuleUrl* module) { |
736 } | 720 } |
737 | 721 |
738 | 722 |
739 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { | 723 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { |
740 RECURSE(Visit(stmt->body())); | 724 RECURSE(Visit(stmt->body())); |
741 } | 725 } |
742 | 726 |
743 | 727 |
744 } } // namespace v8::internal | 728 } } // namespace v8::internal |
OLD | NEW |