Internals: Rework addFilesp towards parallel emit (#3620). No functional change intended.

This commit is contained in:
Kamil Rakoczy 2022-09-13 18:15:34 +02:00 committed by GitHub
parent 81fe35ee2e
commit 93a044f587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 16 deletions

View File

@ -57,11 +57,11 @@ string EmitCBaseVisitor::funcNameProtect(const AstCFunc* nodep, const AstNodeMod
return name; return name;
} }
AstCFile* EmitCBaseVisitor::newCFile(const string& filename, bool slow, bool source) { AstCFile* EmitCBaseVisitor::newCFile(const string& filename, bool slow, bool source, bool add) {
AstCFile* const cfilep = new AstCFile(v3Global.rootp()->fileline(), filename); AstCFile* const cfilep = new AstCFile(v3Global.rootp()->fileline(), filename);
cfilep->slow(slow); cfilep->slow(slow);
cfilep->source(source); cfilep->source(source);
v3Global.rootp()->addFilesp(cfilep); if (add) v3Global.rootp()->addFilesp(cfilep);
return cfilep; return cfilep;
} }

View File

@ -100,7 +100,7 @@ public:
&& (varp->basicp() && !varp->basicp()->isOpaque()); // Aggregates can't be anon && (varp->basicp() && !varp->basicp()->isOpaque()); // Aggregates can't be anon
} }
static AstCFile* newCFile(const string& filename, bool slow, bool source); static AstCFile* newCFile(const string& filename, bool slow, bool source, bool add = true);
string cFuncArgs(const AstCFunc* nodep); string cFuncArgs(const AstCFunc* nodep);
void emitCFuncHeader(const AstCFunc* funcp, const AstNodeModule* modp, bool withScope); void emitCFuncHeader(const AstCFunc* funcp, const AstNodeModule* modp, bool withScope);
void emitCFuncDecl(const AstCFunc* funcp, const AstNodeModule* modp, bool cLinkage = false); void emitCFuncDecl(const AstCFunc* funcp, const AstNodeModule* modp, bool cLinkage = false);

View File

