Skip to content

Commit

Permalink
drop support for LLVM <= 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jbuening authored and MartinNowack committed Mar 21, 2019
1 parent eee4408 commit 9767a37
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 683 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
###########################################################################

# Check a subset of the matrix of:
# LLVM : {3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7}
# LLVM : {3.8, 3.9, 4.0, 5.0, 6.0, 7}
# SOLVERS : {Z3, STP, STP:Z3, metaSMT}
# STP_VERSION : {2.1.2, master}
# METASMT_VERSION : {v4.rc1}
Expand Down Expand Up @@ -62,10 +62,6 @@ env:
- LLVM_VERSION=4.0
- LLVM_VERSION=3.9
- LLVM_VERSION=3.8
- LLVM_VERSION=3.7
- LLVM_VERSION=3.6 USE_LIBCXX=0
- LLVM_VERSION=3.5 USE_LIBCXX=0
- LLVM_VERSION=3.4 USE_LIBCXX=0

# *Sanitizer builds. Do unoptimized build otherwise the optimizer might remove problematic code
- SANITIZER_BUILD=address ENABLE_OPTIMIZED=0 USE_TCMALLOC=0
Expand Down
21 changes: 4 additions & 17 deletions cmake/find_llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
# * llvm-config executable. This method is portable across LLVM build systems
# (i.e. works if LLVM was built with autoconf/Makefile or with CMake).
#
# * find_package(LLVM CONFIG). This method only works if LLVM was built with
# CMake or with LLVM >= 3.5 when built with the autoconf/Makefile build system
# This method relies on the `LLVMConfig.cmake` file generated to be generated
# by LLVM's build system.
# * find_package(LLVM CONFIG). This method relies on the `LLVMConfig.cmake` file
# generated by LLVM's build system.
#
#===------------------------------------------------------------------------===#

Expand All @@ -26,11 +24,7 @@ if (USE_CMAKE_FIND_PACKAGE_LLVM)

# Provide function to map LLVM components to libraries.
function(klee_get_llvm_libs output_var)
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.5")
llvm_map_components_to_libraries(${output_var} ${ARGN})
else()
llvm_map_components_to_libnames(${output_var} ${ARGN})
endif()
llvm_map_components_to_libnames(${output_var} ${ARGN})
set(${output_var} ${${output_var}} PARENT_SCOPE)
endfunction()
# HACK: This information is not exported so just pretend its OFF for now.
Expand Down Expand Up @@ -154,14 +148,7 @@ else()
string_to_list("${_llvm_libs}" _llvm_libs_list)

# Now find the system libs that are needed.
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.5")
# For LLVM 3.4 and older system libraries
# appeared in the output of `--ldflags`.
_run_llvm_config(_system_libs "--ldflags")
# TODO: Filter out `-L<path>` flag.
else()
_run_llvm_config(_system_libs "--system-libs")
endif()
_run_llvm_config(_system_libs "--system-libs")
string_to_list("${_system_libs}" _system_libs_list)

# Create an imported target for each LLVM library
Expand Down
5 changes: 0 additions & 5 deletions include/klee/Internal/Support/FloatEvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,10 @@ inline uint64_t mod(uint64_t l, uint64_t r, unsigned inWidth) {
// determine if l represents NaN
inline bool isNaN(uint64_t l, unsigned inWidth) {
switch( inWidth ) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
case FLT_BITS:
return std::isnan(UInt64AsFloat(l));
case DBL_BITS:
return std::isnan(UInt64AsDouble(l));
#else
case FLT_BITS: return llvm::IsNAN( UInt64AsFloat(l) );
case DBL_BITS: return llvm::IsNAN( UInt64AsDouble(l) );
#endif
default: llvm::report_fatal_error("unsupported floating point width");
}
}
Expand Down
7 changes: 1 addition & 6 deletions include/klee/Internal/Support/ModuleUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@

#include "klee/Config/Version.h"

#include "llvm/IR/Module.h"

#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
#include "llvm/IR/CallSite.h"
#else
#include "llvm/Support/CallSite.h"
#endif
#include "llvm/IR/Module.h"

