HAL
common_successor_predecessor.cpp
Go to the documentation of this file.
2 #include "gui/gui_globals.h"
6 
7 //#include "hal_core/netlist/
8 
9 namespace hal {
10 
12  : mIndex(i), mGate(g)
13  {
14  mLastWaypoint[g] = nullptr;
15  mQueue.append(g);
16  }
17 
19  {
20  QList<Gate*> retval;
21 
22  for (Gate* origin : mQueue)
23  {
24  for (Gate*g : netlist_utils::get_next_gates(origin, forward, 1))
25  {
26  if (mLastWaypoint.contains(g)) continue;
27  mLastWaypoint[g] = origin;
28  retval.append(g);
29  }
30  }
31 
32  return retval;
33  }
34 
36  {
37  QList<Gate*> retval;
38  while (g)
39  {
40  retval.append(g);
41  g = mLastWaypoint.value(g);
42  }
43  return retval;
44  }
45 
46  CommonSuccessorPredecessor::CommonSuccessorPredecessor(const QList<u32>& gateIds, bool forw, int maxRound)
47  : mForward(forw), mMaskAll(0)
48  {
49  if (gateIds.size() > 31)
50  {
51  log_warning("gui","Cannot find common {} for more than 31 gates", (forw?"successor":"predecessor"));
52  return;
53  }
54 
55  for (u32 id : gateIds)
56  {
57  Gate* g = gNetlist->get_gate_by_id(id);
58  Q_ASSERT(g);
59  CommonSuccessorPredecessorGateQueue cspgq(mQueues.size(),g);
60  int msk = cspgq.mask();
61  mMaskAll |= msk;
62  mFoundBit[g] |= msk;
63  mQueues.append(cspgq);
64  }
65 
66  for (int iRound = 0; iRound<maxRound; iRound++)
67  {
68  for (auto it = mQueues.begin(); it!=mQueues.end(); ++it)
69  {
70  QList nextGates = it->getNext(mForward);
71  for (Gate* g: nextGates)
72  if ((mFoundBit[g] |= it->mask()) == mMaskAll)
73  mFoundSet.insert(g);
74 
75  it->setQueue(nextGates);
76  }
77  if (!mFoundSet.isEmpty()) break;
78  }
79 
80  if (mFoundSet.isEmpty())
81  log_info("gui", "No common {} found.", (forw?"successor":"predecessor"));
82  }
83 
85  {
86  QSet<Gate*> retval;
87  for (Gate* g : mFoundSet)
88  {
89  for (const CommonSuccessorPredecessorGateQueue& cspgq : mQueues)
90  for (Gate* wayp : cspgq.waypoints(g))
91  retval.insert(wayp);
92  }
93  return retval;
94  }
95 }
96 
CommonSuccessorPredecessor(const QList< u32 > &gateIds, bool forw, int maxRound)
Definition: gate.h:58
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
#define log_info(channel,...)
Definition: log.h:70
#define log_warning(channel,...)
Definition: log.h:76
std::vector< Gate * > get_next_gates(const Gate *gate, bool get_successors, int depth, const std::function< bool(const Gate *)> &filter)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
quint32 u32
void append(const T &value)
int size() const const
QSet::iterator insert(const T &value)