diff options
Diffstat (limited to 'lib/Module')
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 33 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 34 | ||||
-rw-r--r-- | lib/Module/RaiseAsm.cpp | 10 |
3 files changed, 73 insertions, 4 deletions
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) |