[CMake] Use object library to build the two flavours of Polly.
[polly-mirror.git] / lib / CMakeLists.txt
blob63c7646359436485e27e9efb47106df93ac6bce0
1 set(LLVM_NO_RTTI 1)
3 set(POLLY_JSON_FILES
4     External/JSON/json_reader.cpp
5     External/JSON/json_value.cpp
6     External/JSON/json_writer.cpp
9 set(ISL_CODEGEN_FILES
10     CodeGen/IslAst.cpp
11     CodeGen/IslExprBuilder.cpp
12     CodeGen/IslNodeBuilder.cpp
13     CodeGen/CodeGeneration.cpp)
15 if (GPU_CODEGEN)
16   set (GPGPU_CODEGEN_FILES
17        CodeGen/PPCGCodeGeneration.cpp
18        )
19 endif (GPU_CODEGEN)
21 # Compile ISL into a separate library.
22 add_subdirectory(External)
24 set(POLLY_HEADER_FILES)
25 if (MSVC_IDE OR XCODE)
26   file(GLOB_RECURSE POLLY_HEADER_FILES "${POLLY_SOURCE_DIR}/include/polly/*.h")
27 endif ()
29 # Use an object-library to add the same files to multiple libs without requiring
30 # the sources them to be recompiled for each of them.
31 add_library(PollyCore OBJECT
32   Analysis/DependenceInfo.cpp
33   Analysis/PolyhedralInfo.cpp
34   Analysis/ScopDetection.cpp
35   Analysis/ScopDetectionDiagnostic.cpp
36   Analysis/ScopInfo.cpp
37   Analysis/ScopBuilder.cpp
38   Analysis/ScopGraphPrinter.cpp
39   Analysis/ScopPass.cpp
40   Analysis/PruneUnprofitable.cpp
41   CodeGen/BlockGenerators.cpp
42   ${ISL_CODEGEN_FILES}
43   CodeGen/LoopGenerators.cpp
44   CodeGen/IRBuilder.cpp
45   CodeGen/Utils.cpp
46   CodeGen/RuntimeDebugBuilder.cpp
47   CodeGen/CodegenCleanup.cpp
48   CodeGen/PerfMonitor.cpp
49   ${GPGPU_CODEGEN_FILES}
50   Exchange/JSONExporter.cpp
51   Support/GICHelper.cpp
52   Support/SCEVAffinator.cpp
53   Support/SCEVValidator.cpp
54   Support/RegisterPasses.cpp
55   Support/ScopHelper.cpp
56   Support/ScopLocation.cpp
57   Support/ISLTools.cpp
58   Support/DumpModulePass.cpp
59   ${POLLY_JSON_FILES}
60   Transform/Canonicalization.cpp
61   Transform/CodePreparation.cpp
62   Transform/DeadCodeElimination.cpp
63   Transform/ScheduleOptimizer.cpp
64   Transform/FlattenSchedule.cpp
65   Transform/FlattenAlgo.cpp
66   Transform/DeLICM.cpp
67   Transform/Simplify.cpp
68   ${POLLY_HEADER_FILES}
69   )
71 # Create the library that can be linked into LLVM's tools and Polly's unittests.
72 # It depends on all library it needs, such that with
73 # LLVM_POLLY_LINK_INTO_TOOLS=ON, its dependencies like PollyISL are linked as
74 # well.
75 add_polly_library(Polly $<TARGET_OBJECTS:PollyCore>)
76 target_link_libraries(Polly
77   ${ISL_TARGET}
80 # Additional dependencies for Polly-ACC.
81 if (GPU_CODEGEN)
82   target_link_libraries(Polly PollyPPCG)
83 endif ()
85 # Add Polly's LLVM dependencies.
86 # When built inside the LLVM source tree, these are CMake targets that will
87 # depend on their dependencies and CMake ensures they are added in the right
88 # order.
89 # If Polly is built independently, just add all LLVM libraries. LLVM_ROOT_DIR
90 # might have been configured to compile to individual libraries or a single
91 # libLLVM.so (called dylib), reported by llvm-config, so there is no fixed list
92 # of required libraries.
93 if (DEFINED LLVM_MAIN_SRC_DIR)
95   # Polly-ACC requires the NVPTX backend to work. Ask LLVM about its libraries.
96   set(nvptx_libs)
97   if (GPU_CODEGEN)
98     # This call emits an error if they NVPTX backend is not enable.
99     llvm_map_components_to_libnames(nvptx_libs NVPTX)
100   endif ()
102   if (LLVM_LINK_LLVM_DYLIB)
103     # The shlib/dylib contains all the LLVM components
104     # (including NVPTX is enabled) already. Adding them to target_link_libraries
105     # would cause them being twice in the address space
106     # (their LLVM*.a/so and their copies in libLLVM.so)
107     # which results in errors when the two instances try to register the same
108     # command-line switches.
109     target_link_libraries(Polly LLVM)
110   else ()
111     target_link_libraries(Polly
112       LLVMSupport
113       LLVMCore
114       LLVMScalarOpts
115       LLVMInstCombine
116       LLVMTransformUtils
117       LLVMAnalysis
118       LLVMipo
119       LLVMMC
120       ${nvptx_libs}
121 # The libraries below are required for darwin: http://PR26392
122       LLVMBitReader
123       LLVMMCParser
124       LLVMObject
125       LLVMProfileData
126       LLVMTarget
127       LLVMVectorize
128     )
129   endif ()
130 else ()
131   # When Polly-ACC is enabled, we assume that the host LLVM was also built with
132   # the NVPTX target enabled.
133   target_link_libraries(Polly
134     ${LLVM_LIBS}
135     ${LLVM_SYSTEM_LIBS}
136   )
137 endif ()
139 # Create a loadable module Polly.so that can be loaded using
140 # LLVM's/clang's "-load" option.
141 if (MSVC)
142   # Add dummy target, because loadable modules are not supported on Windows
143   add_custom_target(LLVMPolly)
144   set_target_properties(LLVMPolly PROPERTIES FOLDER "Polly")
145 else ()
146   add_polly_loadable_module(LLVMPolly
147     Polly.cpp
148     $<TARGET_OBJECTS:PollyCore>
149   )
151   # Only add the dependencies that are not part of LLVM. The latter are assumed
152   # to be already available in the address space the module is loaded into.
153   # Adding them once more would have the effect that both copies try to register
154   # the same command line options, to which LLVM reacts with an error.
155   # If Polly-ACC is enabled, the NVPTX target is also expected to reside in the
156   # hosts. This is not the case for bugpoint. Use LLVM_POLLY_LINK_INTO_TOOLS=ON
157   # instead which will automatically resolve the additional dependencies by
158   # Polly.
159   target_link_libraries(LLVMPolly ${ISL_TARGET})
160   if (GPU_CODEGEN)
161     target_link_libraries(LLVMPolly PollyPPCG)
162   endif ()
164   set_target_properties(LLVMPolly
165     PROPERTIES
166     LINKER_LANGUAGE CXX
167     PREFIX "")
168 endif ()
170 if (TARGET intrinsics_gen)
171   # Check if we are building as part of an LLVM build
172   add_dependencies(Polly intrinsics_gen)
173 endif()