aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen/Main.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2018-04-24 17:29:05 +0000
committerNico Weber <nicolasweber@gmx.de>2018-04-24 17:29:05 +0000
commitebc7c74f2f54a3cb6cf86ab26e1296f8311f11e9 (patch)
tree12450de9e45d439844594358d52591123292ff46 /llvm/lib/TableGen/Main.cpp
parentd2ac0faf3bdcdc3629b7447f009d98face285ba0 (diff)
downloadllvm-ebc7c74f2f54a3cb6cf86ab26e1296f8311f11e9.zip
llvm-ebc7c74f2f54a3cb6cf86ab26e1296f8311f11e9.tar.gz
llvm-ebc7c74f2f54a3cb6cf86ab26e1296f8311f11e9.tar.bz2
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. https://reviews.llvm.org/D45899 llvm-svn: 330742
Diffstat (limited to 'llvm/lib/TableGen/Main.cpp')
-rw-r--r--llvm/lib/TableGen/Main.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index be35f89..d230300 100644
--- a/llvm/lib/TableGen/Main.cpp
+++ b/llvm/lib/TableGen/Main.cpp
@@ -96,8 +96,21 @@ int llvm::TableGenMain(char *argv0, TableGenMainFn *MainFn) {
if (Parser.ParseFile())
return 1;
+ // Write output to memory.
+ std::string OutString;
+ raw_string_ostream Out(OutString);
+ if (MainFn(Out, 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 Out(OutputFilename, EC, sys::fs::F_Text);
+ ToolOutputFile OutFile(OutputFilename, EC, sys::fs::F_Text);
if (EC)
return reportError(argv0, "error opening " + OutputFilename + ":" +
EC.message() + "\n");
@@ -105,14 +118,12 @@ int llvm::TableGenMain(char *argv0, TableGenMainFn *MainFn) {
if (int Ret = createDependencyFile(Parser, argv0))
return Ret;
}
-
- if (MainFn(Out.os(), Records))
- return 1;
+ OutFile.os() << Out.str();
if (ErrorsPrinted > 0)
return reportError(argv0, Twine(ErrorsPrinted) + " errors.\n");
// Declare success.
- Out.keep();
+ OutFile.keep();
return 0;
}