20
20
//
21
21
// *************************************************************************
22
22
23
- #include " V3PchAstNoMT .h" // VL_MT_DISABLED_CODE_UNIT
23
+ #include " V3PchAstMT .h"
24
24
25
25
#include " V3VariableOrder.h"
26
26
27
27
#include " V3AstUserAllocator.h"
28
28
#include " V3EmitCBase.h"
29
29
#include " V3ExecGraph.h"
30
30
#include " V3TSP.h"
31
+ #include " V3ThreadPool.h"
31
32
32
33
#include < vector>
33
34
@@ -127,17 +128,12 @@ class VarTspSorter final : public V3TSP::TspStateBase {
127
128
128
129
uint32_t VarTspSorter::s_serialNext = 0 ;
129
130
131
+ struct VarAttributes final {
132
+ uint8_t stratum; // Roughly equivalent to alignment requirement, to avoid padding
133
+ bool anonOk; // Can be emitted as part of anonymous structure
134
+ };
130
135
class VariableOrder final {
131
- // NODE STATE
132
- // AstVar::user1() -> attributes, via m_attributes
133
- const VNUser1InUse m_user1InUse; // AstVar
134
-
135
- struct VarAttributes final {
136
- uint32_t stratum; // Roughly equivalent to alignment requirement, to avoid padding
137
- bool anonOk; // Can be emitted as part of anonymous structure
138
- };
139
-
140
- AstUser1Allocator<AstVar, VarAttributes> m_attributes; // Attributes used for sorting
136
+ std::unordered_map<const AstVar*, VarAttributes> m_attributes;
141
137
142
138
const MTaskAffinityMap& m_mTaskAffinity;
143
139
@@ -157,8 +153,11 @@ class VariableOrder final {
157
153
if (ap->isStatic () != bp->isStatic ()) { // Non-statics before statics
158
154
return bp->isStatic ();
159
155
}
160
- const auto & attrA = m_attributes (ap);
161
- const auto & attrB = m_attributes (bp);
156
+ UASSERT (m_attributes.find (ap) != m_attributes.end ()
157
+ && m_attributes.find (bp) != m_attributes.end (),
158
+ " m_attributes should be populated for each AstVar" );
159
+ const auto & attrA = m_attributes.at (ap);
160
+ const auto & attrB = m_attributes.at (bp);
162
161
if (attrA.anonOk != attrB.anonOk ) { // Anons before non-anons
163
162
return attrA.anonOk ;
164
163
}
@@ -218,22 +217,21 @@ class VariableOrder final {
218
217
// Unlink, add to vector
219
218
varp->unlinkFrBack ();
220
219
varps.push_back (varp);
220
+
221
221
// Compute attributes up front
222
- auto & attributes = m_attributes (varp);
223
222
// Stratum
224
223
const int sigbytes = varp->dtypeSkipRefp ()->widthAlignBytes ();
225
- attributes.stratum = (v3Global.opt .hierChild () && varp->isPrimaryIO ()) ? 0
226
- : (varp->isUsedClock () && varp->widthMin () == 1 ) ? 1
227
- : VN_IS (varp->dtypeSkipRefp (), UnpackArrayDType) ? 9
228
- : (varp->basicp () && varp->basicp ()->isOpaque ()) ? 8
229
- : (varp->isScBv () || varp->isScBigUint ()) ? 7
230
- : (sigbytes == 8 ) ? 6
231
- : (sigbytes == 4 ) ? 5
232
- : (sigbytes == 2 ) ? 3
233
- : (sigbytes == 1 ) ? 2
234
- : 10 ;
235
- // Anonymous structure ok
236
- attributes.anonOk = EmitCBase::isAnonOk (varp);
224
+ const uint8_t stratum = (v3Global.opt .hierChild () && varp->isPrimaryIO ()) ? 0
225
+ : (varp->isUsedClock () && varp->widthMin () == 1 ) ? 1
226
+ : VN_IS (varp->dtypeSkipRefp (), UnpackArrayDType) ? 9
227
+ : (varp->basicp () && varp->basicp ()->isOpaque ()) ? 8
228
+ : (varp->isScBv () || varp->isScBigUint ()) ? 7
229
+ : (sigbytes == 8 ) ? 6
230
+ : (sigbytes == 4 ) ? 5
231
+ : (sigbytes == 2 ) ? 3
232
+ : (sigbytes == 1 ) ? 2
233
+ : 10 ;
234
+ m_attributes.emplace (varp, VarAttributes{stratum, EmitCBase::isAnonOk (varp)});
237
235
}
238
236
}
239
237
@@ -281,10 +279,15 @@ void V3VariableOrder::orderAll(AstNetlist* netlistp) {
281
279
});
282
280
}
283
281
284
- // Order variables in each module
285
- for (AstNodeModule* modp = v3Global.rootp ()->modulesp (); modp;
286
- modp = VN_AS (modp->nextp (), NodeModule)) {
287
- VariableOrder::processModule (modp, mTaskAffinity );
282
+ {
283
+ V3ThreadScope threadScope;
284
+
285
+ // Order variables in each module
286
+ for (AstNodeModule* modp = v3Global.rootp ()->modulesp (); modp;
287
+ modp = VN_AS (modp->nextp (), NodeModule)) {
288
+ threadScope.enqueue (
289
+ [modp, mTaskAffinity ]() { VariableOrder::processModule (modp, mTaskAffinity ); });
290
+ }
288
291
}
289
292
290
293
// Done
0 commit comments