diff options
-rw-r--r-- | lib/Core/Executor.cpp | 16 | ||||
-rw-r--r-- | lib/Core/MemoryManager.cpp | 5 | ||||
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 33 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 34 | ||||
-rw-r--r-- | lib/Module/RaiseAsm.cpp | 10 | ||||
-rw-r--r-- | tools/kleaver/main.cpp | 4 | ||||
-rw-r--r-- | tools/klee/main.cpp | 4 |
7 files changed, 101 insertions, 5 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index b053d488..7f69a618 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -1338,10 +1338,18 @@ void Executor::executeCall(ExecutionState &state, // // Alignment requirements for scalar types is the same as their size if (argWidth > Expr::Int64) { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + size = llvm::alignTo(size, 16); +#else size = llvm::RoundUpToAlignment(size, 16); +#endif requires16ByteAlignment = true; } +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + size += llvm::alignTo(argWidth, WordSize) / 8; +#else size += llvm::RoundUpToAlignment(argWidth, WordSize) / 8; +#endif } } @@ -1374,10 +1382,18 @@ void Executor::executeCall(ExecutionState &state, Expr::Width argWidth = arguments[i]->getWidth(); if (argWidth > Expr::Int64) { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + offset = llvm::alignTo(offset, 16); +#else offset = llvm::RoundUpToAlignment(offset, 16); +#endif } os->write(offset, arguments[i]); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + offset += llvm::alignTo(argWidth, WordSize) / 8; +#else offset += llvm::RoundUpToAlignment(argWidth, WordSize) / 8; +#endif } } } diff --git a/lib/Core/MemoryManager.cpp b/lib/Core/MemoryManager.cpp index 24e2ed97..f40e8bc9 100644 --- a/lib/Core/MemoryManager.cpp +++ b/lib/Core/MemoryManager.cpp @@ -111,9 +111,12 @@ MemoryObject *MemoryManager::allocate(uint64_t size, bool isLocal, uint64_t address = 0; if (DeterministicAllocation) { - +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + address = llvm::alignTo((uint64_t)nextFreeSlot + alignment - 1, alignment); +#else address = llvm::RoundUpToAlignment((uint64_t)nextFreeSlot + alignment - 1, alignment); +#endif // Handle the case of 0-sized allocations as 1-byte allocations. // This way, we make sure we have this allocation between its own red zones diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index 5f9a12b7..79395da6 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -285,7 +285,11 @@ Function *klee::getDirectCallTarget(CallSite cs, bool moduleIsFullyLinked) { 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 = NULL; @@ -394,7 +398,13 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, } if (magic == sys::fs::file_magic::archive) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) +#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(); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ErrorOr<std::unique_ptr<object::Binary>> archOwner = object::createBinary(Buffer, &context); ec = archOwner.getError(); @@ -415,7 +425,12 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, if (auto archive = dyn_cast<object::Archive>(arch)) { // Load all bitcode files into memory -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + Error Err; + for (object::Archive::child_iterator AI = archive->child_begin(Err), + AE = archive->child_end(); + AI != AE; ++AI) +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) for (object::Archive::child_iterator AI = archive->child_begin(), AE = archive->child_end(); AI != AE; ++AI) @@ -456,7 +471,12 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context, return false; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + Expected<std::unique_ptr<llvm::object::Binary> > child = + childOrErr->getAsBinary(); + if (!child) + ec = errorToErrorCode(child.takeError()); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ErrorOr<std::unique_ptr<llvm::object::Binary>> child = childOrErr->getAsBinary(); ec = child.getError(); @@ -520,7 +540,14 @@ 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; } if (magic.is_object()) { diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index c788ee36..34af4626 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -39,6 +39,11 @@ #include "llvm/Analysis/GlobalsModRef.h" #endif +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) +#include "llvm/Transforms/IPO/FunctionAttrs.h" +#include "llvm/Transforms/Scalar/GVN.h" +#endif + using namespace llvm; // Don't verify at the end @@ -107,7 +112,11 @@ static void AddStandardCompilePasses(klee::LegacyLLVMPassManagerTy &PM) { addPass(PM, createPruneEHPass()); // Remove dead EH info #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + addPass(PM, createPostOrderFunctionAttrsLegacyPass()); +#else addPass(PM, createPostOrderFunctionAttrsPass()); +#endif addPass(PM, createReversePostOrderFunctionAttrsPass()); // Deduce function attrs #else addPass(PM, createFunctionAttrsPass()); // Deduce function attrs @@ -120,7 +129,11 @@ static void AddStandardCompilePasses(klee::LegacyLLVMPassManagerTy &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 @@ -183,7 +196,20 @@ 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(); + + for (const char *fun: preservedFunctions) + if (GVName.equals(fun)) + return true; + + return false; + }; + ModulePass *pass = createInternalizePass(PreserveFunctions); +#else ModulePass *pass = createInternalizePass(preservedFunctions); +#endif addPass(Passes, pass); } @@ -222,11 +248,19 @@ 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, 8) +#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 #else diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp index c597fa2a..4967a2fa 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -60,7 +60,11 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) { if (ia->getAsmString() == "" && ia->hasSideEffects()) { 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; } @@ -81,7 +85,11 @@ bool RaiseAsmPass::runOnModule(Module &M) { klee_warning("Warning: unable to select native target: %s", Err.c_str()); TLI = 0; } else { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions(), + None); + TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering(); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions()); TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering(); #elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp index b8b32e31..800cece9 100644 --- a/tools/kleaver/main.cpp +++ b/tools/kleaver/main.cpp @@ -400,7 +400,11 @@ static bool printInputAsSMTLIBv2(const char *Filename, int main(int argc, char **argv) { bool success = true; +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); +#else llvm::sys::PrintStackTraceOnErrorSignal(); +#endif llvm::cl::SetVersionPrinter(klee::printVersion); llvm::cl::ParseCommandLineOptions(argc, argv); diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp index 77b1fe7c..2c653251 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -1071,7 +1071,11 @@ int main(int argc, char **argv, char **envp) { llvm::InitializeNativeTarget(); parseArguments(argc, argv); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) + sys::PrintStackTraceOnErrorSignal(argv[0]); +#else sys::PrintStackTraceOnErrorSignal(); +#endif if (Watchdog) { if (MaxTime==0) { |