OSDN Git Service

Fix interaction of static plugins with -DLLVM_LINK_LLVM_DYLIB=ON.
[android-x86/external-llvm-project.git] / polly / lib / CMakeLists.txt
1 set(LLVM_NO_RTTI 1)
2
3 set(ISL_CODEGEN_FILES
4     CodeGen/IslAst.cpp
5     CodeGen/IslExprBuilder.cpp
6     CodeGen/IslNodeBuilder.cpp
7     CodeGen/CodeGeneration.cpp)
8
9 if (GPU_CODEGEN)
10   set (GPGPU_CODEGEN_FILES
11        CodeGen/PPCGCodeGeneration.cpp
12        CodeGen/ManagedMemoryRewrite.cpp
13        )
14 endif (GPU_CODEGEN)
15
16 # Compile ISL into a separate library.
17 add_subdirectory(External)
18
19 set(POLLY_HEADER_FILES)
20 if (MSVC_IDE OR XCODE)
21   file(GLOB_RECURSE POLLY_HEADER_FILES "${POLLY_SOURCE_DIR}/include/polly/*.h")
22 endif ()
23
24 # Use an object-library to add the same files to multiple libs without requiring
25 # the sources them to be recompiled for each of them.
26 add_llvm_pass_plugin(Polly
27   NO_MODULE
28   SUBPROJECT Polly
29   Analysis/DependenceInfo.cpp
30   Analysis/PolyhedralInfo.cpp
31   Analysis/ScopDetection.cpp
32   Analysis/ScopDetectionDiagnostic.cpp
33   Analysis/ScopInfo.cpp
34   Analysis/ScopBuilder.cpp
35   Analysis/ScopGraphPrinter.cpp
36   Analysis/ScopPass.cpp
37   Analysis/PruneUnprofitable.cpp
38   CodeGen/BlockGenerators.cpp
39   ${ISL_CODEGEN_FILES}
40   CodeGen/LoopGenerators.cpp
41   CodeGen/LoopGeneratorsGOMP.cpp
42   CodeGen/LoopGeneratorsKMP.cpp
43   CodeGen/IRBuilder.cpp
44   CodeGen/Utils.cpp
45   CodeGen/RuntimeDebugBuilder.cpp
46   CodeGen/CodegenCleanup.cpp
47   CodeGen/PerfMonitor.cpp
48   ${GPGPU_CODEGEN_FILES}
49   Exchange/JSONExporter.cpp
50   Support/GICHelper.cpp
51   Support/SCEVAffinator.cpp
52   Support/SCEVValidator.cpp
53   Support/RegisterPasses.cpp
54   Support/ScopHelper.cpp
55   Support/ScopLocation.cpp
56   Support/ISLTools.cpp
57   Support/DumpModulePass.cpp
58   Support/VirtualInstruction.cpp
59   Transform/Canonicalization.cpp
60   Transform/CodePreparation.cpp
61   Transform/DeadCodeElimination.cpp
62   Transform/ScheduleOptimizer.cpp
63   Transform/ScheduleTreeTransform.cpp
64   Transform/FlattenSchedule.cpp
65   Transform/FlattenAlgo.cpp
66   Transform/ForwardOpTree.cpp
67   Transform/DeLICM.cpp
68   Transform/ZoneAlgo.cpp
69   Transform/Simplify.cpp
70   Transform/MaximalStaticExpansion.cpp
71   Transform/RewriteByReferenceParameters.cpp
72   Transform/ScopInliner.cpp
73   ${POLLY_HEADER_FILES}
74   )
75 set_target_properties(obj.Polly PROPERTIES FOLDER "Polly")
76 set_target_properties(Polly PROPERTIES FOLDER "Polly")
77
78 if (MSVC_IDE OR XCODE)
79   # Configure source groups for Polly source files. By default, in the IDE there
80   # will be a source and include folder. In the source folder will be all the
81   # source files in a flat list, and in the include folder will be all the
82   # headers in a flat list. Sets the CMake source_group for each folder such
83   # the organization of the sources and headers in the IDE matches how it is
84   # laid out on disk
85   setup_polly_source_groups(${CMAKE_CURRENT_LIST_DIR}
86     ${CMAKE_CURRENT_LIST_DIR}/../include/polly)
87 endif()
88
89 # Create the library that can be linked into LLVM's tools and Polly's unittests.
90 # It depends on all library it needs, such that with
91 # LLVM_POLLY_LINK_INTO_TOOLS=ON, its dependencies like PollyISL are linked as
92 # well.
93 target_link_libraries(Polly PUBLIC
94   ${ISL_TARGET}
95 )
96
97 # Additional dependencies for Polly-ACC.
98 if (GPU_CODEGEN)
99   target_link_libraries(Polly PUBLIC PollyPPCG)
100 endif ()
101
102
103 # Polly-ACC requires the NVPTX backend to work. Ask LLVM about its libraries.
104 set(nvptx_libs)
105 if (GPU_CODEGEN)
106   # This call emits an error if they NVPTX backend is not enable.
107   llvm_map_components_to_libnames(nvptx_libs NVPTX)
108 endif ()
109
110 if (LLVM_LINK_LLVM_DYLIB AND NOT LLVM_POLLY_LINK_INTO_TOOLS)
111   # The shlib/dylib contains all the LLVM components
112   # (including NVPTX is enabled) already. Adding them to target_link_libraries
113   # would cause them being twice in the address space
114   # (their LLVM*.a/so and their copies in libLLVM.so)
115   # which results in errors when the two instances try to register the same
116   # command-line switches.
117   target_link_libraries(Polly PUBLIC LLVM)
118 else ()
119   target_link_libraries(Polly PUBLIC
120     LLVMSupport
121     LLVMCore
122     LLVMScalarOpts
123     LLVMInstCombine
124     LLVMTransformUtils
125     LLVMAnalysis
126     LLVMipo
127     LLVMMC
128     LLVMPasses
129     LLVMLinker
130     LLVMIRReader
131     ${nvptx_libs}
132     # The libraries below are required for darwin: http://PR26392
133     LLVMBitReader
134     LLVMMCParser
135     LLVMObject
136     LLVMProfileData
137     LLVMTarget
138     LLVMVectorize
139     )
140
141     # Polly-ACC requires the NVPTX target to be present in the executable it is linked to
142     set_property(TARGET bugpoint APPEND PROPERTY LINK_LIBRARIES LLVMTarget)
143 endif ()
144
145 # Create a loadable module Polly.so that can be loaded using
146 # LLVM's/clang's "-load" option.
147 if (MSVC)
148   # Add dummy target, because loadable modules are not supported on Windows
149   add_custom_target(LLVMPolly)
150   set_target_properties(LLVMPolly PROPERTIES FOLDER "Polly")
151 else ()
152   add_polly_loadable_module(LLVMPolly
153     Plugin/Polly.cpp
154     $<TARGET_OBJECTS:obj.Polly>
155   )
156
157   # Only add the dependencies that are not part of LLVM. The latter are assumed
158   # to be already available in the address space the module is loaded into.
159   # Adding them once more would have the effect that both copies try to register
160   # the same command line options, to which LLVM reacts with an error.
161   # If Polly-ACC is enabled, the NVPTX target is also expected to reside in the
162   # hosts. This is not the case for bugpoint. Use LLVM_POLLY_LINK_INTO_TOOLS=ON
163   # instead which will automatically resolve the additional dependencies by
164   # Polly.
165   target_link_libraries(LLVMPolly PUBLIC ${ISL_TARGET})
166   if (GPU_CODEGEN)
167     target_link_libraries(LLVMPolly PUBLIC PollyPPCG)
168   endif ()
169
170   set_target_properties(LLVMPolly
171     PROPERTIES
172     LINKER_LANGUAGE CXX
173     PREFIX "")
174 endif ()
175
176 if (TARGET intrinsics_gen)
177   # Check if we are building as part of an LLVM build
178   add_dependencies(obj.Polly intrinsics_gen)
179 endif()