Repository: The-OpenROAD-Project/OpenROAD
Pull request #6796: drt: unique_inst_patterns_ structure structure refactor
Author: login: bnmfw
Labels: name: drt
description: Detailed Routing
Created: 2025-03-02T23:35:42Z | Merged: 2025-03-26T00:58:23Z

Supports #5867.
ISPD and Secure CI associated, will be opened once safe.

### `unique_inst_patterns_` structure change.
One of the requirements of incremental PA is for the used structures to be dynamic. Once a complete run of PA is done, it is necessary to run it again for a set of instances while keeping data of unaltered instances. While #6778 introduces a function to allow for solving the access patterns of a single unique instance, the `unique_inst_patterns_` does not allow for new entries to be inserted. The structure used to be a vector of fixed sized, which made the managing of new entries very difficult. In that light the structure was changed to an unordered map, in which the unique instance pointer acts as a key. This allows for inserting and deleting entries without major disruptions of the whole structure.

#### Related minor changes.
- `FlexPA.h` now includes `#include <boost/serialization/unordered_map.hpp>` to support the unordered map serialization.
- `FrInst()` now has an empty default constructor, also required for serialization.
- `UniqueInsts` now has a function to retrieve the unique instance related to the instance.
- Modifications of `unique_inst_patterns_` are protected by `#pragma omp critical` to avoid race conditions.


Diff:
diff --git a/src/drt/src/db/obj/frInst.h b/src/drt/src/db/obj/frInst.h
index 5ca65ea9f92..22b12275e11 100644
--- a/src/drt/src/db/obj/frInst.h
+++ b/src/drt/src/db/obj/frInst.h
@@ -50,6 +50,9 @@ class frInst : public frRef
       : name_(name), master_(master), db_inst_(db_inst)
   {
   }
+  // used for archive serialization
+  frInst() : master_(nullptr), db_inst_(nullptr) {}
+
   // getters
   const frString& getName() const { return name_; }
   frMaster* getMaster() const { return master_; }
diff --git a/src/drt/src/db/obj/frInstTerm.h b/src/drt/src/db/obj/frInstTerm.h
index be959eb6960..6c2a93539d7 100644
--- a/src/drt/src/db/obj/frInstTerm.h
+++ b/src/drt/src/db/obj/frInstTerm.h
@@ -63,6 +63,7 @@ class frInstTerm : public frBlockObject
   void addAccessPoint(frAccessPoint* in) { ap_.push_back(in); }
   void setAccessPoints(const std::vector<frAccessPoint*>& in) { ap_ = in; }
   // others
+  void clearAccessPoints() { ap_.clear(); }
   frBlockObjectEnum typeId() const override { return frcInstTerm; }
   frAccessPoint* getAccessPoint(frCoord x, frCoord y, frLayerNum lNum);
   bool hasAccessPoint(frCoord x, frCoord y, frLayerNum lNum);
diff --git a/src/drt/src/pa/FlexPA.h b/src/drt/src/pa/FlexPA.h
index 9cbcc65ab5f..d102dc51f4e 100644
--- a/src/drt/src/pa/FlexPA.h
+++ b/src/drt/src/pa/FlexPA.h
@@ -29,6 +29,7 @@
 #pragma once
 
 #include <boost/polygon/polygon.hpp>
+#include <boost/serialization/unordered_map.hpp>
 #include <cstdint>
 #include <vector>
 
@@ -100,7 +101,8 @@ class FlexPA
   int macro_cell_pin_valid_planar_ap_cnt_ = 0;
   int macro_cell_pin_valid_via_ap_cnt_ = 0;
   int macro_cell_pin_no_ap_cnt_ = 0;
-  std::vector<std::vector<std::unique_ptr<FlexPinAccessPattern>>>
+  std::unordered_map<frInst*,
+                     std::vector<std::unique_ptr<FlexPinAccessPattern>>>
       unique_inst_patterns_;
 
   UniqueInsts unique_insts_;
