diff --git a/clang/tools/c-index-test/CMakeLists.txt b/clang/tools/c-index-test/CMakeLists.txt index 41e80e66ffa7a..301d5ff8b7983 100644 --- a/clang/tools/c-index-test/CMakeLists.txt +++ b/clang/tools/c-index-test/CMakeLists.txt @@ -5,6 +5,9 @@ set(LLVM_LINK_COMPONENTS add_clang_executable(c-index-test c-index-test.c core_main.cpp + + # Prevent CMake error with C source files. + DISABLE_PCH_REUSE ) if(NOT MSVC) diff --git a/clang/tools/clang-fuzzer/dictionary/CMakeLists.txt b/clang/tools/clang-fuzzer/dictionary/CMakeLists.txt index 6b72b98f5e1c4..eec692a3b2e48 100644 --- a/clang/tools/clang-fuzzer/dictionary/CMakeLists.txt +++ b/clang/tools/clang-fuzzer/dictionary/CMakeLists.txt @@ -1,5 +1,8 @@ set(CMAKE_CXX_FLAGS ${CXX_FLAGS_NOFUZZ}) add_clang_executable(clang-fuzzer-dictionary dictionary.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index c01eb56d5e496..e21304d2e4da7 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -441,11 +441,6 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) if (BUILD_SHARED_LIBS AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-semantic-interposition") endif() - - # GCC requires this flag in order for precompiled headers to work with ccache - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpch-preprocess") - endif() endif() # Clang on Darwin enables non-POSIX extensions by default, which allows the @@ -456,11 +451,6 @@ if (APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809") endif() -# Clang requires this flag in order for precompiled headers to work with ccache -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fno-pch-timestamp") -endif() - list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS) # Determine HOST_LINK_VERSION on Darwin. diff --git a/flang/lib/Evaluate/CMakeLists.txt b/flang/lib/Evaluate/CMakeLists.txt index 24a1c9004bc3b..472ecb6d8d079 100644 --- a/flang/lib/Evaluate/CMakeLists.txt +++ b/flang/lib/Evaluate/CMakeLists.txt @@ -66,15 +66,8 @@ add_flang_library(FortranEvaluate ${LIBPGMATH} ${QUADMATHLIB} - LINK_COMPONENTS - Support - - DEPENDS - acc_gen - omp_gen -) - -target_precompile_headers(FortranEvaluate PRIVATE + DISABLE_PCH_REUSE + PRECOMPILE_HEADERS [["flang/Evaluate/common.h"]] [["flang/Evaluate/call.h"]] [["flang/Evaluate/traverse.h"]] @@ -86,4 +79,11 @@ target_precompile_headers(FortranEvaluate PRIVATE [["flang/Evaluate/integer.h"]] [["flang/Evaluate/expression.h"]] [["flang/Evaluate/tools.h"]] + + LINK_COMPONENTS + Support + + DEPENDS + acc_gen + omp_gen ) diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt index 4ebe497e65676..bd67ec444f358 100644 --- a/flang/lib/Frontend/CMakeLists.txt +++ b/flang/lib/Frontend/CMakeLists.txt @@ -13,6 +13,14 @@ add_flang_library(flangFrontend TextDiagnosticBuffer.cpp TextDiagnostic.cpp + DISABLE_PCH_REUSE + PRECOMPILE_HEADERS + [["flang/Parser/parsing.h"]] + [["flang/Parser/parse-tree.h"]] + [["flang/Parser/dump-parse-tree.h"]] + [["flang/Lower/PFTBuilder.h"]] + [["flang/Lower/Bridge.h"]] + DEPENDS CUFDialect FIRDialect @@ -78,11 +86,3 @@ add_flang_library(flangFrontend clangBasic clangOptions ) - -target_precompile_headers(flangFrontend PRIVATE - [["flang/Parser/parsing.h"]] - [["flang/Parser/parse-tree.h"]] - [["flang/Parser/dump-parse-tree.h"]] - [["flang/Lower/PFTBuilder.h"]] - [["flang/Lower/Bridge.h"]] -) diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt index 230a56ab66ec5..f5424c78b9a98 100644 --- a/flang/lib/Lower/CMakeLists.txt +++ b/flang/lib/Lower/CMakeLists.txt @@ -38,6 +38,17 @@ add_flang_library(FortranLower Support/Utils.cpp SymbolMap.cpp VectorSubscripts.cpp + + DISABLE_PCH_REUSE + PRECOMPILE_HEADERS + [["flang/Lower/ConvertExpr.h"]] + [["flang/Lower/SymbolMap.h"]] + [["flang/Lower/AbstractConverter.h"]] + [["flang/Lower/IterationSpace.h"]] + [["flang/Lower/CallInterface.h"]] + [["flang/Lower/BoxAnalyzer.h"]] + [["flang/Lower/PFTBuilder.h"]] + [["flang/Lower/DirectivesCommon.h"]] DEPENDS CUFAttrs @@ -79,14 +90,3 @@ add_flang_library(FortranLower MLIRLLVMDialect MLIRSCFToControlFlow ) - -target_precompile_headers(FortranLower PRIVATE - [["flang/Lower/ConvertExpr.h"]] - [["flang/Lower/SymbolMap.h"]] - [["flang/Lower/AbstractConverter.h"]] - [["flang/Lower/IterationSpace.h"]] - [["flang/Lower/CallInterface.h"]] - [["flang/Lower/BoxAnalyzer.h"]] - [["flang/Lower/PFTBuilder.h"]] - [["flang/Lower/DirectivesCommon.h"]] -) diff --git a/flang/lib/Parser/CMakeLists.txt b/flang/lib/Parser/CMakeLists.txt index 20c6c2a7c8f80..e0479b0da3eb8 100644 --- a/flang/lib/Parser/CMakeLists.txt +++ b/flang/lib/Parser/CMakeLists.txt @@ -25,6 +25,14 @@ add_flang_library(FortranParser unparse.cpp user-state.cpp + DISABLE_PCH_REUSE + PRECOMPILE_HEADERS + [["flang/Parser/parsing.h"]] + [["flang/Parser/parse-tree.h"]] + [["flang/Parser/provenance.h"]] + [["flang/Parser/message.h"]] + [["flang/Parser/parse-tree-visitor.h"]] + LINK_LIBS FortranSupport @@ -37,11 +45,3 @@ add_flang_library(FortranParser omp_gen acc_gen ) - -target_precompile_headers(FortranParser PRIVATE - [["flang/Parser/parsing.h"]] - [["flang/Parser/parse-tree.h"]] - [["flang/Parser/provenance.h"]] - [["flang/Parser/message.h"]] - [["flang/Parser/parse-tree-visitor.h"]] -) diff --git a/flang/lib/Semantics/CMakeLists.txt b/flang/lib/Semantics/CMakeLists.txt index 109bc2dbb8569..44e6dfb4dd09f 100644 --- a/flang/lib/Semantics/CMakeLists.txt +++ b/flang/lib/Semantics/CMakeLists.txt @@ -53,6 +53,15 @@ add_flang_library(FortranSemantics type.cpp unparse-with-symbols.cpp + DISABLE_PCH_REUSE + PRECOMPILE_HEADERS + [["flang/Semantics/semantics.h"]] + [["flang/Semantics/type.h"]] + [["flang/Semantics/openmp-modifiers.h"]] + [["flang/Semantics/expression.h"]] + [["flang/Semantics/tools.h"]] + [["flang/Semantics/symbol.h"]] + DEPENDS acc_gen omp_gen @@ -68,12 +77,3 @@ add_flang_library(FortranSemantics FrontendOpenACC TargetParser ) - -target_precompile_headers(FortranSemantics PRIVATE - [["flang/Semantics/semantics.h"]] - [["flang/Semantics/type.h"]] - [["flang/Semantics/openmp-modifiers.h"]] - [["flang/Semantics/expression.h"]] - [["flang/Semantics/tools.h"]] - [["flang/Semantics/symbol.h"]] -) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 9954053591d30..a539a2182efa5 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -313,6 +313,22 @@ if(LLVM_CCACHE_BUILD) set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}") endif() set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) + + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # ccache with PCH can lead to false-positives when only a macro + # definition changes with non-Clang compilers, because macro definitions + # are not compared in preprocessed mode. + # See: https://github.com/ccache/ccache/issues/1668 + if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS) + message(NOTICE "Using ccache with precompiled headers with non-Clang " + "compilers is not supported. CMAKE_DISABLE_PRECOMPILE_HEADERS will be set to ON. " + "Pass -DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF to override this.") + set(CMAKE_DISABLE_PRECOMPILE_HEADERS "ON") + elseif(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) + message(WARNING "Using ccache with precompiled headers with non-Clang " + "compilers is not supported.") + endif() + endif() else() # Until a way to reliably configure ccache on Windows is found, # disable precompiled headers for Windows + ccache builds diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index d938214f9d0df..fc038499940f2 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -79,6 +79,48 @@ function(llvm_update_compile_flags name) target_compile_definitions(${name} PRIVATE ${LLVM_COMPILE_DEFINITIONS}) endfunction() +function(llvm_update_pch name) + if(LLVM_REQUIRES_RTTI OR LLVM_REQUIRES_EH) + # Non-default RTTI/EH results in incompatible flags, precluding PCH reuse. + set(ARG_DISABLE_PCH_REUSE ON) + endif() + + # Find PCH with highest priority from dependencies. We reuse the first PCH + # with the highest priority. If the target has its own set of PCH, we give it + # a higher priority so that dependents will prefer the new PCH. We don't do + # transitive PCH reuse, because this causes too many unrelated naming + # collisions (e.g., in A -> B -> C{pch}, only B would reuse the PCH of C). + set(pch_priority 0) + llvm_map_components_to_libnames(libs + ${LLVM_LINK_COMPONENTS} + ) + list(APPEND libs ${ARG_LINK_LIBS}) + foreach(lib ${libs}) + if(TARGET ${lib}) + get_target_property(lib_pch_priority ${lib} LLVM_PCH_PRIORITY) + if(${lib_pch_priority} GREATER ${pch_priority}) + set(pch_priority ${lib_pch_priority}) + set(pch_reuse ${lib}) + endif() + endif() + endforeach() + + if(ARG_PRECOMPILE_HEADERS) + message(DEBUG "Adding PCH ${ARG_PRECOMPILE_HEADERS} for ${name} (prio ${pch_priority})") + target_precompile_headers(${name} PRIVATE $<$:${ARG_PRECOMPILE_HEADERS}>) + if(NOT ARG_DISABLE_PCH_REUSE) + # Set priority so that dependants can reuse the PCH. + math(EXPR pch_priority "${pch_priority} + 1") + set_target_properties(${name} PROPERTIES LLVM_PCH_PRIORITY ${pch_priority}) + endif() + elseif(pch_reuse AND NOT ARG_DISABLE_PCH_REUSE) + message(DEBUG "Using PCH ${pch_reuse} for ${name} (prio ${pch_priority})") + target_precompile_headers(${name} REUSE_FROM ${pch_reuse}) + else() + message(DEBUG "Using NO PCH for ${name}") + endif() +endfunction() + function(add_llvm_symbol_exports target_name export_file) if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") set(native_export_file "${target_name}.exports") @@ -485,6 +527,13 @@ endfunction(set_windows_version_resource_properties) # Corresponds to OUTPUT_NAME in target properties. # DEPENDS targets... # Same semantics as add_dependencies(). +# PRECOMPILE_HEADERS include_directives... +# Pre-compiled C++ headers to use. PCH can be reused by dependants. If +# specified, no PCHs from dependencies will be reused. +# DISABLE_PCH_REUSE +# Disable reuse of pre-compiled headers in both directions: the library will +# not reuse the PCH of a dependency and a defined PCH will not be offered +# for reuse by dependants. # LINK_COMPONENTS components... # Same as the variable LLVM_LINK_COMPONENTS. # LINK_LIBS lib_targets... @@ -504,11 +553,12 @@ endfunction(set_windows_version_resource_properties) # ) function(llvm_add_library name) cmake_parse_arguments(ARG - "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB" + "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB;DISABLE_PCH_REUSE" "OUTPUT_NAME;PLUGIN_TOOL;ENTITLEMENTS;BUNDLE_PATH" - "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" + "ADDITIONAL_HEADERS;PRECOMPILE_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" ${ARGN}) list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) + list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS}) if(ARG_ADDITIONAL_HEADERS) # Pass through ADDITIONAL_HEADERS. set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS}) @@ -550,6 +600,7 @@ function(llvm_add_library name) ${ALL_FILES} ) llvm_update_compile_flags(${obj_name}) + llvm_update_pch(${obj_name}) if(CMAKE_GENERATOR STREQUAL "Xcode") set(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/Dummy.c) file(WRITE ${DUMMY_FILE} "// This file intentionally empty\n") @@ -604,7 +655,7 @@ function(llvm_add_library name) ${output_name} OBJLIBS ${ALL_FILES} # objlib LINK_LIBS ${ARG_LINK_LIBS} - LINK_COMPONENTS ${ARG_LINK_COMPONENTS} + LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} ) set_target_properties(${name_static} PROPERTIES FOLDER "${subproject_title}/Libraries") @@ -676,6 +727,11 @@ function(llvm_add_library name) # $ doesn't require compile flags. if(NOT obj_name) llvm_update_compile_flags(${name}) + llvm_update_pch(${name}) + else() + target_precompile_headers(${name} REUSE_FROM ${obj_name}) + get_target_property(pch_priority ${obj_name} LLVM_PCH_PRIORITY) + set_target_properties(${name} PROPERTIES LLVM_PCH_PRIORITY ${pch_priority}) endif() add_link_opts( ${name} ) if(ARG_OUTPUT_NAME) @@ -758,8 +814,7 @@ function(llvm_add_library name) target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC) endif() llvm_map_components_to_libnames(llvm_libs - ${ARG_LINK_COMPONENTS} - ${LLVM_LINK_COMPONENTS} + ${LLVM_LINK_COMPONENTS} ) endif() else() @@ -770,7 +825,7 @@ function(llvm_add_library name) # It would be nice to verify that we have the dependencies for this library # name, but using get_property(... SET) doesn't suffice to determine if a # property has been set to an empty value. - set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS}) + set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) # This property is an internal property only used to make sure the # link step applied in LLVMBuildResolveComponentsLink uses the same @@ -993,6 +1048,7 @@ macro(generate_llvm_objects name) ${ALL_FILES} ) llvm_update_compile_flags(${obj_name}) + llvm_update_pch(${obj_name}) set(ALL_FILES "$") if(ARG_DEPENDS) add_dependencies(${obj_name} ${ARG_DEPENDS}) @@ -1032,7 +1088,7 @@ endmacro() macro(add_llvm_executable name) cmake_parse_arguments(ARG - "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS;EXPORT_SYMBOLS" + "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS;EXPORT_SYMBOLS;DISABLE_PCH_REUSE" "ENTITLEMENTS;BUNDLE_PATH" "" ${ARGN}) @@ -1070,9 +1126,23 @@ macro(add_llvm_executable name) set_windows_version_resource_properties(${name} ${windows_resource_file}) endif() + # CMake position-independent code sets -fPIE for source files in executables. + # With LLVM_ENABLE_PIC, we add -fPIC to all source files, but -fPIE is added + # later and therefore wins. To avoid option mismatch between the PCH (-fPIC) + # and the executable (-fPIE), disable PCH reuse for PIE. + get_target_property(cmake_pie ${name} POSITION_INDEPENDENT_CODE) + if(${cmake_pie}) + set(ARG_DISABLE_PCH_REUSE ON) + endif() + # $ doesn't require compile flags. if(NOT LLVM_ENABLE_OBJLIB) llvm_update_compile_flags(${name}) + llvm_update_pch(${name}) + elseif(NOT ARG_DISABLE_PCH_REUSE) + target_precompile_headers(${name} REUSE_FROM ${obj_name}) + get_target_property(pch_priority ${obj_name} LLVM_PCH_PRIORITY) + set_target_properties(${name} PROPERTIES LLVM_PCH_PRIORITY ${pch_priority}) endif() if (ARG_SUPPORT_PLUGINS AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "AIX") @@ -1780,7 +1850,7 @@ function(add_unittest test_suite test_name) endif() list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream - add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN}) + add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH DISABLE_PCH_REUSE ${ARGN}) get_subproject_title(subproject_title) set_target_properties(${test_name} PROPERTIES FOLDER "${subproject_title}/Tests/Unit") diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index 8b7c8cd4028bd..63f7877e82364 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -1304,11 +1304,55 @@ if (LLVM_BUILD_INSTRUMENTED AND LLVM_BUILD_INSTRUMENTED_COVERAGE) message(FATAL_ERROR "LLVM_BUILD_INSTRUMENTED and LLVM_BUILD_INSTRUMENTED_COVERAGE cannot both be specified") endif() +if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Pre-compiled headers with GCC (tested versions 14+15) provide very little + # compile-time improvements, but substantially increase the build dir size. + # Therefore, disable PCH with GCC by default. + message(NOTICE "Precompiled headers are disabled by default with GCC. " + "Pass -DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF to override.") + set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON) + endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) + # Clang before version 18 has problems with mixed default visibility. + # Therefore, disable PCH with older Clang versions by default. + message(NOTICE "Precompiled headers are disabled by default with Clang <18. " + "Pass -DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF to override.") + set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON) + endif() + + # Warn on possibly unintended interactions with ccache/sccache if the user + # sets this via CMAKE_CXX_COMPILER_LAUNCHER (and not using LLVM_CCACHE_BUILD). + if(CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # ccache with PCH can lead to false-positives when only a macro + # definition changes with non-Clang compilers, because macro definitions + # are not compared in preprocessed mode. + # See: https://github.com/ccache/ccache/issues/1668 + # + # It is unclear to what extent sccache supports PCH, but Clang seems to work + # fine. + # See: https://github.com/mozilla/sccache/issues/615 + # See: https://github.com/mozilla/sccache/issues/2562 + message(WARNING "Using sccache/ccache with precompiled headers with non-Clang " + "compilers is not supported and may lead to false positives. " + "Set CMAKE_DISABLE_PRECOMPILE_HEADERS to ON/OFF to silence this warning.") + endif() +endif() if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) + message(STATUS "Precompiled headers enabled.") # CMake weirdly marks all PCH as system headers. This undocumented variable # can be used to suppress the "#pragma clang system_header". # See: https://gitlab.kitware.com/cmake/cmake/-/issues/21219 set(CMAKE_PCH_PROLOGUE "") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang requires this flag in order for precompiled headers to work with ccache. + append("-Xclang -fno-pch-timestamp" CMAKE_CXX_FLAGS) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # GCC requires this flag in order for precompiled headers to work with ccache. + append("-fpch-preprocess" CMAKE_CXX_FLAGS) + endif() +else() + message(STATUS "Precompiled headers disabled.") endif() set(LLVM_THINLTO_CACHE_PATH "${PROJECT_BINARY_DIR}/lto.cache" CACHE STRING "Set ThinLTO cache path. This can be used when building LLVM from several different directiories.") diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/CMakeLists.txt index cc50112f326ea..a09ac0e8148d0 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsAddObjectFile OrcV2CBindingsAddObjectFile.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/CMakeLists.txt index 0f18d6c24912f..9939bcf6e5ec9 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsBasicUsage OrcV2CBindingsBasicUsage.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects/CMakeLists.txt index 8e2c97d782062..e62f0256e3f86 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsDumpObjects OrcV2CBindingsDumpObjects.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsIRTransforms/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsIRTransforms/CMakeLists.txt index af1b43e43e111..8fb344b5d523c 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsIRTransforms/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsIRTransforms/CMakeLists.txt @@ -13,4 +13,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsIRTransforms OrcV2CBindingsIRTransforms.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/CMakeLists.txt index 52eb2d496fc23..4b415d0114d2e 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsLazy OrcV2CBindingsLazy.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsMCJITLikeMemoryManager/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsMCJITLikeMemoryManager/CMakeLists.txt index 4cdc2b114e9a5..df7996519382c 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsMCJITLikeMemoryManager/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsMCJITLikeMemoryManager/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsMCJITLikeMemoryManager OrcV2CBindingsMCJITLikeMemoryManager.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/CMakeLists.txt index 5b737557bb1ef..346aa5d62066d 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsRemovableCode OrcV2CBindingsRemovableCode.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/CMakeLists.txt b/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/CMakeLists.txt index 0bc9610b1ad7e..c71b2c20136d3 100644 --- a/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/CMakeLists.txt @@ -12,4 +12,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_example(OrcV2CBindingsVeryLazy OrcV2CBindingsVeryLazy.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/llvm/include/llvm/Support/pch.h b/llvm/include/llvm/Support/pch.h new file mode 100644 index 0000000000000..ccfeceb231f61 --- /dev/null +++ b/llvm/include/llvm/Support/pch.h @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// Precompiled header for LLVMSupport. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/ADL.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/BitVector.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Hashing.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/JSON.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/VersionTuple.h" +#include "llvm/Support/YAMLTraits.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt index 9af1854852436..f0faaff307997 100644 --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -3,8 +3,8 @@ include(LLVM-Build) # `Demangle', `Support' and `TableGen' libraries are added on the top-level # CMakeLists.txt -add_subdirectory(ABI) add_subdirectory(IR) +add_subdirectory(ABI) add_subdirectory(FuzzMutate) add_subdirectory(FileCheck) add_subdirectory(InterfaceStub) diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index 099b0e55579be..b4e39fced3853 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -135,7 +135,6 @@ if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX") endif() add_subdirectory(BLAKE3) -add_subdirectory(LSP) add_llvm_component_library(LLVMSupport ABIBreak.cpp @@ -322,6 +321,9 @@ add_llvm_component_library(LLVMSupport ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support ${Backtrace_INCLUDE_DIRS} + PRECOMPILE_HEADERS + [["llvm/Support/pch.h"]] + LINK_LIBS ${system_libs} ${imported_libs} ${delayload_flags} @@ -396,3 +398,6 @@ target_include_directories(LLVMSupport PRIVATE ${LLVM_THIRD_PARTY_DIR}/siphash/include ) + +# SupportLSP depends on Support and therefore must be included afterwards. +add_subdirectory(LSP) diff --git a/llvm/tools/llvm-c-test/CMakeLists.txt b/llvm/tools/llvm-c-test/CMakeLists.txt index 939164e636216..99d79443f1bc4 100644 --- a/llvm/tools/llvm-c-test/CMakeLists.txt +++ b/llvm/tools/llvm-c-test/CMakeLists.txt @@ -53,6 +53,9 @@ add_llvm_tool(llvm-c-test metadata.c object.c targets.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) if(USE_LLVM_DYLIB) diff --git a/llvm/utils/count/CMakeLists.txt b/llvm/utils/count/CMakeLists.txt index cfd1f4a85d8a1..94250a2ef6374 100644 --- a/llvm/utils/count/CMakeLists.txt +++ b/llvm/utils/count/CMakeLists.txt @@ -4,4 +4,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_utility(count count.c + + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ) diff --git a/mlir/test/CAPI/CMakeLists.txt b/mlir/test/CAPI/CMakeLists.txt index d45142510a496..313a3a8d9ba46 100644 --- a/mlir/test/CAPI/CMakeLists.txt +++ b/mlir/test/CAPI/CMakeLists.txt @@ -8,6 +8,8 @@ function(_add_capi_test_executable name) ) add_llvm_executable(${name} PARTIAL_SOURCES_INTENDED + # No C++ files, prevent CMake error. + DISABLE_PCH_REUSE ${ARG_UNPARSED_ARGUMENTS}) set_target_properties(${name} PROPERTIES FOLDER "MLIR/Tests") set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL ON) diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt index 41c3b97764ac7..6f6e4d5782dfb 100644 --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -91,6 +91,10 @@ add_llvm_pass_plugin(Polly Transform/MatmulOptimizer.cpp ${POLLY_HEADER_FILES} + # Polly unconditionally uses -fno-rtti -fno-exceptions. This can be + # incompatible with PCH if LLVM is built with RTTI or exceptions. + DISABLE_PCH_REUSE + LINK_COMPONENTS ${POLLY_COMPONENTS} )