Skip to content

Commit

Permalink
Compiles with llvm 17. Solves #98.
Browse files Browse the repository at this point in the history
  • Loading branch information
HFTrader authored and banach-space committed Sep 17, 2023
1 parent 80faca9 commit 4e980f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ endif()
# `find_package(llvm)`. So there's no need to add it here.
list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/")

find_package(LLVM 16 REQUIRED CONFIG)

# Another sanity check
if(NOT "16" VERSION_EQUAL "${LLVM_VERSION_MAJOR}")
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 16")
# The way LLVMConfigVersion.cmake is set up, it will only match MAJOR.MINOR
# exactly, even if we do not specify "REQUIRED" in the statement below.
# So we accept any version and do the proper ranged check below.
find_package(LLVM CONFIG)

# We defer the version checking to this statement
if("${LLVM_VERSION_MAJOR}" VERSION_LESS 16)
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 16 or above")
endif()

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand Down
5 changes: 4 additions & 1 deletion HelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ set(LT_LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory")
list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/")

# FIXME: This is a warkaround for #25. Remove once resolved and use
find_package(LLVM 16 REQUIRED CONFIG)
find_package(LLVM CONFIG)
if("${LLVM_VERSION_MAJOR}" VERSION_LESS 16)
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 16 or above")
endif()

# HelloWorld includes headers from LLVM - update the include paths accordingly
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
Expand Down
11 changes: 7 additions & 4 deletions lib/RIV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// -------------------------------------------------------------------------
//
// REFERENCES:
// Based on examples from:
// Based on examples from:
// "Building, Testing and Debugging a Simple out-of-tree LLVM Pass", Serge
// Guelton and Adrien Guinet, LLVM Dev Meeting 2015
//
Expand Down Expand Up @@ -75,7 +75,11 @@ RIV::Result RIV::buildRIV(Function &F, NodeTy CFGRoot) {
// variables and input arguments.
auto &EntryBBValues = ResultMap[&F.getEntryBlock()];

#if LLVM_VERSION_MAJOR >= 17
for (auto &Global : F.getParent()->globals())
#else
for (auto &Global : F.getParent()->getGlobalList())
#endif
if (Global.getValueType()->isIntegerTy())
EntryBBValues.insert(&Global);

Expand Down Expand Up @@ -120,9 +124,8 @@ RIV::Result RIV::run(llvm::Function &F, llvm::FunctionAnalysisManager &FAM) {
return Res;
}

PreservedAnalyses
RIVPrinter::run(Function &Func,
FunctionAnalysisManager &FAM) {
PreservedAnalyses RIVPrinter::run(Function &Func,
FunctionAnalysisManager &FAM) {

auto RIVMap = FAM.getResult<RIV>(Func);

Expand Down

0 comments on commit 4e980f9

Please sign in to comment.