-
Notifications
You must be signed in to change notification settings - Fork 171
/
CMakeLists.txt
465 lines (381 loc) · 14.4 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
cmake_minimum_required(VERSION 3.8)
project(Souper)
set(CMAKE_MACOSX_RPATH NEW)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
if (NOT LLVM_BUILD_TYPE)
set(LLVM_BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()
set(LLVM_CONFIG_EXECUTABLE ${CMAKE_SOURCE_DIR}/third_party/llvm-${LLVM_BUILD_TYPE}-install/bin/llvm-config)
if(NOT EXISTS ${LLVM_CONFIG_EXECUTABLE})
message(FATAL_ERROR "llvm-config could not be found!")
endif()
find_path(ZSTD_LIBRARY_DIR
NAMES libzstd.a libzstd.dylib libzstd.so libzstd.so.1
HINTS /usr/local/lib /opt/homebrew/lib /usr/lib/x86_64-linux-gnu)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
OUTPUT_VARIABLE LLVM_INCLUDEDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --cppflags
OUTPUT_VARIABLE LLVM_CXXFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-exceptions -fno-rtti -Wno-deprecated-enum-enum-conversion")
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LLVM_LIBS "${LLVM_LIBS} ${LLVM_SYSTEM_LIBS}")
string(STRIP ${LLVM_LIBS} LLVM_LIBS)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags
OUTPUT_VARIABLE LLVM_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PASS_LDFLAGS "${LLVM_LDFLAGS}")
set(LLVM_LDFLAGS "${LLVM_LDFLAGS} -L ${ZSTD_LIBRARY_DIR}")
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --bindir
OUTPUT_VARIABLE LLVM_BINDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --obj-root
OUTPUT_VARIABLE LLVM_BUILD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(ALIVE_SRCDIR "${CMAKE_SOURCE_DIR}/third_party/alive2")
set(ALIVE_BUILDDIR "${CMAKE_SOURCE_DIR}/third_party/alive2-build")
include_directories("${CMAKE_SOURCE_DIR}/third_party")
include_directories("${ALIVE_SRCDIR}")
set(GTEST_CXXFLAGS "-DGTEST_HAS_RTTI=0")
set(GTEST_INCLUDEDIR "${LLVM_BINDIR}/../include/llvm-gtest/")
set(GTEST_LIBS "-lllvm_gtest_main -lllvm_gtest")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -std=c++20")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++20")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fvisibility-inlines-hidden")
set(PASS_LDFLAGS "-Wl,-undefined,dynamic_lookup")
endif()
include_directories(include third_party/klee/include)
include_directories(include "${CMAKE_BINARY_DIR}/include")
set(KLEE_EXPR_FILES
third_party/klee/lib/Expr/ArrayCache.cpp
third_party/klee/lib/Expr/Constraints.cpp
third_party/klee/lib/Expr/ExprBuilder.cpp
third_party/klee/lib/Expr/Expr.cpp
third_party/klee/lib/Expr/ExprEvaluator.cpp
third_party/klee/lib/Expr/ExprPPrinter.cpp
third_party/klee/lib/Expr/ExprSMTLIBPrinter.cpp
third_party/klee/lib/Expr/ExprUtil.cpp
third_party/klee/lib/Expr/ExprVisitor.cpp
third_party/klee/lib/Expr/Lexer.cpp
third_party/klee/lib/Expr/Parser.cpp
third_party/klee/lib/Expr/Updates.cpp
)
add_library(kleeExpr STATIC
${KLEE_EXPR_FILES}
)
find_path(HIREDIS_INCLUDE_DIR
NAMES
hiredis/hiredis.h
PATHS
third_party/hiredis-install/include
NO_DEFAULT_PATH)
include_directories(${HIREDIS_INCLUDE_DIR}/hiredis)
find_library(HIREDIS_LIBRARY
NAMES
hiredis
PATHS
third_party/hiredis-install/lib
NO_DEFAULT_PATH)
find_library(ALIVE_IR ir PATHS "${ALIVE_BUILDDIR}" NO_DEFAULT_PATH)
if (ALIVE_IR)
message(STATUS "Alive2 IR")
else()
message(SEND_ERROR "Alive2 libir.a not found")
endif()
find_library(ALIVE_SMT smt PATHS "${ALIVE_BUILDDIR}" NO_DEFAULT_PATH)
if (ALIVE_SMT)
message(STATUS "Alive2 SMT")
else()
message(SEND_ERROR "Alive2 libsmt.a not found")
endif()
find_library(ALIVE_TOOLS tools PATHS "${ALIVE_BUILDDIR}" NO_DEFAULT_PATH)
if (ALIVE_TOOLS)
message(STATUS "Alive2 TOOLS")
else()
message(SEND_ERROR "Alive2 libtools.a not found")
endif()
find_library(ALIVE_UTIL util PATHS "${ALIVE_BUILDDIR}" NO_DEFAULT_PATH)
if (ALIVE_UTIL)
message(STATUS "Alive2 UTIL")
else()
message(SEND_ERROR "Alive2 libutil.a not found")
endif()
set(Z3 "${CMAKE_SOURCE_DIR}/third_party/z3-install/bin/z3")
set(Z3_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/third_party/z3-install/include")
include_directories(${Z3_INCLUDE_DIR})
find_library(Z3_LIBRARY z3 PATHS "${CMAKE_SOURCE_DIR}/third_party/z3-install/lib" NO_DEFAULT_PATH)
if (Z3_LIBRARY)
message(STATUS "Z3 shared lib: ${Z3_LIBRARY}")
else()
message(SEND_ERROR "Z3 shared lib not found")
endif()
set(ALIVE_LIBRARY ${ALIVE_IR} ${ALIVE_SMT} ${ALIVE_TOOLS} ${ALIVE_UTIL} ${Z3_LIBRARY})
set(SOUPER_EXTRACTOR_FILES
lib/Extractor/Candidates.cpp
lib/Extractor/ExprBuilder.cpp
lib/Extractor/KLEEBuilder.cpp
lib/Extractor/Solver.cpp
include/souper/Extractor/Candidates.h
include/souper/Extractor/ExprBuilder.h
include/souper/Extractor/Solver.h
)
add_library(souperExtractor STATIC
${SOUPER_EXTRACTOR_FILES}
)
set(SOUPER_KVSTORE_FILES
lib/KVStore/KVStore.cpp
include/souper/KVStore/KVStore.h
)
add_library(souperKVStore STATIC
${SOUPER_KVSTORE_FILES}
)
set(SOUPER_INFER_FILES
lib/Infer/InstSynthesis.cpp
include/souper/Infer/InstSynthesis.h
lib/Infer/ConstantSynthesis.cpp
include/souper/Infer/ConstantSynthesis.h
lib/Infer/EnumerativeSynthesis.cpp
include/souper/Infer/EnumerativeSynthesis.h
lib/Infer/AliveDriver.cpp
include/souper/Infer/AliveDriver.h
lib/Infer/Pruning.cpp
include/souper/Infer/Pruning.h
lib/Infer/Interpreter.cpp
lib/Infer/AbstractInterpreter.cpp
include/souper/Infer/Interpreter.h
lib/Infer/Preconditions.cpp
include/souper/Infer/Preconditions.h
)
add_library(souperInfer STATIC
${SOUPER_INFER_FILES}
)
set(SOUPER_INST_FILES
lib/Inst/Inst.cpp
include/souper/Inst/Inst.h
include/souper/Inst/InstGraph.h
)
add_library(souperInst STATIC
${SOUPER_INST_FILES}
)
set(SOUPER_PARSER_FILES
lib/Parser/Parser.cpp
include/souper/Parser/Parser.h
)
add_library(souperParser STATIC
${SOUPER_PARSER_FILES}
)
set(SOUPER_SMTLIB2_FILES
lib/SMTLIB2/Solver.cpp
include/souper/SMTLIB2/Solver.h
)
add_library(souperSMTLIB2 STATIC
${SOUPER_SMTLIB2_FILES}
)
set(SOUPER_TOOL_FILES
lib/Tool/CandidateMapUtils.cpp
include/souper/Tool/CandidateMapUtils.h
include/souper/Tool/GetSolver.h.in
)
add_library(souperTool STATIC
${SOUPER_TOOL_FILES}
)
set(SOUPER_CODEGEN_FILES
lib/Codegen/Codegen.cpp
include/souper/Codegen/Codegen.h
)
add_library(souperCodegen STATIC
${SOUPER_CODEGEN_FILES}
)
set(SOUPER_SOURCES
${SOUPER_EXTRACTOR_FILES}
${SOUPER_INST_FILES}
${SOUPER_KVSTORE_FILES}
${SOUPER_PARSER_FILES}
${SOUPER_SMTLIB2_FILES}
${SOUPER_TOOL_FILES}
${SOUPER_INFER_FILES}
${SOUPER_CODEGEN_FILES})
add_library(souperPass SHARED
${KLEE_EXPR_FILES}
${SOUPER_SOURCES}
lib/Pass/Pass.cpp
)
add_library(souperPassProfileAll SHARED
${KLEE_EXPR_FILES}
${SOUPER_SOURCES}
lib/Pass/Pass.cpp
)
target_compile_definitions(souperPassProfileAll PRIVATE DYNAMIC_PROFILE_ALL=1)
add_executable(souper
tools/souper.cpp
)
add_executable(internal-solver-test
tools/internal-solver-test.cpp
)
add_executable(lexer-test
tools/lexer-test.cpp
)
add_executable(parser-test
tools/parser-test.cpp
)
add_executable(souper-check
tools/souper-check.cpp
)
add_executable(souper-interpret
tools/souper-interpret.cpp
)
add_executable(count-insts
tools/count-insts.cpp
)
add_executable(souper2llvm
tools/souper2llvm.cpp
)
add_executable(extractor_tests
unittests/Extractor/ExtractorTests.cpp
)
add_executable(inst_tests
unittests/Inst/InstTests.cpp
)
add_executable(parser_tests
unittests/Parser/ParserTests.cpp
)
add_executable(codegen_tests
unittests/Codegen/CodegenTests.cpp
)
add_executable(interpreter_tests
unittests/Interpreter/InterpreterInfra.cpp
unittests/Interpreter/InterpreterTests.cpp)
set(LLVM_LDFLAGS "${LLVM_LDFLAGS}")
add_executable(bulk_tests
unittests/Interpreter/InterpreterInfra.cpp
utils/gen-xfer-funcs/BulkTests.cpp
utils/gen-xfer-funcs/Verification.cpp)
target_include_directories(bulk_tests PUBLIC "${CMAKE_SOURCE_DIR}/unittests/Interpreter")
configure_file(
${CMAKE_SOURCE_DIR}/utils/gen-xfer-funcs/run_n.pl.in
${CMAKE_BINARY_DIR}/utils/gen-xfer-funcs/run_n.pl
@ONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/utils/gen-xfer-funcs/gen_xfer.pl.in
${CMAKE_BINARY_DIR}/utils/gen-xfer-funcs/gen_xfer.pl
@ONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/utils/gen-xfer-funcs/compile.sh.in
${CMAKE_BINARY_DIR}/utils/gen-xfer-funcs/compile.sh
@ONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/utils/gen-xfer-funcs/funcs.h
${CMAKE_BINARY_DIR}/utils/gen-xfer-funcs/funcs.h
COPYONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/utils/gen-xfer-funcs/look_n.pl
${CMAKE_BINARY_DIR}/utils/gen-xfer-funcs/look_n.pl
COPYONLY
)
foreach(target souper internal-solver-test lexer-test parser-test souper-check count-insts
souper2llvm souper-interpret
souperExtractor souperInfer souperInst souperKVStore souperParser
souperSMTLIB2 souperTool souperPass souperPassProfileAll kleeExpr
souperCodegen)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${LLVM_CXXFLAGS}")
target_include_directories(${target} PRIVATE "${LLVM_INCLUDEDIR}")
endforeach()
foreach(target extractor_tests inst_tests parser_tests interpreter_tests bulk_tests codegen_tests)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${GTEST_CXXFLAGS} ${LLVM_CXXFLAGS}")
target_include_directories(${target} PRIVATE "${LLVM_INCLUDEDIR}" "${GTEST_INCLUDEDIR}")
endforeach()
# static
target_link_libraries(kleeExpr ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperExtractor souperParser souperKVStore souperInfer souperInst kleeExpr souperCodegen)
target_link_libraries(souperInfer souperExtractor ${LLVM_LIBS} ${LLVM_LDFLAGS} ${Z3_LIBRARY})
target_link_libraries(souperInst ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperKVStore ${HIREDIS_LIBRARY} ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperParser souperInst ${LLVM_LIBS} ${LLVM_LDFLAGS} ${ALIVE_LIBRARY})
target_link_libraries(souperSMTLIB2 ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperTool souperExtractor souperSMTLIB2)
target_link_libraries(souperCodegen ${LLVM_LIBS} ${LLVM_LDFLAGS})
# dynamic
target_link_libraries(souperCodegen ${PASS_LDFLAGS})
target_link_libraries(souperPass ${PASS_LDFLAGS} ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} ${Z3_LIBRARY})
target_link_libraries(souperPassProfileAll ${PASS_LDFLAGS} ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} ${Z3_LIBRARY})
# executables
target_link_libraries(souper souperExtractor souperKVStore souperParser souperSMTLIB2 souperTool kleeExpr ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} ${Z3_LIBRARY})
target_link_libraries(internal-solver-test souperSMTLIB2)
target_link_libraries(lexer-test souperParser)
target_link_libraries(parser-test souperParser)
target_link_libraries(souper-check souperTool souperExtractor souperKVStore souperSMTLIB2 souperParser ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} ${Z3_LIBRARY})
target_link_libraries(souper-interpret souperTool souperExtractor souperKVStore souperSMTLIB2 souperParser ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} ${Z3_LIBRARY})
target_link_libraries(count-insts souperParser)
target_link_libraries(souper2llvm souperParser souperCodegen)
target_link_libraries(extractor_tests souperExtractor souperParser ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(inst_tests souperInfer souperPass souperInst souperExtractor ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(parser_tests souperParser ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(codegen_tests souperCodegen souperInst ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(interpreter_tests souperInfer souperInst ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(bulk_tests souperInfer souperInst ${GTEST_LIBS} ${ALIVE_LIBRARY} ${Z3_LIBRARY})
set(TEST_SYNTHESIS "ON" CACHE STRING "Enable additional, computationally intensive synthesis tests")
set(TEST_LONG_DURATION_SYNTHESIS "" CACHE STRING "Enable long duration (> 10 min) synthesis tests")
configure_file(
${CMAKE_SOURCE_DIR}/test/lit.site.cfg.in
${CMAKE_BINARY_DIR}/test/lit.site.cfg
)
configure_file(
${CMAKE_SOURCE_DIR}/utils/run_lit.in
${CMAKE_BINARY_DIR}/run_lit
)
configure_file(
${CMAKE_SOURCE_DIR}/tools/gdbprinter.py
${CMAKE_BINARY_DIR}/souper-check-gdb.py
)
add_custom_target(check
COMMAND ${CMAKE_BINARY_DIR}/run_lit
DEPENDS extractor_tests inst_tests parser-test parser_tests profileRuntime souper souper-check souper-interpret souperPass souper2llvm souperPassProfileAll count-insts interpreter_tests bulk_tests codegen_tests
USES_TERMINAL)
# we want assertions even in release mode!
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
add_library(profileRuntime STATIC
runtime/souperPassProfile.c)
set(SOUPER_PASS ${CMAKE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}souperPass${CMAKE_SHARED_LIBRARY_SUFFIX})
set(SOUPER_PASS_PROFILE_ALL ${CMAKE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}souperPassProfileAll${CMAKE_SHARED_LIBRARY_SUFFIX})
set(PROFILE_LIBRARY ${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}profileRuntime${CMAKE_STATIC_LIBRARY_SUFFIX})
configure_file(${CMAKE_SOURCE_DIR}/utils/compare_pruning_output.in ${CMAKE_BINARY_DIR}/compare_pruning_output @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/reduce.in ${CMAKE_BINARY_DIR}/reduce @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_dump.in ${CMAKE_BINARY_DIR}/cache_dump @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_dfa.in ${CMAKE_BINARY_DIR}/cache_dfa @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_import.in ${CMAKE_BINARY_DIR}/cache_import @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_infer.in ${CMAKE_BINARY_DIR}/cache_infer @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/py_souper2llvm.in ${CMAKE_BINARY_DIR}/py_souper2llvm @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/include/souper/Tool/GetSolver.h.in ${CMAKE_BINARY_DIR}/include/souper/Tool/GetSolver.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/include/souper/KVStore/KVSocket.h.in ${CMAKE_BINARY_DIR}/include/souper/KVStore/KVSocket.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/redis-unix-socket.conf.in ${CMAKE_BINARY_DIR}/redis-unix-socket.conf @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/sclang.in ${CMAKE_BINARY_DIR}/sclang @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/sclang.in ${CMAKE_BINARY_DIR}/sclang++ @ONLY)
add_subdirectory(docs)