BlockList rpoSortCfg(const IRUnit& unit) { BlockList blocks; blocks.reserve(unit.numBlocks()); postorderWalk(unit, [&](Block* block) { blocks.push_back(block); }); std::reverse(blocks.begin(), blocks.end()); assert(blocks.size() <= unit.numBlocks()); return blocks; }
BlockList rpoSortCfg(IRTrace* trace, const IRFactory& factory) { assert(trace->isMain()); BlockList blocks; blocks.reserve(factory.numBlocks()); unsigned next_id = 0; postorderWalk( [&](Block* block) { block->setPostId(next_id++); blocks.push_back(block); }, factory.numBlocks(), trace->front() ); std::reverse(blocks.begin(), blocks.end()); assert(blocks.size() <= factory.numBlocks()); assert(next_id <= factory.numBlocks()); return blocks; }