@@ -318,6 +318,7 @@ static e_find_affected_blocks_result identify_macro_self_swap_affected_macros(st
318
318
static e_find_affected_blocks_result record_macro_self_swaps (const int imacro, t_pl_offset swap_offset);
319
319
320
320
bool is_legal_swap_to_location (ClusterBlockId blk, t_pl_loc to);
321
+ bool is_legal_blk_swap (t_pl_loc from, t_pl_loc to);
321
322
322
323
std::set<t_pl_loc> determine_locations_emptied_by_move ();
323
324
@@ -1675,23 +1676,38 @@ bool is_legal_swap_to_location(ClusterBlockId blk, t_pl_loc to) {
1675
1676
auto blk_type_from = cluster_ctx.clb_nlist .block_type (blk);
1676
1677
auto blk_type_to = device_ctx.grid [to.x ][to.y ].type ;
1677
1678
1678
- // First check is to see if `from` type can be placed in `to` type
1679
+ // Check is to see if `from` type can be placed in `to` type
1679
1680
if (!blk_type_from->is_available_tile_index (blk_type_to->index )) {
1680
1681
return false ;
1681
1682
}
1682
1683
1683
1684
t_pl_loc from = place_ctx.block_locs [blk].loc ;
1685
+ if (!is_legal_blk_swap (from, to)) {
1686
+ return false ;
1687
+ }
1688
+
1689
+ return true ;
1690
+ }
1691
+
1692
+ bool is_legal_blk_swap (t_pl_loc from, t_pl_loc to) {
1693
+ // Make sure that when swapping, the block in the `to` location
1694
+ // can be moved in the `from` location
1695
+
1696
+ auto & device_ctx = g_vpr_ctx.device ();
1697
+ auto & cluster_ctx = g_vpr_ctx.clustering ();
1698
+ auto & place_ctx = g_vpr_ctx.placement ();
1699
+
1684
1700
ClusterBlockId blk_to = place_ctx.grid_blocks [to.x ][to.y ].blocks [to.z ];
1685
1701
1686
1702
// In case `blk_to` is empty we can skip the second check
1687
1703
if (blk_to == EMPTY_BLOCK_ID) {
1688
1704
return true ;
1689
1705
}
1690
1706
1691
- blk_type_from = device_ctx.grid [from.x ][from.y ].type ;
1692
- blk_type_to = cluster_ctx.clb_nlist .block_type (blk_to);
1707
+ auto blk_type_from = device_ctx.grid [from.x ][from.y ].type ;
1708
+ auto blk_type_to = cluster_ctx.clb_nlist .block_type (blk_to);
1693
1709
1694
- // Second check is to see if `to` type can be placed in `from` type
1710
+ // Check is to see if `to` type can be placed in `from` type
1695
1711
if (!blk_type_to->is_available_tile_index (blk_type_from->index )) {
1696
1712
return false ;
1697
1713
}
@@ -2179,7 +2195,7 @@ static bool find_to(t_type_ptr to_type, t_type_ptr from_type, float rlim, const
2179
2195
VTR_ASSERT_MSG (device_ctx.grid [to.x ][to.y ].width_offset == 0 , " Should be at block base location" );
2180
2196
VTR_ASSERT_MSG (device_ctx.grid [to.x ][to.y ].height_offset == 0 , " Should be at block base location" );
2181
2197
2182
- return true ;
2198
+ return is_legal_blk_swap (from, to) ;
2183
2199
}
2184
2200
2185
2201
static e_swap_result assess_swap (double delta_c, double t) {
0 commit comments