diff options
author | Frank Busse <bb0xfb@gmail.com> | 2022-06-13 10:42:51 +0100 |
---|---|---|
committer | MartinNowack <2443641+MartinNowack@users.noreply.github.com> | 2022-06-30 10:02:30 +0100 |
commit | 6cc8ee707c1b4337120aa2972e2ad13a4861bbc3 (patch) | |
tree | 52aa6fc4f793239963679550e673b6f3a18c3e71 /lib/Module | |
parent | b8539333fdaf32b0f4911d6569ad56a0443190bb (diff) | |
download | klee-6cc8ee707c1b4337120aa2972e2ad13a4861bbc3.tar.gz |
remove LLVM < 9
Diffstat (limited to 'lib/Module')
-rw-r--r-- | lib/Module/CMakeLists.txt | 4 | ||||
-rw-r--r-- | lib/Module/IntrinsicCleaner.cpp | 12 | ||||
-rw-r--r-- | lib/Module/KModule.cpp | 22 | ||||
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 16 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 14 | ||||
-rw-r--r-- | lib/Module/Passes.h | 12 | ||||
-rw-r--r-- | lib/Module/RaiseAsm.cpp | 4 | ||||
-rw-r--r-- | lib/Module/WorkaroundLLVMPR39177.cpp | 92 |
8 files changed, 3 insertions, 173 deletions
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<Function>(C.getCallee())) { -#else - if (auto *F = dyn_cast<Function>(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 <sstream> @@ -138,14 +131,8 @@ static Function *getStubFunctionForCtorList(Module *m, for (unsigned i=0; i<arr->getNumOperands(); i++) { auto cs = cast<ConstantStruct>(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<llvm::ConstantExpr>(fp)) @@ -303,11 +290,7 @@ void KModule::manifest(InterpreterHandler *ih, bool forceSourceOutput) { if (OutputModule) { std::unique_ptr<llvm::raw_fd_ostream> 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<CallInst>(it) || isa<InvokeInst>(it)) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0) const CallBase &cs = cast<CallBase>(*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<std::unique_ptr<llvm::Module>> &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<CallBase>(user)) { const CallBase &cs = *cs_ptr; -#else - if (const auto *instr = dyn_cast<Instruction>(user)) { - // Make sure the instruction is a call or invoke. - const CallSite cs(const_cast<Instruction *>(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<const char *> 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<InlineAsm>(ci->getCalledOperand()); -#else - InlineAsm *ia = dyn_cast<InlineAsm>(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<GlobalAlias>(gv); - if (alias == nullptr) - continue; - - // get aliasee function if exists - while (auto *ga = dyn_cast<GlobalAlias>(alias->getAliasee())) { - assert(ga != alias && "alias pointing to itself"); - alias = ga; - } - Function *f = dyn_cast<Function>(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 |