|
1 | 1 |
|
2 | 2 | #include "blk_loc_registry.h" |
| 3 | + |
| 4 | +#include "move_transactions.h" |
3 | 5 | #include "globals.h" |
4 | 6 |
|
| 7 | +BlkLocRegistry::BlkLocRegistry() |
| 8 | + : expected_transaction_(e_expected_transaction::APPLY) {} |
| 9 | + |
5 | 10 | const vtr::vector_map<ClusterBlockId, t_block_loc>& BlkLocRegistry::block_locs() const { |
6 | 11 | return block_locs_; |
7 | 12 | } |
@@ -112,3 +117,93 @@ void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk) |
112 | 117 | } |
113 | 118 | } |
114 | 119 | } |
| 120 | + |
| 121 | +void BlkLocRegistry::apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { |
| 122 | + auto& device_ctx = g_vpr_ctx.device(); |
| 123 | + |
| 124 | + VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::APPLY); |
| 125 | + |
| 126 | + // Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks |
| 127 | + // yet since we don't know whether the swap will be accepted |
| 128 | + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { |
| 129 | + ClusterBlockId blk = moved_block.block_num; |
| 130 | + |
| 131 | + const t_pl_loc& old_loc = moved_block.old_loc; |
| 132 | + const t_pl_loc& new_loc = moved_block.new_loc; |
| 133 | + |
| 134 | + // move the block to its new location |
| 135 | + block_locs_[blk].loc = new_loc; |
| 136 | + |
| 137 | + // get physical tile type of the old location |
| 138 | + t_physical_tile_type_ptr old_type = device_ctx.grid.get_physical_type({old_loc.x,old_loc.y,old_loc.layer}); |
| 139 | + // get physical tile type of the new location |
| 140 | + t_physical_tile_type_ptr new_type = device_ctx.grid.get_physical_type({new_loc.x,new_loc.y, new_loc.layer}); |
| 141 | + |
| 142 | + // if physical tile type of old location does not equal physical tile type of new location, sync the new physical pins |
| 143 | + if (old_type != new_type) { |
| 144 | + place_sync_external_block_connections(blk); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + expected_transaction_ = e_expected_transaction::COMMIT_REVERT; |
| 149 | +} |
| 150 | + |
| 151 | +void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { |
| 152 | + VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT); |
| 153 | + |
| 154 | + // Swap physical location |
| 155 | + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { |
| 156 | + ClusterBlockId blk = moved_block.block_num; |
| 157 | + |
| 158 | + const t_pl_loc& to = moved_block.new_loc; |
| 159 | + const t_pl_loc& from = moved_block.old_loc; |
| 160 | + |
| 161 | + // Remove from old location only if it hasn't already been updated by a previous block update |
| 162 | + if (grid_blocks_.block_at_location(from) == blk) { |
| 163 | + grid_blocks_.set_block_at_location(from, ClusterBlockId::INVALID()); |
| 164 | + grid_blocks_.decrement_usage({from.x, from.y, from.layer}); |
| 165 | + } |
| 166 | + |
| 167 | + // Add to new location |
| 168 | + if (grid_blocks_.block_at_location(to) == ClusterBlockId::INVALID()) { |
| 169 | + //Only need to increase usage if previously unused |
| 170 | + grid_blocks_.increment_usage({to.x, to.y, to.layer}); |
| 171 | + } |
| 172 | + grid_blocks_.set_block_at_location(to, blk); |
| 173 | + |
| 174 | + } // Finish updating clb for all blocks |
| 175 | + |
| 176 | + expected_transaction_ = e_expected_transaction::APPLY; |
| 177 | +} |
| 178 | + |
| 179 | +void BlkLocRegistry::revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { |
| 180 | + auto& device_ctx = g_vpr_ctx.device(); |
| 181 | + |
| 182 | + VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT); |
| 183 | + |
| 184 | + // Swap the blocks back, nets not yet swapped they don't need to be changed |
| 185 | + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { |
| 186 | + ClusterBlockId blk = moved_block.block_num; |
| 187 | + |
| 188 | + const t_pl_loc& old_loc = moved_block.old_loc; |
| 189 | + const t_pl_loc& new_loc = moved_block.new_loc; |
| 190 | + |
| 191 | + // return the block to where it was before the swap |
| 192 | + block_locs_[blk].loc = old_loc; |
| 193 | + |
| 194 | + // get physical tile type of the old location |
| 195 | + t_physical_tile_type_ptr old_type = device_ctx.grid.get_physical_type({old_loc.x, old_loc.y, old_loc.layer}); |
| 196 | + // get physical tile type of the new location |
| 197 | + t_physical_tile_type_ptr new_type = device_ctx.grid.get_physical_type({new_loc.x, new_loc.y, new_loc.layer}); |
| 198 | + |
| 199 | + // if physical tile type of old location does not equal physical tile type of new location, sync the new physical pins |
| 200 | + if (old_type != new_type) { |
| 201 | + place_sync_external_block_connections(blk); |
| 202 | + } |
| 203 | + |
| 204 | + VTR_ASSERT_SAFE_MSG(grid_blocks_.block_at_location(old_loc) == blk, |
| 205 | + "Grid blocks should only have been updated if swap committed (not reverted)"); |
| 206 | + } |
| 207 | + |
| 208 | + expected_transaction_ = e_expected_transaction::APPLY; |
| 209 | +} |
0 commit comments