klee/0007-llvm-make-KLEE-compile-against-LLVM-3.9.patch

290 lines
11 KiB
Diff
Raw Normal View History

From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 22 Feb 2017 15:57:55 +0100
Subject: llvm: make KLEE compile against LLVM 3.9
Patch-mainline: no
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Core/Executor.cpp | 16 ++++++++++++++++
lib/Core/MemoryManager.cpp | 5 ++++-
lib/Module/ModuleUtil.cpp | 33 ++++++++++++++++++++++++++++++---
lib/Module/Optimize.cpp | 28 ++++++++++++++++++++++++++++
lib/Module/RaiseAsm.cpp | 10 +++++++++-
tools/kleaver/main.cpp | 4 ++++
tools/klee/main.cpp | 4 ++++
7 files changed, 95 insertions(+), 5 deletions(-)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 65f75ef6dde8..d0f1b8caaaec 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1302,10 +1302,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
}
}
@@ -1338,10 +1346,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 24e2ed97581f..f40e8bc9deb8 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 9068a6b40f73..17595716136b 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -196,7 +196,11 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading modules\n");
// Load all bitcode files in to memory so we can examine their symbols
-#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)
#else
@@ -236,7 +240,14 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
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 =
+ childErr->getAsBinary();
+ if (!child) {
+ ec = errorToErrorCode(child.takeError());
+ consumeError(child.takeError());
+ }
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
ErrorOr<std::unique_ptr<llvm::object::Binary> > child =
childErr->getAsBinary();
ec = child.getError();
@@ -319,6 +330,13 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
}
}
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ if (Err) {
+ SS << "Cannot iterate over archive";
+ SS.flush();
+ return false;
+ }
+#endif
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loaded " << archiveModules.size() << " modules\n");
@@ -490,7 +508,12 @@ Module *klee::linkWithLibrary(Module *module,
#endif
} else 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> > arch =
+ object::createBinary(Buffer, &Context);
+ if (!arch)
+ ec = errorToErrorCode(arch.takeError());
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
ErrorOr<std::unique_ptr<object::Binary> > arch =
object::createBinary(Buffer, &Context);
ec = arch.getError();
@@ -548,7 +571,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;
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index 944f51ef336d..ae1d4839f772 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -35,6 +35,11 @@
#include "llvm/Analysis/Verifier.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
@@ -103,7 +108,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());
#else
addPass(PM, createFunctionAttrsPass()); // Deduce function attrs
@@ -116,7 +125,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
@@ -179,8 +192,15 @@ void Optimize(Module *M, const std::string &EntryPoint) {
// for a main function. If main is defined, mark all other functions
// internal.
if (!DisableInternalize) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ auto PreserveEP = [=](const GlobalValue &GV) {
+ return GV.getName().equals(EntryPoint);
+ };
+ ModulePass *pass = createInternalizePass(PreserveEP);
+#else
ModulePass *pass = createInternalizePass(
std::vector<const char *>(1, EntryPoint.c_str()));
+#endif
addPass(Passes, pass);
}
@@ -219,11 +239,19 @@ void Optimize(Module *M, const std::string &EntryPoint) {
// 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());
// addPass(Passes, createGlobalsAAWrapperPass());
#else
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index e56ac4687e30..0557ae7f250e 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 b8b32e31264a..800cece95e9c 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 e61b86b54d89..b15cb1deb0a1 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -1128,7 +1128,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) {
--
2.14.1