@@ -613,11 +615,11 @@ class FlexPA
    */
   int prepPatternInstHelper(frInst* unique_inst, bool use_x);
 
-  int genPatterns(frInst* inst,
+  int genPatterns(frInst* unique_inst,
                   const std::vector<std::pair<frMPin*, frInstTerm*>>& pins);
 
   int genPatternsHelper(
-      frInst* inst,
+      frInst* unique_inst,
       const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
       std::set<std::vector<int>>& inst_access_patterns,
       std::set<std::pair<int, int>>& used_access_points,
@@ -647,7 +649,7 @@ class FlexPA
    * @brief Determines the value of all the paths of the DP problem
    */
   void genPatternsPerform(
-      frInst* inst,
+      frInst* unique_inst,
       std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
       const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
       std::vector<int>& vio_edges,
@@ -658,7 +660,7 @@ class FlexPA
   /**
    * @brief Determines the edge cost between two DP nodes
    */
-  int getEdgeCost(frInst* inst,
+  int getEdgeCost(frInst* unique_inst,
                   FlexDPNode* prev_node,
                   FlexDPNode* curr_node,
                   const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
@@ -687,7 +689,7 @@ class FlexPA
    * @brief Commits to the best path (solution) on the DP graph
    */
   bool genPatternsCommit(
-      frInst* inst,
+      frInst* unique_inst,
       const std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
       const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
       bool& is_valid,
diff --git a/src/drt/src/pa/FlexPA_acc_pattern.cpp b/src/drt/src/pa/FlexPA_acc_pattern.cpp
index 9815be13908..264a498fba1 100644
--- a/src/drt/src/pa/FlexPA_acc_pattern.cpp
+++ b/src/drt/src/pa/FlexPA_acc_pattern.cpp
@@ -51,8 +51,9 @@ namespace drt {
 using utl::ThreadException;
 
 static inline void serializePatterns(
-    const std::vector<std::vector<std::unique_ptr<FlexPinAccessPattern>>>&
-        patterns,
+    const std::unordered_map<
+        frInst*,
+        std::vector<std::unique_ptr<FlexPinAccessPattern>>>& patterns,
     const std::string& file_name)
 {
   std::ofstream file(file_name.c_str());
@@ -99,7 +100,7 @@ void FlexPA::prepPattern()
   const auto& unique = unique_insts_.getUnique();
 
   // revert access points to origin
-  unique_inst_patterns_.resize(unique.size());
+  unique_inst_patterns_.reserve(unique.size());
 
   int cnt = 0;
 
@@ -192,6 +193,10 @@ void FlexPA::prepPattern()
 
 void FlexPA::prepPatternInst(frInst* unique_inst)
 {
+#pragma omp critical
+  unique_inst_patterns_[unique_inst]
+      = std::vector<std::unique_ptr<FlexPinAccessPattern>>();
+
   int num_valid_pattern = prepPatternInstHelper(unique_inst, true);
 
   if (num_valid_pattern > 0) {
@@ -258,7 +263,7 @@ int FlexPA::prepPatternInstHelper(frInst* unique_inst, const bool use_x)
 }
 
 int FlexPA::genPatterns(
-    frInst* inst,
+    frInst* unique_inst,
     const std::vector<std::pair<frMPin*, frInstTerm*>>& pins)
 {
   if (pins.empty()) {
@@ -282,7 +287,7 @@ int FlexPA::genPatterns(
   std::set<std::pair<int, int>> viol_access_points;
   int num_valid_pattern = 0;
 
-  num_valid_pattern += FlexPA::genPatternsHelper(inst,
+  num_valid_pattern += FlexPA::genPatternsHelper(unique_inst,
                                                  pins,
                                                  inst_access_patterns,
                                                  used_access_points,
@@ -293,7 +298,7 @@ int FlexPA::genPatterns(
     auto reversed_pins = pins;
     reverse(reversed_pins.begin(), reversed_pins.end());
 
-    num_valid_pattern += FlexPA::genPatternsHelper(inst,
+    num_valid_pattern += FlexPA::genPatternsHelper(unique_inst,
                                                    reversed_pins,
                                                    inst_access_patterns,
                                                    used_access_points,
@@ -305,7 +310,7 @@ int FlexPA::genPatterns(
 }
 
 int FlexPA::genPatternsHelper(
-    frInst* inst,
+    frInst* unique_inst,
     const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
     std::set<std::vector<int>>& inst_access_patterns,
     std::set<std::pair<int, int>>& used_access_points,
@@ -327,7 +332,7 @@ int FlexPA::genPatternsHelper(
 
   for (int i = 0; i < router_cfg_->ACCESS_PATTERN_END_ITERATION_NUM; i++) {
     genPatternsReset(nodes, pins);
-    genPatternsPerform(inst,
+    genPatternsPerform(unique_inst,
                        nodes,
                        pins,
                        vio_edge,
@@ -335,7 +340,7 @@ int FlexPA::genPatternsHelper(
                        viol_access_points,
                        max_access_point_size);
     bool is_valid = false;
-    if (genPatternsCommit(inst,
+    if (genPatternsCommit(unique_inst,
                           nodes,
                           pins,
                           is_valid,
@@ -483,7 +488,7 @@ bool FlexPA::genPatternsGC(
 }
 
 void FlexPA::genPatternsPerform(
-    frInst* inst,
+    frInst* unique_inst,
     std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
     const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
     std::vector<int>& vio_edges,
@@ -510,7 +515,7 @@ void FlexPA::genPatternsPerform(
           continue;
         }
 
-        const int edge_cost = getEdgeCost(inst,
+        const int edge_cost = getEdgeCost(unique_inst,
                                           prev_node,
                                           curr_node,
                                           pins,
@@ -530,7 +535,7 @@ void FlexPA::genPatternsPerform(
 }
 
 int FlexPA::getEdgeCost(
-    frInst* inst,
+    frInst* unique_inst,
     FlexDPNode* prev_node,
     FlexDPNode* curr_node,
     const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
@@ -556,7 +561,7 @@ int FlexPA::getEdgeCost(
   if (vio_edges[edge_idx] != -1) {
     has_vio = (vio_edges[edge_idx] == 1);
   } else {
-    dbTransform xform = inst->getNoRotationTransform();
+    dbTransform xform = unique_inst->getNoRotationTransform();
     // check DRC
     std::vector<std::pair<frConnFig*, frBlockObject*>> objs;
     const auto& [pin_1, inst_term_1] = pins[prev_pin_idx];
@@ -684,7 +689,7 @@ std::vector<int> FlexPA::extractAccessPatternFromNodes(
 }
 
 bool FlexPA::genPatternsCommit(
-    frInst* inst,
+    frInst* unique_inst,
     const std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
     const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
     bool& is_valid,
@@ -711,8 +716,8 @@ bool FlexPA::genPatternsCommit(
   for (int pin_idx = 0; pin_idx < (int) pins.size(); pin_idx++) {
     auto acc_point_idx = access_pattern[pin_idx];
     auto& [pin, inst_term] = pins[pin_idx];
-    target_obj = inst;
-    const int pin_access_idx = unique_insts_.getPAIndex(inst);
+    target_obj = unique_inst;
+    const int pin_access_idx = unique_insts_.getPAIndex(unique_inst);
     const auto pa = pin->getPinAccess(pin_access_idx);
     const auto access_point = pa->getAccessPoint(acc_point_idx);
     pin_to_access_point[pin] = access_point;
@@ -724,7 +729,7 @@ bool FlexPA::genPatternsCommit(
       auto rvia = via.get();
       temp_vias.push_back(std::move(via));
 
-      dbTransform xform = inst->getNoRotationTransform();
+      dbTransform xform = unique_inst->getNoRotationTransform();
       Point pt(access_point->getPoint());
       xform.apply(pt);
       rvia->setOrigin(pt);
@@ -741,7 +746,7 @@ bool FlexPA::genPatternsCommit(
   frCoord left_pt = std::numeric_limits<frCoord>::max();
   frCoord right_pt = std::numeric_limits<frCoord>::min();
 
-  for (auto& inst_term : inst->getInstTerms()) {
+  for (auto& inst_term : unique_inst->getInstTerms()) {
     if (isSkipInstTerm(inst_term.get())) {
       continue;
     }
@@ -778,8 +783,7 @@ bool FlexPA::genPatternsCommit(
   if (target_obj != nullptr
       && genPatternsGC({target_obj}, objs, Commit, &owners)) {
     pin_access_pattern->updateCost();
-    const int inst_idx = unique_insts_.getIndex(inst);
-    unique_inst_patterns_[inst_idx].push_back(std::move(pin_access_pattern));
+    unique_inst_patterns_[unique_inst].push_back(std::move(pin_access_pattern));
     // genPatternsPrint(nodes, pins);
     is_valid = true;
   } else {
@@ -811,8 +815,8 @@ void FlexPA::genPatternsPrintDebug(
   dbTransform xform;
   auto& [pin, inst_term] = pins[0];
   if (inst_term) {
-    frInst* inst = inst_term->getInst();
-    xform = inst->getNoRotationTransform();
+    frInst* unique_inst = inst_term->getInst();
+    xform = unique_inst->getNoRotationTransform();
   }
 
   std::cout << "failed pattern:";
@@ -822,9 +826,9 @@ void FlexPA::genPatternsPrintDebug(
     // non-virtual node
     if (pin_cnt != (int) pins.size()) {
       auto& [pin, inst_term] = pins[pin_cnt];
-      auto inst = inst_term->getInst();
+      auto unique_inst = inst_term->getInst();
       std::cout << " " << inst_term->getTerm()->getName();
-      const int pin_access_idx = unique_insts_.getPAIndex(inst);
+      const int pin_access_idx = unique_insts_.getPAIndex(unique_inst);
       auto pa = pin->getPinAccess(pin_access_idx);
       auto [curr_pin_idx, curr_acc_point_idx] = curr_node->getIdx();
       Point pt(pa->getAccessPoint(curr_acc_point_idx)->getPoint());
@@ -855,17 +859,17 @@ void FlexPA::genPatternsPrint(
     // non-virtual node
     if (pin_cnt != (int) pins.size()) {
       auto& [pin, inst_term] = pins[pin_cnt];
-      auto inst = inst_term->getInst();
-      const int pin_access_idx = unique_insts_.getPAIndex(inst);
+      auto unique_inst = inst_term->getInst();
+      const int pin_access_idx = unique_insts_.getPAIndex(unique_inst);
       auto pa = pin->getPinAccess(pin_access_idx);
       auto [curr_pin_idx, curr_acc_point_idx] = curr_node->getIdx();
       std::unique_ptr<frVia> via = std::make_unique<frVia>(
           pa->getAccessPoint(curr_acc_point_idx)->getViaDef());
       Point pt(pa->getAccessPoint(curr_acc_point_idx)->getPoint());
-      std::cout << " gccleanvia " << inst->getMaster()->getName() << " "
+      std::cout << " gccleanvia " << unique_inst->getMaster()->getName() << " "
                 << inst_term->getTerm()->getName() << " "
                 << via->getViaDef()->getName() << " " << pt.x() << " " << pt.y()
-                << " " << inst->getOrient().getString() << "\n";
+                << " " << unique_inst->getOrient().getString() << "\n";
     }
 
     curr_node = curr_node->getPrevNode();
diff --git a/src/drt/src/pa/FlexPA_row_pattern.cpp b/src/drt/src/pa/FlexPA_row_pattern.cpp
index 0aa69010909..921b877d7a2 100644
--- a/src/drt/src/pa/FlexPA_row_pattern.cpp
+++ b/src/drt/src/pa/FlexPA_row_pattern.cpp
@@ -134,15 +134,12 @@ void FlexPA::prepPatternInstRows(std::vector<std::vector<frInst*>> inst_rows)
   } else {
     omp_set_num_threads(router_cfg_->MAX_THREADS);
     // choose access pattern of a row of insts
-    int rowIdx = 0;
 #pragma omp parallel for schedule(dynamic)
-    for (int i = 0; i < (int) inst_rows.size(); i++) {  // NOLINT
+    for (auto& inst_row : inst_rows) {  // NOLINT
       try {
-        auto& instRow = inst_rows[i];
-        genInstRowPattern(instRow);
+        genInstRowPattern(inst_row);
 #pragma omp critical
         {
-          rowIdx++;
           cnt++;
           if (router_cfg_->VERBOSE > 0) {
             if (cnt % (cnt > 100000 ? 100000 : 10000) == 0) {
@@ -200,8 +197,8 @@ void FlexPA::genInstRowPatternInit(
   // init inst nodes
   for (int inst_idx = 0; inst_idx < (int) insts.size(); inst_idx++) {
     auto& inst = insts[inst_idx];
-    const int unique_inst_idx = unique_insts_.getIndex(inst);
-    auto& inst_patterns = unique_inst_patterns_[unique_inst_idx];
+    auto unique_inst = unique_insts_.getUnique(inst);
+    auto& inst_patterns = unique_inst_patterns_[unique_inst];
     nodes[inst_idx]
         = std::vector<std::unique_ptr<FlexDPNode>>(inst_patterns.size());
     for (int acc_pattern_idx = 0; acc_pattern_idx < (int) inst_patterns.size();
@@ -256,52 +253,50 @@ void FlexPA::genInstRowPatternCommit(
     const std::vector<frInst*>& insts)
 {
   const bool is_debug_mode = false;
-  FlexDPNode* curr_node = nodes[insts.size()][0].get();
-  int inst_cnt = insts.size();
-  std::vector<int> inst_access_pattern_idx(insts.size(), -1);
-  while (curr_node->hasPrevNode()) {
-    // non-virtual node
-    if (inst_cnt != (int) insts.size()) {
-      auto [curr_inst_idx, curr_acc_patterns_idx] = curr_node->getIdx();
-      inst_access_pattern_idx[curr_inst_idx] = curr_acc_patterns_idx;
-
-      auto& inst = insts[curr_inst_idx];
-      int access_point_idx = 0;
-      const int unique_inst_idx = unique_insts_.getIndex(inst);
-      auto access_pattern
-          = unique_inst_patterns_[unique_inst_idx][curr_acc_patterns_idx].get();
-      auto& access_points = access_pattern->getPattern();
 
-      // update inst_term ap
-      for (auto& inst_term : inst->getInstTerms()) {
-        if (isSkipInstTerm(inst_term.get())) {
-          continue;
-        }
+  const FlexDPNode* source_node = nodes[insts.size() + 1][0].get();
+  const FlexDPNode* sink_node = nodes[insts.size()][0].get();
 
-        int pin_idx = 0;
-        // to avoid unused variable warning in GCC
-        for (int i = 0; i < (int) (inst_term->getTerm()->getPins().size());
-             i++) {
-          auto& access_point = access_points[access_point_idx];
-          inst_term->setAccessPoint(pin_idx, access_point);
-          pin_idx++;
-          access_point_idx++;
-        }
+  FlexDPNode* curr_node = sink_node->getPrevNode();
+  std::vector<int> inst_access_pattern_idx(insts.size(), -1);
+  while (curr_node != source_node) {
+    if (!curr_node) {
+      std::string inst_names;
+      for (frInst* inst : insts) {
+        inst_names += '\n' + inst->getName();
       }
+      logger_->error(DRT,
+                     85,
+                     "Valid access pattern combination not found for {}",
+                     inst_names);
     }
-    curr_node = curr_node->getPrevNode();
-    inst_cnt--;
-  }
 
-  if (inst_cnt != -1) {
-    std::string inst_names;
-    for (frInst* inst : insts) {
-      inst_names += '\n' + inst->getName();
+    // non-virtual node
+    auto [curr_inst_idx, curr_acc_patterns_idx] = curr_node->getIdx();
+    inst_access_pattern_idx[curr_inst_idx] = curr_acc_patterns_idx;
+
+    frInst* inst = insts[curr_inst_idx];
+    int access_point_idx = 0;
+    frInst* unique_inst = unique_insts_.getUnique(inst);
+    auto access_pattern
+        = unique_inst_patterns_[unique_inst][curr_acc_patterns_idx].get();
+    auto& access_points = access_pattern->getPattern();
+
+    // update inst_term ap
+    for (auto& inst_term : inst->getInstTerms()) {
+      if (isSkipInstTerm(inst_term.get())) {
+        continue;
+      }
+
+      // to avoid unused variable warning in GCC
+      for (int pin_idx = 0; pin_idx < inst_term->getTerm()->getPins().size();
+           pin_idx++) {
+        frAccessPoint* access_point = access_points[access_point_idx];
+        inst_term->setAccessPoint(pin_idx, access_point);
+        access_point_idx++;
+      }
     }
-    logger_->error(DRT,
-                   85,
-                   "Valid access pattern combination not found for {}",
-                   inst_names);
+    curr_node = curr_node->getPrevNode();
   }
 
   if (is_debug_mode) {
@@ -326,9 +321,9 @@ void FlexPA::genInstRowPatternPrint(
       // print debug information
       auto& inst = insts[curr_inst_idx];
       int access_point_idx = 0;
-      const int unique_inst_idx = unique_insts_.getIndex(inst);
+      auto unique_inst = unique_insts_.getUnique(inst);
       auto access_pattern
-          = unique_inst_patterns_[unique_inst_idx][curr_acc_pattern_idx].get();
+          = unique_inst_patterns_[unique_inst][curr_acc_pattern_idx].get();
       auto& access_points = access_pattern->getPattern();
 
       for (auto& inst_term : inst->getInstTerms()) {
@@ -383,13 +378,13 @@ int FlexPA::getEdgeCost(FlexDPNode* prev_node,
   std::vector<std::pair<frConnFig*, frBlockObject*>> objs;
   // push the vias from prev inst access pattern and curr inst access pattern
   const auto prev_inst = insts[prev_inst_idx];
-  const auto prev_unique_inst_idx = unique_insts_.getIndex(prev_inst);
+  const auto prev_unique_inst = unique_insts_.getUnique(prev_inst);
   const auto curr_inst = insts[curr_inst_idx];
-  const auto curr_unique_inst_idx = unique_insts_.getIndex(curr_inst);
+  const auto curr_unique_inst = unique_insts_.getUnique(curr_inst);
   const auto prev_pin_access_pattern
-      = unique_inst_patterns_[prev_unique_inst_idx][prev_acc_pattern_idx].get();
+      = unique_inst_patterns_[prev_unique_inst][prev_acc_pattern_idx].get();
   const auto curr_pin_access_pattern
-      = unique_inst_patterns_[curr_unique_inst_idx][curr_acc_pattern_idx].get();
+      = unique_inst_patterns_[curr_unique_inst][curr_acc_pattern_idx].get();
   addAccessPatternObj(
       prev_inst, prev_pin_access_pattern, objs, temp_vias, true);
   addAccessPatternObj(
diff --git a/src/drt/src/pa/FlexPA_unique.cpp b/src/drt/src/pa/FlexPA_unique.cpp
index 715aa0849e5..b73c1d47147 100644
--- a/src/drt/src/pa/FlexPA_unique.cpp
+++ b/src/drt/src/pa/FlexPA_unique.cpp
@@ -365,4 +365,9 @@ frInst* UniqueInsts::getUnique(int idx) const
   return unique_[idx];
 }
 
+frInst* UniqueInsts::getUnique(frInst* inst) const
+{
+  return inst_to_unique_.at(inst);
+}
+
 }  // namespace drt
diff --git a/src/drt/src/pa/FlexPA_unique.h b/src/drt/src/pa/FlexPA_unique.h
index 9c46bf163ed..b793cf3568d 100644
--- a/src/drt/src/pa/FlexPA_unique.h
+++ b/src/drt/src/pa/FlexPA_unique.h
@@ -69,6 +69,7 @@ class UniqueInsts
 
   const std::vector<frInst*>& getUnique() const;
   frInst* getUnique(int idx) const;
+  frInst* getUnique(frInst* inst) const;
   bool hasUnique(frInst* inst) const;
 
   /**


Reviews:
user: login: github-actions[bot]
body: clang-tidy made some suggestions
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-02T23:43:42Z
user: login: github-actions[bot]
body: clang-tidy made some suggestions
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-17T17:21:17Z
user: login: osamahammad21
body: - unique_inst_patterns_ is not touched in deleteInst which doesn't seem right. The entry should be removed or edited if the class head is changed.
- If you're planning to use frInst* as the key, then you should remove all index related APIs and members.
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-21T15:31:28Z
user: login: osamahammad21
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-26T00:58:16Z

Review comments:
diff_hunk: @@ -50,6 +50,9 @@ class frInst : public frRef
       : name_(name), master_(master), db_inst_(db_inst)
   {
   }
+  // used for archive serialization
+  frInst() : name_(""), master_(nullptr), db_inst_(nullptr) {}
path: src/drt/src/db/obj/frInst.h
user: login: github-actions[bot]
body: warning: redundant string initialization [[readability-redundant-string-init](https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-string-init.html)]

```suggestion
  frInst() : , master_(nullptr), db_inst_(nullptr) {}
```

created_at: 2025-03-02T23:43:42Z
author_association: CONTRIBUTOR
diff_hunk: @@ -50,6 +50,9 @@ class frInst : public frRef
       : name_(name), master_(master), db_inst_(db_inst)
   {
   }
+  // used for archive serialization
+  frInst() :, master_(nullptr), db_inst_(nullptr) {}
path: src/drt/src/db/obj/frInst.h
user: login: github-actions[bot]
body: warning: expected class member or base class name [clang-diagnostic-error]
```cpp
  frInst() :, master_(nullptr), db_inst_(nullptr) {}
            ^
```

created_at: 2025-03-17T17:21:17Z
author_association: CONTRIBUTOR
diff_hunk: @@ -778,8 +783,8 @@ bool FlexPA::genPatternsCommit(
   if (target_obj != nullptr
       && genPatternsGC({target_obj}, objs, Commit, &owners)) {
     pin_access_pattern->updateCost();
-    const int inst_idx = unique_insts_.getIndex(inst);
-    unique_inst_patterns_[inst_idx].push_back(std::move(pin_access_pattern));
+#pragma omp critical
+    unique_inst_patterns_[unique_inst].push_back(std::move(pin_access_pattern));
path: src/drt/src/pa/FlexPA_acc_pattern.cpp
user: login: osamahammad21
body: Not critical. No other thread would access the same entry for the current unique_inst. And we already created the entry beforehand, so the map would not be touched.
created_at: 2025-03-21T15:23:20Z
author_association: MEMBER

PR comments:
user: login: github-actions[bot]
created_at: 2025-03-17T17:51:51Z
body: clang-tidy review says "All clean, LGTM! :+1:"
author_association: CONTRIBUTOR
user: login: bnmfw
created_at: 2025-03-25T20:02:22Z
body: @osamahammad21 `UniqueInsts::deleteInst` does not own `unique_inst_patterns_`, that is why does not cover the deletion of the function. #6866, which is branched from this PR created `FlexPA::deleteInst` and covers this issue.

There is indeed an effort to use frInst* as keys. Using the index of unique_ as keys to other structures does not fit very well the attempt to make structures dynamic. There might be a PR later on that revamps the index usage as a key.
author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-03-25T20:12:04Z
body: clang-tidy review says "All clean, LGTM! :+1:"
author_association: CONTRIBUTOR