From 6cc8ee707c1b4337120aa2972e2ad13a4861bbc3 Mon Sep 17 00:00:00 2001 From: Frank Busse Date: Mon, 13 Jun 2022 10:42:51 +0100 Subject: remove LLVM < 9 --- lib/Core/Executor.cpp | 38 --------------- lib/Core/ExternalDispatcher.cpp | 10 ---- lib/Core/StatsTracker.cpp | 17 +------ lib/Module/CMakeLists.txt | 4 -- lib/Module/IntrinsicCleaner.cpp | 12 ----- lib/Module/KModule.cpp | 22 --------- lib/Module/ModuleUtil.cpp | 16 +------ lib/Module/Optimize.cpp | 14 +----- lib/Module/Passes.h | 12 ----- lib/Module/RaiseAsm.cpp | 4 -- lib/Module/WorkaroundLLVMPR39177.cpp | 92 ------------------------------------ lib/Solver/SolverCmdLine.cpp | 5 -- lib/Support/CompressionStream.cpp | 5 -- lib/Support/FileHandling.cpp | 6 --- 14 files changed, 5 insertions(+), 252 deletions(-) delete mode 100644 lib/Module/WorkaroundLLVMPR39177.cpp (limited to 'lib') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index a2928864..529f8b43 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -56,9 +56,6 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" -#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0) -#include "llvm/IR/CallSite.h" -#endif #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" @@ -1782,7 +1779,6 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f, } #endif -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) case Intrinsic::fshr: case Intrinsic::fshl: { ref op1 = eval(ki, 1, state).value; @@ -1807,7 +1803,6 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f, } break; } -#endif // va_arg is handled by caller and intrinsic lowering, see comment for // ExecutionState::varargs @@ -1928,21 +1923,10 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f, uint64_t offsets[callingArgs]; // offsets of variadic arguments uint64_t argWidth; // width of current variadic argument -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*i); -#else - const CallSite cs(i); -#endif for (unsigned k = funcArgs; k < callingArgs; k++) { if (cs.isByValArgument(k)) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) Type *t = cs.getParamByValType(k); -#else - auto arg = cs.getArgOperand(k); - Type *t = arg->getType(); - assert(t->isPointerTy()); - t = t->getPointerElementType(); -#endif argWidth = kmodule->targetData->getTypeSizeInBits(t); } else { argWidth = arguments[k]->getWidth(); @@ -2152,13 +2136,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { Expr::Width to = getWidthForLLVMType(t); if (from != to) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*caller); -#else - const CallSite cs(isa(caller) - ? CallSite(cast(caller)) - : CallSite(cast(caller))); -#endif // XXX need to check other param attrs ? bool isSExt = cs.hasRetAttr(llvm::Attribute::SExt); @@ -2416,14 +2394,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (isa(i)) break; -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*i); Value *fp = cs.getCalledOperand(); -#else - const CallSite cs(i); - Value *fp = cs.getCalledValue(); -#endif - unsigned numArgs = cs.arg_size(); Function *f = getTargetFunction(fp, state); @@ -2830,8 +2802,6 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { } // Floating point instructions - -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) case Instruction::FNeg: { ref arg = toConstant(state, eval(ki, 0, state).value, "floating point"); @@ -2843,7 +2813,6 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt())); break; } -#endif case Instruction::FAdd: { ref left = toConstant(state, eval(ki, 0, state).value, @@ -4643,14 +4612,7 @@ size_t Executor::getAllocationAlignment(const llvm::Value *allocSite) const { type = AI->getAllocatedType(); } else if (isa(allocSite) || isa(allocSite)) { // FIXME: Model the semantics of the call to use the right alignment -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*allocSite); -#else - llvm::Value *allocSiteNonConst = const_cast(allocSite); - const CallSite cs(isa(allocSiteNonConst) - ? CallSite(cast(allocSiteNonConst)) - : CallSite(cast(allocSiteNonConst))); -#endif llvm::Function *fn = klee::getDirectCallTarget(cs, /*moduleIsFullyLinked=*/true); if (fn) diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp index aadb340d..c58e2ec8 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -10,9 +10,6 @@ #include "ExternalDispatcher.h" #include "klee/Config/Version.h" -#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0) -#include "llvm/IR/CallSite.h" -#endif #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/IRBuilder.h" @@ -258,14 +255,7 @@ Function *ExternalDispatcherImpl::createDispatcher(Function *target, if (!resolveSymbol(target->getName().str())) return 0; -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*inst); -#else - const CallSite cs(inst->getOpcode() == Instruction::Call - ? CallSite(cast(inst)) - : CallSite(cast(inst))); -#endif - Value **args = new Value *[cs.arg_size()]; std::vector nullary; diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index 28c52b7f..11199db1 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -29,9 +29,6 @@ #include "llvm/ADT/SmallBitVector.h" #include "llvm/IR/BasicBlock.h" -#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0) -#include "llvm/IR/CallSite.h" -#endif #include "llvm/IR/CFG.h" #include "llvm/IR/Function.h" #include "llvm/IR/InlineAsm.h" @@ -139,13 +136,8 @@ static bool instructionIsCoverable(Instruction *i) { } else { Instruction *prev = &*(--it); if (isa(prev) || isa(prev)) { - Function *target = getDirectCallTarget( -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) - cast(*prev), -#else - CallSite(prev), -#endif - /*moduleIsFullyLinked=*/true); + Function *target = getDirectCallTarget(cast(*prev), + /*moduleIsFullyLinked=*/true); if (target && target->doesNotReturn()) return false; } @@ -794,13 +786,8 @@ void StatsTracker::computeReachableUncovered() { it != ie; ++it) { Instruction *inst = &*it; if (isa(inst) || isa(inst)) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*inst); if (isa(cs.getCalledOperand())) { -#else - const CallSite cs(inst); - if (isa(cs.getCalledValue())) { -#endif // We can never call through here so assume no targets // (which should be correct anyhow). callTargets.insert(std::make_pair(inst, diff --git a/lib/Module/CMakeLists.txt b/lib/Module/CMakeLists.txt index f78575fb..6c2a24b3 100644 --- a/lib/Module/CMakeLists.txt +++ b/lib/Module/CMakeLists.txt @@ -22,10 +22,6 @@ set(KLEE_MODULE_COMPONENT_SRCS RaiseAsm.cpp ) -if (USE_WORKAROUND_LLVM_PR39177) - list(APPEND KLEE_MODULE_COMPONENT_SRCS WorkaroundLLVMPR39177.cpp) -endif() - klee_add_component(kleeModule ${KLEE_MODULE_COMPONENT_SRCS} ) diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp index adef513e..bdaca425 100644 --- a/lib/Module/IntrinsicCleaner.cpp +++ b/lib/Module/IntrinsicCleaner.cpp @@ -68,10 +68,8 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { case Intrinsic::fabs: case Intrinsic::fma: case Intrinsic::fmuladd: -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) case Intrinsic::fshr: case Intrinsic::fshl: -#endif #if LLVM_VERSION_CODE >= LLVM_VERSION(12, 0) case Intrinsic::abs: case Intrinsic::smax: @@ -216,7 +214,6 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { dirty = true; break; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) case Intrinsic::sadd_sat: case Intrinsic::ssub_sat: case Intrinsic::uadd_sat: @@ -284,17 +281,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { dirty = true; break; } -#endif case Intrinsic::trap: { // Intrinsic instruction "llvm.trap" found. Directly lower it to // a call of the abort() function. auto C = M.getOrInsertFunction("abort", Type::getVoidTy(ctx)); -#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) if (auto *F = dyn_cast(C.getCallee())) { -#else - if (auto *F = dyn_cast(C)) { -#endif F->setDoesNotReturn(); F->setDoesNotThrow(); } @@ -326,7 +318,6 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { dirty = true; break; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) case Intrinsic::is_constant: { if(auto* constant = llvm::ConstantFoldInstruction(ii, ii->getModule()->getDataLayout())) ii->replaceAllUsesWith(constant); @@ -336,7 +327,6 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { dirty = true; break; } -#endif // The following intrinsics are currently handled by LowerIntrinsicCall // (Invoking LowerIntrinsicCall with any intrinsics not on this @@ -352,9 +342,7 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { case Intrinsic::ctpop: case Intrinsic::cttz: case Intrinsic::dbg_declare: -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) case Intrinsic::dbg_label: -#endif #ifndef SUPPORT_KLEE_EH_CXX case Intrinsic::eh_typeid_for: #endif diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 139149e5..049c6744 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -23,9 +23,6 @@ #include "klee/Support/ModuleUtil.h" #include "llvm/Bitcode/BitcodeWriter.h" -#if LLVM_VERSION_CODE < LLVM_VERSION(8, 0) -#include "llvm/IR/CallSite.h" -#endif #include "llvm/IR/DataLayout.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" @@ -40,13 +37,9 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_os_ostream.h" #include "llvm/Transforms/Scalar.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) #include "llvm/Transforms/Scalar/Scalarizer.h" -#endif #include "llvm/Transforms/Utils/Cloning.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) #include "llvm/Transforms/Utils.h" -#endif #include @@ -138,14 +131,8 @@ static Function *getStubFunctionForCtorList(Module *m, for (unsigned i=0; igetNumOperands(); i++) { auto cs = cast(arr->getOperand(i)); // There is a third element in global_ctor elements (``i8 @data``). -#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) assert(cs->getNumOperands() == 3 && "unexpected element in ctor initializer list"); -#else - // before LLVM 9.0, the third operand was optional - assert((cs->getNumOperands() == 2 || cs->getNumOperands() == 3) && - "unexpected element in ctor initializer list"); -#endif auto fp = cs->getOperand(1); if (!fp->isNullValue()) { if (auto ce = dyn_cast(fp)) @@ -303,11 +290,7 @@ void KModule::manifest(InterpreterHandler *ih, bool forceSourceOutput) { if (OutputModule) { std::unique_ptr f(ih->openOutputFile("final.bc")); -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) WriteBitcodeToFile(*module, *f); -#else - WriteBitcodeToFile(module.get(), *f); -#endif } /* Build shadow structures */ @@ -468,13 +451,8 @@ KFunction::KFunction(llvm::Function *_function, ki->dest = registerMap[inst]; if (isa(it) || isa(it)) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast(*inst); Value *val = cs.getCalledOperand(); -#else - const CallSite cs(inst); - Value *val = cs.getCalledValue(); -#endif unsigned numArgs = cs.arg_size(); ki->operands = new int[numArgs+1]; ki->operands[0] = getOperandNum(val, registerMap, km, ki); diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index 87a9c917..e1c6e8bd 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -270,17 +270,9 @@ klee::linkModules(std::vector> &modules, } Function *klee::getDirectCallTarget( -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs, -#else - const CallSite &cs, -#endif bool moduleIsFullyLinked) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) Value *v = cs.getCalledOperand(); -#else - Value *v = cs.getCalledValue(); -#endif bool viaConstantExpr = false; // Walk through aliases and bitcasts to try to find // the function being called. @@ -318,16 +310,10 @@ Function *klee::getDirectCallTarget( static bool valueIsOnlyCalled(const Value *v) { for (auto user : v->users()) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) // Make sure the instruction is a call or invoke. if (const auto *cs_ptr = dyn_cast(user)) { const CallBase &cs = *cs_ptr; -#else - if (const auto *instr = dyn_cast(user)) { - // Make sure the instruction is a call or invoke. - const CallSite cs(const_cast(instr)); - if (!cs) return false; -#endif + // Make sure that the value is only the target of this call and // not an argument. if (cs.hasArgument(v)) diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index a58d2459..c982b73d 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -18,10 +18,6 @@ #include "klee/Config/Version.h" #include "klee/Support/OptionCategories.h" -#ifdef USE_WORKAROUND_LLVM_PR39177 -#include "Passes.h" -#endif - #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/LoopPass.h" @@ -33,15 +29,13 @@ #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/PluginLoader.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/FunctionAttrs.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" - -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) #include "llvm/Transforms/Utils.h" -#include "llvm/Transforms/InstCombine/InstCombine.h" -#endif + using namespace llvm; @@ -167,10 +161,6 @@ void Optimize(Module *M, llvm::ArrayRef preservedFunctions) { if (VerifyEach) Passes.add(createVerifierPass()); -#ifdef USE_WORKAROUND_LLVM_PR39177 - addPass(Passes, new klee::WorkaroundLLVMPR39177Pass()); -#endif - // DWD - Run the opt standard pass list as well. AddStandardCompilePasses(Passes); diff --git a/lib/Module/Passes.h b/lib/Module/Passes.h index ae1ce6fd..3eb43ec3 100644 --- a/lib/Module/Passes.h +++ b/lib/Module/Passes.h @@ -185,18 +185,6 @@ private: }; -#ifdef USE_WORKAROUND_LLVM_PR39177 -/// WorkaroundLLVMPR39177Pass - Workaround for LLVM PR39177 within KLEE repo. -/// For more information on this, please refer to the comments in -/// cmake/workaround_llvm_pr39177.cmake -class WorkaroundLLVMPR39177Pass : public llvm::ModulePass { -public: - static char ID; - WorkaroundLLVMPR39177Pass() : llvm::ModulePass(ID) {} - bool runOnModule(llvm::Module &M) override; -}; -#endif - /// Instruments every function that contains a KLEE function call as nonopt class OptNonePass : public llvm::ModulePass { public: diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp index 248b4344..98e580a8 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -42,11 +42,7 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) { if (!ci) return false; -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) InlineAsm *ia = dyn_cast(ci->getCalledOperand()); -#else - InlineAsm *ia = dyn_cast(ci->getCalledValue()); -#endif if (!ia) return false; diff --git a/lib/Module/WorkaroundLLVMPR39177.cpp b/lib/Module/WorkaroundLLVMPR39177.cpp deleted file mode 100644 index 92458847..00000000 --- a/lib/Module/WorkaroundLLVMPR39177.cpp +++ /dev/null @@ -1,92 +0,0 @@ -//===-- WorkaroundLLVMPR39177.cpp -------------------------------*- C++ -*-===// -// -// The KLEE Symbolic Virtual Machine -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// This pass provides a workaround for LLVM bug PR39177 within the KLEE repo. -// For more information on this, please refer to the comments in -// cmake/workaround_llvm_pr39177.cmake - -#include "Passes.h" -#include "klee/Support/ErrorHandling.h" - -#include "llvm/Transforms/Utils/Cloning.h" - -using namespace llvm; - -namespace klee { - -bool WorkaroundLLVMPR39177Pass::runOnModule(Module &M) { - bool modified = false; - - const char *libfunctions[] = { - "strlen", - "strchr", - "strncmp", - "strcpy", - "strncpy", - "__memcpy_chk", - "memchr", - "memcmp", - "putchar", - "puts", - "fputc", - "fputc_unlocked", - "fputs", - "fputs_unlocked", - "fwrite", - "malloc", - "calloc", - "fwrite_unlocked", - "fgetc_unlocked", - "fgets_unlocked", - "fread_unlocked", - "memset_pattern16", - "fopen" - }; - - for (auto *funcname : libfunctions) { - if (M.getFunction(funcname) != nullptr) - continue; - - GlobalValue *gv = M.getNamedValue(funcname); - auto *alias = dyn_cast_or_null(gv); - if (alias == nullptr) - continue; - - // get aliasee function if exists - while (auto *ga = dyn_cast(alias->getAliasee())) { - assert(ga != alias && "alias pointing to itself"); - alias = ga; - } - Function *f = dyn_cast(alias->getAliasee()); - if (f == nullptr) - continue; - - std::string aliasName = alias->getName().str(); - - // clone function - ValueToValueMapTy VMap; - Function *g = CloneFunction(f, VMap); - - // replace alias with cloned function - alias->replaceAllUsesWith(g); - g->takeName(alias); - alias->eraseFromParent(); - - klee_message( - "WorkaroundLLVMPR39177: replaced alias @%s with clone of function @%s", - aliasName.c_str(), f->getName().str().c_str()); - modified = true; - } - - return modified; -} - -char WorkaroundLLVMPR39177Pass::ID = 0; - -} // namespace klee diff --git a/lib/Solver/SolverCmdLine.cpp b/lib/Solver/SolverCmdLine.cpp index d91261dc..b0bff6e6 100644 --- a/lib/Solver/SolverCmdLine.cpp +++ b/lib/Solver/SolverCmdLine.cpp @@ -117,12 +117,7 @@ void KCommandLine::HideOptions(llvm::cl::OptionCategory &Category) { StringMap &map = cl::getRegisteredOptions(); for (auto &elem : map) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) for (auto &cat : elem.second->Categories) { -#else - { - auto &cat = elem.second->Category; -#endif if (cat == &Category) { elem.second->setHiddenFlag(cl::Hidden); } diff --git a/lib/Support/CompressionStream.cpp b/lib/Support/CompressionStream.cpp index 95dbe006..3dc50558 100644 --- a/lib/Support/CompressionStream.cpp +++ b/lib/Support/CompressionStream.cpp @@ -26,13 +26,8 @@ compressed_fd_ostream::compressed_fd_ostream(const std::string &Filename, : llvm::raw_ostream(), pos(0) { ErrorInfo = ""; // Open file in binary mode -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) std::error_code EC = llvm::sys::fs::openFileForWrite(Filename, FD); -#else - std::error_code EC = - llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_None); -#endif if (EC) { ErrorInfo = EC.message(); FD = -1; diff --git a/lib/Support/FileHandling.cpp b/lib/Support/FileHandling.cpp index 46205521..8658f462 100644 --- a/lib/Support/FileHandling.cpp +++ b/lib/Support/FileHandling.cpp @@ -25,14 +25,8 @@ klee_open_output_file(const std::string &path, std::string &error) { error.clear(); std::error_code ec; -#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) auto f = std::make_unique(path.c_str(), ec, llvm::sys::fs::OF_None); -#else - auto f = std::make_unique(path.c_str(), ec, - llvm::sys::fs::F_None); -#endif - if (ec) error = ec.message(); if (!error.empty()) { -- cgit 1.4.1