Fix `--stats` overridden by skipping identical build (#6220).

This commit is contained in:
Wilson Snyder 2025-07-25 07:23:02 -04:00
parent 10ac99ac05
commit fa62cd3486
3 changed files with 29 additions and 16 deletions

View File

@ -45,6 +45,7 @@ Verilator 5.039 devel
* Fix VPI signal range order (#6189) (#6200). [Ibrahim Burak Yorulmaz] * Fix VPI signal range order (#6189) (#6200). [Ibrahim Burak Yorulmaz]
* Fix structure select causing 'Wide Op' error (#6191). [Danny Oler] * Fix structure select causing 'Wide Op' error (#6191). [Danny Oler]
* Fix 'driver same component' assertion (#6211) (#6215). [Geza Lore] * Fix 'driver same component' assertion (#6211) (#6215). [Geza Lore]
* Fix `--stats` overridden by skipping identical build (#6220). [Geza Lore]
Verilator 5.038 2025-07-08 Verilator 5.038 2025-07-08

View File

@ -651,7 +651,8 @@ static void process() {
if (v3Global.opt.stats()) V3Stats::statsStage("emit"); if (v3Global.opt.stats()) V3Stats::statsStage("emit");
} }
static void verilate(const string& argString) { static bool verilate(const string& argString) {
// Run verilation, and return false if skipped
UINFO(1, "Option --verilate: Start Verilation"); UINFO(1, "Option --verilate: Start Verilation");
// Can we skip doing everything if times are ok? // Can we skip doing everything if times are ok?
@ -661,7 +662,7 @@ static void verilate(const string& argString) {
+ "__verFiles.dat", + "__verFiles.dat",
argString)) { argString)) {
UINFO(1, "--skip-identical: No change to any source files, exiting"); UINFO(1, "--skip-identical: No change to any source files, exiting");
return; return false;
} }
// Undocumented debugging - cannot be a switch as then command line // Undocumented debugging - cannot be a switch as then command line
// would mismatch forcing non-identicalness when we set it // would mismatch forcing non-identicalness when we set it
@ -775,10 +776,12 @@ static void verilate(const string& argString) {
V3Error::abortIfWarnings(); V3Error::abortIfWarnings();
// Free memory so compiler has more for --build // Free memory so compiler has more for --build
// No need to do this if skipped (above) as didn't alloc much
UINFO(1, "Releasing netlist memory"); UINFO(1, "Releasing netlist memory");
v3Global.rootp()->deleteContents(); v3Global.rootp()->deleteContents();
V3Os::releaseMemory(); V3Os::releaseMemory();
if (v3Global.opt.stats()) V3Stats::statsStage("released"); if (v3Global.opt.stats()) V3Stats::statsStage("released");
return true;
} }
static string buildMakeCmd(const string& makefile, const string& target) { static string buildMakeCmd(const string& makefile, const string& target) {
@ -862,8 +865,9 @@ int main(int argc, char** argv) {
V3Error::abortIfErrors(); V3Error::abortIfErrors();
bool didVerilate = false;
if (v3Global.opt.verilate()) { if (v3Global.opt.verilate()) {
verilate(argString); didVerilate = verilate(argString);
} else { } else {
UINFO(1, "Option --no-verilate: Skip Verilation"); UINFO(1, "Option --no-verilate: Skip Verilation");
} }
@ -874,7 +878,7 @@ int main(int argc, char** argv) {
execBuildJob(); execBuildJob();
} }
reportStatsIfEnabled(); if (didVerilate) reportStatsIfEnabled();
V3DiagSarif::output(true); V3DiagSarif::output(true);
// Explicitly release resources // Explicitly release resources

View File

@ -10,27 +10,35 @@
import vltest_bootstrap import vltest_bootstrap
import time import time
FileTimes = {}
def prep_output_file(filename):
oldstats = os.path.getmtime(filename)
if not oldstats:
test.error("No output file found: " + filename)
print("Old %s mtime=%d" % (filename, oldstats))
FileTimes[filename] = oldstats
test.scenarios('vlt') test.scenarios('vlt')
test.compile() test.compile(verilator_flags2=['--stats'])
print("NOTE: use --debugi, as --debug in driver turns off skip-identical") print("NOTE: use --debugi, as --debug in driver turns off skip-identical")
outfile = test.obj_dir + "/V" + test.name + ".cpp" prep_output_file(test.obj_dir + "/V" + test.name + ".cpp")
oldstats = os.path.getmtime(outfile) prep_output_file(test.obj_dir + "/V" + test.name + "__stats.txt")
if not oldstats:
test.error("No output file found: " + outfile)
print("Old mtime=", oldstats)
time.sleep(2) # Or else it might take < 1 second to compile and see no diff. time.sleep(2) # Or else it might take < 1 second to compile and see no diff.
test.setenv('VERILATOR_DEBUG_SKIP_IDENTICAL', "1") test.setenv('VERILATOR_DEBUG_SKIP_IDENTICAL', "1")
test.compile() test.compile(verilator_flags2=['--stats'])
newstats = os.path.getmtime(outfile) for filename, oldtime in FileTimes.items():
print("New mtime=", newstats) newstats = os.path.getmtime(filename)
print("New %s mtime=%d" % (filename, newstats))
if oldstats != newstats: if oldtime != newstats:
test.error("--skip-identical was ignored -- recompiled") test.error("--skip-identical was ignored -- regenerated %s" % (filename))
test.passes() test.passes()