| 686 | // ============================ |
| 687 | |
| 688 | Error BaseRAPass::remove_unreachable_code() noexcept { |
| 689 | size_t num_all_blocks = block_count(); |
| 690 | size_t num_reachable_blocks = reachable_block_count(); |
| 691 | |
| 692 | // All reachable -> nothing to do. |
| 693 | if (num_all_blocks == num_reachable_blocks) { |
| 694 | return Error::kOk; |
| 695 | } |
| 696 | |
| 697 | #ifndef ASMJIT_NO_LOGGING |
| 698 | Logger* logger = logger_if(DiagnosticOptions::kRADebugUnreachable); |
| 699 | String& sb = _tmp_string; |
| 700 | ASMJIT_RA_LOG_FORMAT("[remove_unreachable_code - detected %zu of %zu unreachable blocks]\n", num_all_blocks - num_reachable_blocks, num_all_blocks); |
| 701 | #endif |
| 702 | |
| 703 | for (RABlock* block : _blocks.iterate()) { |
| 704 | if (block->is_reachable()) { |
| 705 | continue; |
| 706 | } |
| 707 | |
| 708 | ASMJIT_RA_LOG_FORMAT(" removing code from unreachable block {%u}\n", uint32_t(block->block_id())); |
| 709 | BaseNode* first = block->first(); |
| 710 | BaseNode* last = block->last(); |
| 711 | |
| 712 | BaseNode* before_first = first->prev(); |
| 713 | BaseNode* after_last = last->next(); |
| 714 | |
| 715 | BaseNode* node = first; |
| 716 | while (node != after_last) { |
| 717 | BaseNode* next = node->next(); |
| 718 | |
| 719 | if (node->is_code() || node->is_removable()) { |
| 720 | #ifndef ASMJIT_NO_LOGGING |
| 721 | if (logger) { |
| 722 | sb.clear(); |
| 723 | Formatter::format_node(sb, _format_options, &_cb, node); |
| 724 | logger->logf(" %s\n", sb.data()); |
| 725 | } |
| 726 | #endif |
| 727 | cc().remove_node(node); |
| 728 | } |
| 729 | node = next; |
| 730 | } |
| 731 | |
| 732 | if (before_first->next() == after_last) { |
| 733 | block->set_first(nullptr); |
| 734 | block->set_last(nullptr); |
| 735 | } |
| 736 | else { |
| 737 | block->set_first(before_first->next()); |
| 738 | block->set_last(after_last->prev()); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return Error::kOk; |
| 743 | } |
| 744 | |
| 745 | BaseNode* BaseRAPass::find_successor_starting_at(BaseNode* node) noexcept { |
nothing calls this directly
no test coverage detected