source: icGREP/icgrep-devel/icgrep/CMakeLists.txt @ 4750

Last change on this file since 4750 was 4750, checked in by cameron, 4 years ago

Clean ups for compilation with gcc 4.8

File size: 10.8 KB
RevLine 
[3850]1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
[4096]5enable_testing()
[3850]6# The version number.
[4508]7set (icgrep_VERSION_MAJOR 1)
8set (icgrep_VERSION_MINOR 0)
[4096]9
[4151]10option(BLOCK_SIZE_256 "Compiling with BLOCK_SIZE=256")
11if (BLOCK_SIZE_256)
12  message("-- Build with BLOCK_SIZE=256")
13else ()
14  message("-- Build with BLOCK_SIZE=128")
15endif()
[4583]16option(ENABLE_MULTIPLEXING "Compiling the Multiplexing Module")
[4686]17option(DISABLE_PREGENERATED_UCD_FUNCTIONS "Disable compiling the pregenerated UCD functions")
[4151]18
[4583]19
[3850]20# configure a header file to pass some of the CMake settings
21# to the source code
22#configure_file (
23#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
24#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
25#  )
26
27# LLVM set up
28#
29# A convenience variable:
30set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
31
32# A bit of a sanity check:
33if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
34message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
35endif()
36
37# We incorporate the CMake features provided by LLVM:
38set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
39include(LLVMConfig)
40
41# Now set the header and library paths:
42include_directories( ${LLVM_INCLUDE_DIRS} )
43link_directories( ${LLVM_LIBRARY_DIRS} )
44add_definitions( ${LLVM_DEFINITIONS} )
45
46# Let's suppose we want to build a JIT compiler with support for
47# binary code (no interpreter):
[4734]48llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader)
[3850]49
[4118]50message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
[4096]51
[4196]52# Check if boost has been installed on this system.
[4210]53set(Boost_USE_STATIC_LIBS ON)
54set(Boost_USE_MULTITHREADED OFF)
[4583]55set(Boost_USE_STATIC_RUNTIME ON)
56
57if(ENABLE_MULTIPLEXING)
[4684]58find_package(Boost COMPONENTS system REQUIRED)
[4583]59else()
[4416]60find_package(Boost)
[4583]61endif()
[4212]62
[4741]63SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/function.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp)
64SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp IDISA/idisa_builder.cpp)
65SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/optimizers/booleanreassociationpass.cpp)
[4583]66IF (ENABLE_MULTIPLEXING)
[4741]67SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
[4583]68ENDIF()
69
70add_library(PabloADT ${PABLO_SRC})
[4684]71add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_rep.cpp re/re_diff.cpp re/re_intersect.cpp re/printer_re.cpp)
72add_library(RegExpCompiler re/re_parser.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/re_analysis.cpp)
[4418]73add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
[4684]74add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
[4198]75
[4583]76
[4684]77# add the executable
78target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
79target_link_libraries (CCADT PabloADT)
80target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
81target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
82target_link_libraries (RegExpCompiler RegExpADT)
83
[4686]84set(PRECOMPILED_FILES "")
85
86IF(DISABLE_PREGENERATED_UCD_FUNCTIONS)
87set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
88MESSAGE("Disabling predefined UCD functions...")
89ELSE()
[4692]90
[4684]91# add the executable
92add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
[4686]93target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT)
[4684]94
95set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
96set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
97
98if(ENABLE_MULTIPLEXING)
[4686]99set(MULTIPLEXING_FLAG -multiplexing -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv)
[4684]100endif()
101
102add_custom_command(OUTPUT ${PRECOMPILED_FILES}
103  COMMAND generate_predefined_ucd_functions
[4736]104  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
[4684]105  DEPENDS generate_predefined_ucd_functions
106  COMMENT "Building predefined UCD functions..."
107  VERBATIM)
108
[4692]109add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
[4684]110
[4686]111add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
112ENDIF()
113
[4734]114add_executable(icgrep icgrep.cpp do_grep.cpp ${PRECOMPILED_FILES})
[4686]115IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
116add_dependencies(icgrep run_generate_predefined_ucd_functions)
117ENDIF()
[4583]118IF(Boost_FOUND)
119    include_directories("${Boost_INCLUDE_DIRS}")
120    link_directories(${Boost_LIBRARY_DIR})
121    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
122ENDIF()
123
[4734]124target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
125
126
127
[4583]128IF (ENABLE_MULTIPLEXING)
129message(STATUS "Enabling Multiplexing")
130SET(CUDD_ROOT "${CMAKE_SOURCE_DIR}/../cudd-2.5.1")
[4598]131file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
132file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
[4583]133file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
134file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
[4598]135file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
[4583]136add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
[4598]137include_directories(${CUDD_ROOT}/cudd)
138include_directories(${CUDD_ROOT}/epd)
139include_directories(${CUDD_ROOT}/mtr)
140include_directories(${CUDD_ROOT}/st)
141include_directories(${CUDD_ROOT}/util)
[4583]142target_link_libraries (PabloADT CUDD)
143SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
144ENDIF()
145
[4096]146include_directories("${PROJECT_SOURCE_DIR}")
147
[4152]148#Check compiler support for 0x / 11
149include(CheckCXXCompilerFlag)
150CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
151if(COMPILER_SUPPORTS_CXX11)
152  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
153else()
154  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
155  if(COMPILER_SUPPORTS_CXX0X)
156    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
157  else()
158    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
159    if(COMPILER_SUPPORTS_GNU11)
160      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
161    else() 
162      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
163      if(COMPILER_SUPPORTS_GNU0X)
164        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
165      endif()
166    endif()
167  endif()
168endif()
[4096]169
[4200]170#Disable RunTime Type Information
171IF (MSVC) # using Visual Studio C++
[4436]172  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
[4200]173ELSE() # using Clang, GCC, Intel C++, etc
[4436]174  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
[4200]175ENDIF()
176
[4227]177#Enable all warnings
[4356]178SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
[4200]179
180#Check compiler and system architecture support for SSE or AVX
[4152]181include(CheckCXXSourceRuns)
182
183set(SSE1_CODE "
184#include <xmmintrin.h>
185int main()
186{
187__m128 a;
188float vals[4] = {0,0,0,0};
189a = _mm_loadu_ps(vals);
190return 0;
191}")
192
193set(SSE2_CODE "
194#include <emmintrin.h>
195int main()
196{
197__m128d a;
198double vals[2] = {0,0};
199a = _mm_loadu_pd(vals);
200return 0;
201}")
202
203set(SSE3_CODE "
204#include <pmmintrin.h>
205int main( )
206{
207const int vals[4] = {0,0,0,0};
208__m128i a;
209a = _mm_lddqu_si128( (const __m128i*)vals );
210return 0;
211}")
212
213set(SSE4_1_CODE "
214#include <smmintrin.h>
215int main ()
216{
217__m128i a, b;
218__m128i res = _mm_max_epi8(a, b);
219return 0;
220}")
221
222set(SSE4_2_CODE "
223#include <nmmintrin.h>
224int main()
225{
226__m128i a, b, c;
227c = _mm_cmpgt_epi64(a, b);
228return 0;
229}")
230
[4480]231set(AVX1_CODE "
[4152]232#include <immintrin.h>
233int main()
234{
235__m256* a=(__m256*)_mm_malloc(4, 32);
236__m256 b = _mm256_load_ps((float*)a);
237b = _mm256_or_ps(b, b);
238_mm_free(a);
239return 0;
240}")
241
[4480]242set(AVX2_CODE "
[4152]243#include <immintrin.h>
244int main()
245{
246__m256i* a = (__m256i*)_mm_malloc(4, 32);
247__m256i b = _mm256_load_si256(a);
248b = _mm256_or_si256(b, b);
249_mm_free(a);
250return 0;
251}")
252
253IF (MSVC) # using Visual Studio C++
254  SET(ENABLE_SSE1 "/arch:SSE")
255  SET(ENABLE_SSE2 "/arch:SSE2")
256  SET(ENABLE_SSE3 "/arch:SSE3")
257  SET(ENABLE_SSE4_1 "/arch:SSE4")
258  SET(ENABLE_SSE4_2 "/arch:SSE4")
[4480]259  SET(ENABLE_AVX1 "/arch:AVX1")
260  SET(ENABLE_AVX2 "/arch:AVX2")
[4209]261ELSE() # using Clang, GCC, Intel C++, etc 
[4152]262  SET(ENABLE_SSE1 "-msse")
263  SET(ENABLE_SSE2 "-msse2")
264  SET(ENABLE_SSE3 "-msse3")
265  SET(ENABLE_SSE4_1 "-msse4.1")
266  SET(ENABLE_SSE4_2 "-msse4.2")
[4209]267  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
[4480]268    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
269    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
[4209]270  ELSE()
[4480]271    SET(ENABLE_AVX1 "-mavx")
272    SET(ENABLE_AVX2 "-mavx2")
[4209]273  ENDIF()
[4152]274ENDIF()
275
[4480]276SET(CMAKE_REQUIRED_FLAGS)
[4152]277
[4480]278MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
279  IF(NOT RESULT) 
280    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
281    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
282    SET(SUCCESS "${SIMD_TYPE}")
283    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
284    IF(${SUCCESS})
285      SET(${RESULT} "${SIMD_TYPE}")
[4152]286    ENDIF()
287    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
288  ENDIF()
289ENDMACRO()
290
[4480]291IF(NOT SIMD_SUPPORT)
292SET(RESULT)
293CHECK_SIMD_SUPPORT("AVX2" RESULT)
294CHECK_SIMD_SUPPORT("AVX1" RESULT)
295CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
296CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
297CHECK_SIMD_SUPPORT("SSE3" RESULT)
298CHECK_SIMD_SUPPORT("SSE2" RESULT)
299CHECK_SIMD_SUPPORT("SSE1" RESULT)
300SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
301ENDIF()
[4750]302#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
[4480]303SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
[4152]304
[4118]305# detect LLVM version and add compiler flags.
[4508]306IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
[4152]307  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
[4480]308ENDIF()
[4118]309
[4209]310IF (BLOCK_SIZE_256)
[4750]311    IF ("${SIMD_SUPPORT}" STREQUAL "AVX1")
312        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX -DUSE_AVX -DBLOCK_SIZE=256 -mavx -m64")
313    ELSEIF ("${SIMD_SUPPORT}" STREQUAL "AVX2")
314        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
315    ENDIF()
[4209]316ENDIF()
[4151]317
[4200]318SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
[4522]319IF (${CMAKE_SYSTEM} MATCHES "Linux")
[4594]320    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
[4522]321ENDIF()
[4152]322
[4096]323add_test(
324  NAME greptest
325  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
326  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
327
[4137]328add_test(
[4456]329  NAME proptest
330  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
331  COMMAND python greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
332
333add_test(
[4137]334  NAME abc_test
335  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
336  COMMAND ./run_abc ../icgrep-build/icgrep)
337
338add_custom_target (abc_test
339  COMMAND python abc_testgen.py
340  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
341
[4096]342add_custom_target (check
[4130]343  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
[4137]344  DEPENDS icgrep abc_test)
[4128]345
346add_custom_target (perf_icgrep
347  COMMAND python perf.py icgrep
348  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
349  DEPENDS icgrep)
350
351add_custom_target (viewer
352  COMMAND python viewer.py
353  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
354
[4275]355add_custom_target (text_viewer
356  COMMAND python viewer.py -t
357  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.