Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phasar DynLib and LTO #621

Merged
merged 10 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# Breaking Changes

## Development HEAD

- 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.

## v0323

- `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.
- 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:
- All API functions of `EdgeFunction` must be `const` qualified.
- `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()`.
- `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.
- `void print(llvm::raw_ostream &OS, bool IsForDebug)` has been changed to `friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const T& EF)`.
- All API functions of `EdgeFunction` must be `const` qualified.
- `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()`.
- `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.
- `void print(llvm::raw_ostream &OS, bool IsForDebug)` has been changed to `friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const T& EF)`.
- `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.
- `EdgeFunctionSingletonFactory` has been removed. Use `EdgeFunctionSingletonCache` instead.
- `TaintConfig` has been renamed to `LLVMTaintConfig`. For generic code you may want to use the LLVM-independent `TaintConfigBase` CRTP interface instead.
- 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/`.
An incomplete list of moved/renamed files:
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/*` => `phasar/DataFlow/IfdsIde/Solver/*`
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IDETabulationProblem.h` => `phasar/DataFlow/IfdsIde/IDETabulationProblem.h`
- `phasar/DB/LLVMProjectIRDB.h` => `phasar/PhasarLLVM/DB/LLVMProjectIRDB.h`
- ...
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/*` => `phasar/DataFlow/IfdsIde/Solver/*`
- `phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IDETabulationProblem.h` => `phasar/DataFlow/IfdsIde/IDETabulationProblem.h`
- `phasar/DB/LLVMProjectIRDB.h` => `phasar/PhasarLLVM/DB/LLVMProjectIRDB.h`
- ...
- Renamed and split up some libraries:
- `phasar_phasarllvm_utils` => `phasar_llvm_utils`
- `phasar_typehierarchy` => `phasar_llvm_typehierarchy`
- `phasar_ifdside` => `phasar_llvm_ifdside`
- `phasar_controlflow` has its LLVM dependent stuff moved to `phasar_llvm_controlflow`
- `phasar_db` has its LLVM dependent stuff moved to `phasar_llvm_db`
- `phasar_pointer` has its LLVM dependent stuff moved to `phasar_llvm_pointer`
- `phasar_phasarllvm_utils` => `phasar_llvm_utils`
- `phasar_typehierarchy` => `phasar_llvm_typehierarchy`
- `phasar_ifdside` => `phasar_llvm_ifdside`
- `phasar_controlflow` has its LLVM dependent stuff moved to `phasar_llvm_controlflow`
- `phasar_db` has its LLVM dependent stuff moved to `phasar_llvm_db`
- `phasar_pointer` has its LLVM dependent stuff moved to `phasar_llvm_pointer`
- Renamed the phasar tool `phasar-llvm` to `phasar-cli`
- `LLVMPointsTo[.*]` has been renamed to `LLVMAlias[.*]`
- 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.
Expand Down
43 changes: 33 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.9)

# Avoid IPO/LTO Warnings:
cmake_policy(SET CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)

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

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

set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
if(PHASAR_EXPERIMENTAL_CXX20)
Expand Down Expand Up @@ -38,7 +42,21 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g")
else()
message(STATUS "Selected Release Build")

include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_SUPPORT_ERROR)


if(LTO_SUPPORTED)
message(STATUS "IPO/LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # LTO
else()
message(STATUS "IPO/LTO not supported: ${LTO_SUPPORT_ERROR}")
endif()


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe")

MMory marked this conversation as resolved.
Show resolved Hide resolved
endif()

# Enable testing
Expand Down Expand Up @@ -77,7 +95,12 @@ option(PHASAR_BUILD_DOC "Build documentation" OFF)

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

option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
#option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
option(PHASAR_BUILD_DYNLIB "Build one fat shared library. Requires BUILD_SHARED_LIBS to be turned OFF (default is OFF)" OFF)

if(PHASAR_BUILD_DYNLIB AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "PHASAR_BUILD_DYNLIB is incompatible with BUILD_SHARED_LIBS")
endif()

option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON)
if (PHASAR_ENABLE_WARNINGS)
Expand Down Expand Up @@ -156,7 +179,7 @@ find_package(Threads)
# Boost
find_package(Boost 1.65.1 COMPONENTS graph ${BOOST_THREAD} REQUIRED)
#find_package(Boost 1.72.0 COMPONENTS graph ${BOOST_THREAD} REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})

# Disable clang-tidy for the external projects
set(CMAKE_CXX_CLANG_TIDY "")
Expand Down Expand Up @@ -184,7 +207,7 @@ set(nlohmann_json_DIR ${PHASAR_SRC_DIR}/external/json/single_include/)
# Json Schema Validator
set(JSON_VALIDATOR_INSTALL ON)
add_subdirectory(external/json-schema-validator)
include_directories(external/json-schema-validator/src/)
include_directories(SYSTEM external/json-schema-validator/src/)

# now we finally add the subdirectory
set(JSON_BuildTests OFF)
Expand All @@ -194,8 +217,8 @@ add_subdirectory(external/json)
# Googletest
if (NOT PHASAR_IN_TREE)
add_subdirectory(external/googletest EXCLUDE_FROM_ALL)
include_directories(external/googletest/googletest/include)
include_directories(external/googletest/googlemock/include)
include_directories(SYSTEM external/googletest/googletest/include)
include_directories(SYSTEM external/googletest/googlemock/include)
else()
# Set llvm distributed includes for gtest header
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
Expand All @@ -205,13 +228,13 @@ endif()
# SQL
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
find_library(SQLITE3_LIBRARY NAMES sqlite3)
include_directories(${SQLITE3_INCLUDE_DIR})
include_directories(SYSTEM ${SQLITE3_INCLUDE_DIR})

# LLVM
if (NOT PHASAR_IN_TREE)
# Only search for LLVM if we build out of tree
find_package(LLVM 14 REQUIRED CONFIG)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIB_PATH} ${LLVM_LIBRARY_DIRS})
endif()

Expand Down Expand Up @@ -265,7 +288,7 @@ endif()

if (PHASAR_IN_TREE)
# Phasar needs clang headers, specificaly some that are generated by clangs table-gen
include_directories(
include_directories(SYSTEM
${CLANG_INCLUDE_DIR}
${PHASAR_SRC_DIR}/../clang/include
${PROJECT_BINARY_DIR}/tools/clang/include
Expand Down
Loading