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

Last change on this file since 4187 was 4187, checked in by nmedfort, 5 years ago

Some refactoring of the RE CC class and CC Compiler; Moved RE into re subdirectory.

File size: 6.7 KB
Line 
1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
5enable_testing()
6# The version number.
7set (icgrep_VERSION_MAJOR 0)
8set (icgrep_VERSION_MINOR 8)
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()
16
17# configure a header file to pass some of the CMake settings
18# to the source code
19#configure_file (
20#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
21#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
22#  )
23
24# LLVM set up
25#
26# A convenience variable:
27set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
28
29# A bit of a sanity check:
30if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
31message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
32endif()
33
34# We incorporate the CMake features provided by LLVM:
35set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
36include(LLVMConfig)
37
38# Now set the header and library paths:
39include_directories( ${LLVM_INCLUDE_DIRS} )
40link_directories( ${LLVM_LIBRARY_DIRS} )
41add_definitions( ${LLVM_DEFINITIONS} )
42
43# Let's suppose we want to build a JIT compiler with support for
44# binary code (no interpreter):
45llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES mcjit native)
46
47message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
48
49add_library(PabloADT pe_advance.cpp  pe_all.cpp  pe_and.cpp pe_call.cpp pe_charclass.cpp  pe_matchstar.cpp pe_scanthru.cpp pe_not.cpp  pe_or.cpp  pe_pabloe.cpp  pe_sel.cpp  pe_var.cpp  pe_xor.cpp ps_assign.cpp  ps_if.cpp  ps_pablos.cpp  ps_while.cpp printer_pablos.cpp)
50
51add_library(RegExpADT re/re_alt.cpp  re/re_cc.cpp  re/re_end.cpp  re/re_name.cpp re/re_parser.cpp  re/re_re.cpp  re/re_rep.cpp  re/re_seq.cpp re/re_start.cpp re/parsefailure.cpp  printer_re.cpp)
52
53
54#include_directories("${PROJECT_BINARY_DIR}")
55include_directories("${PROJECT_SOURCE_DIR}")
56include_directories("${PROJECT_SOURCE_DIR}/include")
57include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
58include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
59
60# add the executable
61add_executable(icgrep icgrep.cpp llvm_gen.cpp llvm_gen_helper.cpp utf_encoding.cpp cc_compiler.cpp  cc_compiler_helper.cpp re/re_simplifier.cpp re/re_reducer.cpp re/re_nullable.cpp re/re_compiler.cpp pbix_compiler.cpp  symbol_generator.cpp utf8_encoder.cpp unicode_categories.h unicode_categories-flat.h unicode_categories-simple.h)
62
63target_link_libraries (icgrep PabloADT RegExpADT ${REQ_LLVM_LIBRARIES})
64
65#Check compiler support for 0x / 11
66include(CheckCXXCompilerFlag)
67CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
68if(COMPILER_SUPPORTS_CXX11)
69  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
70else()
71  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
72  if(COMPILER_SUPPORTS_CXX0X)
73    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
74  else()
75    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
76    if(COMPILER_SUPPORTS_GNU11)
77      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
78    else() 
79      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
80      if(COMPILER_SUPPORTS_GNU0X)
81        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
82      endif()
83    endif()
84  endif()
85endif()
86
87#Check compiler and system support for SSE or AVX
88include(CheckCXXSourceRuns)
89
90set(SSE1_CODE "
91#include <xmmintrin.h>
92int main()
93{
94__m128 a;
95float vals[4] = {0,0,0,0};
96a = _mm_loadu_ps(vals);
97return 0;
98}")
99
100set(SSE2_CODE "
101#include <emmintrin.h>
102int main()
103{
104__m128d a;
105double vals[2] = {0,0};
106a = _mm_loadu_pd(vals);
107return 0;
108}")
109
110set(SSE3_CODE "
111#include <pmmintrin.h>
112int main( )
113{
114const int vals[4] = {0,0,0,0};
115__m128i a;
116a = _mm_lddqu_si128( (const __m128i*)vals );
117return 0;
118}")
119
120set(SSE4_1_CODE "
121#include <smmintrin.h>
122int main ()
123{
124__m128i a, b;
125__m128i res = _mm_max_epi8(a, b);
126return 0;
127}")
128
129set(SSE4_2_CODE "
130#include <nmmintrin.h>
131int main()
132{
133__m128i a, b, c;
134c = _mm_cmpgt_epi64(a, b);
135return 0;
136}")
137
138set(AVX_1_CODE "
139#include <immintrin.h>
140int main()
141{
142__m256* a=(__m256*)_mm_malloc(4, 32);
143__m256 b = _mm256_load_ps((float*)a);
144b = _mm256_or_ps(b, b);
145_mm_free(a);
146return 0;
147}")
148
149set(AVX_2_CODE "
150#include <immintrin.h>
151int main()
152{
153__m256i* a = (__m256i*)_mm_malloc(4, 32);
154__m256i b = _mm256_load_si256(a);
155b = _mm256_or_si256(b, b);
156_mm_free(a);
157return 0;
158}")
159
160IF (MSVC) # using Visual Studio C++
161  SET(ENABLE_SSE1 "/arch:SSE")
162  SET(ENABLE_SSE2 "/arch:SSE2")
163  SET(ENABLE_SSE3 "/arch:SSE3")
164  SET(ENABLE_SSE4_1 "/arch:SSE4")
165  SET(ENABLE_SSE4_2 "/arch:SSE4")
166  SET(ENABLE_AVX_1 "/arch:AVX1")
167  SET(ENABLE_AVX_2 "/arch:AVX2")
168ELSE() # using Clang, GCC, Intel C++, etc
169  SET(ENABLE_SSE1 "-msse")
170  SET(ENABLE_SSE2 "-msse2")
171  SET(ENABLE_SSE3 "-msse3")
172  SET(ENABLE_SSE4_1 "-msse4.1")
173  SET(ENABLE_SSE4_2 "-msse4.2")
174  SET(ENABLE_AVX_1 "-mavx")
175  SET(ENABLE_AVX_2 "-mavx2")   
176ENDIF()
177
178set(CMAKE_REQUIRED_FLAGS)
179set(SIMD_SUPPORT_FOUND)
180
181MACRO(CHECK_SIMD_SUPPORT type) 
182  IF(NOT SIMD_SUPPORT_FOUND) 
183    set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
184    set(CMAKE_REQUIRED_FLAGS ${ENABLE_${type}})
185    check_cxx_source_runs("${${type}_CODE}" ${type})   
186    IF(${type})
187      SET(SIMD_SUPPORT_FOUND ${CMAKE_REQUIRED_FLAGS})
188    ENDIF()
189    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
190  ENDIF()
191ENDMACRO()
192
193CHECK_SIMD_SUPPORT("AVX_2")
194CHECK_SIMD_SUPPORT("AVX_1")
195CHECK_SIMD_SUPPORT("SSE4_2")
196CHECK_SIMD_SUPPORT("SSE4_1")
197CHECK_SIMD_SUPPORT("SSE3")
198CHECK_SIMD_SUPPORT("SSE2")
199CHECK_SIMD_SUPPORT("SSE1")
200
201SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_SUPPORT_FOUND}")
202
203# detect LLVM version and add compiler flags.
204if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
205  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
206elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
207  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
208endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
209
210if (BLOCK_SIZE_256)
211  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -mavx2 -m64 -fabi-version=6")
212endif()
213
214SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
215
216add_test(
217  NAME greptest
218  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
219  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
220
221add_test(
222  NAME abc_test
223  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
224  COMMAND ./run_abc ../icgrep-build/icgrep)
225
226add_custom_target (abc_test
227  COMMAND python abc_testgen.py
228  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
229
230add_custom_target (check
231  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
232  DEPENDS icgrep abc_test)
233
234add_custom_target (perf_icgrep
235  COMMAND python perf.py icgrep
236  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
237  DEPENDS icgrep)
238
239add_custom_target (viewer
240  COMMAND python viewer.py
241  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
242
Note: See TracBrowser for help on using the repository browser.