[llvm] r373338 - Revert rL349624 : Let TableGen write output only if it changed, instead of doing so in cmake, attempt 2
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 06:39:43 PDT 2019
Author: rksimon
Date: Tue Oct 1 06:39:43 2019
New Revision: 373338
URL: http://llvm.org/viewvc/llvm-project?rev=373338&view=rev
Log:
Revert rL349624 : Let TableGen write output only if it changed, instead of doing so in cmake, attempt 2
Differential Revision: https://reviews.llvm.org/D55842
-----------------
As discussed on PR43385 this is causing Visual Studio msbuilds to perpetually rebuild all tablegen generated files
Modified:
llvm/trunk/cmake/modules/TableGen.cmake
llvm/trunk/lib/TableGen/Main.cpp
llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni
Modified: llvm/trunk/cmake/modules/TableGen.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/TableGen.cmake?rev=373338&r1=373337&r2=373338&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/TableGen.cmake (original)
+++ llvm/trunk/cmake/modules/TableGen.cmake Tue Oct 1 06:39:43 2019
@@ -23,7 +23,7 @@ function(tablegen project ofn)
file(RELATIVE_PATH ofn_rel
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
set(additional_cmdline
- -o ${ofn_rel}
+ -o ${ofn_rel}.tmp
-d ${ofn_rel}.d
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d
@@ -34,7 +34,7 @@ function(tablegen project ofn)
file(GLOB local_tds "*.td")
file(GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR}/llvm/*.td")
set(additional_cmdline
- -o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
+ -o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
)
endif()
@@ -67,7 +67,8 @@ function(tablegen project ofn)
# dependency twice in the result file when
# ("${${project}_TABLEGEN_TARGET}" STREQUAL "${${project}_TABLEGEN_EXE}")
# but lets us having smaller and cleaner code here.
- add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
+ # Generate tablegen output in a temporary file.
COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
${LLVM_TABLEGEN_FLAGS}
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
@@ -80,9 +81,20 @@ function(tablegen project ofn)
${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
COMMENT "Building ${ofn}..."
)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
+ # Only update the real output file if there are any differences.
+ # This prevents recompilation of all the files depending on it if there
+ # aren't any.
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
+ ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
+ COMMENT "Updating ${ofn}..."
+ )
# `make clean' must remove all those generated files:
- set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ofn})
+ set_property(DIRECTORY APPEND
+ PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ofn}.tmp ${ofn})
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn} PARENT_SCOPE)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${ofn} PROPERTIES
Modified: llvm/trunk/lib/TableGen/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Main.cpp?rev=373338&r1=373337&r2=373338&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Main.cpp (original)
+++ llvm/trunk/lib/TableGen/Main.cpp Tue Oct 1 06:39:43 2019
@@ -99,39 +99,23 @@ int llvm::TableGenMain(char *argv0, Tabl
if (Parser.ParseFile())
return 1;
- // 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.
+ std::error_code EC;
+ ToolOutputFile Out(OutputFilename, EC, sys::fs::OF_None);
+ if (EC)
+ return reportError(argv0, "error opening " + OutputFilename + ":" +
+ EC.message() + "\n");
if (!DependFilename.empty()) {
if (int Ret = createDependencyFile(Parser, argv0))
return Ret;
}
- // 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::OF_None);
- if (EC)
- return reportError(argv0, "error opening " + OutputFilename + ":" +
- EC.message() + "\n");
- OutFile.os() << Out.str();
+ if (MainFn(Out.os(), Records))
+ return 1;
if (ErrorsPrinted > 0)
return reportError(argv0, Twine(ErrorsPrinted) + " errors.\n");
// Declare success.
- OutFile.keep();
+ Out.keep();
return 0;
}
Modified: llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni?rev=373338&r1=373337&r2=373338&view=diff
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni (original)
+++ llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni Tue Oct 1 06:39:43 2019
@@ -64,6 +64,11 @@ template("tablegen") {
depfile = "$gen_output.d"
td_file = rebase_path(td_file, root_build_dir)
+ # FIXME: The cmake build lets tablegen write to a temp file and then copies
+ # it over the final output only if it has changed, for ninja's restat
+ # optimization. Instead of doing that in cmake, llvm-tblgen should do this
+ # itself. r330742 tried this, but it caused problems. Fix those and reland,
+ # so that the gn build has the optimization too.
args = [
rebase_path(tblgen_executable, root_build_dir),
"-I",
More information about the llvm-commits
mailing list