source: trunk/lib_ir/CMakeLists.txt @ 4042

Last change on this file since 4042 was 4042, checked in by linmengl, 5 years ago

checkin u8u16 project, add cmake target and auto test.

File size: 4.0 KB
Line 
1cmake_minimum_required (VERSION 2.8)
2project (IR_Library)
3
4enable_testing()
5
6option (USE_AVX2 "Compile for Haswell arch with AVX2, BMI, BMI2")
7if (USE_AVX2)
8    message("---- Compiling for AVX2")
9    set(CXX_SSE_FLAGS "-msse2 -m64") #"-march=core-avx2")
10    set(LLVM_SSE_FLAGS "-mattr=+sse,+sse2,+avx2,+bmi2,+bmi -march=x86-64")
11else (USE_AVX2)
12    set(CXX_SSE_FLAGS "-msse2")
13    set(LLVM_SSE_FLAGS "-mattr=+sse,+sse2")
14endif (USE_AVX2)
15
16# perf_flags for xmlwf perf script
17set(CXX_PERF_FLAGS "-DBUFFER_PROFILING -DPERF_SCRIPT")
18set(CMAKE_CXX_FLAGS "${CXX_SSE_FLAGS} -std=c++11 ")
19
20set(LLVM_OPT "opt-svn")
21set(LLVM_LLC "llc-svn")
22
23set(LLVM_LLC_FLAGS )#-x86-experimental-vector-shuffle-lowering)
24
25add_executable(test_s2p test_s2p.cpp s2p_optimized.o)
26add_executable(test_link test_link.cpp s2p_optimized.o)
27add_executable(test_pack test_pack.cpp s2p_optimized.o)
28
29# gen/ is used to test llc backend.
30add_subdirectory(gen)
31
32# test packh_2,4,8 only on avx2
33if (USE_AVX2)
34    add_executable(test_pack_avx2 test_pack_avx2.cpp s2p_optimized.o)
35    add_test(
36      NAME ctest_pack_avx2
37      COMMAND ./test_pack_avx2)
38endif (USE_AVX2)
39
40include_directories("xmlwf/util" "xmlwf/lib")
41add_executable(xmlwf xmlwf/src/xmlwf.cpp s2p_optimized.o)
42
43add_executable(xmlwf_perf xmlwf/src/xmlwf.cpp s2p_optimized.o)
44set_target_properties(xmlwf_perf
45  PROPERTIES
46  COMPILE_FLAGS ${CXX_PERF_FLAGS}
47  )
48
49add_executable(u8u16 u8u16/src/u8u16.cpp s2p_optimized.o)
50
51add_custom_target(asm_s2p
52  COMMAND ${LLVM_LLC} -O3 ${LLVM_SSE_FLAGS} s2p_optimized.bc
53  DEPENDS s2p_optimized.bc)
54
55# a little bit tricky here, on USE_AVX2, we need to append s2p_ideal.ll to s2p.ll
56# in order to have function s2p_ideal
57if (USE_AVX2)
58  message("---- Concat s2p.ll with s2p_ideal.ll")
59  add_custom_command(
60    OUTPUT s2p.ll
61    COMMAND cp ${PROJECT_SOURCE_DIR}/s2p.ll .
62    COMMAND cat ${PROJECT_SOURCE_DIR}/s2p_ideal.ll >> s2p.ll
63    DEPENDS ${PROJECT_SOURCE_DIR}/s2p.ll ${PROJECT_SOURCE_DIR}/s2p_ideal.ll)
64
65else (USE_AVX2)
66  add_custom_command(
67    OUTPUT s2p.ll
68    COMMAND cp ${PROJECT_SOURCE_DIR}/s2p.ll .
69    DEPENDS ${PROJECT_SOURCE_DIR}/s2p.ll)
70
71endif (USE_AVX2)
72
73# compile s2p.ll, and make sure test_s2p depends on it.
74add_custom_command(
75  OUTPUT  s2p_optimized.o s2p_optimized.bc
76  COMMAND ${LLVM_OPT} -O3 -std-compile-opts ${LLVM_SSE_FLAGS} s2p.ll -o s2p_optimized.bc
77  COMMAND ${LLVM_LLC} -O3 ${LLVM_SSE_FLAGS} -filetype=obj s2p_optimized.bc
78  DEPENDS s2p.ll)
79
80add_test(
81  NAME ctest_s2p
82  COMMAND python ${PROJECT_SOURCE_DIR}/test_s2p.py)
83add_test(
84  NAME ctest_link
85  COMMAND python ${PROJECT_SOURCE_DIR}/test_link.py)
86add_test(
87  NAME ctest_pack
88  COMMAND ./test_pack)
89add_test(
90  NAME ctest_xmlwf
91  COMMAND python ${PROJECT_SOURCE_DIR}/xmlwf/run_all.py)
92add_test(
93  NAME ctest_u8u16
94  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../../proto/u8u16/QA
95  COMMAND ${PROJECT_SOURCE_DIR}/u8u16/run_all ${CMAKE_BINARY_DIR}/u8u16)
96
97add_custom_target (check
98  COMMAND ${CMAKE_CTEST_COMMAND}
99  DEPENDS test_s2p test_link test_pack test_llc xmlwf u8u16)
100
101# `make check` also depends on test_pack_avx2
102if (USE_AVX2)
103  add_dependencies(check test_pack_avx2)
104endif (USE_AVX2)
105
106add_custom_target (perf_xmlwf
107  COMMAND python ${PROJECT_SOURCE_DIR}/xmlwf/perf_script.py
108  DEPENDS xmlwf_perf)
109
110
111# Try IR inline. Compile the whole xmlwf in IR and inline s2p into it.
112set(LLVM_LINK "llvm-link")
113set(LLVM_CLANG "/usr/local/bin/clang")
114# cxx_include should only be used for ir_inline approach.
115set(CXX_INCLUDE -I${PROJECT_SOURCE_DIR}/xmlwf/util -I${PROJECT_SOURCE_DIR}/xmlwf/lib)
116
117add_custom_target(xmlwf_ir_inline
118  COMMAND ${LLVM_LINK} ${PROJECT_SOURCE_DIR}/s2p.ll xmlwf.ll -o xmlwf_all.bc
119  COMMAND ${LLVM_OPT} -O3 -std-compile-opts -std-link-opts xmlwf_all.bc -o xmlwf_ir_inline.bc
120  COMMAND ${LLVM_LLC} -O3 ${LLVM_SSE_FLAGS} -filetype=obj xmlwf_ir_inline.bc
121  COMMAND ${CMAKE_CXX_COMPILER} xmlwf_ir_inline.o -o xmlwf_ir_inline
122  DEPENDS s2p.ll xmlwf.ll)
123
124add_custom_command(
125  OUTPUT xmlwf.ll
126  COMMAND ${LLVM_CLANG} -S -emit-llvm ${CXX_INCLUDE} ${PROJECT_SOURCE_DIR}/xmlwf/src/xmlwf.cpp ${CXX_PERF_FLAGS} -o xmlwf.ll
127  DEPENDS xmlwf/src/xmlwf.cpp)
128
Note: See TracBrowser for help on using the repository browser.