| 651 | } |
| 652 | |
| 653 | Pass::Status LoopPeelingPass::ProcessFunction(Function* f) { |
| 654 | bool modified = false; |
| 655 | LoopDescriptor& loop_descriptor = *context()->GetLoopDescriptor(f); |
| 656 | |
| 657 | std::vector<Loop*> to_process_loop; |
| 658 | to_process_loop.reserve(loop_descriptor.NumLoops()); |
| 659 | for (Loop& l : loop_descriptor) { |
| 660 | to_process_loop.push_back(&l); |
| 661 | } |
| 662 | |
| 663 | ScalarEvolutionAnalysis scev_analysis(context()); |
| 664 | |
| 665 | for (Loop* loop : to_process_loop) { |
| 666 | CodeMetrics loop_size; |
| 667 | loop_size.Analyze(*loop); |
| 668 | |
| 669 | auto try_peel = [&loop_size, &modified, this]( |
| 670 | Loop* loop_to_peel) -> std::pair<Pass::Status, Loop*> { |
| 671 | if (!loop_to_peel->IsLCSSA()) { |
| 672 | if (!LoopUtils(context(), loop_to_peel).MakeLoopClosedSSA()) { |
| 673 | return {Pass::Status::Failure, nullptr}; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | Pass::Status status; |
| 678 | Loop* still_peelable_loop; |
| 679 | std::tie(status, still_peelable_loop) = |
| 680 | ProcessLoop(loop_to_peel, &loop_size); |
| 681 | |
| 682 | if (status == Pass::Status::SuccessWithChange) { |
| 683 | modified = true; |
| 684 | } |
| 685 | |
| 686 | return {status, still_peelable_loop}; |
| 687 | }; |
| 688 | |
| 689 | Pass::Status status; |
| 690 | Loop* still_peelable_loop; |
| 691 | std::tie(status, still_peelable_loop) = try_peel(loop); |
| 692 | |
| 693 | if (status == Pass::Status::Failure) { |
| 694 | return Pass::Status::Failure; |
| 695 | } |
| 696 | |
| 697 | // The pass is working out the maximum factor by which a loop can be peeled. |
| 698 | // If the loop can potentially be peeled again, then there is only one |
| 699 | // possible direction, so only one call is still needed. |
| 700 | if (still_peelable_loop) { |
| 701 | std::tie(status, still_peelable_loop) = try_peel(still_peelable_loop); |
| 702 | if (status == Pass::Status::Failure) { |
| 703 | return Pass::Status::Failure; |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | return modified ? Pass::Status::SuccessWithChange |
| 709 | : Pass::Status::SuccessWithoutChange; |
| 710 | } |
nothing calls this directly
no test coverage detected