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