Skip to content

Commit 4f568a7

Browse files
fabianbs96MMory
andauthored
Phasar DynLib and LTO (#621)
* Add consolidated header files * Add build rules for building a fat lib * Some docs * Follow new practices in myphasartool * Update docs * minor in docs + pre-commit * Changes according to review * Add CG to ControlFlow.h --------- Co-authored-by: Martin Mory <[email protected]>
1 parent c3b932c commit 4f568a7

37 files changed

+724
-162
lines changed

BreakingChanges.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
# Breaking Changes
22

3+
## Development HEAD
4+
5+
- Default build mode is no longer `SHARED` but `STATIC`. To build in shared mode, use the cmake option `BUILD_SHARED_LIBS` which we don't recommend anymore. Consider using `PHASAR_BUILD_DYNLIB` instead to build one big libphasar.so.
6+
37
## v0323
48

59
- `EdgeFunctionPtrType` is no longer a `std::shared_ptr`. Instead `EdgeFunction<l_t>` should be used directly. `EdgeFunction` is now a *value-type* that encapsulates its memory management by itself.
610
- Concrete `EdgeFunction` types no longer derive from any base-class. Instead they just need to implement the required API functions. `EdgeFunction` implementations should me move-constructible and can be implicitly cast to `EdgeFunction`. To verify that your type implements the edge function interface use the `IsEdgeFunction` type trait. The API functions have been changed as follows:
7-
- All API functions of `EdgeFunction` must be `const` qualified.
8-
- `EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction)` and `EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction)` have been changed to `static EdgeFunction<l_t> compose(EdgeFunctionRef<T> This, const EdgeFunction<l_t>& SecondFunction)` and `static EdgeFunction<l_t> join(EdgeFunctionRef<T> This, const EdgeFunction<l_t>& OtherFunction)` respectively. Here, the `This` parameter models the former `shared_from_this()`.
9-
- `bool equal_to(EdgeFunctionPtrType Other)const` has been changed to `bool operator==(const T &Other)const noexcept`, where `T` is your concrete edge function type.
10-
- `void print(llvm::raw_ostream &OS, bool IsForDebug)` has been changed to `friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const T& EF)`.
11+
- All API functions of `EdgeFunction` must be `const` qualified.
12+
- `EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction)` and `EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction)` have been changed to `static EdgeFunction<l_t> compose(EdgeFunctionRef<T> This, const EdgeFunction<l_t>& SecondFunction)` and `static EdgeFunction<l_t> join(EdgeFunctionRef<T> This, const EdgeFunction<l_t>& OtherFunction)` respectively. Here, the `This` parameter models the former `shared_from_this()`.
13+
- `bool equal_to(EdgeFunctionPtrType Other)const` has been changed to `bool operator==(const T &Other)const noexcept`, where `T` is your concrete edge function type.
14+
- `void print(llvm::raw_ostream &OS, bool IsForDebug)` has been changed to `friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const T& EF)`.
1115
- `EdgeFunction` is tagged with `[[clang::trivial_abi]]`. Hence, you should not rely on any destruction order within a top-level statement that uses temporary `EdgeFunction` objects.
1216
- `EdgeFunctionSingletonFactory` has been removed. Use `EdgeFunctionSingletonCache` instead.
1317
- `TaintConfig` has been renamed to `LLVMTaintConfig`. For generic code you may want to use the LLVM-independent `TaintConfigBase` CRTP interface instead.
1418
- Renamed `phasar/PhasarLLVM/DataFlowSolver/` to either `phasar/DataFlow/` or `phasar/PhasarLLVM/DataFlow/` depending on whether the components need LLVMCore. Analoguous changes in `lib/` and `unittests/`.
1519
An incomplete list of moved/renamed files:
16-
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/*` => `phasar/DataFlow/IfdsIde/Solver/*`
17-
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IDETabulationProblem.h` => `phasar/DataFlow/IfdsIde/IDETabulationProblem.h`
18-
- `phasar/DB/LLVMProjectIRDB.h` => `phasar/PhasarLLVM/DB/LLVMProjectIRDB.h`
19-
- ...
20+
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/*` => `phasar/DataFlow/IfdsIde/Solver/*`
21+
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IDETabulationProblem.h` => `phasar/DataFlow/IfdsIde/IDETabulationProblem.h`
22+
- `phasar/DB/LLVMProjectIRDB.h` => `phasar/PhasarLLVM/DB/LLVMProjectIRDB.h`
23+
- ...
2024
- Renamed and split up some libraries:
21-
- `phasar_phasarllvm_utils` => `phasar_llvm_utils`
22-
- `phasar_typehierarchy` => `phasar_llvm_typehierarchy`
23-
- `phasar_ifdside` => `phasar_llvm_ifdside`
24-
- `phasar_controlflow` has its LLVM dependent stuff moved to `phasar_llvm_controlflow`
25-
- `phasar_db` has its LLVM dependent stuff moved to `phasar_llvm_db`
26-
- `phasar_pointer` has its LLVM dependent stuff moved to `phasar_llvm_pointer`
25+
- `phasar_phasarllvm_utils` => `phasar_llvm_utils`
26+
- `phasar_typehierarchy` => `phasar_llvm_typehierarchy`
27+
- `phasar_ifdside` => `phasar_llvm_ifdside`
28+
- `phasar_controlflow` has its LLVM dependent stuff moved to `phasar_llvm_controlflow`
29+
- `phasar_db` has its LLVM dependent stuff moved to `phasar_llvm_db`
30+
- `phasar_pointer` has its LLVM dependent stuff moved to `phasar_llvm_pointer`
2731
- Renamed the phasar tool `phasar-llvm` to `phasar-cli`
2832
- `LLVMPointsTo[.*]` has been renamed to `LLVMAlias[.*]`
2933
- The ctor of `LLVMAliasSet` now takes the `LLVMProjectIRDB` as pointer instead of a reference to better document that it may capture the IRDB by reference.

CMakeLists.txt

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
cmake_minimum_required (VERSION 3.0)
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
# Avoid IPO/LTO Warnings:
4+
cmake_policy(SET CMP0069 NEW)
5+
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
26

37
# Check if we build within the llvm source tree
48
if (DEFINED LLVM_MAIN_SRC_DIR)
@@ -10,7 +14,7 @@ if (NOT PHASAR_IN_TREE)
1014
set(CMAKE_PROJECT_NAME "phasar")
1115
endif ()
1216

13-
option(PHASAR_EXPERIMENTAL_CXX20 "Build phasar in C++20 mode. THis is an experimental feature" OFF)
17+
option(PHASAR_EXPERIMENTAL_CXX20 "Build phasar in C++20 mode. This is an experimental feature" OFF)
1418

1519
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
1620
if(PHASAR_EXPERIMENTAL_CXX20)
@@ -38,7 +42,21 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
3842
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g")
3943
else()
4044
message(STATUS "Selected Release Build")
45+
46+
include(CheckIPOSupported)
47+
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_SUPPORT_ERROR)
48+
49+
50+
if(LTO_SUPPORTED)
51+
message(STATUS "IPO/LTO enabled")
52+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # LTO
53+
else()
54+
message(STATUS "IPO/LTO not supported: ${LTO_SUPPORT_ERROR}")
55+
endif()
56+
57+
4158
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe")
59+
4260
endif()
4361

4462
# Enable testing
@@ -77,7 +95,12 @@ option(PHASAR_BUILD_DOC "Build documentation" OFF)
7795

7896
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
7997

80-
option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
98+
#option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
99+
option(PHASAR_BUILD_DYNLIB "Build one fat shared library. Requires BUILD_SHARED_LIBS to be turned OFF (default is OFF)" OFF)
100+
101+
if(PHASAR_BUILD_DYNLIB AND BUILD_SHARED_LIBS)
102+
message(FATAL_ERROR "PHASAR_BUILD_DYNLIB is incompatible with BUILD_SHARED_LIBS")
103+
endif()
81104

82105
option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON)
83106
if (PHASAR_ENABLE_WARNINGS)
@@ -156,7 +179,7 @@ find_package(Threads)
156179
# Boost
157180
find_package(Boost 1.65.1 COMPONENTS graph ${BOOST_THREAD} REQUIRED)
158181
#find_package(Boost 1.72.0 COMPONENTS graph ${BOOST_THREAD} REQUIRED)
159-
include_directories(${Boost_INCLUDE_DIRS})
182+
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
160183

161184
# Disable clang-tidy for the external projects
162185
set(CMAKE_CXX_CLANG_TIDY "")
@@ -184,7 +207,7 @@ set(nlohmann_json_DIR ${PHASAR_SRC_DIR}/external/json/single_include/)
184207
# Json Schema Validator
185208
set(JSON_VALIDATOR_INSTALL ON)
186209
add_subdirectory(external/json-schema-validator)
187-
include_directories(external/json-schema-validator/src/)
210+
include_directories(SYSTEM external/json-schema-validator/src/)
188211

189212
# now we finally add the subdirectory
190213
set(JSON_BuildTests OFF)
@@ -194,8 +217,8 @@ add_subdirectory(external/json)
194217
# Googletest
195218
if (NOT PHASAR_IN_TREE)
196219
add_subdirectory(external/googletest EXCLUDE_FROM_ALL)
197-
include_directories(external/googletest/googletest/include)
198-
include_directories(external/googletest/googlemock/include)
220+
include_directories(SYSTEM external/googletest/googletest/include)
221+
include_directories(SYSTEM external/googletest/googlemock/include)
199222
else()
200223
# Set llvm distributed includes for gtest header
201224
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
@@ -205,13 +228,13 @@ endif()
205228
# SQL
206229
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
207230
find_library(SQLITE3_LIBRARY NAMES sqlite3)
208-
include_directories(${SQLITE3_INCLUDE_DIR})
231+
include_directories(SYSTEM ${SQLITE3_INCLUDE_DIR})
209232

210233
# LLVM
211234
if (NOT PHASAR_IN_TREE)
212235
# Only search for LLVM if we build out of tree
213236
find_package(LLVM 14 REQUIRED CONFIG)
214-
include_directories(${LLVM_INCLUDE_DIRS})
237+
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
215238
link_directories(${LLVM_LIB_PATH} ${LLVM_LIBRARY_DIRS})
216239
endif()
217240

@@ -265,7 +288,7 @@ endif()
265288

266289
if (PHASAR_IN_TREE)
267290
# Phasar needs clang headers, specificaly some that are generated by clangs table-gen
268-
include_directories(
291+
include_directories(SYSTEM
269292
${CLANG_INCLUDE_DIR}
270293
${PHASAR_SRC_DIR}/../clang/include
271294
${PROJECT_BINARY_DIR}/tools/clang/include

0 commit comments

Comments
 (0)