diff --git a/src/V3EmitMk.h b/src/V3EmitMk.h index a23748fb0..0ddfdba66 100644 --- a/src/V3EmitMk.h +++ b/src/V3EmitMk.h @@ -26,6 +26,9 @@ class V3HierBlockPlan; class V3EmitMk final { public: + // Number of source files after which to use parallel compiles + static const size_t PARALLEL_FILE_CNT_THRESHOLD = 128; + static void emitmk(); static void emitHierVerilation(const V3HierBlockPlan* planp); }; diff --git a/src/Verilator.cpp b/src/Verilator.cpp index a833335ea..294320613 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -565,6 +565,13 @@ static void process() { reportStatsIfEnabled(); if (!v3Global.opt.lintOnly() && !v3Global.opt.xmlOnly() && !v3Global.opt.dpiHdrOnly()) { + size_t src_f_cnt = 0; + for (AstNode* nodep = v3Global.rootp()->filesp(); nodep; nodep = nodep->nextp()) { + if (const AstCFile* cfilep = VN_CAST(nodep, CFile)) + src_f_cnt += cfilep->source() ? 1 : 0; + } + if (src_f_cnt >= V3EmitMk::PARALLEL_FILE_CNT_THRESHOLD) v3Global.useParallelBuild(true); + // Makefile must be after all other emitters if (v3Global.opt.main()) V3EmitCMain::emit(); if (v3Global.opt.cmake()) V3EmitCMake::emit();