Skip to content

Commit 279620a

Browse files
committed
Parallelize V3VariableOrder
Signed-off-by: Bartłomiej Chmiel <bchmiel@antmicro.com>
1 parent 4e86e60 commit 279620a

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

src/Makefile_obj.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ RAW_OBJS_PCH_ASTMT = \
210210
V3Options.o \
211211
V3Stats.o \
212212
V3StatsReport.o \
213+
V3VariableOrder.o \
213214

214215
RAW_OBJS_PCH_ASTNOMT = \
215216
V3Active.o \
@@ -309,7 +310,6 @@ RAW_OBJS_PCH_ASTNOMT = \
309310
V3Undriven.o \
310311
V3Unknown.o \
311312
V3Unroll.o \
312-
V3VariableOrder.o \
313313
V3Width.o \
314314
V3WidthCommit.o \
315315
V3WidthSel.o \

src/V3VariableOrder.cpp

+33-30
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
//
2121
//*************************************************************************
2222

23-
#include "V3PchAstNoMT.h" // VL_MT_DISABLED_CODE_UNIT
23+
#include "V3PchAstMT.h"
2424

2525
#include "V3VariableOrder.h"
2626

2727
#include "V3AstUserAllocator.h"
2828
#include "V3EmitCBase.h"
2929
#include "V3ExecGraph.h"
3030
#include "V3TSP.h"
31+
#include "V3ThreadPool.h"
3132

3233
#include <vector>
3334

@@ -127,17 +128,12 @@ class VarTspSorter final : public V3TSP::TspStateBase {
127128

128129
uint32_t VarTspSorter::s_serialNext = 0;
129130

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+
};
130135
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;
141137

142138
const MTaskAffinityMap& m_mTaskAffinity;
143139

@@ -157,8 +153,11 @@ class VariableOrder final {
157153
if (ap->isStatic() != bp->isStatic()) { // Non-statics before statics
158154
return bp->isStatic();
159155
}
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);
162161
if (attrA.anonOk != attrB.anonOk) { // Anons before non-anons
163162
return attrA.anonOk;
164163
}
@@ -218,22 +217,21 @@ class VariableOrder final {
218217
// Unlink, add to vector
219218
varp->unlinkFrBack();
220219
varps.push_back(varp);
220+
221221
// Compute attributes up front
222-
auto& attributes = m_attributes(varp);
223222
// Stratum
224223
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)});
237235
}
238236
}
239237

@@ -281,10 +279,15 @@ void V3VariableOrder::orderAll(AstNetlist* netlistp) {
281279
});
282280
}
283281

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+
}
288291
}
289292

290293
// Done

src/V3VariableOrder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AstNetlist;
2626

2727
class V3VariableOrder final {
2828
public:
29-
static void orderAll(AstNetlist*) VL_MT_DISABLED;
29+
static void orderAll(AstNetlist*);
3030
};
3131

3232
#endif // Guard

0 commit comments

Comments
 (0)