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

Side by Side Diff: src/codegen.cc

Issue 5002: Port of fast-case switch to ARM (Closed)
Patch Set: Updates based on review comments Created 12 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/codegen.h ('k') | src/codegen-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (node->name()->IsEqualTo(CStrVector(entry->name))) { 244 if (node->name()->IsEqualTo(CStrVector(entry->name))) {
245 ((*this).*(entry->method))(args); 245 ((*this).*(entry->method))(args);
246 return true; 246 return true;
247 } 247 }
248 } 248 }
249 } 249 }
250 return false; 250 return false;
251 } 251 }
252 252
253 253
254 void CodeGenerator::GenerateFastCaseSwitchStatement(
255 SwitchStatement *node, int min_index, int range, int default_index) {
256
257 ZoneList<CaseClause*>* cases = node->cases();
258 int length = cases->length();
259
260 // Label pointer per number in range
261 SmartPointer<Label*> case_targets(NewArray<Label*>(range));
262
263 // Label per switch case
264 SmartPointer<Label> case_labels(NewArray<Label>(length));
265
266 Label* fail_label = (default_index >= 0 ? &(case_labels[default_index])
267 : node->break_target());
268
269 // Populate array of label pointers for each number in the range.
270 // Initally put the failure label everywhere.
271 for (int i = 0; i < range; i++) {
272 case_targets[i] = fail_label;
273 }
274
275 // Overwrite with label of a case for the number value of that case.
276 // (In reverse order, so that if the same label occurs twice, the
277 // first one wins).
278 for (int i = length-1; i >= 0 ; i--) {
279 CaseClause* clause = cases->at(i);
280 if (!clause->is_default()) {
281 Object* label_value = *(clause->label()->AsLiteral()->handle());
282 int case_value = Smi::cast(label_value)->value();
283 case_targets[case_value - min_index] = &(case_labels[i]);
284 }
285 }
286
287 GenerateFastCaseSwitchJumpTable(node, min_index, range, fail_label,
288 case_targets, case_labels);
289 }
290
291 void CodeGenerator::GenerateFastCaseSwitchCases(
292 SwitchStatement* node, SmartPointer<Label> &case_labels) {
293
294 ZoneList<CaseClause*>* cases = node->cases();
295 int length = cases->length();
296
297 for (int i = 0; i < length; i++) {
298 Comment cmnt(masm(), "[ case clause");
299 masm()->bind(&(case_labels[i]));
300 VisitStatements(cases->at(i)->statements());
301 }
302
303 masm()->bind(node->break_target());
304 }
305
306
307 bool CodeGenerator::TryGenerateFastCaseSwitchStatement(SwitchStatement* node) {
308 ZoneList<CaseClause*>* cases = node->cases();
309 int length = cases->length();
310
311 if (length < FastCaseSwitchMinCaseCount()) {
312 return false;
313 }
314
315 // Test whether fast-case should be used.
316 int default_index = -1;
317 int min_index = Smi::kMaxValue;
318 int max_index = Smi::kMinValue;
319 for (int i = 0; i < length; i++) {
320 CaseClause* clause = cases->at(i);
321 if (clause->is_default()) {
322 if (default_index >= 0) {
323 return false; // More than one default label:
324 // Defer to normal case for error.
325 }
326 default_index = i;
327 } else {
328 Expression* label = clause->label();
329 Literal* literal = label->AsLiteral();
330 if (literal == NULL) {
331 return false; // fail fast case
332 }
333 Object* value = *(literal->handle());
334 if (!value->IsSmi()) {
335 return false;
336 }
337 int smi = Smi::cast(value)->value();
338 if (smi < min_index) { min_index = smi; }
339 if (smi > max_index) { max_index = smi; }
340 }
341 }
342
343 // All labels are known to be Smis.
344 int range = max_index - min_index + 1; // |min..max| inclusive
345 if (range / FastCaseSwitchMaxOverheadFactor() > length) {
346 return false; // range of labels is too sparse
347 }
348
349 // Optimization accepted, generate code.
350 GenerateFastCaseSwitchStatement(node, min_index, range, default_index);
351 return true;
352 }
353
354
254 const char* RuntimeStub::GetName() { 355 const char* RuntimeStub::GetName() {
255 return Runtime::FunctionForId(id_)->stub_name; 356 return Runtime::FunctionForId(id_)->stub_name;
256 } 357 }
257 358
258 359
259 void RuntimeStub::Generate(MacroAssembler* masm) { 360 void RuntimeStub::Generate(MacroAssembler* masm) {
260 masm->TailCallRuntime(ExternalReference(id_), num_arguments_); 361 masm->TailCallRuntime(ExternalReference(id_), num_arguments_);
261 } 362 }
262 363
263 364
264 } } // namespace v8::internal 365 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/codegen.h ('k') | src/codegen-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698