1+ #include " move_transactions.h"
12#include " move_utils.h"
23
34#include " globals.h"
45#include " place_util.h"
6+ #include " vtr_assert.h"
7+
8+ t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved (size_t max_blocks){
9+ moved_blocks.reserve (max_blocks);
10+ }
11+
12+ size_t t_pl_blocks_to_be_moved::get_size_and_increment () {
13+ VTR_ASSERT_SAFE (moved_blocks.size () < moved_blocks.capacity ());
14+ moved_blocks.resize (moved_blocks.size () + 1 );
15+ return moved_blocks.size () - 1 ;
16+ }
517
618// Records that block 'blk' should be moved to the specified 'to' location
7- e_block_move_result record_block_move (t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk, t_pl_loc to) {
8- auto res = blocks_affected. moved_to .emplace (to);
9- if (!res. second ) {
19+ e_block_move_result t_pl_blocks_to_be_moved:: record_block_move (ClusterBlockId blk, t_pl_loc to) {
20+ auto [to_it, to_success] = moved_to.emplace (to);
21+ if (!to_success ) {
1022 log_move_abort (" duplicate block move to location" );
1123 return e_block_move_result::ABORT;
1224 }
@@ -15,36 +27,57 @@ e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected,
1527
1628 t_pl_loc from = place_ctx.block_locs [blk].loc ;
1729
18- auto res2 = blocks_affected.moved_from .emplace (from);
19- if (!res2.second ) {
30+ auto [_, from_success] = moved_from.emplace (from);
31+ if (!from_success) {
32+ moved_to.erase (to_it);
2033 log_move_abort (" duplicate block move from location" );
2134 return e_block_move_result::ABORT;
2235 }
2336
2437 VTR_ASSERT_SAFE (to.sub_tile < int (place_ctx.grid_blocks .num_blocks_at_location ({to.x , to.y , to.layer })));
2538
2639 // Sets up the blocks moved
27- int imoved_blk = blocks_affected.num_moved_blocks ;
28- blocks_affected.moved_blocks [imoved_blk].block_num = blk;
29- blocks_affected.moved_blocks [imoved_blk].old_loc = from;
30- blocks_affected.moved_blocks [imoved_blk].new_loc = to;
31- blocks_affected.num_moved_blocks ++;
40+ size_t imoved_blk = get_size_and_increment ();
41+ moved_blocks[imoved_blk].block_num = blk;
42+ moved_blocks[imoved_blk].old_loc = from;
43+ moved_blocks[imoved_blk].new_loc = to;
3244
3345 return e_block_move_result::VALID;
3446}
3547
48+ // Examines the currently proposed move and determine any empty locations
49+ std::set<t_pl_loc> t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved::determine_locations_emptied_by_move () {
50+ std::set<t_pl_loc> moved_from_set;
51+ std::set<t_pl_loc> moved_to_set;
52+
53+ for (const t_pl_moved_block& moved_block : moved_blocks) {
54+ // When a block is moved its old location becomes free
55+ moved_from_set.emplace (moved_block.old_loc );
56+
57+ // But any block later moved to a position fills it
58+ moved_to_set.emplace (moved_block.new_loc );
59+ }
60+
61+ std::set<t_pl_loc> empty_locs;
62+ std::set_difference (moved_from_set.begin (), moved_from_set.end (),
63+ moved_to_set.begin (), moved_to_set.end (),
64+ std::inserter (empty_locs, empty_locs.begin ()));
65+
66+ return empty_locs;
67+ }
68+
3669// Moves the blocks in blocks_affected to their new locations
3770void apply_move_blocks (const t_pl_blocks_to_be_moved& blocks_affected) {
3871 auto & place_ctx = g_vpr_ctx.mutable_placement ();
3972 auto & device_ctx = g_vpr_ctx.device ();
4073
4174 // Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks
4275 // yet since we don't know whether the swap will be accepted
43- for (int iblk = 0 ; iblk < blocks_affected.num_moved_blocks ; ++iblk ) {
44- ClusterBlockId blk = blocks_affected. moved_blocks [iblk] .block_num ;
76+ for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks ) {
77+ ClusterBlockId blk = moved_block .block_num ;
4578
46- const t_pl_loc& old_loc = blocks_affected. moved_blocks [iblk] .old_loc ;
47- const t_pl_loc& new_loc = blocks_affected. moved_blocks [iblk] .new_loc ;
79+ const t_pl_loc& old_loc = moved_block .old_loc ;
80+ const t_pl_loc& new_loc = moved_block .new_loc ;
4881
4982 // move the block to its new location
5083 place_ctx.block_locs [blk].loc = new_loc;
@@ -67,11 +100,11 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
67100 auto & place_ctx = g_vpr_ctx.mutable_placement ();
68101
69102 /* Swap physical location */
70- for (int iblk = 0 ; iblk < blocks_affected.num_moved_blocks ; ++iblk ) {
71- ClusterBlockId blk = blocks_affected. moved_blocks [iblk] .block_num ;
103+ for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks ) {
104+ ClusterBlockId blk = moved_block .block_num ;
72105
73- const t_pl_loc& to = blocks_affected. moved_blocks [iblk] .new_loc ;
74- const t_pl_loc& from = blocks_affected. moved_blocks [iblk] .old_loc ;
106+ const t_pl_loc& to = moved_block .new_loc ;
107+ const t_pl_loc& from = moved_block .old_loc ;
75108
76109 // Remove from old location only if it hasn't already been updated by a previous block update
77110 if (place_ctx.grid_blocks .block_at_location (from) == blk) {
@@ -97,11 +130,11 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
97130 auto & device_ctx = g_vpr_ctx.device ();
98131
99132 // Swap the blocks back, nets not yet swapped they don't need to be changed
100- for (int iblk = 0 ; iblk < blocks_affected.num_moved_blocks ; ++iblk ) {
101- ClusterBlockId blk = blocks_affected. moved_blocks [iblk] .block_num ;
133+ for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks ) {
134+ ClusterBlockId blk = moved_block .block_num ;
102135
103- const t_pl_loc& old_loc = blocks_affected. moved_blocks [iblk] .old_loc ;
104- const t_pl_loc& new_loc = blocks_affected. moved_blocks [iblk] .new_loc ;
136+ const t_pl_loc& old_loc = moved_block .old_loc ;
137+ const t_pl_loc& new_loc = moved_block .new_loc ;
105138
106139 // return the block to where it was before the swap
107140 place_ctx.block_locs [blk].loc = old_loc;
@@ -121,15 +154,15 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
121154}
122155
123156// Clears the current move so a new move can be proposed
124- void clear_move_blocks (t_pl_blocks_to_be_moved& blocks_affected ) {
157+ void t_pl_blocks_to_be_moved:: clear_move_blocks () {
125158 // Reset moved flags
126- blocks_affected. moved_to .clear ();
127- blocks_affected. moved_from .clear ();
159+ moved_to.clear ();
160+ moved_from.clear ();
128161
129- // For run-time, we just reset num_moved_blocks to zero, but do not free the blocks_affected
162+ // For run-time, we just reset size of blocks_affected.moved_blocks to zero, but do not free the blocks_affected
130163 // array to avoid memory allocation
131164
132- blocks_affected. num_moved_blocks = 0 ;
165+ moved_blocks. resize ( 0 ) ;
133166
134- blocks_affected. affected_pins .clear ();
167+ affected_pins.clear ();
135168}
0 commit comments