@@ -1179,6 +1179,64 @@ static void alloc_and_load_pb_stats(t_pb* pb, const int feasible_block_array_siz
1179
1179
}
1180
1180
/* ****************************************/
1181
1181
1182
+ /* *
1183
+ * Cleans up a pb after unsuccessful molecule packing
1184
+ */
1185
+ static bool cleanup_pb (t_pb* pb) {
1186
+ bool can_free = true ;
1187
+
1188
+ /* Recursively check if there are any children with already assigned atoms */
1189
+ if (pb->child_pbs != nullptr ) {
1190
+ const t_mode* mode = &pb->pb_graph_node ->pb_type ->modes [pb->mode ];
1191
+ VTR_ASSERT (mode != nullptr );
1192
+
1193
+ /* Check each mode */
1194
+ for (int i = 0 ; i < mode->num_pb_type_children ; ++i) {
1195
+ /* Check each child */
1196
+ if (pb->child_pbs [i] != nullptr ) {
1197
+ for (int j = 0 ; j < mode->pb_type_children [i].num_pb ; ++j) {
1198
+ t_pb* pb_child = &pb->child_pbs [i][j];
1199
+ t_pb_type* pb_type = pb_child->pb_graph_node ->pb_type ;
1200
+
1201
+ /* Primitive, check occupancy */
1202
+ if (pb_type->num_modes == 0 ) {
1203
+ if (pb_child->name != nullptr ) {
1204
+ can_free = false ;
1205
+ }
1206
+ }
1207
+
1208
+ /* Non-primitive, recurse */
1209
+ else {
1210
+ if (!cleanup_pb (pb_child)) {
1211
+ can_free = false ;
1212
+ }
1213
+ }
1214
+ }
1215
+ }
1216
+ }
1217
+
1218
+ /* Free if can */
1219
+ if (can_free) {
1220
+ for (int i = 0 ; i < mode->num_pb_type_children ; ++i) {
1221
+ if (pb->child_pbs [i] != nullptr ) {
1222
+ delete[] pb->child_pbs [i];
1223
+ }
1224
+ }
1225
+
1226
+ delete[] pb->child_pbs ;
1227
+ pb->child_pbs = nullptr ;
1228
+ pb->mode = 0 ;
1229
+
1230
+ if (pb->name ) {
1231
+ free (pb->name );
1232
+ pb->name = nullptr ;
1233
+ }
1234
+ }
1235
+ }
1236
+
1237
+ return can_free;
1238
+ }
1239
+
1182
1240
/* *
1183
1241
* Try pack molecule into current cluster
1184
1242
*/
@@ -1358,6 +1416,10 @@ static enum e_block_pack_status try_pack_molecule(t_cluster_placement_stats* clu
1358
1416
revert_place_atom_block (molecule->atom_block_ids [i], router_data, atom_molecules);
1359
1417
}
1360
1418
}
1419
+
1420
+ /* Placement failed, clean the pb */
1421
+ cleanup_pb (pb);
1422
+
1361
1423
} else {
1362
1424
VTR_LOGV (verbosity > 3 , " \t\t PASSED pack molecule\n " );
1363
1425
}
0 commit comments