@ -148,6 +148,7 @@ class EmitCImp final : EmitCFunc {
const std::set<string>* m_requiredHeadersp; // Header files required by output file const std::set<string>* m_requiredHeadersp; // Header files required by output file
std::string m_subFileName; // substring added to output filenames std::string m_subFileName; // substring added to output filenames
V3UniqueNames m_uniqueNames; // For generating unique file names V3UniqueNames m_uniqueNames; // For generating unique file names
std::deque<AstCFile*>& m_cfilesr; // cfiles generated by this emit
// METHODS // METHODS
void openNextOutputFile(const std::set<string>& headers, const string& subFileName) { void openNextOutputFile(const std::set<string>& headers, const string& subFileName) {
@ -160,7 +161,8 @@ class EmitCImp final : EmitCFunc {
// Unfortunately we have some lint checks here, so we can't just skip processing. // Unfortunately we have some lint checks here, so we can't just skip processing.
// We should move them to a different stage. // We should move them to a different stage.
const string filename = VL_DEV_NULL; const string filename = VL_DEV_NULL;
newCFile(filename, /* slow: */ m_slow, /* source: */ true); m_cfilesr.push_back(
newCFile(filename, /* slow: */ m_slow, /* source: */ true, /* add */ false));
m_ofp = new V3OutCFile(filename); m_ofp = new V3OutCFile(filename);
} else { } else {
string filename = v3Global.opt.makeDir() + "/" + prefixNameProtect(m_fileModp); string filename = v3Global.opt.makeDir() + "/" + prefixNameProtect(m_fileModp);
@ -170,7 +172,8 @@ class EmitCImp final : EmitCFunc {
} }
if (m_slow) filename += "__Slow"; if (m_slow) filename += "__Slow";
filename += ".cpp"; filename += ".cpp";
newCFile(filename, /* slow: */ m_slow, /* source: */ true); m_cfilesr.push_back(
newCFile(filename, /* slow: */ m_slow, /* source: */ true, /* add */ false));
m_ofp = v3Global.opt.systemC() ? new V3OutScFile(filename) : new V3OutCFile(filename); m_ofp = v3Global.opt.systemC() ? new V3OutScFile(filename) : new V3OutCFile(filename);
} }
@ -522,9 +525,10 @@ class EmitCImp final : EmitCFunc {
EmitCFunc::visit(nodep); EmitCFunc::visit(nodep);
} }
explicit EmitCImp(const AstNodeModule* modp, bool slow) explicit EmitCImp(const AstNodeModule* modp, bool slow, std::deque<AstCFile*>& cfilesr)
: m_fileModp{modp} : m_fileModp{modp}
, m_slow{slow} { , m_slow{slow}
, m_cfilesr{cfilesr} {
UINFO(5, " Emitting implementation of " << prefixNameProtect(modp) << endl); UINFO(5, " Emitting implementation of " << prefixNameProtect(modp) << endl);
m_modp = modp; m_modp = modp;
@ -543,7 +547,9 @@ class EmitCImp final : EmitCFunc {
virtual ~EmitCImp() override = default; virtual ~EmitCImp() override = default;
public: public:
static void main(const AstNodeModule* modp, bool slow) { EmitCImp{modp, slow}; } static void main(const AstNodeModule* modp, bool slow, std::deque<AstCFile*>& cfilesr) {
EmitCImp{modp, slow, cfilesr};
}
}; };
//###################################################################### //######################################################################
@ -558,6 +564,7 @@ class EmitCTrace final : EmitCFunc {
int m_enumNum = 0; // Enumeration number (whole netlist) int m_enumNum = 0; // Enumeration number (whole netlist)
V3UniqueNames m_uniqueNames; // For generating unique file names V3UniqueNames m_uniqueNames; // For generating unique file names
std::unordered_map<AstNode*, int> m_enumNumMap; // EnumDType to enumeration number std::unordered_map<AstNode*, int> m_enumNumMap; // EnumDType to enumeration number
std::deque<AstCFile*>& m_cfilesr; // cfiles generated by this emit
// METHODS // METHODS
void openNextOutputFile() { void openNextOutputFile() {
@ -572,8 +579,9 @@ class EmitCTrace final : EmitCFunc {
if (m_slow) filename += "__Slow"; if (m_slow) filename += "__Slow";
filename += ".cpp"; filename += ".cpp";
AstCFile* const cfilep = newCFile(filename, m_slow, true /*source*/); AstCFile* const cfilep = newCFile(filename, m_slow, true /*source*/, false /*add*/);
cfilep->support(true); cfilep->support(true);
m_cfilesr.push_back(cfilep);
if (optSystemC()) { if (optSystemC()) {
m_ofp = new V3OutScFile(filename); m_ofp = new V3OutScFile(filename);
@ -862,8 +870,9 @@ class EmitCTrace final : EmitCFunc {
} }
} }
explicit EmitCTrace(AstNodeModule* modp, bool slow) explicit EmitCTrace(AstNodeModule* modp, bool slow, std::deque<AstCFile*>& cfilesr)
: m_slow{slow} { : m_slow{slow}
, m_cfilesr{cfilesr} {
m_modp = modp; m_modp = modp;
// Open output file // Open output file
openNextOutputFile(); openNextOutputFile();
@ -877,7 +886,9 @@ class EmitCTrace final : EmitCFunc {
virtual ~EmitCTrace() override = default; virtual ~EmitCTrace() override = default;
public: public:
static void main(AstNodeModule* modp, bool slow) { EmitCTrace{modp, slow}; } static void main(AstNodeModule* modp, bool slow, std::deque<AstCFile*>& cfilesr) {
EmitCTrace{modp, slow, cfilesr};
}
}; };
//###################################################################### //######################################################################
@ -887,19 +898,27 @@ void V3EmitC::emitcImp() {
UINFO(2, __FUNCTION__ << ": " << endl); UINFO(2, __FUNCTION__ << ": " << endl);
// Make parent module pointers available. // Make parent module pointers available.
const EmitCParentModule emitCParentModule; const EmitCParentModule emitCParentModule;
std::list<std::deque<AstCFile*>> cfiles;
// Process each module in turn // Process each module in turn
for (const AstNode* nodep = v3Global.rootp()->modulesp(); nodep; nodep = nodep->nextp()) { for (const AstNode* nodep = v3Global.rootp()->modulesp(); nodep; nodep = nodep->nextp()) {
if (VN_IS(nodep, Class)) continue; // Imped with ClassPackage if (VN_IS(nodep, Class)) continue; // Imped with ClassPackage
const AstNodeModule* const modp = VN_AS(nodep, NodeModule); const AstNodeModule* const modp = VN_AS(nodep, NodeModule);
EmitCImp::main(modp, /* slow: */ true); cfiles.emplace_back();
EmitCImp::main(modp, /* slow: */ false); EmitCImp::main(modp, /* slow: */ true, cfiles.back());
cfiles.emplace_back();
EmitCImp::main(modp, /* slow: */ false, cfiles.back());
} }
// Emit trace routines (currently they can only exist in the top module) // Emit trace routines (currently they can only exist in the top module)
if (v3Global.opt.trace() && !v3Global.opt.lintOnly()) { if (v3Global.opt.trace() && !v3Global.opt.lintOnly()) {
EmitCTrace::main(v3Global.rootp()->topModulep(), /* slow: */ true); cfiles.emplace_back();
EmitCTrace::main(v3Global.rootp()->topModulep(), /* slow: */ false); EmitCTrace::main(v3Global.rootp()->topModulep(), /* slow: */ true, cfiles.back());
cfiles.emplace_back();
EmitCTrace::main(v3Global.rootp()->topModulep(), /* slow: */ false, cfiles.back());
}
for (const auto& collr : cfiles) {
for (const auto cfilep : collr) v3Global.rootp()->addFilesp(cfilep);
} }
} }