#include <memory>
#include <string>
Expand Down
10 changes: 0 additions & 10 deletions lib/Basic/CmdLineOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ cl::opt<bool> UseAssignmentValidatingSolver(


void KCommandLine::HideOptions(llvm::cl::OptionCategory &Category) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
StringMap<cl::Option *> &map = cl::getRegisteredOptions();
#else
StringMap<cl::Option *> map;
cl::getRegisteredOptions(map);
#endif

for (auto &elem : map) {
if (elem.second->Category == &Category) {
Expand All @@ -129,12 +124,7 @@ void KCommandLine::HideOptions(llvm::cl::OptionCategory &Category) {
}

void KCommandLine::HideUnrelatedOptions(cl::OptionCategory &Category) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
StringMap<cl::Option *> &map = cl::getRegisteredOptions();
#else
StringMap<cl::Option *> map;
cl::getRegisteredOptions(map);
#endif
for (StringMap<cl::Option *>::iterator i = map.begin(), e = map.end(); i != e;
i++) {
if (i->second->Category != &Category) {
Expand Down
11 changes: 3 additions & 8 deletions lib/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ klee_add_component(kleeCore
# kleeCore.
set(LLVM_COMPONENTS
core
executionengine
mcjit
native
support
)

if ("${LLVM_PACKAGE_VERSION}" VERSION_EQUAL "3.6" OR
"${LLVM_PACKAGE_VERSION}" VERSION_GREATER "3.6")
list(APPEND LLVM_COMPONENTS mcjit executionengine native)
else()
list(APPEND LLVM_COMPONENTS jit engine)
endif()


klee_get_llvm_libs(LLVM_LIBS ${LLVM_COMPONENTS})
target_link_libraries(kleeCore PUBLIC ${LLVM_LIBS})
target_link_libraries(kleeCore PRIVATE
Expand Down
26 changes: 1 addition & 25 deletions lib/Core/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
Expand All @@ -70,12 +71,6 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"

#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
#include "llvm/Support/CallSite.h"
#else
#include "llvm/IR/CallSite.h"
#endif

#include <algorithm>
#include <cassert>
#include <cerrno>
Expand Down Expand Up @@ -597,11 +592,7 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os,
for (unsigned i=0, e=cds->getNumElements(); i != e; ++i)
initializeGlobalObject(state, os, cds->getElementAsConstant(i),
offset + i*elementSize);
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
} else if (!isa<UndefValue>(c) && !isa<MetadataAsValue>(c)) {
#else
} else if (!isa<UndefValue>(c)) {
#endif
unsigned StoreBits = targetData->getTypeStoreSizeInBits(c->getType());
ref<ConstantExpr> C = evalConstant(c);

Expand Down Expand Up @@ -1560,13 +1551,8 @@ Function* Executor::getTargetFunction(Value *calledVal, ExecutionState &state) {

while (true) {
if (GlobalValue *gv = dyn_cast<GlobalValue>(c)) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
if (!Visited.insert(gv).second)
return 0;
#else
if (!Visited.insert(gv))
return 0;
#endif
std::string alias = state.getFnAlias(gv->getName());
if (alias != "") {
GlobalValue *old_gv = gv;
Expand Down Expand Up @@ -1814,12 +1800,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
std::map<ref<Expr>, BasicBlock *> expressionOrder;

// Iterate through all non-default cases and order them by expressions
#if LLVM_VERSION_CODE > LLVM_VERSION(3, 4)
for (auto i : si->cases()) {
#else
for (SwitchInst::CaseIt i = si->case_begin(), e = si->case_end(); i != e;
++i) {
#endif
ref<Expr> value = evalConstant(i.getCaseValue());

BasicBlock *caseSuccessor = i.getCaseSuccessor();
Expand Down Expand Up @@ -2402,13 +2383,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
!fpWidthToSemantics(right->getWidth()))
return terminateStateOnExecError(state, "Unsupported FRem operation");
llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue());
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
Res.mod(
APFloat(*fpWidthToSemantics(right->getWidth()), right->getAPValue()));
#else
Res.mod(APFloat(*fpWidthToSemantics(right->getWidth()),right->getAPValue()),
APFloat::rmNearestTiesToEven);
#endif
bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt()));
break;
}
Expand Down
6 changes: 1 addition & 5 deletions lib/Core/ExecutorUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
#include "llvm/Support/GetElementPtrTypeIterator.h"
#else
#include "llvm/IR/GetElementPtrTypeIterator.h"
#endif
#include "llvm/Support/raw_ostream.h"

#include <cassert>
Expand Down
42 changes: 6 additions & 36 deletions lib/Core/ExternalDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,19 @@
#include "ExternalDispatcher.h"
#include "klee/Config/Version.h"

#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
#include "llvm/ExecutionEngine/MCJIT.h"
#else
#include "llvm/ExecutionEngine/JIT.h"
#endif

#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"

#include "llvm/Support/TargetSelect.h"

#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
#include "llvm/Support/CallSite.h"
#else
#include "llvm/IR/CallSite.h"
#endif

#include <csetjmp>
#include <csignal>

Expand Down Expand Up @@ -122,11 +111,6 @@ ExternalDispatcherImpl::ExternalDispatcherImpl(LLVMContext &ctx)
: ctx(ctx), lastErrno(0) {
std::string error;
singleDispatchModule = new Module(getFreshModuleID(), ctx);
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 6)
// Use old JIT
executionEngine = ExecutionEngine::createJIT(singleDispatchModule, &error);
#else
// Use MCJIT.
// The MCJIT JITs whole modules at a time rather than individual functions
// so we will let it manage the modules.
// Note that we don't do anything with `singleDispatchModule`. This is just
Expand All @@ -136,7 +120,6 @@ ExternalDispatcherImpl::ExternalDispatcherImpl(LLVMContext &ctx)
.setErrorStr(&error)
.setEngineKind(EngineKind::JIT)
.create();
#endif

if (!executionEngine) {
llvm::errs() << "unable to make jit: " << error << "\n";
Expand All @@ -146,10 +129,8 @@ ExternalDispatcherImpl::ExternalDispatcherImpl(LLVMContext &ctx)
// If we have a native target, initialize it to ensure it is linked in and
// usable by the JIT.
llvm::InitializeNativeTarget();
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
llvm::InitializeNativeTargetAsmParser();
llvm::InitializeNativeTargetAsmPrinter();
#endif

// from ExecutionEngine::create
if (executionEngine) {
Expand Down Expand Up @@ -197,21 +178,16 @@ bool ExternalDispatcherImpl::executeCall(Function *f, Instruction *i,
#endif

Module *dispatchModule = NULL;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
// The MCJIT generates whole modules at a time so for every call that we
// haven't made before we need to create a new Module.
dispatchModule = new Module(getFreshModuleID(), ctx);
#else
dispatchModule = this->singleDispatchModule;
#endif
dispatcher = createDispatcher(f, i, dispatchModule);
dispatchers.insert(std::make_pair(i, dispatcher));

// Force the JIT execution engine to go ahead and build the function. This
// ensures that any errors or assertions in the compilation process will
// trigger crashes instead of being caught as aborts in the external
// function.
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
// Force the JIT execution engine to go ahead and build the function. This
// ensures that any errors or assertions in the compilation process will
// trigger crashes instead of being caught as aborts in the external
// function.
if (dispatcher) {
// The dispatchModule is now ready so tell MCJIT to generate the code for
// it.
Expand All @@ -228,12 +204,6 @@ bool ExternalDispatcherImpl::executeCall(Function *f, Instruction *i,
// MCJIT didn't take ownership of the module so delete it.
delete dispatchModule;
}
#else
if (dispatcher) {
// Old JIT works on a function at a time so compile the function.
executionEngine->recompileAndRelinkFunction(dispatcher);
}
#endif
return runProtectedCall(dispatcher, args);
}

Expand Down
7 changes: 1 addition & 6 deletions lib/Core/Searcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@
#include "klee/Internal/Support/ModuleUtil.h"
#include "klee/Internal/System/Time.h"
#include "klee/Internal/Support/ErrorHandling.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"

#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
#include "llvm/Support/CallSite.h"
#else
#include "llvm/IR/CallSite.h"
#endif

#include <cassert>
#include <fstream>
#include <climits>
Expand Down
Loading

0 comments on commit 9767a37

Please sign in to comment.