| 1642 | } |
| 1643 | |
| 1644 | void module::repeat_while_changes(std::size_t n, const std::function<void()>& f) |
| 1645 | { |
| 1646 | if(n == 0) |
| 1647 | return; |
| 1648 | if(n == 1) |
| 1649 | { |
| 1650 | f(); |
| 1651 | return; |
| 1652 | } |
| 1653 | auto has_changed = impl->changed.subscribe(); |
| 1654 | for(auto i : range(n)) |
| 1655 | { |
| 1656 | f(); |
| 1657 | if(not has_changed) |
| 1658 | break; |
| 1659 | (void)i; |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | // Hoists external inputs (instructions not in the dependency chain between start_ins and end_ins) |
| 1664 | // to before start_ins, while preserving topological order |