Skip to content

Commit 628d768

Browse files
committed
Allow setting the LLVM version from higher-level projects
1 parent 24fc54e commit 628d768

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
88
cmake_policy(SET CMP0077 NEW)
99
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
1010

11+
# Allow overwriting cache variables of external projects from this CMakeLists file
12+
cmake_policy(SET CMP0126 NEW)
13+
set(CMAKE_POLICY_DEFAULT_CMP0126 NEW)
14+
1115
# Allow portable use of CMAKE_VISIBILITY_INLINES_HIDDEN not only for shared libraries
1216
cmake_policy(SET CMP0063 NEW)
1317
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
@@ -303,6 +307,9 @@ endif()
303307
option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM libraries if possible (default is OFF; always on if BUILD_SHARED_LIBS is ON)" OFF)
304308

305309
# LLVM
310+
if (NOT PHASAR_LLVM_VERSION)
311+
set(PHASAR_LLVM_VERSION 14)
312+
endif()
306313
include(add_llvm)
307314
add_llvm()
308315

cmake/add_llvm.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ macro(add_llvm)
22

33
if (NOT PHASAR_IN_TREE)
44
# Only search for LLVM if we build out of tree
5-
find_package(LLVM 14 REQUIRED CONFIG)
5+
find_package(LLVM ${PHASAR_LLVM_VERSION} REQUIRED CONFIG)
66
find_library(LLVM_LIBRARY NAMES LLVM PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
77

88
if(USE_LLVM_FAT_LIB AND ${LLVM_LIBRARY} STREQUAL "LLVM_LIBRARY-NOTFOUND")

lib/PhasarLLVM/DB/LLVMProjectIRDB.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020

2121
namespace psr {
2222

23+
static void setOpaquePointersForCtx(llvm::LLVMContext &Ctx, bool Enable) {
24+
#if LLVM_VERSION_MAJOR >= 15 && LLVM_VERSION_MAJOR < 17
25+
if (!Enable) {
26+
Ctx.setOpaquePointers(false);
27+
}
28+
#elif LLVM_VERSION_MAJOR < 15
29+
if (Enable) {
30+
Ctx.enableOpaquePointers();
31+
}
32+
#else // LLVM_VERSION_MAJOR >= 17
33+
#error \
34+
"Non-opaque pointers are not supported anymore. Refactor PhASAR to remove typed pointer support."
35+
#endif
36+
}
37+
2338
std::unique_ptr<llvm::Module>
2439
LLVMProjectIRDB::getParsedIRModuleOrNull(llvm::MemoryBufferRef IRFileContent,
2540
llvm::LLVMContext &Ctx) noexcept {
@@ -63,9 +78,7 @@ LLVMProjectIRDB::getParsedIRModuleOrNull(const llvm::Twine &IRFileName,
6378

6479
LLVMProjectIRDB::LLVMProjectIRDB(const llvm::Twine &IRFileName,
6580
bool EnableOpaquePointers) {
66-
if (EnableOpaquePointers) {
67-
Ctx.enableOpaquePointers();
68-
}
81+
setOpaquePointersForCtx(Ctx, EnableOpaquePointers);
6982
auto M = getParsedIRModuleOrNull(IRFileName, Ctx);
7083

7184
if (!M) {
@@ -160,9 +173,7 @@ LLVMProjectIRDB::LLVMProjectIRDB(std::unique_ptr<llvm::Module> Mod,
160173

161174
LLVMProjectIRDB::LLVMProjectIRDB(llvm::MemoryBufferRef Buf,
162175
bool EnableOpaquePointers) {
163-
if (EnableOpaquePointers) {
164-
Ctx.enableOpaquePointers();
165-
}
176+
setOpaquePointersForCtx(Ctx, EnableOpaquePointers);
166177
auto M = getParsedIRModuleOrNull(Buf, Ctx);
167178
if (!M) {
168179
return;

0 commit comments

Comments
 (0)