3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-12-12 14:46:23 +00:00

Forbid creating IdStrings and incrementing autoidx during multithreaded phases, and add dynamic checks for that

We could make it safe to increment autoidx during multithreaded passes, but that's
actually undesirable because it would lead to nondeterminism. If/when we need new
IDs during parallel passes, we'll have to figure out how to allocate them in a
deterministic way, and that will depend on the details of what the pass does.
So don't try to tackle that now.
This commit is contained in:
Robert O'Callahan 2025-11-24 22:29:06 +00:00
parent 4c8b537d71
commit 8f0ecce53f
5 changed files with 55 additions and 4 deletions

View file

@ -187,6 +187,7 @@ struct RTLIL::IdString
static int insert(std::string_view p)
{
log_assert(destruct_guard_ok);
log_assert(!Multithreading::active());
auto it = global_id_index_.find(p);
if (it != global_id_index_.end()) {
@ -202,6 +203,7 @@ struct RTLIL::IdString
// Inserts an ID with string `prefix + autoidx', incrementing autoidx.
// `prefix` must start with '$auto$', end with '$', and live forever.
static IdString new_autoidx_with_prefix(const std::string *prefix) {
log_assert(!Multithreading::active());
int index = -(autoidx++);
global_autoidx_id_prefix_storage_.insert({index, prefix});
return from_index(index);
@ -595,6 +597,8 @@ private:
}
static void get_reference(int idx)
{
log_assert(!Multithreading::active());
if (idx < static_cast<short>(StaticId::STATIC_ID_END))
return;
auto it = global_refcount_storage_.find(idx);
@ -610,6 +614,8 @@ private:
void put_reference()
{
log_assert(!Multithreading::active());
// put_reference() may be called from destructors after the destructor of
// global_refcount_storage_ has been run. in this case we simply do nothing.
if (index_ < static_cast<short>(StaticId::STATIC_ID_END) || !destruct_guard_ok)