From f4d5fb4c258e903231500c553e03f28fd56fcc4b Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 29 Nov 2016 03:32:24 +0100 Subject: [PATCH] Improve drawergen to only recompile the object file if its timestamp does not match --- tools/drawergen/drawergen.cpp | 48 ++++++++++++++++++- .../fixedfunction/drawcolumncodegen.cpp | 1 + .../drawergen/fixedfunction/drawercodegen.cpp | 1 + .../fixedfunction/drawskycodegen.cpp | 1 + .../fixedfunction/drawspancodegen.cpp | 1 + .../fixedfunction/drawtrianglecodegen.cpp | 1 + .../fixedfunction/drawwallcodegen.cpp | 1 + tools/drawergen/timestamp.h | 12 +++++ 8 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tools/drawergen/timestamp.h diff --git a/tools/drawergen/drawergen.cpp b/tools/drawergen/drawergen.cpp index dfe5fc11be..068fb164fa 100644 --- a/tools/drawergen/drawergen.cpp +++ b/tools/drawergen/drawergen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawspancodegen.h" #include "fixedfunction/drawwallcodegen.h" #include "fixedfunction/drawcolumncodegen.h" @@ -618,6 +619,18 @@ std::string LLVMProgram::DumpModule() ///////////////////////////////////////////////////////////////////////////// +std::string &AllTimestamps() +{ + static std::string timestamps; + return timestamps; +} + +void AddSourceFileTimestamp(const char *timestamp) +{ + if (!AllTimestamps().empty()) AllTimestamps().push_back(' '); + AllTimestamps() += timestamp; +} + int main(int argc, char **argv) { if (argc != 2) @@ -626,6 +639,25 @@ int main(int argc, char **argv) return 1; } + std::string timestamp_filename = argv[1] + std::string(".timestamp"); + + FILE *file = fopen(timestamp_filename.c_str(), "rb"); + if (file != nullptr) + { + char buffer[4096]; + int bytes_read = fread(buffer, 1, 4096, file); + fclose(file); + std::string last_timestamp; + if (bytes_read > 0) + last_timestamp = std::string(buffer, bytes_read); + + if (AllTimestamps() == last_timestamp) + { + std::cout << "Not recompiling drawers because the object file is already up to date." << std::endl; + exit(0); + } + } + llvm::install_fatal_error_handler([](void *user_data, const std::string& reason, bool gen_crash_diag) { std::cerr << "LLVM fatal error: " << reason; @@ -640,7 +672,7 @@ int main(int argc, char **argv) LLVMDrawers drawersSSE2(cpuName, "_SSE2"); - FILE *file = fopen(argv[1], "wb"); + file = fopen(argv[1], "wb"); if (file == nullptr) { std::cerr << "Unable to open " << argv[1] << " for writing." << std::endl; @@ -656,6 +688,20 @@ int main(int argc, char **argv) return 1; } + file = fopen(timestamp_filename.c_str(), "wb"); + if (file == nullptr) + { + std::cerr << "Could not create timestamp file" << std::endl; + return 1; + } + result = fwrite(AllTimestamps().data(), AllTimestamps().length(), 1, file); + fclose(file); + if (result != 1) + { + std::cerr << "Could not write timestamp file" << std::endl; + return 1; + } + //LLVMDrawers drawersSSE4("core2"); //LLVMDrawers drawersAVX("sandybridge"); //LLVMDrawers drawersAVX2("haswell"); diff --git a/tools/drawergen/fixedfunction/drawcolumncodegen.cpp b/tools/drawergen/fixedfunction/drawcolumncodegen.cpp index 0ce34c83c9..177074dad3 100644 --- a/tools/drawergen/fixedfunction/drawcolumncodegen.cpp +++ b/tools/drawergen/fixedfunction/drawcolumncodegen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawcolumncodegen.h" #include "ssa/ssa_function.h" #include "ssa/ssa_scope.h" diff --git a/tools/drawergen/fixedfunction/drawercodegen.cpp b/tools/drawergen/fixedfunction/drawercodegen.cpp index c1d24f5940..02c6e302a6 100644 --- a/tools/drawergen/fixedfunction/drawercodegen.cpp +++ b/tools/drawergen/fixedfunction/drawercodegen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawercodegen.h" #include "ssa/ssa_function.h" #include "ssa/ssa_scope.h" diff --git a/tools/drawergen/fixedfunction/drawskycodegen.cpp b/tools/drawergen/fixedfunction/drawskycodegen.cpp index 57016a6202..3a05818703 100644 --- a/tools/drawergen/fixedfunction/drawskycodegen.cpp +++ b/tools/drawergen/fixedfunction/drawskycodegen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawskycodegen.h" #include "ssa/ssa_function.h" #include "ssa/ssa_scope.h" diff --git a/tools/drawergen/fixedfunction/drawspancodegen.cpp b/tools/drawergen/fixedfunction/drawspancodegen.cpp index 2e9fd0d857..c6aacc75a2 100644 --- a/tools/drawergen/fixedfunction/drawspancodegen.cpp +++ b/tools/drawergen/fixedfunction/drawspancodegen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawspancodegen.h" #include "ssa/ssa_function.h" #include "ssa/ssa_scope.h" diff --git a/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp b/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp index 8b7e8001ce..fc2c3db151 100644 --- a/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp +++ b/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawtrianglecodegen.h" #include "ssa/ssa_function.h" #include "ssa/ssa_scope.h" diff --git a/tools/drawergen/fixedfunction/drawwallcodegen.cpp b/tools/drawergen/fixedfunction/drawwallcodegen.cpp index 90ca16a61b..94b807f40f 100644 --- a/tools/drawergen/fixedfunction/drawwallcodegen.cpp +++ b/tools/drawergen/fixedfunction/drawwallcodegen.cpp @@ -21,6 +21,7 @@ */ #include "precomp.h" +#include "timestamp.h" #include "fixedfunction/drawwallcodegen.h" #include "ssa/ssa_function.h" #include "ssa/ssa_scope.h" diff --git a/tools/drawergen/timestamp.h b/tools/drawergen/timestamp.h new file mode 100644 index 0000000000..6dd11bcffd --- /dev/null +++ b/tools/drawergen/timestamp.h @@ -0,0 +1,12 @@ + +#pragma once + +void AddSourceFileTimestamp(const char *timestamp); + +namespace +{ + struct TimestampSourceFile + { + TimestampSourceFile() { AddSourceFileTimestamp(__TIME__); } + } timestamp; +}