• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# External: Integer Set Library
2if (POLLY_BUNDLED_ISL)
3  set(ISL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/isl")
4  set(ISL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/isl")
5
6  # Determine version of isl
7  if (EXISTS "${ISL_SOURCE_DIR}/GIT_HEAD_ID")
8    # The source comes from a 'make dist' archive
9    file(READ "${ISL_SOURCE_DIR}/GIT_HEAD_ID" ISL_GIT_HEAD_ID)
10    string(STRIP "${ISL_GIT_HEAD_ID}" ISL_GIT_HEAD_ID)
11  elseif (EXISTS "${ISL_SOURCE_DIR}/gitversion.h")
12    # The source directory is preconfigured
13    file(READ "${ISL_SOURCE_DIR}/gitversion.h" GITVERSION_H)
14    string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" ISL_GIT_HEAD_ID "${GITVERSION_H}")
15  elseif ()
16    # Unknown revision
17    # TODO: We could look for a .git and get the revision from HEAD
18    set(ISL_GIT_HEAD_ID "UNKNOWN")
19  endif ()
20
21  message(STATUS "ISL version: ${ISL_GIT_HEAD_ID}")
22
23  # Enable small integer optimization and imath
24  set(USE_GMP_FOR_MP OFF)
25  set(USE_IMATH_FOR_MP ON)
26  set(USE_SMALL_INT_OPT ON)
27
28  # Determine compiler characteristics
29  include(CheckCSourceCompiles)
30
31  # Like check_c_source_compiles, but sets the result to either
32  # 0 (error while compiling) or 1 (compiled successfully)
33  # Required for compatibility with autotool's AC_CHECK_DECLS
34  function (check_c_source_compiles_numeric _prog _var)
35    check_c_source_compiles("${_prog}" "${_var}")
36    if ("${${_var}}")
37      set("${_var}" 1 PARENT_SCOPE)
38    else ()
39      set("${_var}" 0 PARENT_SCOPE)
40    endif ()
41  endfunction ()
42
43  # Check for the existance of a type
44  function (check_c_type_exists _type _files _variable)
45    set(_includes "")
46    foreach (file_name ${_files})
47      set(_includes "${_includes}#include<${file_name}>\n")
48    endforeach()
49    check_c_source_compiles("
50    ${_includes}
51    ${_type} typeVar;
52    int main() {
53    return 0;
54    }
55    " ${_variable})
56  endfunction ()
57
58
59  check_c_source_compiles("
60  int func(void) __attribute__((__warn_unused_result__));
61  int main() { return 0; }
62  " HAS_ATTRIBUTE_WARN_UNUSED_RESULT)
63  set(GCC_WARN_UNUSED_RESULT)
64  if (HAS_ATTRIBUTE_WARN_UNUSED_RESULT)
65    set(GCC_WARN_UNUSED_RESULT "__attribute__((__warn_unused_result__))")
66  endif ()
67
68  check_c_source_compiles("
69  __attribute__ ((unused)) static void foo(void);
70  int main() { return 0; }
71  " HAVE___ATTRIBUTE__)
72
73
74  check_c_source_compiles_numeric("
75  #include <strings.h>
76  int main() { (void)ffs(0); return 0; }
77  " HAVE_DECL_FFS)
78
79  check_c_source_compiles_numeric("
80  int main() { (void)__builtin_ffs(0); return 0; }
81  " HAVE_DECL___BUILTIN_FFS)
82
83  check_c_source_compiles_numeric("
84  #include <intrin.h>
85  int main() { (void)_BitScanForward(NULL, 0); return 0; }
86  " HAVE_DECL__BITSCANFORWARD)
87
88  if (NOT HAVE_DECL_FFS AND
89      NOT HAVE_DECL___BUILTIN_FFS AND
90      NOT HAVE_DECL__BITSCANFORWARD)
91    message(FATAL_ERROR "No ffs implementation found")
92  endif ()
93
94
95  check_c_source_compiles_numeric("
96  #include <strings.h>
97  int main() { (void)strcasecmp(\"\", \"\"); return 0; }
98  " HAVE_DECL_STRCASECMP)
99
100  check_c_source_compiles_numeric("
101  #include <string.h>
102  int main() { (void)_stricmp(\"\", \"\"); return 0; }
103  " HAVE_DECL__STRICMP)
104
105  if (NOT HAVE_DECL_STRCASECMP AND NOT HAVE_DECL__STRICMP)
106    message(FATAL_ERROR "No strcasecmp implementation found")
107  endif ()
108
109
110  check_c_source_compiles_numeric("
111  #include <strings.h>
112  int main() { (void)strncasecmp(\"\", \"\", 0); return 0; }
113  " HAVE_DECL_STRNCASECMP)
114
115  check_c_source_compiles_numeric("
116  #include <string.h>
117  int main() { (void)_strnicmp(\"\", \"\", 0); return 0; }
118  " HAVE_DECL__STRNICMP)
119
120  if (NOT HAVE_DECL_STRNCASECMP AND NOT HAVE_DECL__STRNICMP)
121    message(FATAL_ERROR "No strncasecmp implementation found")
122  endif ()
123
124
125  check_c_source_compiles_numeric("
126  #include <stdio.h>
127  int main() { snprintf((void*)0, 0, \" \"); return 0; }
128  " HAVE_DECL_SNPRINTF)
129
130  check_c_source_compiles_numeric("
131  #include <stdio.h>
132  int main() { _snprintf((void*)0, 0, \" \"); return 0; }
133  " HAVE_DECL__SNPRINTF)
134
135  if (NOT HAVE_DECL_SNPRINTF AND NOT HAVE_DECL__SNPRINTF)
136    message(FATAL_ERROR "No snprintf implementation found")
137  endif ()
138
139
140  check_c_type_exists(uint8_t "" HAVE_UINT8T)
141  check_c_type_exists(uint8_t "stdint.h" HAVE_STDINT_H)
142  check_c_type_exists(uint8_t "inttypes.h" HAVE_INTTYPES_H)
143  check_c_type_exists(uint8_t "sys/types.h" HAVE_SYS_INTTYPES_H)
144  if (HAVE_UINT8T)
145    set(INCLUDE_STDINT_H "")
146  elseif (HAVE_STDINT_H)
147    set(INCLUDE_STDINT_H "#include <stdint.h>")
148  elseif (HAVE_INTTYPES_H)
149    set(INCLUDE_STDINT_H "#include <inttypes.h>")
150  elseif (HAVE_SYS_INTTYPES_H)
151    set(INCLUDE_STDINT_H "#include <sys/inttypes.h>")
152  else ()
153    message(FATAL_ERROR "No stdint.h or compatible found")
154  endif ()
155
156  # Write configure result
157  # configure_file(... COPYONLY) avoids that the time stamp changes if the file is identical
158  file(WRITE "${ISL_BINARY_DIR}/gitversion.h.tmp"
159    "#define GIT_HEAD_ID \"${ISL_GIT_HEAD_ID}\"")
160  configure_file("${ISL_BINARY_DIR}/gitversion.h.tmp"
161    "${ISL_BINARY_DIR}/gitversion.h" COPYONLY)
162
163  file(WRITE "${ISL_BINARY_DIR}/include/isl/stdint.h.tmp"
164    "${INCLUDE_STDINT_H}\n")
165  configure_file("${ISL_BINARY_DIR}/include/isl/stdint.h.tmp"
166    "${ISL_BINARY_DIR}/include/isl/stdint.h" COPYONLY)
167
168  configure_file("isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h")
169  configure_file("isl_srcdir.c.cmake" "${ISL_BINARY_DIR}/isl_srcdir.c")
170
171  include_directories(BEFORE
172    ${ISL_BINARY_DIR}
173    ${ISL_SOURCE_DIR}/imath
174    ${ISL_SOURCE_DIR}/include
175    ${ISL_SOURCE_DIR}
176    )
177
178  # ISL files to compile
179  set (ISL_FILES
180    isl/basis_reduction_tab.c
181    isl/isl_aff.c
182    isl/isl_aff_map.c
183    isl/isl_affine_hull.c
184    isl/isl_arg.c
185    isl/isl_ast_build.c
186    isl/isl_ast_build_expr.c
187    isl/isl_ast.c
188    isl/isl_ast_codegen.c
189    isl/isl_ast_graft.c
190    isl/isl_bernstein.c
191    isl/isl_blk.c
192    isl/isl_bound.c
193    isl/isl_box.c
194    isl/isl_coalesce.c
195    isl/isl_constraint.c
196    isl/isl_convex_hull.c
197    isl/isl_ctx.c
198    isl/isl_deprecated.c
199    isl/isl_dim_map.c
200    isl/isl_equalities.c
201    isl/isl_factorization.c
202    isl/isl_farkas.c
203    isl/isl_ffs.c
204    isl/isl_flow.c
205    isl/isl_fold.c
206    isl/isl_hash.c
207    isl/isl_id.c
208    isl/isl_id_to_ast_expr.c
209    isl/isl_id_to_id.c
210    isl/isl_id_to_pw_aff.c
211    isl/isl_ilp.c
212    isl/isl_imath.c
213    isl/isl_input.c
214    isl/isl_int_sioimath.c
215    isl/isl_local.c
216    isl/isl_local_space.c
217    isl/isl_lp.c
218    isl/isl_map.c
219    isl/isl_map_list.c
220    isl/isl_map_simplify.c
221    isl/isl_map_subtract.c
222    isl/isl_map_to_basic_set.c
223    isl/isl_mat.c
224    isl/isl_morph.c
225    isl/isl_obj.c
226    isl/isl_options.c
227    isl/isl_output.c
228    isl/isl_point.c
229    isl/isl_polynomial.c
230    isl/isl_printer.c
231    isl/isl_range.c
232    isl/isl_reordering.c
233    isl/isl_sample.c
234    isl/isl_scan.c
235    isl/isl_schedule.c
236    isl/isl_schedule_band.c
237    isl/isl_schedule_constraints.c
238    isl/isl_schedule_node.c
239    isl/isl_schedule_read.c
240    isl/isl_schedule_tree.c
241    isl/isl_scheduler.c
242    isl/isl_seq.c
243    isl/isl_set_list.c
244    isl/isl_set_to_ast_graft_list.c
245    isl/isl_sort.c
246    isl/isl_space.c
247    isl/isl_stride.c
248    isl/isl_stream.c
249    isl/isl_tab.c
250    isl/isl_tab_pip.c
251    isl/isl_tarjan.c
252    isl/isl_transitive_closure.c
253    isl/isl_union_map.c
254    isl/isl_val.c
255    isl/isl_val_sioimath.c
256    isl/isl_vec.c
257    isl/isl_version.c
258    isl/isl_vertices.c
259    isl/print.c
260    isl/set_to_map.c
261    isl/set_from_map.c
262    isl/uset_to_umap.c
263    isl/uset_from_umap.c
264    isl/imath/gmp_compat.c
265    isl/imath/imath.c
266    isl/imath/imrat.c
267    )
268
269  add_polly_library(PollyISL
270    ${ISL_FILES}
271    )
272
273
274  if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
275    install(DIRECTORY
276      ${ISL_SOURCE_DIR}/include/
277      ${ISL_BINARY_DIR}/include/
278      DESTINATION include/polly
279      FILES_MATCHING
280      PATTERN "*.h"
281      PATTERN "CMakeFiles" EXCLUDE
282      )
283  endif()
284
285  add_executable(polly-isl-test
286    isl/isl_test.c
287    )
288  set_target_properties(polly-isl-test PROPERTIES FOLDER "Polly")
289
290  target_link_libraries(polly-isl-test PRIVATE
291    PollyISL
292    )
293
294  # ISL requires at least C99 to compile. gcc < 5.0 use -std=gnu89 as default.
295  set_property(TARGET PollyISL polly-isl-test PROPERTY C_STANDARD 99)
296endif (POLLY_BUNDLED_ISL)
297
298set(PET_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pet")
299set(PPCG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ppcg")
300set(PPCG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ppcg")
301
302# Determine version of ppcg
303if (EXISTS "${PPCG_SOURCE_DIR}/GIT_HEAD_ID")
304  # The source comes from a 'make dist' archive
305  file(READ "${PPCG_SOURCE_DIR}/GIT_HEAD_ID" PPCG_GIT_HEAD_ID)
306  string(STRIP "${PPCG_GIT_HEAD_ID}" PPCG_GIT_HEAD_ID)
307elseif (EXISTS "${PPCG_SOURCE_DIR}/gitversion.h")
308  # The source directory is preconfigured
309  file(READ "${PPCG_SOURCE_DIR}/gitversion.h" GITVERSION_H)
310  string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" PPCG_GIT_HEAD_ID "${GITVERSION_H}")
311elseif ()
312  # Unknown revision
313  # TODO: We could look for a .git and get the revision from HEAD
314  set(PPCG_GIT_HEAD_ID "UNKNOWN")
315endif ()
316
317message(STATUS "PPCG version: ${PPCG_GIT_HEAD_ID}")
318
319set (PPCG_FILES
320     ppcg/cuda.c
321     ppcg/cuda_common.c
322     ppcg/external.c
323     ppcg/gpu_array_tile.c
324     ppcg/gpu.c
325     ppcg/gpu_array_tile.c
326     ppcg/gpu_group.c
327     ppcg/gpu_hybrid.c
328     ppcg/gpu_print.c
329     ppcg/gpu_tree.c
330     ppcg/grouping.c
331     ppcg/hybrid.c
332     ppcg/ppcg.c
333     ppcg/ppcg_options.c
334     ppcg/print.c
335     ppcg/schedule.c
336     ppcg/util.c
337     )
338
339include_directories(BEFORE
340  ${PPCG_BINARY_DIR}
341  ${PPCG_SOURCE_DIR}/imath
342  ${PPCG_SOURCE_DIR}/include
343  ${PET_SOURCE_DIR}/include
344)
345
346add_polly_library(PollyPPCG
347  ${PPCG_FILES}
348)
349
350target_link_libraries(PollyPPCG PUBLIC ${ISL_TARGET})
351
352# Disable warnings for upstream projects.
353if (MSVC)
354  set(DISABLE_WARNING_FLAGS
355    -wd4018 # 'expression' : signed/unsigned mismatch
356    -wd4090 # 'operation' : different 'modifier' qualifiers
357    -wd4200 # nonstandard extension used: zero-sized array in struct/union
358    -wd4201 # nonstandard extension used: nameless struct/union
359    -wd4334 # 'operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
360    -wd4221 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
361  )
362  if (POLLY_BUNDLED_ISL)
363    target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS})
364    target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS})
365  endif (POLLY_BUNDLED_ISL)
366  target_compile_options(PollyPPCG PRIVATE ${DISABLE_WARNING_FLAGS})
367else ()
368  if (POLLY_BUNDLED_ISL)
369    set_target_properties(PollyISL polly-isl-test PROPERTIES COMPILE_FLAGS "-w")
370  endif (POLLY_BUNDLED_ISL)
371  set_target_properties(PollyPPCG PROPERTIES COMPILE_FLAGS "-w")
372endif ()
373
374if(MSVC)
375  # In the Windows API (with some exceptions), the maximum length for a path is
376  # MAX_PATH, which is defined as 260 characters.
377  target_compile_definitions(PollyPPCG PRIVATE "-DPATH_MAX=260")
378endif ()
379