| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 if (old_entry != NULL) { | 465 if (old_entry != NULL) { |
| 466 old_entry->name = entry->name; | 466 old_entry->name = entry->name; |
| 467 old_entry->method = entry->method; | 467 old_entry->method = entry->method; |
| 468 } | 468 } |
| 469 entry->name = new_entry.name; | 469 entry->name = new_entry.name; |
| 470 entry->method = new_entry.method; | 470 entry->method = new_entry.method; |
| 471 return true; | 471 return true; |
| 472 } | 472 } |
| 473 | 473 |
| 474 | 474 |
| 475 void CodeGenerator::GenerateFastCaseSwitchStatement(SwitchStatement* node, | |
| 476 int min_index, | |
| 477 int range, | |
| 478 int default_index) { | |
| 479 ZoneList<CaseClause*>* cases = node->cases(); | |
| 480 int length = cases->length(); | |
| 481 | |
| 482 // Label pointer per number in range. | |
| 483 SmartPointer<Label*> case_targets(NewArray<Label*>(range)); | |
| 484 | |
| 485 // Label per switch case. | |
| 486 SmartPointer<Label> case_labels(NewArray<Label>(length)); | |
| 487 | |
| 488 Label* fail_label = | |
| 489 default_index >= 0 ? &(case_labels[default_index]) : NULL; | |
| 490 | |
| 491 // Populate array of label pointers for each number in the range. | |
| 492 // Initally put the failure label everywhere. | |
| 493 for (int i = 0; i < range; i++) { | |
| 494 case_targets[i] = fail_label; | |
| 495 } | |
| 496 | |
| 497 // Overwrite with label of a case for the number value of that case. | |
| 498 // (In reverse order, so that if the same label occurs twice, the | |
| 499 // first one wins). | |
| 500 for (int i = length - 1; i >= 0 ; i--) { | |
| 501 CaseClause* clause = cases->at(i); | |
| 502 if (!clause->is_default()) { | |
| 503 Object* label_value = *(clause->label()->AsLiteral()->handle()); | |
| 504 int case_value = Smi::cast(label_value)->value(); | |
| 505 case_targets[case_value - min_index] = &(case_labels[i]); | |
| 506 } | |
| 507 } | |
| 508 | |
| 509 GenerateFastCaseSwitchJumpTable(node, | |
| 510 min_index, | |
| 511 range, | |
| 512 fail_label, | |
| 513 Vector<Label*>(*case_targets, range), | |
| 514 Vector<Label>(*case_labels, length)); | |
| 515 } | |
| 516 | |
| 517 | |
| 518 void CodeGenerator::GenerateFastCaseSwitchCases( | |
| 519 SwitchStatement* node, | |
| 520 Vector<Label> case_labels, | |
| 521 VirtualFrame* start_frame) { | |
| 522 ZoneList<CaseClause*>* cases = node->cases(); | |
| 523 int length = cases->length(); | |
| 524 | |
| 525 for (int i = 0; i < length; i++) { | |
| 526 Comment cmnt(masm(), "[ Case clause"); | |
| 527 | |
| 528 // We may not have a virtual frame if control flow did not fall | |
| 529 // off the end of the previous case. In that case, use the start | |
| 530 // frame. Otherwise, we have to merge the existing one to the | |
| 531 // start frame as part of the previous case. | |
| 532 if (!has_valid_frame()) { | |
| 533 RegisterFile empty; | |
| 534 SetFrame(new VirtualFrame(start_frame), &empty); | |
| 535 } else { | |
| 536 frame_->MergeTo(start_frame); | |
| 537 } | |
| 538 masm()->bind(&case_labels[i]); | |
| 539 VisitStatements(cases->at(i)->statements()); | |
| 540 } | |
| 541 } | |
| 542 | |
| 543 | |
| 544 bool CodeGenerator::TryGenerateFastCaseSwitchStatement(SwitchStatement* node) { | |
| 545 // TODO(238): Due to issue 238, fast case switches can crash on ARM | |
| 546 // and possibly IA32. They are disabled for now. | |
| 547 // See http://code.google.com/p/v8/issues/detail?id=238 | |
| 548 return false; | |
| 549 | |
| 550 ZoneList<CaseClause*>* cases = node->cases(); | |
| 551 int length = cases->length(); | |
| 552 | |
| 553 if (length < FastCaseSwitchMinCaseCount()) { | |
| 554 return false; | |
| 555 } | |
| 556 | |
| 557 // Test whether fast-case should be used. | |
| 558 int default_index = -1; | |
| 559 int min_index = Smi::kMaxValue; | |
| 560 int max_index = Smi::kMinValue; | |
| 561 for (int i = 0; i < length; i++) { | |
| 562 CaseClause* clause = cases->at(i); | |
| 563 if (clause->is_default()) { | |
| 564 if (default_index >= 0) { | |
| 565 // There is more than one default label. Defer to the normal case | |
| 566 // for error. | |
| 567 return false; | |
| 568 } | |
| 569 default_index = i; | |
| 570 } else { | |
| 571 Expression* label = clause->label(); | |
| 572 Literal* literal = label->AsLiteral(); | |
| 573 if (literal == NULL) { | |
| 574 return false; // fail fast case | |
| 575 } | |
| 576 Object* value = *(literal->handle()); | |
| 577 if (!value->IsSmi()) { | |
| 578 return false; | |
| 579 } | |
| 580 int int_value = Smi::cast(value)->value(); | |
| 581 min_index = Min(int_value, min_index); | |
| 582 max_index = Max(int_value, max_index); | |
| 583 } | |
| 584 } | |
| 585 | |
| 586 // All labels are known to be Smis. | |
| 587 int range = max_index - min_index + 1; // |min..max| inclusive | |
| 588 if (range / FastCaseSwitchMaxOverheadFactor() > length) { | |
| 589 return false; // range of labels is too sparse | |
| 590 } | |
| 591 | |
| 592 // Optimization accepted, generate code. | |
| 593 GenerateFastCaseSwitchStatement(node, min_index, range, default_index); | |
| 594 return true; | |
| 595 } | |
| 596 | |
| 597 | |
| 598 void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) { | 475 void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) { |
| 599 if (FLAG_debug_info) { | 476 if (FLAG_debug_info) { |
| 600 int pos = fun->start_position(); | 477 int pos = fun->start_position(); |
| 601 if (pos != RelocInfo::kNoPosition) { | 478 if (pos != RelocInfo::kNoPosition) { |
| 602 masm()->RecordStatementPosition(pos); | 479 masm()->RecordStatementPosition(pos); |
| 603 masm()->RecordPosition(pos); | 480 masm()->RecordPosition(pos); |
| 604 } | 481 } |
| 605 } | 482 } |
| 606 } | 483 } |
| 607 | 484 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { | 527 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { |
| 651 switch (type_) { | 528 switch (type_) { |
| 652 case READ_LENGTH: GenerateReadLength(masm); break; | 529 case READ_LENGTH: GenerateReadLength(masm); break; |
| 653 case READ_ELEMENT: GenerateReadElement(masm); break; | 530 case READ_ELEMENT: GenerateReadElement(masm); break; |
| 654 case NEW_OBJECT: GenerateNewObject(masm); break; | 531 case NEW_OBJECT: GenerateNewObject(masm); break; |
| 655 } | 532 } |
| 656 } | 533 } |
| 657 | 534 |
| 658 | 535 |
| 659 } } // namespace v8::internal | 536 } } // namespace v8::internal |
| OLD | NEW |