[polly] static builds

Sebastian Pop spop at codeaurora.org
Fri Nov 15 12:45:07 PST 2013


Hi,

I would like to advance on this side to make Polly build under Windows.  Could
somebody please review the patches below?  The patches add the ability to static
link Polly.

Thanks,
Sebastian

Sebastian Pop wrote:
> Sebastian Pop wrote:
> > Here are the patches to link polly statically with cmake -D WITH_POLLY:Bool=true
> > -D POLLY_BUILD_SHARED_LIB:Bool=false. The static link succeeds on all tools
> > except llvm-lto.  The problem is described in the other email thread on cmake
> > vs. LLVMBuild infrastructure.
> 
> Attached the patches without the problem mentioned above.
> Patches pass cmake + ninja builds and check-all.  Ok to commit?
> 
> Thanks,
> Sebastian
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> hosted by The Linux Foundation

> From f488ab7b9cff2e61f9ff11692a00091585b306be Mon Sep 17 00:00:00 2001
> From: Sebastian Pop <spop at codeaurora.org>
> Date: Thu, 31 Oct 2013 06:38:45 -0500
> Subject: [PATCH] link polly statically
> 
> ---
>  CMakeLists.txt                            |   14 ++++++++++++++
>  cmake/modules/FindGmp.cmake               |   21 +++++++++++++++++++++
>  cmake/modules/FindIsl.cmake               |   27 +++++++++++++++++++++++++++
>  cmake/modules/LLVM-Config.cmake           |    3 +++
>  include/llvm/Config/config.h.cmake        |    6 ++++++
>  include/llvm/Config/llvm-config.h.cmake   |    6 ++++++
>  lib/Transforms/IPO/CMakeLists.txt         |    4 ++++
>  lib/Transforms/IPO/PassManagerBuilder.cpp |   13 +++++++++++++
>  tools/CMakeLists.txt                      |    9 ++++++++-
>  9 files changed, 102 insertions(+), 1 deletions(-)
>  create mode 100644 cmake/modules/FindGmp.cmake
>  create mode 100644 cmake/modules/FindIsl.cmake
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 096e3e7..895077c 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -527,3 +527,17 @@ if(MSVC_VERSION EQUAL 1600)
>      file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
>    endif()
>  endif()
> +
> +option(WITH_POLLY "Build LLVM with Polly" OFF)
> +option(POLLY_BUILD_SHARED_LIB "Build Polly as a shared library (only static builds are supported under Windows)" ON)
> +
> +if(NOT WITH_POLLY)
> +  if(LLVM_EXTERNAL_POLLY_BUILD OR NOT LLVM_EXTERNAL_POLLY_SOURCE_DIR STREQUAL "")
> +    set(WITH_POLLY ON)
> +  endif()
> +endif(NOT WITH_POLLY)
> +
> +if(WITH_POLLY)
> +  FIND_PACKAGE(Isl REQUIRED)
> +  FIND_PACKAGE(Gmp REQUIRED)
> +endif(WITH_POLLY)
> diff --git a/cmake/modules/FindGmp.cmake b/cmake/modules/FindGmp.cmake
> new file mode 100644
> index 0000000..3725d42
> --- /dev/null
> +++ b/cmake/modules/FindGmp.cmake
> @@ -0,0 +1,21 @@
> +FIND_PATH(GMP_INCLUDE_DIR gmp.h)
> +
> +FIND_LIBRARY(GMP_LIBRARY NAMES gmp)
> +
> +IF (POLLY_USE_GMP)
> +  IF (GMP_INCLUDE_DIR AND GMP_LIBRARY)
> +    SET(GMP_FOUND TRUE)
> +  ENDIF (GMP_INCLUDE_DIR AND GMP_LIBRARY)
> +ENDIF (POLLY_USE_GMP)
> +
> +
> +IF (GMP_FOUND)
> +  IF (NOT GMP_FIND_QUIETLY)
> +    MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
> +  ENDIF (NOT GMP_FIND_QUIETLY)
> +ELSE (GMP_FOUND)
> +  IF (GMP_FIND_REQUIRED)
> +    MESSAGE(FATAL_ERROR "Could not find GMP")
> +  ENDIF (GMP_FIND_REQUIRED)
> +ENDIF (GMP_FOUND)
> +
> diff --git a/cmake/modules/FindIsl.cmake b/cmake/modules/FindIsl.cmake
> new file mode 100644
> index 0000000..bf7a0a0
> --- /dev/null
> +++ b/cmake/modules/FindIsl.cmake
> @@ -0,0 +1,27 @@
> +IF (POLLY_EXTERNAL_ISL_SOURCE_DIR)
> +  add_subdirectory(${POLLY_EXTERNAL_ISL_SOURCE_DIR} "${CMAKE_CURRENT_BINARY_DIR}/isl")
> +  IF (POLLY_BUILD_SHARED_LIB)
> +    SET(ISL_LIBRARY "${ISL_BINARY_DIR}/lib/isl.so")
> +  ELSE(POLLY_BUILD_SHARED_LIB)
> +    SET(ISL_LIBRARY "${ISL_BINARY_DIR}/lib/isl.a")
> +  ENDIF(POLLY_BUILD_SHARED_LIB)
> +  SET(ISL_INCLUDE_DIR "${POLLY_EXTERNAL_ISL_SOURCE_DIR}/include")
> +  INCLUDE_DIRECTORIES("${POLLY_EXTERNAL_ISL_SOURCE_DIR}/imath")
> +ENDIF (POLLY_EXTERNAL_ISL_SOURCE_DIR)
> +
> +FIND_PATH(ISL_INCLUDE_DIR isl/val.h)
> +FIND_LIBRARY(ISL_LIBRARY NAMES isl)
> +
> +IF (ISL_INCLUDE_DIR AND ISL_LIBRARY)
> +  SET(ISL_FOUND TRUE)
> +ENDIF (ISL_INCLUDE_DIR AND ISL_LIBRARY)
> +
> +IF (ISL_FOUND)
> +  IF (NOT Isl_FIND_QUIETLY)
> +    MESSAGE(STATUS "Found Isl: ${ISL_LIBRARY}")
> +  ENDIF (NOT Isl_FIND_QUIETLY)
> +ELSE (ISL_FOUND)
> +  IF (Isl_FIND_REQUIRED)
> +    MESSAGE(FATAL_ERROR "Could not find Isl")
> +  ENDIF (Isl_FIND_REQUIRED)
> +ENDIF (ISL_FOUND)
> diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake
> index e26fabd..a8dfb7a 100644
> --- a/cmake/modules/LLVM-Config.cmake
> +++ b/cmake/modules/LLVM-Config.cmake
> @@ -30,6 +30,9 @@ endfunction(get_system_libs)
>  function(link_system_libs target)
>    get_system_libs(llvm_system_libs)
>    target_link_libraries(${target} ${llvm_system_libs})
> +  if (WITH_POLLY)
> +    target_link_libraries(${target} ${ISL_LIBRARY} ${GMP_LIBRARY})
> +  endif()
>  endfunction(link_system_libs)
>  
>  
> diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
> index 4c49cbb..4030fb9 100644
> --- a/include/llvm/Config/config.h.cmake
> +++ b/include/llvm/Config/config.h.cmake
> @@ -638,6 +638,9 @@
>  /* Define to the version of this package. */
>  #cmakedefine PACKAGE_VERSION "${PACKAGE_VERSION}"
>  
> +/* Define if we build Polly as a shared library */
> +#cmakedefine POLLY_BUILD_SHARED_LIB
> +
>  /* Define as the return type of signal handlers (`int' or `void'). */
>  #cmakedefine RETSIGTYPE ${RETSIGTYPE}
>  
> @@ -659,6 +662,9 @@
>  /* Type of 1st arg on ELM Callback */
>  #cmakedefine WIN32_ELMCB_PCSTR ${WIN32_ELMCB_PCSTR}
>  
> +/* Define if we have the required libraries to build Polly */
> +#cmakedefine WITH_POLLY
> +
>  /* Define to empty if `const' does not conform to ANSI C. */
>  #undef const
>  
> diff --git a/include/llvm/Config/llvm-config.h.cmake b/include/llvm/Config/llvm-config.h.cmake
> index 80616ef..452339a 100644
> --- a/include/llvm/Config/llvm-config.h.cmake
> +++ b/include/llvm/Config/llvm-config.h.cmake
> @@ -124,4 +124,10 @@
>  /* Define to 1 if you have the <sanitizer/msan_interface.h> header file. */
>  #cmakedefine HAVE_SANITIZER_MSAN_INTERFACE_H ${HAVE_SANITIZER_MSAN_INTERFACE_H}
>  
> +/* Define if we build Polly as a shared library */
> +#cmakedefine POLLY_BUILD_SHARED_LIB
> +
> +/* Define if we have the required libraries to build Polly */
> +#cmakedefine WITH_POLLY
> +
>  #endif
> diff --git a/lib/Transforms/IPO/CMakeLists.txt b/lib/Transforms/IPO/CMakeLists.txt
> index 90c1c33..bd042db 100644
> --- a/lib/Transforms/IPO/CMakeLists.txt
> +++ b/lib/Transforms/IPO/CMakeLists.txt
> @@ -23,3 +23,7 @@ add_llvm_library(LLVMipo
>    )
>  
>  add_dependencies(LLVMipo intrinsics_gen)
> +
> +if (WITH_POLLY AND NOT POLLY_BUILD_SHARED_LIB)
> +  target_link_libraries(LLVMipo LLVMPolly LLVMPollyAnalysis LLVMPollyCodeGen LLVMPollyExchange LLVMPollyJSON LLVMPollySupport)
> +endif (WITH_POLLY AND NOT POLLY_BUILD_SHARED_LIB)
> diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp
> index 0017c1b..083055f 100644
> --- a/lib/Transforms/IPO/PassManagerBuilder.cpp
> +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp
> @@ -105,8 +105,18 @@ PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const {
>    PM.add(createBasicAliasAnalysisPass());
>  }
>  
> +#if defined(WITH_POLLY) && !defined(POLLY_BUILD_SHARED_LIB)
> +void registerPollyEarlyAsPossiblePasses(const llvm::PassManagerBuilder &Builder,
> +                                        llvm::PassManagerBase &PM);
> +void registerPollyOptLevel0Passes(const llvm::PassManagerBuilder &Builder,
> +                                  llvm::PassManagerBase &PM);
> +#endif // WITH_POLLY
> +
>  void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) {
>    addExtensionsToPM(EP_EarlyAsPossible, FPM);
> +#if defined(WITH_POLLY) && !defined(POLLY_BUILD_SHARED_LIB)
> +  registerPollyEarlyAsPossiblePasses(*this, FPM);
> +#endif // WITH_POLLY
>  
>    // Add LibraryInfo if we have some.
>    if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo));
> @@ -140,6 +150,9 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
>        MPM.add(createBarrierNoopPass());
>  
>      addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
> +#if defined(WITH_POLLY) && !defined(POLLY_BUILD_SHARED_LIB)
> +    registerPollyOptLevel0Passes(*this, MPM);
> +#endif // WITH_POLLY
>      return;
>    }
>  
> diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> index 12e10fd..a3c0875 100644
> --- a/tools/CMakeLists.txt
> +++ b/tools/CMakeLists.txt
> @@ -4,6 +4,11 @@
>  
>  add_llvm_tool_subdirectory(llvm-config)
>  
> +# Build polly before opt, as opt links against polly.
> +if(NOT POLLY_BUILD_SHARED_LIB)
> +  add_llvm_external_project(polly)
> +endif()
> +
>  add_llvm_tool_subdirectory(opt)
>  add_llvm_tool_subdirectory(llvm-as)
>  add_llvm_tool_subdirectory(llvm-dis)
> @@ -69,7 +74,9 @@ add_llvm_external_project(clang)
>  if( NOT LLVM_INCLUDE_TOOLS STREQUAL "bootstrap-only" )
>    add_llvm_external_project(lld)
>    add_llvm_external_project(lldb)
> -  add_llvm_external_project(polly)
> +  if(POLLY_BUILD_SHARED_LIB)
> +    add_llvm_external_project(polly)
> +  endif(POLLY_BUILD_SHARED_LIB)
>  
>    # Automatically add remaining sub-directories containing a 'CMakeLists.txt'
>    # file as external projects.
> -- 
> 1.7.6.4
> 

