sort on insert

This commit is contained in:
em2machine 2025-12-24 08:49:02 +01:00
parent 184502471d
commit 3497e0f8ad
2 changed files with 16 additions and 8 deletions

View File

@ -101,10 +101,10 @@ void V3UndrivenCapture::sortUniqueVars(std::vector<AstVar*>& vec) {
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
}
void V3UndrivenCapture::sortUniqueFTasks(std::vector<const AstNodeFTask*>& vec) {
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
}
//void V3UndrivenCapture::sortUniqueFTasks(std::vector<const AstNodeFTask*>& vec) {
// std::sort(vec.begin(), vec.end());
// vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
//}
V3UndrivenCapture::V3UndrivenCapture(AstNetlist* netlistp) {
gather(netlistp);
@ -112,7 +112,7 @@ V3UndrivenCapture::V3UndrivenCapture(AstNetlist* netlistp) {
// Normalize direct lists
for (auto& kv : m_info) {
sortUniqueVars(kv.second.directWrites);
sortUniqueFTasks(kv.second.callees);
//sortUniqueFTasks(kv.second.callees);
}
// Compute summaries for all tasks
@ -194,8 +194,13 @@ void V3UndrivenCapture::noteDirectWrite(const AstNodeFTask* taskp, AstVar* varp)
}
void V3UndrivenCapture::noteCallEdge(const AstNodeFTask* callerp, const AstNodeFTask* calleep) {
m_info[callerp].callees.push_back(calleep);
(void)m_info[calleep]; // ensure callee entry exists
//m_info[callerp].callees.push_back(calleep);
//(void)m_info[calleep]; // ensure callee entry exists
FTaskInfo& callerInfo = m_info[callerp];
if (callerInfo.calleesSet.insert(calleep).second) {
callerInfo.callees.push_back(calleep);
}
(void)m_info[calleep];
}
void V3UndrivenCapture::debugDumpTask(const AstNodeFTask* taskp, int level) const {

View File

@ -55,6 +55,9 @@ public:
std::vector<AstVar*> writeSummary;
// State for writeSummary computation.
State state = State::UNVISITED;
// This is used to test whether weve already recorded a callee. Used to 'filter' on insert
// versus sorting at the end.
std::unordered_set<const AstNodeFTask*> calleesSet;
};
// Enable writeSummary computation. If disabled, then the existing V3Undriven behaviour is
@ -74,7 +77,7 @@ private:
static void sortUniqueVars(std::vector<AstVar*>& vec);
// Sort and remove duplicates from a vector of callees. The visitor can record the same callee
// multiple times (multiple call sites, branches, etc).
static void sortUniqueFTasks(std::vector<const AstNodeFTask*>& vec);
//static void sortUniqueFTasks(std::vector<const AstNodeFTask*>& vec);
// Collect direct writes and call edges for all tasks/functions. Run one time when
// UndrivenCapture is created. This runs the visitor over the tree.