| 296 | |
| 297 | template <class It> |
| 298 | void Function::ReorderBasicBlocks(It begin, It end) { |
| 299 | // Asserts to make sure every node in the function is in new_order. |
| 300 | assert(ContainsAllBlocksInTheFunction(begin, end)); |
| 301 | |
| 302 | // We have a pointer to all the elements in order, so we can release all |
| 303 | // pointers in |block_|, and then create the new unique pointers from |{begin, |
| 304 | // end}|. |
| 305 | std::for_each(blocks_.begin(), blocks_.end(), |
| 306 | [](std::unique_ptr<BasicBlock>& bb) { bb.release(); }); |
| 307 | std::transform(begin, end, blocks_.begin(), [](BasicBlock* bb) { |
| 308 | return std::unique_ptr<BasicBlock>(bb); |
| 309 | }); |
| 310 | } |
| 311 | |
| 312 | template <class It> |
| 313 | bool Function::ContainsAllBlocksInTheFunction(It begin, It end) { |