@@ -997,11 +997,70 @@ static void update_molecule_chain_info(t_pack_molecule* chain_molecule, const t_
997997 VTR_ASSERT (false );
998998}
999999
1000+ /* *
1001+ * @brief Revalidate the molecules associated with this pb. The mol_validated
1002+ * flag is used to check if the mol has already been validated.
1003+ */
1004+ static void revalid_molecules (const t_pb* pb,
1005+ bool &mol_validated,
1006+ const Prepacker& prepacker) {
1007+ const t_pb_type* pb_type = pb->pb_graph_node ->pb_type ;
1008+
1009+ if (pb_type->blif_model == nullptr ) {
1010+ int mode = pb->mode ;
1011+ for (int i = 0 ; i < pb_type->modes [mode].num_pb_type_children && pb->child_pbs != nullptr ; i++) {
1012+ for (int j = 0 ; j < pb_type->modes [mode].pb_type_children [i].num_pb && pb->child_pbs [i] != nullptr ; j++) {
1013+ if (pb->child_pbs [i][j].name != nullptr || pb->child_pbs [i][j].child_pbs != nullptr ) {
1014+ revalid_molecules (&pb->child_pbs [i][j], mol_validated, prepacker);
1015+ }
1016+ }
1017+ }
1018+ } else {
1019+ // Primitive
1020+ auto & atom_ctx = g_vpr_ctx.mutable_atom ();
1021+
1022+ auto blk_id = atom_ctx.lookup .pb_atom (pb);
1023+ if (blk_id) {
1024+ /* If any molecules were marked invalid because of this logic block getting packed, mark them valid */
1025+
1026+ // Update atom netlist mapping
1027+ atom_ctx.lookup .set_atom_clb (blk_id, ClusterBlockId::INVALID ());
1028+ atom_ctx.lookup .set_atom_pb (blk_id, nullptr );
1029+
1030+ t_pack_molecule* cur_molecule = prepacker.get_atom_molecule (blk_id);
1031+ if (!mol_validated) {
1032+ int i;
1033+ for (i = 0 ; i < get_array_size_of_molecule (cur_molecule); i++) {
1034+ if (cur_molecule->atom_block_ids [i]) {
1035+ if (atom_ctx.lookup .atom_clb (cur_molecule->atom_block_ids [i]) != ClusterBlockId::INVALID ()) {
1036+ break ;
1037+ }
1038+ }
1039+ }
1040+ /* All atom blocks are open for this molecule, place back in queue */
1041+ if (i == get_array_size_of_molecule (cur_molecule)) {
1042+ mol_validated = true ;
1043+ // when invalidating a molecule check if it's a chain molecule
1044+ // that is part of a long chain. If so, check if this molecule
1045+ // have modified the chain_id value based on the stale packing
1046+ // then reset the chain id and the first packed molecule pointer
1047+ // this is packing is being reset
1048+ if (cur_molecule->is_chain () && cur_molecule->chain_info ->is_long_chain && cur_molecule->chain_info ->first_packed_molecule == cur_molecule) {
1049+ cur_molecule->chain_info ->first_packed_molecule = nullptr ;
1050+ cur_molecule->chain_info ->chain_id = -1 ;
1051+ }
1052+ }
1053+ }
1054+ }
1055+ }
1056+ }
1057+
10001058/*
10011059 * @brief Revert trial atom block iblock and free up memory space accordingly.
10021060 */
10031061static void revert_place_atom_block (const AtomBlockId blk_id,
10041062 t_lb_router_data* router_data,
1063+ bool &mol_validated,
10051064 const Prepacker& prepacker,
10061065 vtr::vector_map<AtomBlockId, LegalizationClusterId>& atom_cluster) {
10071066 const AtomContext& atom_ctx = g_vpr_ctx.atom ();
@@ -1020,7 +1079,7 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
10201079 */
10211080
10221081 t_pb* next = pb->parent_pb ;
1023- revalid_molecules (pb, prepacker);
1082+ revalid_molecules (pb, mol_validated, prepacker);
10241083 free_pb (pb);
10251084 pb = next;
10261085
@@ -1037,7 +1096,7 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
10371096 /* If the code gets here, then that means that placing the initial seed molecule
10381097 * failed, don't free the actual complex block itself as the seed needs to find
10391098 * another placement */
1040- revalid_molecules (pb, prepacker);
1099+ revalid_molecules (pb, mol_validated, prepacker);
10411100 free_pb (pb);
10421101 }
10431102 }
@@ -1386,14 +1445,6 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
13861445 if (!atom_blk_id.is_valid ())
13871446 continue ;
13881447
1389- /* invalidate all molecules that share atom block with current molecule */
1390- t_pack_molecule* cur_molecule = prepacker_.get_atom_molecule (atom_blk_id);
1391- // TODO: This should really be named better. Something like
1392- // "is_clustered". and then it should be set to true.
1393- // Right now, valid implies "not clustered" which is
1394- // confusing.
1395- cur_molecule->valid = false ;
1396-
13971448 commit_primitive (cluster.placement_stats , primitives_list[i]);
13981449
13991450 atom_cluster_[atom_blk_id] = cluster_id;
@@ -1421,10 +1472,11 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
14211472 remove_atom_from_target (cluster.router_data , atom_blk_id);
14221473 }
14231474 }
1475+ bool mol_validated = false ;
14241476 for (int i = 0 ; i < failed_location; i++) {
14251477 AtomBlockId atom_blk_id = molecule->atom_block_ids [i];
14261478 if (atom_blk_id) {
1427- revert_place_atom_block (atom_blk_id, cluster.router_data , prepacker_, atom_cluster_);
1479+ revert_place_atom_block (atom_blk_id, cluster.router_data , mol_validated, prepacker_, atom_cluster_);
14281480 }
14291481 }
14301482
@@ -1562,17 +1614,13 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
15621614 VTR_ASSERT_SAFE (molecule_cluster_.find (mol) != molecule_cluster_.end () &&
15631615 molecule_cluster_[mol] == cluster_id);
15641616 molecule_cluster_[mol] = LegalizationClusterId::INVALID ();
1565- // The overall clustering algorithm uses this valid flag to indicate
1566- // that a molecule has not been packed (clustered) yet. Since we are
1567- // destroying a cluster, all of its molecules are now no longer clustered
1568- // so they are all validated.
1569- mol->valid = true ;
15701617 // Revert the placement of all blocks in the molecule.
1618+ bool mol_validated = false ;
15711619 int molecule_size = get_array_size_of_molecule (mol);
15721620 for (int i = 0 ; i < molecule_size; i++) {
15731621 AtomBlockId atom_blk_id = mol->atom_block_ids [i];
15741622 if (atom_blk_id) {
1575- revert_place_atom_block (atom_blk_id, cluster.router_data , prepacker_, atom_cluster_);
1623+ revert_place_atom_block (atom_blk_id, cluster.router_data , mol_validated, prepacker_, atom_cluster_);
15761624 }
15771625 }
15781626 }
0 commit comments