Index: cmake/CMakeLists.txt =================================================================== --- cmake/CMakeLists.txt +++ cmake/CMakeLists.txt @@ -14,10 +14,13 @@ set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake") endif() -set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET}) -if (NOT MSVC) - # LLVMPolly is a dummy target on Win +set(POLLY_CONFIG_EXPORTED_TARGETS ${ISL_TARGET}) +if (DEFINED LLVM_MAIN_SRC_DIR) list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly) +endif () +if (NOT MSVC) + # Polly is a dummy target on Win + list(APPEND POLLY_CONFIG_EXPORTED_TARGETS Polly) endif() if (POLLY_ENABLE_GPGPU_CODEGEN) list(APPEND POLLY_CONFIG_EXPORTED_TARGETS PollyPPCG) Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -26,7 +26,7 @@ file(GLOB_RECURSE POLLY_HEADER_FILES "${POLLY_SOURCE_DIR}/include/polly/*.h") endif () -add_polly_library(Polly +add_library(PollyCore OBJECT Analysis/DependenceInfo.cpp Analysis/PolyhedralInfo.cpp Analysis/ScopDetection.cpp @@ -64,65 +64,84 @@ Transform/DeLICM.cpp Transform/Simplify.cpp ${POLLY_HEADER_FILES} - ) - -if (GPU_CODEGEN) - target_link_libraries(Polly PollyPPCG) -endif (GPU_CODEGEN) - -target_link_libraries(Polly ${ISL_TARGET}) +) -if (BUILD_SHARED_LIBS) - target_link_libraries(Polly - LLVMSupport - LLVMCore - LLVMScalarOpts - LLVMInstCombine - LLVMTransformUtils - LLVMAnalysis - LLVMipo - LLVMMC -# The libraries below are required for darwin: http://PR26392 - LLVMBitReader - LLVMMCParser - LLVMObject - LLVMProfileData - LLVMTarget - LLVMVectorize +# Create the library that can be linked into LLVM's tools and Polly's unittests. +# It depends on all library it needs, such that with +# LLVM_POLLY_LINK_INTO_TOOLS=ON, its dependencies like PollyISL are linked as +# well. +# The library name must be prefixed with "LLVM" to be allowed to be used in +# LLVM_LINK_COMPONENTS. +# It is only useful when building inside the LLVM source tree and +# LLVM_POLLY_LINK_INTO_TOOLS=ON, in all other cases the loadable module has to +# be used. We still create it in case of LLVM_POLLY_LINK_INTO_TOOLS=OFF such +# that unittests can still link against it. +if (DEFINED LLVM_MAIN_SRC_DIR) + set(required_components + Support + Core + ScalarOpts + InstCombine + TransformUtils + Analysis + ipo + MC + # The libraries below are required for darwin: http://PR26392 + BitReader + MCParser + Object + ProfileData + Target + Vectorize ) - link_directories( - ${LLVM_LIBRARY_DIR} + set(required_libs ${ISL_TARGET}) + if (GPU_CODEGEN) + list(APPEND required_components NVPTX) + list(APPEND required_libs PollyPPCG) + endif () + + # Using add_llvm_library also has the effect of Polly becoming part of + # libLLVM.so if LLVM_BUILD_LLVM_DYLIB=ON. The LLVM_LINK_COMPONENTS mechanism + # will take care for Polly not being linked in multiple times, since there + # might already be a copy of Polly in libLLVM.so. + add_llvm_library(LLVMPolly + OBJLIBS $ + LINK_COMPONENTS ${required_components} + DEPENDS intrinsics_gen ) -elseif (LLVM_LINK_LLVM_DYLIB) - target_link_libraries(Polly - LLVM - ) - link_directories( - ${LLVM_LIBRARY_DIR} - ) -endif() -# Build a monolithic Polly.a and a thin module LLVMPolly.moduleext that links to -# that static library. + # We cannot use the LINK_LIBS parameter of add_llvm_library for these because + # it calls target_link_libraries with the PRIVATE option. + target_link_libraries(LLVMPolly PUBLIC ${required_libs}) +endif () + +# Create a loadable module Polly.so that can be loaded using +# LLVM's/clang's "-load" option. if (MSVC) # Add dummy target, because loadable modules are not supported on Windows - add_custom_target(LLVMPolly) - set_target_properties(LLVMPolly PROPERTIES FOLDER "Polly") + add_custom_target(Polly) + set_target_properties(Polly PROPERTIES FOLDER "Polly") else () - add_polly_loadable_module(LLVMPolly + add_polly_loadable_module(Polly Polly.cpp + $ ) - target_link_libraries(LLVMPolly Polly) + # Only add the dependencies that are not part of LLVM. The latter are assumed + # to be already available in the address space the module is loaded into. + # Adding them once more would have the effect that both copies try to register + # the same command line options, to which LLVM reacts with an error. + # If Polly-ACC is enabled, the NVPTX target is also expected to reside in the + # hosts. This is not the case for bugpoint. Use LLVM_POLLY_LINK_INTO_TOOLS=ON + # instead which will automatically resolve the additional dependencies by + # Polly. + target_link_libraries(Polly ${ISL_TARGET}) + if (GPU_CODEGEN) + target_link_libraries(Polly PollyPPCG) + endif () - set_target_properties(LLVMPolly + set_target_properties(Polly PROPERTIES LINKER_LANGUAGE CXX PREFIX "") endif () - -if (TARGET intrinsics_gen) - # Check if we are building as part of an LLVM build - add_dependencies(Polly intrinsics_gen) -endif() - Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -21,7 +21,7 @@ # FIXME: FileCheck is not available in llvm install directory at the moment. set(LLVM_LIT ${LLVM_INSTALL_ROOT}/bin/llvm-lit) if (POLLY_BUNDLED_ISL) - set(POLLY_TEST_DEPS LLVMPolly polly-isl-test) + set(POLLY_TEST_DEPS Polly polly-isl-test) endif (POLLY_BUNDLED_ISL) if (POLLY_GTEST_AVAIL) list(APPEND POLLY_TEST_DEPS PollyUnitTests) @@ -120,7 +120,7 @@ else (NOT DEFINED LLVM_MAIN_SRC_DIR) set(LLVM_LIT ${LLVM_TOOLS_BINARY_DIR}/llvm-lit) - set(POLLY_TEST_DEPS llvm-config opt LLVMPolly FileCheck not) + set(POLLY_TEST_DEPS llvm-config opt Polly FileCheck not) if (POLLY_BUNDLED_ISL) list(APPEND POLLY_TEST_DEPS polly-isl-test) endif() Index: test/lit.site.cfg.in =================================================================== --- test/lit.site.cfg.in +++ test/lit.site.cfg.in @@ -39,7 +39,7 @@ config.link_polly_into_tools.lower() == 'notfound' or \ config.link_polly_into_tools.lower() == 'link_polly_into_tools-notfound': config.substitutions.append(('%loadPolly', '-load ' - + config.polly_lib_dir + '/LLVMPolly@LLVM_SHLIBEXT@' + + config.polly_lib_dir + '/Polly@LLVM_SHLIBEXT@' + ' -polly-process-unprofitable ' + ' -polly-remarks-minimal ' )) Index: unittests/CMakeLists.txt =================================================================== --- unittests/CMakeLists.txt +++ unittests/CMakeLists.txt @@ -6,24 +6,16 @@ # Will compile the list of files together and link against Polly and its dependences. function(add_polly_unittest test_name) if(COMMAND add_unittest) + set(LLVM_LINK_COMPONENTS Polly) add_unittest(PollyUnitTests ${test_name} ${ARGN}) - target_link_libraries(${test_name} Polly) - - # The Polly target does not depend on its required libraries, except: - # - BUILD_SHARED_LIBS=ON - # in which case calling target_link_libraries again is redundant. - # - LLVM_LINK_LLVM_DYLIB=ON - # in which case it depends on libLLVM.so, so no additional libs needed. - # We are also not allowed to link against the plain LLVM* libraries, - # which would result in multiple instances of these to be loaded. - if (NOT LLVM_LINK_LLVM_DYLIB) - target_link_libraries(${test_name} LLVMCore LLVMSupport LLVMDemangle LLVMipo) - endif () else() - add_executable(${test_name} EXCLUDE_FROM_ALL ${ARGN}) + add_executable(${test_name} EXCLUDE_FROM_ALL $ ${ARGN}) set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - target_link_libraries(${test_name} gtest_main gtest Polly ${LLVM_LIBS}) + target_link_libraries(${test_name} gtest_main gtest ${LLVM_LIBS} ${ISL_TARGET}) + if (GPU_CODEGEN) + target_link_libraries(${test_name} PollyPPCG) + endif () add_dependencies(PollyUnitTests ${test_name}) set_property(TARGET ${test_name} PROPERTY FOLDER "Polly")