> From 7b162776f7fe52fb11a2d61ed4d1833fc1a03bcc Mon Sep 17 00:00:00 2001
> From: Sebastian Pop <spop at codeaurora.org>
> Date: Thu, 31 Oct 2013 07:17:25 -0500
> Subject: [PATCH] link polly statically
> 
> ---
>  cmake/FindIsl.cmake          |   13 ++++++-
>  lib/Analysis/CMakeLists.txt  |    9 ++++-
>  lib/Analysis/MayAliasSet.cpp |   42 ++++++++++++++++++++++
>  lib/CMakeLists.txt           |   80 ++++++++++++++++++++++++++++++------------
>  lib/CodeGen/CMakeLists.txt   |   17 ++++++++-
>  lib/Exchange/CMakeLists.txt  |   19 +++++++++-
>  lib/JSON/CMakeLists.txt      |    7 +++-
>  lib/MayAliasSet.cpp          |   42 ----------------------
>  lib/RegisterPasses.cpp       |   32 +++++++++++-----
>  lib/Support/CMakeLists.txt   |    8 ++++-
>  test/lit.site.cfg.in         |    8 +++-
>  11 files changed, 191 insertions(+), 86 deletions(-)
>  create mode 100644 lib/Analysis/MayAliasSet.cpp
>  delete mode 100644 lib/MayAliasSet.cpp
> 
> diff --git a/cmake/FindIsl.cmake b/cmake/FindIsl.cmake
> index 1c46e72..e3b0701 100644
> --- a/cmake/FindIsl.cmake
> +++ b/cmake/FindIsl.cmake
> @@ -1,12 +1,21 @@
> -FIND_PATH(ISL_INCLUDE_DIR isl/val.h)
> +IF (POLLY_EXTERNAL_ISL_SOURCE_DIR)
> +  add_subdirectory(${POLLY_EXTERNAL_ISL_SOURCE_DIR} "${CMAKE_CURRENT_BINARY_DIR}/isl")
> +  IF (POLLY_BUILD_SHARED_LIB)
> +    SET(ISL_LIBRARY "${ISL_BINARY_DIR}/lib/isl.so")
> +  ELSE(POLLY_BUILD_SHARED_LIB)
> +    SET(ISL_LIBRARY "${ISL_BINARY_DIR}/lib/isl.a")
> +  ENDIF(POLLY_BUILD_SHARED_LIB)
> +  SET(ISL_INCLUDE_DIR "${POLLY_EXTERNAL_ISL_SOURCE_DIR}/include")
> +  INCLUDE_DIRECTORIES("${POLLY_EXTERNAL_ISL_SOURCE_DIR}/imath")
> +ENDIF (POLLY_EXTERNAL_ISL_SOURCE_DIR)
>  
> +FIND_PATH(ISL_INCLUDE_DIR isl/val.h)
>  FIND_LIBRARY(ISL_LIBRARY NAMES isl)
>  
>  IF (ISL_INCLUDE_DIR AND ISL_LIBRARY)
>    SET(ISL_FOUND TRUE)
>  ENDIF (ISL_INCLUDE_DIR AND ISL_LIBRARY)
>  
> -
>  IF (ISL_FOUND)
>    IF (NOT Isl_FIND_QUIETLY)
>      MESSAGE(STATUS "Found Isl: ${ISL_LIBRARY}")
> diff --git a/lib/Analysis/CMakeLists.txt b/lib/Analysis/CMakeLists.txt
> index 9e46527..b40fe7b 100644
> --- a/lib/Analysis/CMakeLists.txt
> +++ b/lib/Analysis/CMakeLists.txt
> @@ -1,8 +1,15 @@
> -add_polly_library(PollyAnalysis
> +set(POLLY_ANALYSIS_SOURCES
>    Dependences.cpp
> +  MayAliasSet.cpp
>    ScopDetection.cpp
>    ScopInfo.cpp
>    ScopGraphPrinter.cpp
>    ScopPass.cpp
>    TempScopInfo.cpp
>  )
> +
> +if(POLLY_BUILD_SHARED_LIB)
> +  add_polly_library(PollyAnalysis ${POLLY_ANALYSIS_SOURCES})
> +else(POLLY_BUILD_SHARED_LIB)
> +  add_llvm_library(LLVMPollyAnalysis ${POLLY_ANALYSIS_SOURCES})
> +endif(POLLY_BUILD_SHARED_LIB)
> diff --git a/lib/Analysis/MayAliasSet.cpp b/lib/Analysis/MayAliasSet.cpp
> new file mode 100644
> index 0000000..0d47d8c
> --- /dev/null
> +++ b/lib/Analysis/MayAliasSet.cpp
> @@ -0,0 +1,42 @@
> +//===---------- MayAliasSet.cpp  - May-Alais Set for base pointers --------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file implements the MayAliasSet class
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "polly/TempScopInfo.h"
> +#include "polly/MayAliasSet.h"
> +#include "llvm/Analysis/AliasAnalysis.h"
> +#include "llvm/Analysis/AliasSetTracker.h"
> +#include "llvm/Analysis/RegionInfo.h"
> +#include "llvm/Analysis/RegionIterator.h"
> +#include "llvm/Assembly/Writer.h"
> +#include "llvm/IR/LLVMContext.h"
> +#include "llvm/Support/Debug.h"
> +#include "llvm/Support/raw_ostream.h"
> +
> +using namespace llvm;
> +using namespace polly;
> +
> +void MayAliasSet::print(raw_ostream &OS) const {
> +  OS << "Must alias {";
> +
> +  for (const_iterator I = mustalias_begin(), E = mustalias_end(); I != E; ++I) {
> +    WriteAsOperand(OS, *I, false);
> +    OS << ", ";
> +  }
> +
> +  OS << "} May alias {";
> +  OS << '}';
> +}
> +
> +void MayAliasSet::dump() const { print(dbgs()); }
> +
> +void MayAliasSetInfo::buildMayAliasSets(TempScop &Scop, AliasAnalysis &AA) {}
> diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
> index f6ace3a..079c5ab 100644
> --- a/lib/CMakeLists.txt
> +++ b/lib/CMakeLists.txt
> @@ -4,31 +4,30 @@ add_subdirectory(Exchange)
>  add_subdirectory(Support)
>  add_subdirectory(JSON)
>  
> -set(MODULE TRUE)
> +if(POLLY_BUILD_SHARED_LIB)
> +  set(MODULE TRUE)
> +endif(POLLY_BUILD_SHARED_LIB)
>  set(LLVM_NO_RTTI 1)
>  
>  if (SCOPLIB_FOUND)
>    set(POLLY_SCOPLIB_FILES Pocc.cpp)
> +elseif(NOT POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES}
> +    Pocc.cpp)
>  endif (SCOPLIB_FOUND)
>  
>  if (PLUTO_FOUND)
>    set(POLLY_PLUTO_FILES Pluto.cpp)
> +elseif(NOT POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES}
> +    Pluto.cpp)
>  endif (PLUTO_FOUND)
>  
> -set(LLVM_USED_LIBS
> -  PollyAnalysis
> -  PollyCodeGen
> -  PollyExchange
> -  PollySupport
> -  PollyJSON
> -  )
> -
> -add_polly_loadable_module(LLVMPolly
> +set(POLLY_SRC
>    CodePreparation.cpp
>    DeadCodeElimination.cpp
>    IndependentBlocks.cpp
>    IndVarSimplify.cpp
> -  MayAliasSet.cpp
>    Pocc.cpp
>    RegisterPasses.cpp
>    ScheduleOptimizer.cpp
> @@ -36,18 +35,53 @@ add_polly_loadable_module(LLVMPolly
>    ${POLLY_PLUTO_FILES}
>    )
>  
> -if (TARGET intrinsics_gen)
> -  # Check if we are building as part of an LLVM build
> -  add_dependencies(LLVMPolly intrinsics_gen)
> -endif()
> -
> -add_dependencies(LLVMPolly
> -  PollyAnalysis
> -  PollyCodeGen
> -  PollyExchange
> -  PollySupport
> -  PollyJSON
> -  )
> +if(POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_USED_LIBS
> +    PollyAnalysis
> +    PollyCodeGen
> +    PollyExchange
> +    PollySupport
> +    PollyJSON
> +    )
> +  add_polly_loadable_module(LLVMPolly ${POLLY_SRC})
> +
> +  if (TARGET intrinsics_gen)
> +    # Check if we are building as part of an LLVM build
> +    add_dependencies(LLVMPolly intrinsics_gen)
> +  endif()
> +
> +  add_dependencies(LLVMPolly
> +    PollyAnalysis
> +    PollyCodeGen
> +    PollyExchange
> +    PollySupport
> +    PollyJSON
> +    )
> +else(POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_USED_LIBS
> +    LLVMPollyAnalysis
> +    LLVMPollyCodeGen
> +    LLVMPollyExchange
> +    LLVMPollySupport
> +    LLVMPollyJSON
> +    )
> +  add_llvm_library(LLVMPolly ${POLLY_SRC})
> +
> +  if (TARGET intrinsics_gen)
> +    # Check if we are building as part of an LLVM build
> +    add_dependencies(LLVMPolly intrinsics_gen)
> +  endif()
> +
> +  add_dependencies(LLVMPolly
> +    LLVMPollyAnalysis
> +    LLVMPollyCodeGen
> +    LLVMPollyExchange
> +    LLVMPollySupport
> +    LLVMPollyJSON
> +    )
> +
> +  target_link_libraries(LLVMPolly LLVMTransformUtils LLVMAnalysis)
> +endif(POLLY_BUILD_SHARED_LIB)
>  
>  set_target_properties(LLVMPolly
>    PROPERTIES
> diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt
> index b1c29c5..39c72b0 100644
> --- a/lib/CodeGen/CMakeLists.txt
> +++ b/lib/CodeGen/CMakeLists.txt
> @@ -2,6 +2,10 @@ if (CLOOG_FOUND)
>    set(CLOOG_FILES
>        Cloog.cpp
>        CodeGeneration.cpp)
> +elseif(NOT POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES}
> +    Cloog.cpp
> +    CodeGeneration.cpp)
>  endif (CLOOG_FOUND)
>  
>  set(ISL_CODEGEN_FILES
> @@ -11,13 +15,22 @@ set(ISL_CODEGEN_FILES
>  if (GPU_CODEGEN)
>    set (GPGPU_CODEGEN_FILES
>         PTXGenerator.cpp)
> +elseif(NOT POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES}
> +    PTXGenerator.cpp)
>  endif (GPU_CODEGEN)
>  
> -add_polly_library(PollyCodeGen
> +set(POLLY_CODEGEN_SOURCES
>    BlockGenerators.cpp
>    ${CLOOG_FILES}
>    ${ISL_CODEGEN_FILES}
>    LoopGenerators.cpp
>    Utils.cpp
>    ${GPGPU_CODEGEN_FILES}
> -)
> +  )
> +
> +if(POLLY_BUILD_SHARED_LIB)
> +  add_polly_library(PollyCodeGen ${POLLY_CODEGEN_SOURCES})
> +else(POLLY_BUILD_SHARED_LIB)
> +  add_llvm_library(LLVMPollyCodeGen ${POLLY_CODEGEN_SOURCES})
> +endif(POLLY_BUILD_SHARED_LIB)
> diff --git a/lib/Exchange/CMakeLists.txt b/lib/Exchange/CMakeLists.txt
> index 391f242..5c544d5 100644
> --- a/lib/Exchange/CMakeLists.txt
> +++ b/lib/Exchange/CMakeLists.txt
> @@ -2,6 +2,10 @@ if (OPENSCOP_FOUND)
>    set(POLLY_OPENSCOP_FILES
>        OpenScopImporter.cpp
>        OpenScopExporter.cpp)
> +elseif(NOT POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES}
> +    OpenScopImporter.cpp
> +    OpenScopExporter.cpp)
>  endif (OPENSCOP_FOUND)
>  
>  if (SCOPLIB_FOUND)
> @@ -9,12 +13,23 @@ if (SCOPLIB_FOUND)
>        ScopLib.cpp
>        ScopLibExporter.cpp
>        ScopLibImporter.cpp)
> +elseif(NOT POLLY_BUILD_SHARED_LIB)
> +  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES}
> +    ScopLib.cpp
> +    ScopLibExporter.cpp
> +    ScopLibImporter.cpp)
>  endif (SCOPLIB_FOUND)
>  
> -add_polly_library(PollyExchange
> +set(POLLY_EXCHANGE_SOURCES
>    JSONExporter.cpp
>    ${POLLY_OPENSCOP_FILES}
>    ${POLLY_SCOPLIB_FILES}
>  )
>  
> -target_link_libraries(PollyExchange PollyJSON)
> +if(POLLY_BUILD_SHARED_LIB)
> +  add_polly_library(PollyExchange ${POLLY_EXCHANGE_SOURCES})
> +  target_link_libraries(PollyExchange PollyJSON)
> +else(POLLY_BUILD_SHARED_LIB)
> +  add_llvm_library(LLVMPollyExchange ${POLLY_EXCHANGE_SOURCES})
> +  target_link_libraries(LLVMPollyExchange LLVMPollyJSON)
> +endif(POLLY_BUILD_SHARED_LIB)
> diff --git a/lib/JSON/CMakeLists.txt b/lib/JSON/CMakeLists.txt
> index 68bc1a1..f6dcc6d 100644
> --- a/lib/JSON/CMakeLists.txt
> +++ b/lib/JSON/CMakeLists.txt
> @@ -1,6 +1,11 @@
> -add_polly_library(PollyJSON
> +set(POLLY_JSON_SOURCES
>    json_reader.cpp
>    json_value.cpp
>    json_writer.cpp
>  )
>  
> +if(POLLY_BUILD_SHARED_LIB)
> +  add_polly_library(PollyJSON ${POLLY_JSON_SOURCES})
> +else(POLLY_BUILD_SHARED_LIB)
> +  add_llvm_library(LLVMPollyJSON ${POLLY_JSON_SOURCES})
> +endif(POLLY_BUILD_SHARED_LIB)
> diff --git a/lib/MayAliasSet.cpp b/lib/MayAliasSet.cpp
> deleted file mode 100644
> index 0d47d8c..0000000
> --- a/lib/MayAliasSet.cpp
> +++ /dev/null
> @@ -1,42 +0,0 @@
> -//===---------- MayAliasSet.cpp  - May-Alais Set for base pointers --------===//
> -//
> -//                     The LLVM Compiler Infrastructure
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -//
> -// This file implements the MayAliasSet class
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#include "polly/TempScopInfo.h"
> -#include "polly/MayAliasSet.h"
> -#include "llvm/Analysis/AliasAnalysis.h"
> -#include "llvm/Analysis/AliasSetTracker.h"
> -#include "llvm/Analysis/RegionInfo.h"
> -#include "llvm/Analysis/RegionIterator.h"
> -#include "llvm/Assembly/Writer.h"
> -#include "llvm/IR/LLVMContext.h"
> -#include "llvm/Support/Debug.h"
> -#include "llvm/Support/raw_ostream.h"
> -
> -using namespace llvm;
> -using namespace polly;
> -
> -void MayAliasSet::print(raw_ostream &OS) const {
> -  OS << "Must alias {";
> -
> -  for (const_iterator I = mustalias_begin(), E = mustalias_end(); I != E; ++I) {
> -    WriteAsOperand(OS, *I, false);
> -    OS << ", ";
> -  }
> -
> -  OS << "} May alias {";
> -  OS << '}';
> -}
> -
> -void MayAliasSet::dump() const { print(dbgs()); }
> -
> -void MayAliasSetInfo::buildMayAliasSets(TempScop &Scop, AliasAnalysis &AA) {}
> diff --git a/lib/RegisterPasses.cpp b/lib/RegisterPasses.cpp
> index 26a138e..bca1cf2 100644
> --- a/lib/RegisterPasses.cpp
> +++ b/lib/RegisterPasses.cpp
> @@ -310,12 +310,9 @@ static void registerPollyPasses(llvm::PassManagerBase &PM) {
>      PM.add(llvm::createCFGPrinterPass());
>  }
>  
> -static void
> -registerPollyEarlyAsPossiblePasses(const llvm::PassManagerBuilder &Builder,
> -                                   llvm::PassManagerBase &PM) {
> -
> -  if (Builder.OptLevel == 0)
> -    return;
> +static bool shouldEnablePolly(unsigned OptLevel) {
> +  if (OptLevel == 0)
> +    return false;
>  
>    if (PollyOnlyPrinter || PollyPrinter || PollyOnlyViewer || PollyViewer)
>      PollyTrackFailures = true;
> @@ -324,7 +321,16 @@ registerPollyEarlyAsPossiblePasses(const llvm::PassManagerBuilder &Builder,
>        ExportJScop || ImportJScop)
>      PollyEnabled = true;
>  
> -  if (!PollyEnabled)
> +  return PollyEnabled;
> +}
> +
> +} // end of anonymous namespace.
> +
> +void
> +registerPollyEarlyAsPossiblePasses(const llvm::PassManagerBuilder &Builder,
> +                                   llvm::PassManagerBase &PM) {
> +
> +  if (!shouldEnablePolly(Builder.OptLevel))
>      return;
>  
>    // We only run Polly at optimization level '-O3'.
> @@ -340,11 +346,15 @@ registerPollyEarlyAsPossiblePasses(const llvm::PassManagerBuilder &Builder,
>    registerPollyPasses(PM);
>  }
>  
> -static void registerPollyOptLevel0Passes(const llvm::PassManagerBuilder &,
> -                                         llvm::PassManagerBase &PM) {
> -  registerCanonicalicationPasses(PM);
> +void registerPollyOptLevel0Passes(const llvm::PassManagerBuilder &Builder,
> +                                  llvm::PassManagerBase &PM) {
> +  if (shouldEnablePolly(Builder.OptLevel))
> +    registerCanonicalicationPasses(PM);
>  }
>  
> +#ifdef POLLY_BUILD_SHARED_LIB
> +namespace {
> +
>  /// @brief Register Polly canonicalization passes at opt level '0'
>  ///
>  /// At '-O0' we schedule the Polly canonicalization passes. This allows us
> @@ -385,3 +395,5 @@ static llvm::RegisterStandardPasses
>  RegisterPollyOptimizer(llvm::PassManagerBuilder::EP_EarlyAsPossible,
>                         registerPollyEarlyAsPossiblePasses);
>  } // end of anonymous namespace.
> +
> +#endif // POLLY_BUILD_SHARED_LIB
> diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt
> index c6dfd87..b10d20a 100644
> --- a/lib/Support/CMakeLists.txt
> +++ b/lib/Support/CMakeLists.txt
> @@ -1,5 +1,11 @@
> -add_polly_library(PollySupport
> +set(POLLY_SUPPORT_SOURCES
>    GICHelper.cpp
>    SCEVValidator.cpp
>    ScopHelper.cpp
>    )
> +
> +if(POLLY_BUILD_SHARED_LIB)
> +  add_polly_library(PollySupport ${POLLY_SUPPORT_SOURCES})
> +else(POLLY_BUILD_SHARED_LIB)
> +  add_llvm_library(LLVMPollySupport ${POLLY_SUPPORT_SOURCES})
> +endif(POLLY_BUILD_SHARED_LIB)
> diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
> index d87f2fe..7abed4a 100644
> --- a/test/lit.site.cfg.in
> +++ b/test/lit.site.cfg.in
> @@ -25,8 +25,12 @@ except KeyError,e:
>      key, = e.args
>      lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
>  
> -config.substitutions.append(('%loadPolly', '-load '
> -                             + config.polly_lib_dir + '/LLVMPolly at LLVM_SHLIBEXT@'))
> +if '@POLLY_BUILD_SHARED_LIB@' == 'true':
> +    config.substitutions.append(('%loadPolly', '-load '
> +                                 + config.polly_lib_dir + '/LLVMPolly at LLVM_SHLIBEXT@'))
> +else:
> +    config.substitutions.append(('%loadPolly', ''))
> +
>  config.substitutions.append(('%defaultOpts', ' -basicaa -polly-prepare'))
>  config.substitutions.append(('%polybenchOpts', ' -O3 -loop-simplify -indvars '))
>  config.substitutions.append(('%vector-opt', '-polly-vectorizer=polly'))
> -- 
> 1.7.6.4
> 


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation



More information about the llvm-commits mailing list