diff options
author | Nico Weber <nicolasweber@gmx.de> | 2018-12-19 13:35:53 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2018-12-19 13:35:53 +0000 |
commit | f7cf1a1a7353dc5c578dfc85eb963e61a4d406cd (patch) | |
tree | b68f7ad17c40e14c0235fb74d0750963bed31578 /llvm/lib/TableGen/Main.cpp | |
parent | 530108cb5cb5a0a2a632c3db1c1de61c09371973 (diff) | |
download | bcm5719-llvm-f7cf1a1a7353dc5c578dfc85eb963e61a4d406cd.tar.gz bcm5719-llvm-f7cf1a1a7353dc5c578dfc85eb963e61a4d406cd.zip |
Let TableGen write output only if it changed, instead of doing so in cmake, attempt 2
This relands r330742:
"""
Let TableGen write output only if it changed, instead of doing so in cmake.
Removes one subprocess and one temp file from the build for each tablegen
invocation.
No intended behavior change.
"""
In particular, if you see rebuilds after this change that you didn't see
before this change, that's unintended and it's fine to revert this change
again (but let me know).
r330742 got reverted because some people reported that llvm-tblgen ran on every
build after it. This could happen if the depfile output got deleted without
deleting the main .inc output. To fix, make TableGen always write the depfile,
but keep writing the main .inc output only if it has changed. This matches what
we did in cmake before.
Differential Revision: https://reviews.llvm.org/D55842
llvm-svn: 349624
Diffstat (limited to 'llvm/lib/TableGen/Main.cpp')
-rw-r--r-- | llvm/lib/TableGen/Main.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp index df4088ad2f8..02698416609 100644 --- a/llvm/lib/TableGen/Main.cpp +++ b/llvm/lib/TableGen/Main.cpp @@ -100,23 +100,39 @@ int llvm::TableGenMain(char *argv0, TableGenMainFn *MainFn) { if (Parser.ParseFile()) return 1; - std::error_code EC; - ToolOutputFile Out(OutputFilename, EC, sys::fs::F_Text); - if (EC) - return reportError(argv0, "error opening " + OutputFilename + ":" + - EC.message() + "\n"); + // Write output to memory. + std::string OutString; + raw_string_ostream Out(OutString); + if (MainFn(Out, Records)) + return 1; + + // Always write the depfile, even if the main output hasn't changed. + // If it's missing, Ninja considers the output dirty. If this was below + // the early exit below and someone deleted the .inc.d file but not the .inc + // file, tablegen would never write the depfile. if (!DependFilename.empty()) { if (int Ret = createDependencyFile(Parser, argv0)) return Ret; } - if (MainFn(Out.os(), Records)) - return 1; + // Only updates the real output file if there are any differences. + // This prevents recompilation of all the files depending on it if there + // aren't any. + if (auto ExistingOrErr = MemoryBuffer::getFile(OutputFilename)) + if (std::move(ExistingOrErr.get())->getBuffer() == Out.str()) + return 0; + + std::error_code EC; + ToolOutputFile OutFile(OutputFilename, EC, sys::fs::F_Text); + if (EC) + return reportError(argv0, "error opening " + OutputFilename + ":" + + EC.message() + "\n"); + OutFile.os() << Out.str(); if (ErrorsPrinted > 0) return reportError(argv0, Twine(ErrorsPrinted) + " errors.\n"); // Declare success. - Out.keep(); + OutFile.keep(); return 0; } |