2828#include " place_and_route.h"
2929#include " place_constraints.h"
3030#include " place_macro.h"
31+ #include " prepack.h"
3132#include " verify_clustering.h"
3233#include " verify_placement.h"
3334#include " vpr_api.h"
@@ -202,7 +203,8 @@ class APClusterPlacer {
202203 * @param primitive_candidate_block_types A list of candidate block types for
203204 * the given molecule.
204205 */
205- static LegalizationClusterId create_new_cluster (t_pack_molecule* seed_molecule,
206+ static LegalizationClusterId create_new_cluster (PackMoleculeId seed_molecule_id,
207+ const Prepacker& prepacker,
206208 ClusterLegalizer& cluster_legalizer,
207209 const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types) {
208210 const AtomContext& atom_ctx = g_vpr_ctx.atom ();
@@ -212,7 +214,9 @@ static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
212214 // placed into.
213215 // TODO: The original implementation sorted based on balance. Perhaps this
214216 // should do the same.
215- AtomBlockId root_atom = seed_molecule->atom_block_ids [seed_molecule->root ];
217+ VTR_ASSERT (seed_molecule_id.is_valid ());
218+ const t_pack_molecule& seed_molecule = prepacker.get_molecule (seed_molecule_id);
219+ AtomBlockId root_atom = seed_molecule.atom_block_ids [seed_molecule.root ];
216220 const t_model* root_model = atom_ctx.nlist .block_model (root_atom);
217221
218222 auto itr = primitive_candidate_block_types.find (root_model);
@@ -224,7 +228,7 @@ static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
224228 for (int mode = 0 ; mode < num_modes; mode++) {
225229 e_block_pack_status pack_status = e_block_pack_status::BLK_STATUS_UNDEFINED;
226230 LegalizationClusterId new_cluster_id;
227- std::tie (pack_status, new_cluster_id) = cluster_legalizer.start_new_cluster (seed_molecule , type, mode);
231+ std::tie (pack_status, new_cluster_id) = cluster_legalizer.start_new_cluster (seed_molecule_id , type, mode);
228232 if (pack_status == e_block_pack_status::BLK_PASSED)
229233 return new_cluster_id;
230234 }
@@ -290,33 +294,29 @@ void FullLegalizer::create_clusters(const PartialPlacement& p_placement) {
290294 for (size_t tile_id_idx = 0 ; tile_id_idx < num_device_tiles; tile_id_idx++) {
291295 DeviceTileId tile_id = DeviceTileId (tile_id_idx);
292296 // Create the molecule list
293- std::list<t_pack_molecule* > mol_list;
297+ std::list<PackMoleculeId > mol_list;
294298 for (APBlockId ap_blk_id : blocks_in_tiles[tile_id]) {
295- // FIXME: The netlist stores a const pointer to mol; but the cluster
296- // legalizer does not accept this. Need to fix one or the other.
297- // For now, using const_cast.
298- t_pack_molecule* mol = const_cast <t_pack_molecule*>(ap_netlist_.block_molecule (ap_blk_id));
299- mol_list.push_back (mol);
299+ mol_list.push_back (ap_netlist_.block_molecule (ap_blk_id));
300300 }
301301 // Clustering algorithm: Create clusters one at a time.
302302 while (!mol_list.empty ()) {
303303 // Arbitrarily choose the first molecule as a seed molecule.
304- t_pack_molecule* seed_mol = mol_list.front ();
304+ PackMoleculeId seed_mol_id = mol_list.front ();
305305 mol_list.pop_front ();
306306 // Use the seed molecule to create a cluster for this tile.
307- LegalizationClusterId new_cluster_id = create_new_cluster (seed_mol , cluster_legalizer, primitive_candidate_block_types);
307+ LegalizationClusterId new_cluster_id = create_new_cluster (seed_mol_id, prepacker_ , cluster_legalizer, primitive_candidate_block_types);
308308 // Insert all molecules that you can into the cluster.
309309 // NOTE: If the mol_list was somehow sorted, we can just stop at
310310 // first failure!
311311 auto it = mol_list.begin ();
312312 while (it != mol_list.end ()) {
313- t_pack_molecule* mol = *it;
314- if (!cluster_legalizer.is_molecule_compatible (mol , new_cluster_id)) {
313+ PackMoleculeId mol_id = *it;
314+ if (!cluster_legalizer.is_molecule_compatible (mol_id , new_cluster_id)) {
315315 ++it;
316316 continue ;
317317 }
318318 // Try to insert it. If successful, remove from list.
319- e_block_pack_status pack_status = cluster_legalizer.add_mol_to_cluster (mol , new_cluster_id);
319+ e_block_pack_status pack_status = cluster_legalizer.add_mol_to_cluster (mol_id , new_cluster_id);
320320 if (pack_status == e_block_pack_status::BLK_PASSED) {
321321 it = mol_list.erase (it);
322322 } else {
@@ -352,8 +352,9 @@ void FullLegalizer::place_clusters(const ClusteredNetlist& clb_nlist,
352352 // Create a lookup from the AtomBlockId to the APBlockId
353353 vtr::vector<AtomBlockId, APBlockId> atom_to_ap_block (atom_netlist_.blocks ().size ());
354354 for (APBlockId ap_blk_id : ap_netlist_.blocks ()) {
355- const t_pack_molecule* blk_mol = ap_netlist_.block_molecule (ap_blk_id);
356- for (AtomBlockId atom_blk_id : blk_mol->atom_block_ids ) {
355+ PackMoleculeId blk_mol_id = ap_netlist_.block_molecule (ap_blk_id);
356+ const t_pack_molecule& blk_mol = prepacker_.get_molecule (blk_mol_id);
357+ for (AtomBlockId atom_blk_id : blk_mol.atom_block_ids ) {
357358 // See issue #2791, some of the atom_block_ids may be invalid. They
358359 // can safely be ignored.
359360 if (!atom_blk_id.is_valid ())
0 commit comments