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

Last change on this file since 4667 was 4661, checked in by nmedfort, 4 years ago

Start of work to make the pablo compiler reenterant. Fixed bug that prevented it from using Less optimization level.

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