1
+ #include " move_transactions.h"
1
2
#include " move_utils.h"
2
3
3
4
#include " globals.h"
6
7
7
8
t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved (size_t max_blocks){
8
9
moved_blocks.reserve (max_blocks);
9
- moved_blocks.resize (0 );
10
10
}
11
11
12
12
size_t t_pl_blocks_to_be_moved::get_size_and_increment () {
@@ -16,9 +16,9 @@ size_t t_pl_blocks_to_be_moved::get_size_and_increment() {
16
16
}
17
17
18
18
// Records that block 'blk' should be moved to the specified 'to' location
19
- e_block_move_result record_block_move (t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk, t_pl_loc to) {
20
- auto res = blocks_affected. moved_to .emplace (to);
21
- 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 ) {
22
22
log_move_abort (" duplicate block move to location" );
23
23
return e_block_move_result::ABORT;
24
24
}
@@ -27,35 +27,57 @@ e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected,
27
27
28
28
t_pl_loc from = place_ctx.block_locs [blk].loc ;
29
29
30
- auto res2 = blocks_affected.moved_from .emplace (from);
31
- if (!res2.second ) {
30
+ auto [_, from_success] = moved_from.emplace (from);
31
+ if (!from_success) {
32
+ moved_to.erase (to_it);
32
33
log_move_abort (" duplicate block move from location" );
33
34
return e_block_move_result::ABORT;
34
35
}
35
36
36
37
VTR_ASSERT_SAFE (to.sub_tile < int (place_ctx.grid_blocks .num_blocks_at_location ({to.x , to.y , to.layer })));
37
38
38
39
// Sets up the blocks moved
39
- size_t imoved_blk = blocks_affected. get_size_and_increment ();
40
- blocks_affected. moved_blocks [imoved_blk].block_num = blk;
41
- blocks_affected. moved_blocks [imoved_blk].old_loc = from;
42
- blocks_affected. moved_blocks [imoved_blk].new_loc = to;
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;
43
44
44
45
return e_block_move_result::VALID;
45
46
}
46
47
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
+
47
69
// Moves the blocks in blocks_affected to their new locations
48
70
void apply_move_blocks (const t_pl_blocks_to_be_moved& blocks_affected) {
49
71
auto & place_ctx = g_vpr_ctx.mutable_placement ();
50
72
auto & device_ctx = g_vpr_ctx.device ();
51
73
52
74
// Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks
53
75
// yet since we don't know whether the swap will be accepted
54
- for (const auto & block : blocks_affected.moved_blocks ) {
55
- ClusterBlockId blk = block .block_num ;
76
+ for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks ) {
77
+ ClusterBlockId blk = moved_block .block_num ;
56
78
57
- const t_pl_loc& old_loc = block .old_loc ;
58
- const t_pl_loc& new_loc = block .new_loc ;
79
+ const t_pl_loc& old_loc = moved_block .old_loc ;
80
+ const t_pl_loc& new_loc = moved_block .new_loc ;
59
81
60
82
// move the block to its new location
61
83
place_ctx.block_locs [blk].loc = new_loc;
@@ -78,11 +100,11 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
78
100
auto & place_ctx = g_vpr_ctx.mutable_placement ();
79
101
80
102
/* Swap physical location */
81
- for (const auto & block : blocks_affected.moved_blocks ) {
82
- ClusterBlockId blk = block .block_num ;
103
+ for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks ) {
104
+ ClusterBlockId blk = moved_block .block_num ;
83
105
84
- const t_pl_loc& to = block .new_loc ;
85
- const t_pl_loc& from = block .old_loc ;
106
+ const t_pl_loc& to = moved_block .new_loc ;
107
+ const t_pl_loc& from = moved_block .old_loc ;
86
108
87
109
// Remove from old location only if it hasn't already been updated by a previous block update
88
110
if (place_ctx.grid_blocks .block_at_location (from) == blk) {
@@ -108,11 +130,11 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
108
130
auto & device_ctx = g_vpr_ctx.device ();
109
131
110
132
// Swap the blocks back, nets not yet swapped they don't need to be changed
111
- for (const auto & block : blocks_affected.moved_blocks ) {
112
- ClusterBlockId blk = block .block_num ;
133
+ for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks ) {
134
+ ClusterBlockId blk = moved_block .block_num ;
113
135
114
- const t_pl_loc& old_loc = block .old_loc ;
115
- const t_pl_loc& new_loc = block .new_loc ;
136
+ const t_pl_loc& old_loc = moved_block .old_loc ;
137
+ const t_pl_loc& new_loc = moved_block .new_loc ;
116
138
117
139
// return the block to where it was before the swap
118
140
place_ctx.block_locs [blk].loc = old_loc;
@@ -132,15 +154,15 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
132
154
}
133
155
134
156
// Clears the current move so a new move can be proposed
135
- void clear_move_blocks (t_pl_blocks_to_be_moved& blocks_affected ) {
157
+ void t_pl_blocks_to_be_moved:: clear_move_blocks () {
136
158
// Reset moved flags
137
- blocks_affected. moved_to .clear ();
138
- blocks_affected. moved_from .clear ();
159
+ moved_to.clear ();
160
+ moved_from.clear ();
139
161
140
162
// For run-time, we just reset size of blocks_affected.moved_blocks to zero, but do not free the blocks_affected
141
163
// array to avoid memory allocation
142
164
143
- blocks_affected. moved_blocks .resize (0 );
165
+ moved_blocks.resize (0 );
144
166
145
- blocks_affected. affected_pins .clear ();
167
+ affected_pins.clear ();
146
168
}
0 commit comments