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

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

More work on reassociation pass

File size: 10.8 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")
17option(DISABLE_PREGENERATED_UCD_FUNCTIONS "Disable compiling the pregenerated UCD functions")
18
19
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):
48llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader)
49
50message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
51
52# Check if boost has been installed on this system.
53set(Boost_USE_STATIC_LIBS ON)
54set(Boost_USE_MULTITHREADED OFF)
55set(Boost_USE_STATIC_RUNTIME ON)
56
57if(ENABLE_MULTIPLEXING)
58find_package(Boost COMPONENTS system REQUIRED)
59else()
60find_package(Boost)
61endif()
62
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)
66IF (ENABLE_MULTIPLEXING)
67SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
68ENDIF()
69
70add_library(PabloADT ${PABLO_SRC})
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)
73add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
74add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
75
76
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
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()
90
91# add the executable
92add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
93target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT)
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)
99set(MULTIPLEXING_FLAG -multiplexing -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv)
100endif()
101
102add_custom_command(OUTPUT ${PRECOMPILED_FILES}
103  COMMAND generate_predefined_ucd_functions
104  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -ldc=ldc.csv -DefaultIfHierarchy
105  DEPENDS generate_predefined_ucd_functions
106  COMMENT "Building predefined UCD functions..."
107  VERBATIM)
108
109add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
110
111add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
112ENDIF()
113
114add_executable(icgrep icgrep.cpp do_grep.cpp ${PRECOMPILED_FILES})
115IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
116add_dependencies(icgrep run_generate_predefined_ucd_functions)
117ENDIF()
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
124target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
125
126
127
128IF (ENABLE_MULTIPLEXING)
129message(STATUS "Enabling Multiplexing")
130SET(CUDD_ROOT "${CMAKE_SOURCE_DIR}/../cudd-2.5.1")
131file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
132file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
133file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
134file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
135file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
136add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
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)
142target_link_libraries (PabloADT CUDD)
143SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
144ENDIF()
145
146include_directories("${PROJECT_SOURCE_DIR}")
147
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()
169
170#Disable RunTime Type Information
171IF (MSVC) # using Visual Studio C++
172  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
173ELSE() # using Clang, GCC, Intel C++, etc
174  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
175ENDIF()
176
177#Enable all warnings
178SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
179
180#Check compiler and system architecture support for SSE or AVX
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
231set(AVX1_CODE "
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
242set(AVX2_CODE "
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")
259  SET(ENABLE_AVX1 "/arch:AVX1")
260  SET(ENABLE_AVX2 "/arch:AVX2")
261ELSE() # using Clang, GCC, Intel C++, etc 
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")
267  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
268    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
269    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
270  ELSE()
271    SET(ENABLE_AVX1 "-mavx")
272    SET(ENABLE_AVX2 "-mavx2")
273  ENDIF()
274ENDIF()
275
276SET(CMAKE_REQUIRED_FLAGS)
277
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}")
286    ENDIF()
287    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
288  ENDIF()
289ENDMACRO()
290
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()
302#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
303SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
304
305# detect LLVM version and add compiler flags.
306IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
307  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
308ENDIF()
309
310IF (BLOCK_SIZE_256)
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()
316ENDIF()
317
318SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
319IF (${CMAKE_SYSTEM} MATCHES "Linux")
320    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g") # -fsanitize=address
321ENDIF()
322
323add_test(
324  NAME greptest
325  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
326  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
327
328add_test(
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(
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
342add_custom_target (check
343  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
344  DEPENDS icgrep abc_test)
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
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.