Block* findMainExitBlock(const IRUnit& unit, SrcKey lastSk) { Block* mainExit = nullptr; FTRACE(5, "findMainExitBlock: starting on unit:\n{}\n", show(unit)); for (auto block : rpoSortCfg(unit)) { if (endsUnitAtSrcKey(block, lastSk)) { if (mainExit == nullptr) { mainExit = block; continue; } always_assert_flog( mainExit->hint() == Block::Hint::Unlikely || block->hint() == Block::Hint::Unlikely, "findMainExit: 2 likely exits found: B{} and B{}\nlastSk = {}", mainExit->id(), block->id(), showShort(lastSk)); if (mainExit->hint() == Block::Hint::Unlikely) mainExit = block; } } always_assert_flog(mainExit, "findMainExit: no exit found for lastSk = {}", showShort(lastSk)); FTRACE(5, "findMainExitBlock: mainExit = B{}\n", mainExit->id()); return mainExit; }
Block* findMainExitBlock(const IRUnit& unit, SrcKey lastSk) { bool unreachable = false; Block* mainExit = nullptr; FTRACE(5, "findMainExitBlock: looking for exit at {} in unit:\n{}\n", showShort(lastSk), show(unit)); for (auto block : rpoSortCfg(unit)) { if (block->back().is(Unreachable)) unreachable = true; if (endsUnitAtSrcKey(block, lastSk)) { if (mainExit == nullptr) { mainExit = block; continue; } always_assert_flog( mainExit->hint() == Block::Hint::Unlikely || block->hint() == Block::Hint::Unlikely, "findMainExit: 2 likely exits found: B{} and B{}\nlastSk = {}", mainExit->id(), block->id(), showShort(lastSk) ); if (mainExit->hint() == Block::Hint::Unlikely) mainExit = block; } } always_assert_flog( mainExit || unreachable, "findMainExit: no exit found for lastSk = {}", showShort(lastSk) ); FTRACE(5, "findMainExitBlock: mainExit = B{}\n", mainExit->id()); return mainExit; }