diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -406,10 +406,14 @@ # This is used to specify that this is a component library of # LLVM which means that the source resides in llvm/lib/ and it is a # candidate for inclusion into libLLVM.so. +# PLUGIN_LIB +# This is used to specify that this is a statically loaded plugin library +# of LLVM which means that it behaves as a component, except that it +# doesn't interact with LLVMBuild.txt. # ) function(llvm_add_library name) cmake_parse_arguments(ARG - "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB;ENABLE_PLUGINS" + "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB;ENABLE_PLUGINS;PLUGIN_LIB" "OUTPUT_NAME;PLUGIN_TOOL;ENTITLEMENTS;BUNDLE_PATH" "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" ${ARGN}) @@ -498,7 +502,7 @@ add_library(${name} STATIC ${ALL_FILES}) endif() - if(ARG_COMPONENT_LIB) + if(ARG_COMPONENT_LIB OR ARG_PLUGIN_LIB) set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE) set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name}) endif() @@ -606,7 +610,7 @@ get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) endif() - if(ARG_STATIC) + if(ARG_STATIC OR ARG_PLUGIN_LIB) set(libtype PUBLIC) else() # We can use PRIVATE since SO knows its dependent libs. @@ -879,11 +883,16 @@ endif() option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" ${link_into_tools_default}) + # If we statically link the plugin, don't use llvm dylib + if(LLVM_${name_upper}_LINK_INTO_TOOLS) + list(APPEND ARG_UNPARSED_ARGUMENTS DISABLE_LLVM_LINK_LLVM_DYLIB) + endif() + if(LLVM_${name_upper}_LINK_INTO_TOOLS) list(REMOVE_ITEM ARG_UNPARSED_ARGUMENTS BUILDTREE_ONLY) # process_llvm_pass_plugins takes care of the actual linking, just create an # object library as of now - add_llvm_component_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS}) + add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS} PLUGIN_LIB) target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS) set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS) if (TARGET intrinsics_gen) diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -21,6 +21,34 @@ file(GLOB_RECURSE POLLY_HEADER_FILES "${POLLY_SOURCE_DIR}/include/polly/*.h") endif () +set(POLLY_COMPONENTS + Support + Core + ScalarOpts + InstCombine + TransformUtils + Analysis + ipo + MC + Passes + Linker + IRReader + Analysis + # The libraries below are required for darwin: http://PR26392 + BitReader + MCParser + Object + ProfileData + Target + Vectorize +) + +# Polly-ACC requires the NVPTX backend to work. Ask LLVM about its libraries. +if (GPU_CODEGEN) + # This call emits an error if they NVPTX backend is not enable. + list(APPEND POLLY_COMPONENTS NVPTX) +endif () + # Use an object-library to add the same files to multiple libs without requiring # the sources them to be recompiled for each of them. add_llvm_pass_plugin(Polly @@ -71,6 +99,9 @@ Transform/RewriteByReferenceParameters.cpp Transform/ScopInliner.cpp ${POLLY_HEADER_FILES} + + LINK_COMPONENTS + ${POLLY_COMPONENTS} ) set_target_properties(obj.Polly PROPERTIES FOLDER "Polly") set_target_properties(Polly PROPERTIES FOLDER "Polly") @@ -99,45 +130,7 @@ target_link_libraries(Polly PUBLIC PollyPPCG) endif () - -# Polly-ACC requires the NVPTX backend to work. Ask LLVM about its libraries. -set(nvptx_libs) -if (GPU_CODEGEN) - # This call emits an error if they NVPTX backend is not enable. - llvm_map_components_to_libnames(nvptx_libs NVPTX) -endif () - -if (LLVM_LINK_LLVM_DYLIB AND NOT LLVM_POLLY_LINK_INTO_TOOLS) - # The shlib/dylib contains all the LLVM components - # (including NVPTX is enabled) already. Adding them to target_link_libraries - # would cause them being twice in the address space - # (their LLVM*.a/so and their copies in libLLVM.so) - # which results in errors when the two instances try to register the same - # command-line switches. - target_link_libraries(Polly PUBLIC LLVM) -else () - target_link_libraries(Polly PUBLIC - LLVMSupport - LLVMCore - LLVMScalarOpts - LLVMInstCombine - LLVMTransformUtils - LLVMAnalysis - LLVMipo - LLVMMC - LLVMPasses - LLVMLinker - LLVMIRReader - ${nvptx_libs} - # The libraries below are required for darwin: http://PR26392 - LLVMBitReader - LLVMMCParser - LLVMObject - LLVMProfileData - LLVMTarget - LLVMVectorize - ) - +if (NOT LLVM_LINK_LLVM_DYLIB AND NOT LLVM_POLLY_LINK_INTO_TOOLS) # Polly-ACC requires the NVPTX target to be present in the executable it is linked to set_property(TARGET bugpoint APPEND PROPERTY LINK_LIBRARIES LLVMTarget) endif ()