vpr/src/pack/cluster.cpp
/**
 * Cleans up a pb after unsuccessful molecule packing
 *
 * Recursively frees pbs from a t_pb tree. The given root pb itself is not
 * deleted.
 *
 * If a pb object has its children allocated then before freeing them the
 * function checks if there is no atom that corresponds to any of them. The
 * check is performed only for leaf (primitive) pbs. The function recurses for
 * non-primitive pbs.
 *
 * The cleaning itself includes deleting all child pbs, resetting mode of the
 * pb and also freeing its name. This prepares the pb for another round of
 * molecule packing tryout. 
 */
Cleans up a pb after unsuccessful molecule packing
Recursively frees pbs from a t_pb tree. The given root pb itself is not
deleted.

If a pb object has its children allocated then before freeing them the
function checks if there is no atom that corresponds to any of them. The
check is performed only for leaf (primitive) pbs. The function recurses for
non-primitive pbs.

The cleaning itself includes deleting all child pbs, resetting mode of the
pb and also freeing its name. This prepares the pb for another round of
molecule packing tryout.
Cleans up a pb after unsuccessful molecule packing Recursively frees pbs from a t_pb tree . The given root pb itself is not deleted . If a pb object has its children allocated then before freeing them the function checks if there is no atom that corresponds to any of them . The check is performed only for leaf ( primitive ) pbs . The function recurses for non - primitive pbs . The cleaning itself includes deleting all child pbs resetting mode of the pb and also freeing its name . This prepares the pb for another round of molecule packing tryout .
static bool cleanup_pb(t_pb* pb) {
    bool can_free = true;
    if (pb->child_pbs != nullptr) {
        const t_mode* mode = &pb->pb_graph_node->pb_type->modes[pb->mode];
        VTR_ASSERT(mode != nullptr);
        for (int i = 0; i < mode->num_pb_type_children; ++i) {
            if (pb->child_pbs[i] != nullptr) {
                for (int j = 0; j < mode->pb_type_children[i].num_pb; ++j) {
                    t_pb* pb_child = &pb->child_pbs[i][j];
                    t_pb_type* pb_type = pb_child->pb_graph_node->pb_type;
                    if (pb_type->num_modes == 0) {
                        if (pb_child->name != nullptr) {
                            can_free = false;
                        }
                    }
                    else {
                        if (!cleanup_pb(pb_child)) {
                            can_free = false;
                        }
                    }
                }
            }
        }
        if (can_free) {
            for (int i = 0; i < mode->num_pb_type_children; ++i) {
                if (pb->child_pbs[i] != nullptr) {
                    delete[] pb->child_pbs[i];
                }
            }
            delete[] pb->child_pbs;
            pb->child_pbs = nullptr;
            pb->mode = 0;
            if (pb->name) {
                free(pb->name);
                pb->name = nullptr;
            }
        }
    }
    return can_free;
}
static bool cleanup_pb ( t_pb * pb ) { bool can_free = true ; if ( pb -> child_pbs != nullptr ) { const t_mode * mode = & pb -> pb_graph_node -> pb_type -> modes [ pb -> mode ] ; VTR_ASSERT ( mode != nullptr ) ; for ( int i = 0 ; i < mode -> num_pb_type_children ; ++ i ) { if ( pb -> child_pbs [ i ] != nullptr ) { for ( int j = 0 ; j < mode -> pb_type_children [ i ] . num_pb ; ++ j ) { t_pb * pb_child = & pb -> child_pbs [ i ] [ j ] ; t_pb_type * pb_type = pb_child -> pb_graph_node -> pb_type ; if ( pb_type -> num_modes == 0 ) { if ( pb_child -> name != nullptr ) { can_free = false ; } } else { if ( ! cleanup_pb ( pb_child ) ) { can_free = false ; } } } } } if ( can_free ) { for ( int i = 0 ; i < mode -> num_pb_type_children ; ++ i ) { if ( pb -> child_pbs [ i ] != nullptr ) { delete [ ] pb -> child_pbs [ i ] ; } } delete [ ] pb -> child_pbs ; pb -> child_pbs = nullptr ; pb -> mode = 0 ; if ( pb -> name ) { free ( pb -> name ) ; pb -> name = nullptr ; } } } return can_free ; }
Cleans up a pb after unsuccessful molecule packing
 Recursively frees pbs from a t_pb tree.
Cleans up a pb after unsuccessful molecule packing Recursively frees pbs from a t_pb tree .
/* Recursively check if there are any children with already assigned atoms */ /* Check each mode */ /* Check each child */ /* Primitive, check occupancy */ /* Non-primitive, recurse */ /* Free if can */