Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions flang/lib/Evaluate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand All @@ -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
)
16 changes: 8 additions & 8 deletions flang/lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]]
)
22 changes: 11 additions & 11 deletions flang/lib/Lower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]]
)
16 changes: 8 additions & 8 deletions flang/lib/Parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]]
)
18 changes: 9 additions & 9 deletions flang/lib/Semantics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]]
)
16 changes: 16 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 94 additions & 8 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,64 @@ 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()

if(NOT ARG_PRECOMPILE_HEADERS)
# We only use PCH for C++. For targets with C source files that re-use a
# precompiled headers from another target, CMake complains that there is no
# PCH for C. There doesn't seem to be a disable PCH reuse for C files only,
# so disable PCH reuse for targets that contain C sources.
get_property(srcs TARGET ${name} PROPERTY SOURCES)
foreach(src ${srcs})
get_filename_component(extension ${src} EXT)
if(extension STREQUAL ".c")
message(DEBUG "Disable PCH for ${name} due to C file ${src}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also needs a case for ".mm" as LLDB uses a few Objective-C++ files which are also an incompatible language mode with the rest of LLVM.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also what is breaking the bot IIUC, but I'm still running a build locally to test it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I speculatively pushed such a change with 8c583bd, it disables PCH entirely if the target contains Objective-C++ sources.

set(ARG_DISABLE_PCH_REUSE ON)
break()
endif()
endforeach()
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 $<$<COMPILE_LANGUAGE:CXX>:${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")
Expand Down Expand Up @@ -485,6 +543,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...
Expand All @@ -504,11 +569,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})
Expand Down Expand Up @@ -550,6 +616,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")
Expand Down Expand Up @@ -604,7 +671,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")

Expand Down Expand Up @@ -676,6 +743,11 @@ function(llvm_add_library name)
# $<TARGET_OBJECTS> 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)
Expand Down Expand Up @@ -758,8 +830,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()
Expand All @@ -770,7 +841,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
Expand Down Expand Up @@ -993,6 +1064,7 @@ macro(generate_llvm_objects name)
${ALL_FILES}
)
llvm_update_compile_flags(${obj_name})
llvm_update_pch(${obj_name})
set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
if(ARG_DEPENDS)
add_dependencies(${obj_name} ${ARG_DEPENDS})
Expand Down Expand Up @@ -1032,7 +1104,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})
Expand Down Expand Up @@ -1070,9 +1142,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()

# $<TARGET_OBJECTS> 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")
Expand Down Expand Up @@ -1780,7 +1866,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")

Expand Down
Loading