diff options
author | Frank Busse <bb0xfb@gmail.com> | 2021-12-15 16:20:29 +0000 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2022-03-17 22:59:26 +0000 |
commit | d8553f3cec042b5af9e21c268cb14ee8f7b30083 (patch) | |
tree | d8545f09d6ae508df5a8d19ad30b6dbd6f1e4182 /lib/Module | |
parent | 8cab09eb98d06d488e036ceec9f4b16090502297 (diff) | |
download | klee-d8553f3cec042b5af9e21c268cb14ee8f7b30083.tar.gz |
remove LLVM < 6 from sources
Diffstat (limited to 'lib/Module')
-rw-r--r-- | lib/Module/FunctionAlias.cpp | 23 | ||||
-rw-r--r-- | lib/Module/InstructionInfoTable.cpp | 5 | ||||
-rw-r--r-- | lib/Module/IntrinsicCleaner.cpp | 23 | ||||
-rw-r--r-- | lib/Module/KModule.cpp | 4 | ||||
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 56 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 25 | ||||
-rw-r--r-- | lib/Module/RaiseAsm.cpp | 21 |
7 files changed, 6 insertions, 151 deletions
diff --git a/lib/Module/FunctionAlias.cpp b/lib/Module/FunctionAlias.cpp index 3fb0ec9a..a98b74fb 100644 --- a/lib/Module/FunctionAlias.cpp +++ b/lib/Module/FunctionAlias.cpp @@ -36,9 +36,7 @@ namespace klee { bool FunctionAliasPass::runOnModule(Module &M) { bool modified = false; -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) assert((M.ifunc_size() == 0) && "Unexpected ifunc"); -#endif for (const auto &pair : FunctionAlias) { bool matchFound = false; @@ -93,28 +91,7 @@ bool FunctionAliasPass::runOnModule(Module &M) { std::vector<GlobalValue *> matches; // find matches for regex -#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0) for (GlobalValue &global : M.global_values()) { -#else - // chain iterators of alias list and function list - auto firstIt = M.getAliasList().begin(); - auto firstIe = M.getAliasList().end(); - auto secondIt = M.getFunctionList().begin(); - auto secondIe = M.getFunctionList().end(); - for (bool firstList = true;; - (firstList && (++firstIt != firstIe)) || (++secondIt != secondIe)) { - GlobalValue *gv = nullptr; - if (firstIt == firstIe) - firstList = false; - if (firstList) { - gv = cast<GlobalValue>(&*firstIt); - } else { - if (secondIt == secondIe) - break; - gv = cast<GlobalValue>(&*secondIt); - } - GlobalValue &global = *gv; -#endif if (!global.hasName()) continue; diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp index 05a1f7b9..3c972edc 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -112,11 +112,8 @@ public: std::unique_ptr<FunctionInfo> getFunctionInfo(const llvm::Function &Func) { auto asmLine = lineTable.at(reinterpret_cast<std::uintptr_t>(&Func)); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) auto dsub = Func.getSubprogram(); -#else - auto dsub = llvm::getDISubprogram(&Func); -#endif + if (dsub != nullptr) { auto path = dsub->getFilename(); return std::make_unique<FunctionInfo>(FunctionInfo( diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp index f4b867e5..d15db10a 100644 --- a/lib/Module/IntrinsicCleaner.cpp +++ b/lib/Module/IntrinsicCleaner.cpp @@ -317,30 +317,9 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { break; } case Intrinsic::objectsize: { -#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) // Lower the call to a concrete value auto replacement = llvm::lowerObjectSizeCall(ii, DataLayout, nullptr, /*MustSucceed=*/true); -#else - // We don't know the size of an object in general so we replace - // with 0 or -1 depending on the second argument to the intrinsic. - assert(ii->getNumArgOperands() == 2 && "wrong number of arguments"); - auto minArg = dyn_cast_or_null<ConstantInt>(ii->getArgOperand(1)); - assert(minArg && - "Failed to get second argument or it is not ConstantInt"); - assert(minArg->getBitWidth() == 1 && "Second argument is not an i1"); - ConstantInt *replacement = nullptr; - IntegerType *intType = dyn_cast<IntegerType>(ii->getType()); - assert(intType && "intrinsic does not have integer return type"); - if (minArg->isZero()) { - // min=false - replacement = ConstantInt::get(intType, -1, /*isSigned=*/true); - } else { - // min=true - replacement = ConstantInt::get(intType, 0, /*isSigned=*/false); - } - -#endif ii->replaceAllUsesWith(replacement); ii->eraseFromParent(); dirty = true; @@ -361,9 +340,7 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { // The following intrinsics are currently handled by LowerIntrinsicCall // (Invoking LowerIntrinsicCall with any intrinsics not on this // list throws an exception.) -#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) case Intrinsic::addressofreturnaddress: -#endif case Intrinsic::annotation: case Intrinsic::assume: case Intrinsic::bswap: diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 50bb28bb..2f78ce14 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -22,11 +22,7 @@ #include "klee/Support/ErrorHandling.h" #include "klee/Support/ModuleUtil.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) #include "llvm/Bitcode/BitcodeWriter.h" -#else -#include "llvm/Bitcode/ReaderWriter.h" -#endif #if LLVM_VERSION_CODE < LLVM_VERSION(8, 0) #include "llvm/IR/CallSite.h" #endif diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index 2c855261..87a9c917 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -14,9 +14,8 @@ #include "klee/Support/ErrorHandling.h" #include "llvm/Analysis/ValueTracking.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0) #include "llvm/BinaryFormat/Magic.h" -#endif +#include "llvm/Bitcode/BitcodeReader.h" #include "llvm/IR/AssemblyAnnotationWriter.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" @@ -31,20 +30,12 @@ #include "llvm/Object/Archive.h" #include "llvm/Object/Error.h" #include "llvm/Object/ObjectFile.h" -#if LLVM_VERSION_CODE < LLVM_VERSION(4, 0) -#include "llvm/Support/DataStream.h" -#endif #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/SourceMgr.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) -#include <llvm/Bitcode/BitcodeReader.h> -#else -#include <llvm/Bitcode/ReaderWriter.h> -#endif #include <algorithm> #include <fstream> @@ -304,11 +295,7 @@ Function *klee::getDirectCallTarget( } else if (Function *f = dyn_cast<Function>(v)) { return f; } else if (llvm::GlobalAlias *ga = dyn_cast<GlobalAlias>(v)) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) if (moduleIsFullyLinked || !(ga->isInterposable())) { -#else - if (moduleIsFullyLinked || !(ga->mayBeOverridden())) { -#endif v = ga->getAliasee(); } else { v = nullptr; @@ -383,18 +370,9 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, } MemoryBufferRef Buffer = bufferErr.get()->getMemBufferRef(); - -#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0) file_magic magic = identify_magic(Buffer.getBuffer()); -#else - sys::fs::file_magic magic = sys::fs::identify_magic(Buffer.getBuffer()); -#endif -#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0) if (magic == file_magic::bitcode) { -#else - if (magic == sys::fs::file_magic::bitcode) { -#endif SMDiagnostic Err; std::unique_ptr<llvm::Module> module(parseIR(Buffer, Err, context)); if (!module) { @@ -405,37 +383,21 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, return true; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0) if (magic == file_magic::archive) { -#else - if (magic == sys::fs::file_magic::archive) { -#endif -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) Expected<std::unique_ptr<object::Binary> > archOwner = object::createBinary(Buffer, &context); if (!archOwner) ec = errorToErrorCode(archOwner.takeError()); llvm::object::Binary *arch = archOwner.get().get(); -#else - ErrorOr<std::unique_ptr<object::Binary>> archOwner = - object::createBinary(Buffer, &context); - ec = archOwner.getError(); - llvm::object::Binary *arch = archOwner.get().get(); -#endif if (ec) klee_error("Loading file %s failed: %s", fileName.c_str(), ec.message().c_str()); if (auto archive = dyn_cast<object::Archive>(arch)) { // Load all bitcode files into memory -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) auto Err = Error::success(); for (auto AI = archive->child_begin(Err), AE = archive->child_end(); AI != AE; ++AI) -#else - for (auto AI = archive->child_begin(), AE = archive->child_end(); - AI != AE; ++AI) -#endif { StringRef memberName; @@ -447,12 +409,8 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, return false; } auto memberNameErr = childOrErr->getName(); -#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) ec = memberNameErr ? std::error_code() : errorToErrorCode(memberNameErr.takeError()); -#else - ec = memberNameErr.getError(); -#endif if (!ec) { memberName = memberNameErr.get(); KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() @@ -463,24 +421,14 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, return false; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) Expected<std::unique_ptr<llvm::object::Binary> > child = childOrErr->getAsBinary(); if (!child) ec = errorToErrorCode(child.takeError()); -#else - ErrorOr<std::unique_ptr<llvm::object::Binary>> child = - childOrErr->getAsBinary(); - ec = child.getError(); -#endif if (ec) { // If we can't open as a binary object file its hopefully a bitcode file auto buff = childOrErr->getMemoryBufferRef(); -#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) ec = buff ? std::error_code() : errorToErrorCode(buff.takeError()); -#else - ec = buff.getError(); -#endif if (ec) { errorMsg = "Failed to get MemoryBuffer: " + ec.message(); return false; @@ -513,12 +461,10 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, return false; } } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) if (Err) { errorMsg = "Cannot iterate over archive"; return false; } -#endif } return true; diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index 153c9bb8..a58d2459 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -34,12 +34,9 @@ #include "llvm/Support/PluginLoader.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO.h" -#include "llvm/Transforms/Scalar.h" - -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) #include "llvm/Transforms/IPO/FunctionAttrs.h" +#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" -#endif #if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0) #include "llvm/Transforms/Utils.h" @@ -118,11 +115,7 @@ static void AddStandardCompilePasses(legacy::PassManager &PM) { addPass(PM, createCFGSimplificationPass()); // Clean up after IPCP & DAE addPass(PM, createPruneEHPass()); // Remove dead EH info -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) addPass(PM, createPostOrderFunctionAttrsLegacyPass()); -#else - addPass(PM, createPostOrderFunctionAttrsPass()); -#endif addPass(PM, createReversePostOrderFunctionAttrsPass()); // Deduce function attrs if (!DisableInline) @@ -132,11 +125,7 @@ static void AddStandardCompilePasses(legacy::PassManager &PM) { addPass(PM, createInstructionCombiningPass()); // Cleanup for scalarrepl. addPass(PM, createJumpThreadingPass()); // Thread jumps. addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) addPass(PM, createSROAPass()); // Break up aggregate allocas -#else - addPass(PM, createScalarReplAggregatesPass()); // Break up aggregate allocas -#endif addPass(PM, createInstructionCombiningPass()); // Combine silly seq's addPass(PM, createTailCallEliminationPass()); // Eliminate tail calls @@ -189,7 +178,6 @@ void Optimize(Module *M, llvm::ArrayRef<const char *> preservedFunctions) { // for a main function. If main is defined, mark all other functions // internal. if (!DisableInternalize) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) auto PreserveFunctions = [=](const GlobalValue &GV) { StringRef GVName = GV.getName(); @@ -200,9 +188,6 @@ void Optimize(Module *M, llvm::ArrayRef<const char *> preservedFunctions) { return false; }; ModulePass *pass = createInternalizePass(PreserveFunctions); -#else - ModulePass *pass = createInternalizePass(preservedFunctions); -#endif addPass(Passes, pass); } @@ -241,18 +226,10 @@ void Optimize(Module *M, llvm::ArrayRef<const char *> preservedFunctions) { // The IPO passes may leave cruft around. Clean up after them. addPass(Passes, createInstructionCombiningPass()); addPass(Passes, createJumpThreadingPass()); // Thread jumps. -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) addPass(Passes, createSROAPass()); // Break up allocas -#else - addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas -#endif // Run a few AA driven optimizations here and now, to cleanup the code. -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) addPass(Passes, createPostOrderFunctionAttrsLegacyPass()); -#else - addPass(Passes, createPostOrderFunctionAttrsPass()); -#endif addPass(Passes, createReversePostOrderFunctionAttrsPass()); // Add nocapture addPass(Passes, createGlobalsAAWrapperPass()); // IP alias analysis diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp index 55550864..248b4344 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -11,6 +11,8 @@ #include "klee/Config/Version.h" #include "klee/Support/ErrorHandling.h" +#include "llvm/CodeGen/TargetLowering.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InlineAsm.h" @@ -18,16 +20,8 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/Support/Host.h" #include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/raw_ostream.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0) -#include "llvm/CodeGen/TargetLowering.h" -#include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/Target/TargetMachine.h" -#else -#include "llvm/Target/TargetLowering.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetSubtargetInfo.h" -#endif + using namespace llvm; using namespace klee; @@ -70,11 +64,7 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) { if (ia->getAsmString() == "" && ia->hasSideEffects() && ia->getFunctionType()->getReturnType()->isVoidTy()) { IRBuilder<> Builder(I); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent); -#else - Builder.CreateFence(llvm::SequentiallyConsistent); -#endif I->eraseFromParent(); return true; } @@ -98,14 +88,9 @@ bool RaiseAsmPass::runOnModule(Module &M) { klee_warning("Warning: unable to select target: %s", Err.c_str()); TLI = 0; } else { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) TM = Target->createTargetMachine(TargetTriple, "", "", TargetOptions(), None); TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering(); -#else - TM = Target->createTargetMachine(TargetTriple, "", "", TargetOptions()); - TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering(); -#endif triple = llvm::Triple(TargetTriple); } |