passes: opt_share: don't statically initialize mergeable_type_map
authorSean Cross <sean@xobs.io>
Mon, 9 Sep 2019 04:40:01 +0000 (12:40 +0800)
committerSean Cross <sean@xobs.io>
Mon, 9 Sep 2019 04:40:01 +0000 (12:40 +0800)
In 3d3779b0376b8204ed7637053176a07b7271ac1d this got turned from a
`std::map<std::string, std::string>` to `std::map<IdString, IdString>`.
Consequently, this exposed some initialization sequencing issues (#1361).

Only initialize the map when it's first used, to avoid these static issues.

This fixes #1361.

Signed-off-by: Sean Cross <sean@xobs.io>
passes/opt/opt_share.cc

index c53fb3113186b373637894cd8a24a0f442f6d0b8..2c456705cf878767de131fa97ad52039306905e4 100644 (file)
@@ -108,12 +108,13 @@ bool cell_supported(RTLIL::Cell *cell)
        return false;
 }
 
-std::map<IdString, IdString> mergeable_type_map{
-  {ID($sub), ID($add)},
-};
+std::map<IdString, IdString> mergeable_type_map;
 
 bool mergeable(RTLIL::Cell *a, RTLIL::Cell *b)
 {
+       if (mergeable_type_map.empty()) {
+               mergeable_type_map.insert({ID($sub), ID($add)});
+       }
        auto a_type = a->type;
        if (mergeable_type_map.count(a_type))
                a_type = mergeable_type_map.at(a_type);