vpr/src/pack/cluster.cpp
/**
 *  * Cleans up a pb after unsuccessful molecule packing
 *   */
Cleans up a pb after unsuccessful molecule packing
Cleans up a pb after unsuccessful molecule packing
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
* Cleans up a pb after unsuccessful molecule packing
/* 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 */