Skip to content

Commit f7b183a

Browse files
remove EMPTY_BLOCK_ID
1 parent 8084079 commit f7b183a

16 files changed

+44
-48
lines changed

vpr/src/base/grid_block.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
#include <vector>
99

10-
/* Defining macros for the placement_ctx t_grid_blocks. Assumes that ClusterBlockId's won't exceed positive 32-bit integers */
11-
constexpr auto EMPTY_BLOCK_ID = ClusterBlockId(-1);
12-
1310
///@brief Stores the clustered blocks placed at a particular grid location
1411
struct t_grid_blocks {
1512
int usage; ///<How many valid blocks are in use at this location
@@ -29,7 +26,7 @@ struct t_grid_blocks {
2926
* as the z-dimensional offset in the grid indexing.
3027
*/
3128
inline bool subtile_empty(size_t isubtile) const {
32-
return blocks[isubtile] == EMPTY_BLOCK_ID;
29+
return blocks[isubtile] == ClusterBlockId::INVALID();
3330
}
3431
};
3532

@@ -42,7 +39,7 @@ class GridBlock {
4239
}
4340

4441
inline void initialized_grid_block_at_location(const t_physical_tile_loc& loc, int num_sub_tiles) {
45-
grid_blocks_[loc.layer_num][loc.x][loc.y].blocks.resize(num_sub_tiles, EMPTY_BLOCK_ID);
42+
grid_blocks_[loc.layer_num][loc.x][loc.y].blocks.resize(num_sub_tiles, ClusterBlockId::INVALID());
4643
}
4744

4845
inline void set_block_at_location(const t_pl_loc& loc, ClusterBlockId blk_id) {

vpr/src/draw/draw.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,14 +1003,14 @@ static void highlight_blocks(double x, double y) {
10031003

10041004
char msg[vtr::bufsize];
10051005
ClusterBlockId clb_index = get_cluster_block_id_from_xy_loc(x, y);
1006-
if (clb_index == EMPTY_BLOCK_ID || clb_index == ClusterBlockId::INVALID()) {
1006+
if (clb_index == ClusterBlockId::INVALID()) {
10071007
return; /* Nothing was found on any layer*/
10081008
}
10091009

10101010
auto& cluster_ctx = g_vpr_ctx.clustering();
10111011
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
10121012

1013-
VTR_ASSERT(clb_index != EMPTY_BLOCK_ID);
1013+
VTR_ASSERT(clb_index != ClusterBlockId::INVALID());
10141014

10151015
ezgl::rectangle clb_bbox = draw_coords->get_absolute_clb_bbox(clb_index, cluster_ctx.clb_nlist.block_type(clb_index));
10161016
// note: this will clear the selected sub-block if show_blk_internal is 0,
@@ -1049,7 +1049,7 @@ static void highlight_blocks(double x, double y) {
10491049
ClusterBlockId get_cluster_block_id_from_xy_loc(double x, double y) {
10501050
t_draw_coords* draw_coords = get_draw_coords_vars();
10511051
t_draw_state* draw_state = get_draw_state_vars();
1052-
ClusterBlockId clb_index = EMPTY_BLOCK_ID;
1052+
auto clb_index = ClusterBlockId::INVALID();
10531053
auto& device_ctx = g_vpr_ctx.device();
10541054
auto& cluster_ctx = g_vpr_ctx.clustering();
10551055
const auto& grid_blocks = get_graphics_blk_loc_registry_ref().grid_blocks();
@@ -1076,20 +1076,20 @@ ClusterBlockId get_cluster_block_id_from_xy_loc(double x, double y) {
10761076
const auto& type = device_ctx.grid.get_physical_type({i, j, layer_num});
10771077
for (int k = 0; k < type->capacity; ++k) {
10781078
clb_index = grid_blocks.block_at_location({i, j, k, layer_num});
1079-
if (clb_index != EMPTY_BLOCK_ID) {
1079+
if (clb_index) {
10801080
clb_bbox = draw_coords->get_absolute_clb_bbox(clb_index,
10811081
cluster_ctx.clb_nlist.block_type(clb_index));
10821082
if (clb_bbox.contains({x, y})) {
10831083
return clb_index; // we've found the clb
10841084
} else {
1085-
clb_index = EMPTY_BLOCK_ID;
1085+
clb_index = ClusterBlockId::INVALID();
10861086
}
10871087
}
10881088
}
10891089
}
10901090
}
10911091
}
1092-
// Searched all layers and found no clb at specified location, returning clb_index = EMPTY_BLOCK_ID.
1092+
// Searched all layers and found no clb at specified location, returning clb_index = ClusterBlockId::INVALID().
10931093
return clb_index;
10941094
}
10951095

vpr/src/draw/draw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ t_draw_layer_display get_element_visibility_and_transparency(int src_layer, int
162162
* @param x
163163
* @param y
164164
* @return returns the ClusterBlockId of the clb at the specified (x,y) location (in world coordinates) as seen by looking downwards from the top of a 3D FPGA.
165-
* Chooses the clb on the top visible layer if there are overlapping blocks. Returns EMPTY_BLOCK_ID (-1) otherwise,if clb is not found on any visible layer.
165+
* Chooses the clb on the top visible layer if there are overlapping blocks. Returns INVALID(-1) otherwise,if clb is not found on any visible layer.
166166
*/
167167
ClusterBlockId get_cluster_block_id_from_xy_loc(double x, double y);
168168

vpr/src/draw/draw_basic.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void drawplace(ezgl::renderer* g) {
158158
}
159159
// No color specified at this location; use the block color.
160160
if (!current_loc_is_highlighted) {
161-
if (bnum != EMPTY_BLOCK_ID) {
161+
if (bnum) {
162162
block_color = draw_state->block_color(bnum);
163163
} else {
164164
block_color = get_block_type_color(type);
@@ -182,15 +182,14 @@ void drawplace(ezgl::renderer* g) {
182182

183183
g->set_color(ezgl::BLACK, transparency_factor);
184184

185-
g->set_line_dash(
186-
(EMPTY_BLOCK_ID == bnum) ? ezgl::line_dash::asymmetric_5_3 : ezgl::line_dash::none);
185+
g->set_line_dash((bnum == ClusterBlockId::INVALID()) ? ezgl::line_dash::asymmetric_5_3 : ezgl::line_dash::none);
187186
if (draw_state->draw_block_outlines) {
188187
g->draw_rectangle(abs_clb_bbox);
189188
}
190189

191190
if (draw_state->draw_block_text) {
192191
/* Draw text if the space has parts of the netlist */
193-
if (bnum != EMPTY_BLOCK_ID) {
192+
if (bnum) {
194193
std::string name = cluster_ctx.clb_nlist.block_name(
195194
bnum)
196195
+ vtr::string_fmt(" (#%zu)", size_t(bnum));

vpr/src/draw/intra_logic_block.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void draw_internal_draw_subblk(ezgl::renderer* g) {
175175
int num_sub_tiles = type->capacity;
176176
for (int k = 0; k < num_sub_tiles; ++k) {
177177
/* Don't draw if block is empty. */
178-
if (grid_blocks.block_at_location({i, j, k, layer_num}) == EMPTY_BLOCK_ID) {
178+
if (!grid_blocks.block_at_location({i, j, k, layer_num})) {
179179
continue;
180180
}
181181

vpr/src/draw/manual_moves.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ bool is_manual_move_legal(ClusterBlockId block_id, t_pl_loc to) {
174174

175175
//If the destination block is user constrained, abort this swap
176176
ClusterBlockId b_to = grid_blocks.block_at_location(to);
177-
if (b_to != EMPTY_BLOCK_ID) {
177+
if (b_to) {
178178
if (get_graphics_blk_loc_registry_ref().block_locs()[b_to].is_fixed) {
179179
invalid_breakpoint_entry_window("Block is fixed");
180180
return false;

vpr/src/draw/search_bar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void highlight_cluster_block(ClusterBlockId clb_index) {
288288
/// determine block ///
289289
ezgl::rectangle clb_bbox;
290290

291-
VTR_ASSERT(clb_index != EMPTY_BLOCK_ID);
291+
VTR_ASSERT(clb_index != ClusterBlockId::INVALID());
292292

293293
ezgl::point2d point_in_clb = clb_bbox.bottom_left();
294294
highlight_sub_block(point_in_clb, clb_index, cluster_ctx.clb_nlist.block_pb(clb_index));

vpr/src/place/cut_spreader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ void CutSpreader::bind_tile(t_pl_loc sub_tile, ClusterBlockId blk) {
965965
auto& grid_blocks = ap->blk_loc_registry_ref_.mutable_grid_blocks();
966966
auto& block_locs = ap->blk_loc_registry_ref_.mutable_block_locs();
967967

968-
VTR_ASSERT(grid_blocks.block_at_location(sub_tile) == EMPTY_BLOCK_ID);
968+
VTR_ASSERT(grid_blocks.block_at_location(sub_tile) == ClusterBlockId::INVALID());
969969
VTR_ASSERT(block_locs[blk].is_fixed == false);
970970
grid_blocks.set_block_at_location(sub_tile, blk);
971971
block_locs[blk].loc = sub_tile;
@@ -982,11 +982,11 @@ void CutSpreader::unbind_tile(t_pl_loc sub_tile) {
982982
auto& grid_blocks = ap->blk_loc_registry_ref_.mutable_grid_blocks();
983983
auto& block_locs = ap->blk_loc_registry_ref_.mutable_block_locs();
984984

985-
VTR_ASSERT(grid_blocks.block_at_location(sub_tile) != EMPTY_BLOCK_ID);
985+
VTR_ASSERT(grid_blocks.block_at_location(sub_tile) != ClusterBlockId::INVALID());
986986
ClusterBlockId blk = grid_blocks.block_at_location(sub_tile);
987987
VTR_ASSERT(block_locs[blk].is_fixed == false);
988988
block_locs[blk].loc = t_pl_loc{};
989-
grid_blocks.set_block_at_location(sub_tile, EMPTY_BLOCK_ID);
989+
grid_blocks.set_block_at_location(sub_tile, ClusterBlockId::INVALID());
990990
grid_blocks.set_usage({sub_tile.x, sub_tile.y, sub_tile.layer},
991991
grid_blocks.get_usage({sub_tile.x, sub_tile.y, sub_tile.layer}) - 1);
992992
}
@@ -1040,7 +1040,7 @@ bool CutSpreader::try_place_blk(ClusterBlockId blk,
10401040
if (exceeds_explore_limit && best_subtile != t_pl_loc{}) {
10411041
// find the logic block bound to (placed on) best_subtile
10421042
ClusterBlockId bound_blk = grid_blocks.block_at_location(best_subtile);
1043-
if (bound_blk != EMPTY_BLOCK_ID) { // if best_subtile has a logic block
1043+
if (bound_blk) { // if best_subtile has a logic block
10441044
unbind_tile(best_subtile); // clear bound_block and best_subtile's placement info
10451045
remaining.emplace(1, bound_blk); // put bound_blk back into remaining blocks to place
10461046
}
@@ -1051,7 +1051,7 @@ bool CutSpreader::try_place_blk(ClusterBlockId blk,
10511051
// if exploration limit is not met or a candidate sub_tile is not found yet
10521052
for (auto sub_t : subtiles_at_location[nx][ny]) { // for each available sub_tile at random location
10531053
ClusterBlockId bound_blk = grid_blocks.block_at_location(sub_t); // logic blk at [nx, ny]
1054-
if (bound_blk == EMPTY_BLOCK_ID
1054+
if (bound_blk == ClusterBlockId::INVALID()
10551055
|| ripup_radius_met
10561056
|| rand() % (20000) < 10) {
10571057
/* conditions when a sub_tile at nx, ny is considered:
@@ -1061,7 +1061,7 @@ bool CutSpreader::try_place_blk(ClusterBlockId blk,
10611061
* OR
10621062
* 2) a 0.05% chance of acceptance.
10631063
*/
1064-
if (bound_blk != EMPTY_BLOCK_ID && imacro(bound_blk) != NO_MACRO)
1064+
if (bound_blk && imacro(bound_blk) != NO_MACRO)
10651065
// do not sub_tiles when the block placed on it is part of a macro, as they have higher priority
10661066
continue;
10671067
if (!exceeds_explore_limit) { // if still in exploration phase, find best_subtile with smallest best_inp_len
@@ -1084,7 +1084,7 @@ bool CutSpreader::try_place_blk(ClusterBlockId blk,
10841084
}
10851085
break;
10861086
} else { // exploration phase passed and still no best_subtile yet, choose the next compatible sub_tile
1087-
if (bound_blk != EMPTY_BLOCK_ID) {
1087+
if (bound_blk) {
10881088
remaining.emplace(1, bound_blk);
10891089
unbind_tile(sub_t); // remove bound_blk and place blk on sub_t
10901090
}
@@ -1136,7 +1136,7 @@ bool CutSpreader::try_place_macro(ClusterBlockId blk,
11361136
// if the target location has a logic block, ensure it's not part of a macro
11371137
// because a macro placed before the current one has higher priority (longer chain)
11381138
ClusterBlockId bound = grid_blocks.block_at_location(target);
1139-
if (bound != EMPTY_BLOCK_ID && imacro(bound) != NO_MACRO) {
1139+
if (bound && imacro(bound) != NO_MACRO) {
11401140
placement_impossible = true;
11411141
break;
11421142
}
@@ -1155,7 +1155,7 @@ bool CutSpreader::try_place_macro(ClusterBlockId blk,
11551155
if (!placement_impossible) { // if placement is possible, apply this placement
11561156
for (auto& target : targets) {
11571157
ClusterBlockId bound = grid_blocks.block_at_location(target.second);
1158-
if (bound != EMPTY_BLOCK_ID) {
1158+
if (bound) {
11591159
// if target location has a logic block, displace it and put it in remaining queue to be placed later
11601160
unbind_tile(target.second);
11611161
remaining.emplace(1, bound);

vpr/src/place/initial_placement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ bool try_place_macro_exhaustively(const t_pl_macro& pl_macro,
791791
int subtile = regions[reg].get_sub_tile();
792792

793793
to_loc.sub_tile = subtile;
794-
if (grid_blocks.block_at_location(to_loc) == EMPTY_BLOCK_ID) {
794+
if (grid_blocks.block_at_location(to_loc) == ClusterBlockId::INVALID()) {
795795
placed = try_place_macro(pl_macro, to_loc, blk_loc_registry);
796796

797797
if (placed) {
@@ -806,7 +806,7 @@ bool try_place_macro_exhaustively(const t_pl_macro& pl_macro,
806806

807807
for (int st = st_low; st <= st_high && !placed; st++) {
808808
to_loc.sub_tile = st;
809-
if (grid_blocks.block_at_location(to_loc) == EMPTY_BLOCK_ID) {
809+
if (grid_blocks.block_at_location(to_loc) == ClusterBlockId::INVALID()) {
810810
placed = try_place_macro(pl_macro, to_loc, blk_loc_registry);
811811
if (placed) {
812812
fix_IO_block_types(pl_macro, to_loc, pad_loc_type, block_locs);
@@ -877,7 +877,7 @@ bool try_place_macro(const t_pl_macro& pl_macro,
877877
bool macro_placed = false;
878878

879879
// If that location is occupied, do nothing.
880-
if (grid_blocks.block_at_location(head_pos) != EMPTY_BLOCK_ID) {
880+
if (grid_blocks.block_at_location(head_pos)) {
881881
return macro_placed;
882882
}
883883

@@ -1134,7 +1134,7 @@ static void clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_b
11341134
if (clear_all_block_types || unplaced_blk_types_index.count(itype)) {
11351135
grid_blocks.set_usage({i, j, layer_num}, 0);
11361136
for (int k = 0; k < device_ctx.physical_tile_types[itype].capacity; k++) {
1137-
grid_blocks.set_block_at_location({i, j, k, layer_num}, EMPTY_BLOCK_ID);
1137+
grid_blocks.set_block_at_location({i, j, k, layer_num}, ClusterBlockId::INVALID());
11381138
}
11391139
}
11401140
}

vpr/src/place/move_transactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected,
109109

110110
//Remove from old location only if it hasn't already been updated by a previous block update
111111
if (grid_blocks.block_at_location(from) == blk) {
112-
grid_blocks.set_block_at_location(from, EMPTY_BLOCK_ID);
112+
grid_blocks.set_block_at_location(from, ClusterBlockId::INVALID());
113113
grid_blocks.set_usage({from.x, from.y, from.layer},
114114
grid_blocks.get_usage({from.x, from.y, from.layer}) - 1);
115115
}
116116

117117
//Add to new location
118-
if (grid_blocks.block_at_location(to) == EMPTY_BLOCK_ID) {
118+
if (grid_blocks.block_at_location(to) == ClusterBlockId::INVALID()) {
119119
//Only need to increase usage if previously unused
120120
grid_blocks.set_usage({to.x, to.y, to.layer},
121121
grid_blocks.get_usage({to.x, to.y, to.layer}) + 1);

vpr/src/place/move_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ e_block_move_result record_single_block_swap(t_pl_blocks_to_be_moved& blocks_aff
149149
e_block_move_result outcome = e_block_move_result::VALID;
150150

151151
// Check whether the to_location is empty
152-
if (b_to == EMPTY_BLOCK_ID) {
152+
if (b_to == ClusterBlockId::INVALID()) {
153153
// Sets up the blocks moved
154154
outcome = blocks_affected.record_block_move(b_from, to, blk_loc_registry);
155155
} else {
@@ -309,7 +309,7 @@ e_block_move_result record_macro_macro_swaps(t_pl_blocks_to_be_moved& blocks_aff
309309
VTR_ASSERT_SAFE(curr_to == block_locs[b_to].loc);
310310

311311
// Check whether block to is compatible with from location
312-
if (b_to != EMPTY_BLOCK_ID) {
312+
if (b_to != ClusterBlockId::INVALID()) {
313313
if (!(is_legal_swap_to_location(b_to, curr_from, blk_loc_registry))) {
314314
return e_block_move_result::ABORT;
315315
}
@@ -506,7 +506,7 @@ bool is_legal_swap_to_location(ClusterBlockId blk,
506506
}
507507
// If the destination block is user constrained, abort this swap
508508
ClusterBlockId b_to = grid_blocks.block_at_location(to);
509-
if (b_to != EMPTY_BLOCK_ID) {
509+
if (b_to) {
510510
if (block_locs[b_to].is_fixed) {
511511
return false;
512512
}
@@ -1306,10 +1306,10 @@ int find_free_layer(t_logical_block_type_ptr logical_block,
13061306
if (device_ctx.grid.get_num_layers() > 1) {
13071307
const auto& compatible_layers = compressed_grids[logical_block->index].get_layer_nums();
13081308
if (compatible_layers.size() > 1) {
1309-
if (grid_blocks.block_at_location(loc) != EMPTY_BLOCK_ID) {
1309+
if (grid_blocks.block_at_location(loc)) {
13101310
for (const auto& layer : compatible_layers) {
13111311
if (layer != free_layer) {
1312-
if (grid_blocks.block_at_location(loc) == EMPTY_BLOCK_ID) {
1312+
if (grid_blocks.block_at_location(loc) == ClusterBlockId::INVALID()) {
13131313
free_layer = layer;
13141314
break;
13151315
}

vpr/src/place/noc_place_checkpoint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void NoCPlacementCheckpoint::restore_checkpoint(t_placer_costs& costs,
5353

5454
for (int k = 0; k < capacity.total(); k++) {
5555
const t_pl_loc loc(phy_loc, k + capacity.low);
56-
grid_blocks.set_block_at_location(loc, EMPTY_BLOCK_ID);
56+
grid_blocks.set_block_at_location(loc, ClusterBlockId::INVALID());
5757
}
5858
}
5959
}

vpr/src/place/place.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ static int check_block_placement_consistency(const BlkLocRegistry& blk_loc_regis
20542054
int usage_check = 0;
20552055
for (int k = 0; k < type->capacity; k++) {
20562056
ClusterBlockId bnum = grid_blocks.block_at_location({i, j, k, layer_num});
2057-
if (EMPTY_BLOCK_ID == bnum) {
2057+
if (bnum == ClusterBlockId::INVALID()) {
20582058
continue;
20592059
}
20602060

vpr/src/place/place_util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @brief Initialize `grid_blocks`, the inverse structure of `block_locs`.
1414
*
1515
* The container at each grid block location should have a length equal to the
16-
* subtile capacity of that block. Unused subtile would be marked EMPTY_BLOCK_ID.
16+
* subtile capacity of that block. Unused subtile would be marked ClusterBlockId::INVALID().
1717
*/
1818
static GridBlock init_grid_blocks();
1919

@@ -306,7 +306,7 @@ void zero_initialize_grid_blocks(GridBlock& grid_blocks) {
306306
auto capacity = sub_tile.capacity;
307307

308308
for (int k = 0; k < capacity.total(); k++) {
309-
grid_blocks.set_block_at_location({i, j, k + capacity.low, layer_num}, EMPTY_BLOCK_ID);
309+
grid_blocks.set_block_at_location({i, j, k + capacity.low, layer_num}, ClusterBlockId::INVALID());
310310
}
311311
}
312312
}
@@ -459,7 +459,7 @@ bool macro_can_be_placed(const t_pl_macro& pl_macro,
459459
// Also check whether the member position is valid, and the member_z is allowed at that location on the grid
460460
if (member_pos.x < int(device_ctx.grid.width()) && member_pos.y < int(device_ctx.grid.height())
461461
&& is_tile_compatible(device_ctx.grid.get_physical_type({member_pos.x, member_pos.y, member_pos.layer}), block_type)
462-
&& grid_blocks.block_at_location(member_pos) == EMPTY_BLOCK_ID) {
462+
&& grid_blocks.block_at_location(member_pos) == ClusterBlockId::INVALID()) {
463463
// Can still accommodate blocks here, check the next position
464464
continue;
465465
} else {

vpr/src/power/power.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ static void power_usage_blocks(t_power_usage* power_usage) {
628628

629629
ClusterBlockId iblk = place_ctx.grid_blocks().block_at_location({x, y, z, layer_num});
630630

631-
if (iblk != EMPTY_BLOCK_ID) {
631+
if (iblk) {
632632
pb = cluster_ctx.clb_nlist.block_pb(iblk);
633633
logical_block = cluster_ctx.clb_nlist.block_type(iblk);
634634
} else {

0 commit comments

Comments
 (0)