| 651 | } |
| 652 | |
| 653 | Pass::Status SSARewriter::RewriteFunctionIntoSSA(Function* fp) { |
| 654 | #if SSA_REWRITE_DEBUGGING_LEVEL > 0 |
| 655 | std::cerr << "Function before SSA rewrite:\n" |
| 656 | << fp->PrettyPrint(0) << "\n\n\n"; |
| 657 | #endif |
| 658 | |
| 659 | // Collect variables that can be converted into SSA IDs. |
| 660 | pass_->CollectTargetVars(fp); |
| 661 | |
| 662 | // Generate all the SSA replacements and Phi candidates. This will |
| 663 | // generate incomplete and trivial Phis. |
| 664 | bool succeeded = pass_->cfg()->WhileEachBlockInReversePostOrder( |
| 665 | fp->entry().get(), [this](BasicBlock* bb) { |
| 666 | if (!GenerateSSAReplacements(bb)) { |
| 667 | return false; |
| 668 | } |
| 669 | return true; |
| 670 | }); |
| 671 | |
| 672 | if (!succeeded) { |
| 673 | return Pass::Status::Failure; |
| 674 | } |
| 675 | |
| 676 | // Remove trivial Phis and add arguments to incomplete Phis. |
| 677 | FinalizePhiCandidates(); |
| 678 | |
| 679 | // Finally, apply all the replacements in the IR. |
| 680 | bool modified = ApplyReplacements(); |
| 681 | |
| 682 | #if SSA_REWRITE_DEBUGGING_LEVEL > 0 |
| 683 | std::cerr << "\n\n\nFunction after SSA rewrite:\n" |
| 684 | << fp->PrettyPrint(0) << "\n"; |
| 685 | #endif |
| 686 | |
| 687 | return modified ? Pass::Status::SuccessWithChange |
| 688 | : Pass::Status::SuccessWithoutChange; |
| 689 | } |
| 690 | |
| 691 | Pass::Status SSARewritePass::Process() { |
| 692 | Status status = Status::SuccessWithoutChange; |
no test coverage detected