From 347795c5d2dbc2815d395e60a08ad3debca68102 Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Fri, 7 Feb 2014 21:04:22 +0100 Subject: Use SmallString and llvm::sys::path/fs API of LLVM 3.4 because Old Path API was removed --- lib/Module/KModule.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/Module') diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 2ecb14b8..5f03728b 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -375,6 +375,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, // FIXME: Find a way that we can test programs without requiring // this to be linked in, it makes low level debugging much more // annoying. +#if LLVM_VERSION_CODE >= LLVM_VERSION(3,4) + SmallString<128> LibPath(opts.LibraryDir); + llvm::sys::path::append(LibPath, "kleeRuntimeIntrinsic.bc"); + module = linkWithLibrary(module, LibPath.str()); +#else llvm::sys::Path path(opts.LibraryDir); #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) path.appendComponent("kleeRuntimeIntrinsic.bc"); @@ -382,6 +387,7 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, path.appendComponent("libkleeRuntimeIntrinsic.bca"); #endif module = linkWithLibrary(module, path.c_str()); +#endif // Add internal functions which are not used to check if instructions // have been already visited -- cgit 1.4.1 From f2ce7b5b53d78c370b01f5f219df0ea0021c7bb2 Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Mon, 10 Feb 2014 08:56:56 +0100 Subject: Add missing include file for LLVM 3.4 --- lib/Module/ModuleUtil.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/Module') diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index 58096de4..4f65d0e7 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -13,6 +13,10 @@ #include "../Core/Common.h" #include "../Core/SpecialFunctionHandler.h" +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) +#include "llvm/IR/LLVMContext.h" +#endif + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Function.h" -- cgit 1.4.1 From 4a9a908739d7d7c833e7985ea7465d95c0dd0b82 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 2 Apr 2014 21:44:51 +0100 Subject: Tidy up code by using LLVM's V2 path API only and removing uses of old V1 path API. LLVM2.9 supports LLVM's V2 path API. Because that is the minimum version we support we should just use this API everywhere so we reduce the number of #if LLVM_VERSION_CODE macros and duplicated code. --- lib/Core/StatsTracker.cpp | 28 ++------ lib/Module/KModule.cpp | 17 ++--- tools/klee/main.cpp | 173 +++------------------------------------------- 3 files changed, 25 insertions(+), 193 deletions(-) (limited to 'lib/Module') diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index fde2eae8..1bb9885a 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -49,9 +49,7 @@ #include "llvm/Support/raw_os_ostream.h" #include "llvm/Support/Process.h" #include "llvm/Support/Path.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) #include "llvm/Support/FileSystem.h" -#endif #include #include @@ -183,27 +181,15 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename, updateMinDistToUncovered(_updateMinDistToUncovered) { KModule *km = executor.kmodule; -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 1) - if (!sys::Path(objectFilename).isAbsolute()) { -#else if (!sys::path::is_absolute(objectFilename)) { -#endif - -#if LLVM_VERSION_CODE < LLVM_VERSION(3,4) - sys::Path current = sys::Path::GetCurrentDirectory(); - current.appendComponent(objectFilename); -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 1) - if (current.exists()) -#else - if (sys::fs::exists(current.c_str())) -#endif - objectFilename = current.c_str(); -#else SmallString<128> current(objectFilename); - if(sys::fs::make_absolute(current) && sys::fs::exists(current.str())) - objectFilename = current.c_str(); -#endif - + if(sys::fs::make_absolute(current)) { + bool exists = false; + error_code ec = sys::fs::exists(current.str(), exists); + if (ec == errc::success && exists) { + objectFilename = current.c_str(); + } + } } if (OutputIStats) diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 5f03728b..e06e722a 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -375,19 +375,16 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, // FIXME: Find a way that we can test programs without requiring // this to be linked in, it makes low level debugging much more // annoying. -#if LLVM_VERSION_CODE >= LLVM_VERSION(3,4) + SmallString<128> LibPath(opts.LibraryDir); - llvm::sys::path::append(LibPath, "kleeRuntimeIntrinsic.bc"); - module = linkWithLibrary(module, LibPath.str()); -#else - llvm::sys::Path path(opts.LibraryDir); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) - path.appendComponent("kleeRuntimeIntrinsic.bc"); + llvm::sys::path::append(LibPath, +#if LLVM_VERSION_CODE >= LLVM_VERSION(3,3) + "kleeRuntimeIntrinsic.bc" #else - path.appendComponent("libkleeRuntimeIntrinsic.bca"); -#endif - module = linkWithLibrary(module, path.c_str()); + "libkleeRuntimeIntrinsic.bca" #endif + ); + module = linkWithLibrary(module, LibPath.str()); // Add internal functions which are not used to check if instructions // have been already visited diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp index e1219747..ff90a644 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -37,6 +37,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/raw_ostream.h" // FIXME: Ugh, this is gross. But otherwise our config.h conflicts with LLVMs. #undef PACKAGE_BUGREPORT @@ -222,11 +223,8 @@ private: TreeStreamWriter *m_pathWriter, *m_symPathWriter; std::ostream *m_infoFile; -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) SmallString<128> m_outputDirectory; -#else - sys::Path m_outputDirectory; -#endif + unsigned m_testIndex; // number of tests written so far unsigned m_pathsExplored; // number of paths explored so far @@ -265,11 +263,7 @@ public: static void getOutFiles(std::string path, std::vector &results); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) static std::string getRunTimeLibraryPath(const char* argv0, void *MainExecAddr); -#else - static llvm::sys::Path getRunTimeLibraryPath(const char* argv0, void *MainExecAddr); -#endif }; KleeHandler::KleeHandler(int argc, char **argv) @@ -283,7 +277,6 @@ KleeHandler::KleeHandler(int argc, char **argv) m_argc(argc), m_argv(argv) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) if (OutputDir=="") { SmallString<128> directory(InputFile); @@ -346,72 +339,6 @@ KleeHandler::KleeHandler(int argc, char **argv) sys::path::append(cwd, m_outputDirectory.str()); m_outputDirectory = cwd; } -#else - if (OutputDir=="") { - - llvm::sys::Path directory(InputFile); - std::stringstream dirname; - directory.eraseComponent(); - - if (directory.isEmpty()) - directory.set("."); - - for (int i = 0; i< INT_MAX ; i++) { - dirname << "klee-out-"; - dirname << i; - - m_outputDirectory = llvm::sys::Path(directory); // Copy - if (!m_outputDirectory.appendComponent(dirname.str())) - klee_error("Failed to append \"%s\" to \"%s\"", dirname.str().c_str(), directory.c_str()); - - bool isDir = true; - llvm::error_code e = llvm::sys::fs::exists(m_outputDirectory.str(), isDir); - if ( e != llvm::errc::success ) - klee_error("Failed to check if \"%s\" exists.", m_outputDirectory.str().c_str()); - - if (!isDir) - { - break; // Found an available directory name - } - - // Warn the user if the klee-out-* exists but is not a directory - e = llvm::sys::fs::is_directory(m_outputDirectory.str(), isDir); - if ( e == llvm::errc::success && !isDir ) - klee_warning("A file \"%s\" exists, but it is not a directory", - m_outputDirectory.str().c_str()); - - dirname.str(""); // Clear - m_outputDirectory.clear(); - } - - if (m_outputDirectory.empty()) - klee_error("Failed to find available output directory in %s", dirname.str().c_str()); - - std::cerr << "KLEE: output directory = \"" << dirname.str() << "\"\n"; - - llvm::sys::Path klee_last(directory); - if(!klee_last.appendComponent("klee-last")) - klee_error("cannot create path name for klee-last"); - - if ((unlink(klee_last.c_str()) < 0) && (errno != ENOENT)) - klee_error("cannot unlink klee-last: %s", strerror(errno)); - - if (symlink(dirname.str().c_str(), klee_last.c_str()) < 0) - klee_error("cannot create klee-last symlink: %s", strerror(errno)); - - } else { - if (!m_outputDirectory.set(OutputDir)) - klee_error("cannot use klee output directory: %s", OutputDir.c_str()); - } - - if (!sys::path::is_absolute(m_outputDirectory.c_str())) { - sys::Path cwd = sys::Path::GetCurrentDirectory(); - if(!cwd.appendComponent( m_outputDirectory.c_str())) - klee_error("cannot create absolute path name for output directory"); - - m_outputDirectory = cwd; - } -#endif if (mkdir(m_outputDirectory.c_str(), 0775) < 0) klee_error("cannot create directory \"%s\": %s", m_outputDirectory.c_str(), strerror(errno)); @@ -452,18 +379,9 @@ void KleeHandler::setInterpreter(Interpreter *i) { } std::string KleeHandler::getOutputFilename(const std::string &filename) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) SmallString<128> path = m_outputDirectory; sys::path::append(path,filename); return path.str(); -#else - sys::Path path(m_outputDirectory); - if(!path.appendComponent(filename)) { - klee_error("cannot create path name for \"%s\"", filename.c_str()); - } - - return path.str(); -#endif } std::ostream *KleeHandler::openOutputFile(const std::string &filename) { @@ -637,7 +555,6 @@ void KleeHandler::loadPathFile(std::string name, void KleeHandler::getOutFiles(std::string path, std::vector &results) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) error_code ec; for (llvm::sys::fs::directory_iterator i(path,ec),e; i!=e && !ec; i.increment(ec)){ std::string f = (*i).path(); @@ -651,37 +568,17 @@ void KleeHandler::getOutFiles(std::string path, << ": " << ec.message() << "\n"; exit(1); } -#else - - llvm::sys::Path p(path); - std::set contents; - std::string error; - if (p.getDirectoryContents(contents, &error)) { - std::cerr << "ERROR: unable to read output directory: " << path - << ": " << error << "\n"; - exit(1); - } - for (std::set::iterator it = contents.begin(), - ie = contents.end(); it != ie; ++it) { - std::string f = it->str(); - if (f.substr(f.size()-6,f.size()) == ".ktest") { - results.push_back(f); - } - } -#endif - } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) -std::string -#else -llvm::sys::Path -#endif -KleeHandler::getRunTimeLibraryPath(const char* argv0, void* MainExecAddr) +std::string KleeHandler::getRunTimeLibraryPath(const char* argv0, void* MainExecAddr) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) SmallString<128> toolRoot( - llvm::sys::fs::getMainExecutable(argv0, MainExecAddr)); + #if LLVM_VERSION_CODE >= LLVM_VERSION(3,4) + llvm::sys::fs::getMainExecutable(argv0, MainExecAddr) + #else + llvm::sys::Path::GetMainExecutable(argv0, MainExecAddr).str() + #endif + ); // Strip off executable so we have a directory path llvm::sys::path::remove_filename(toolRoot); @@ -706,29 +603,6 @@ KleeHandler::getRunTimeLibraryPath(const char* argv0, void* MainExecAddr) DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << libDir.c_str() << "\n"); return libDir.str(); -#else - llvm::sys::Path toolRoot = llvm::sys::Path::GetMainExecutable(argv0, MainExecAddr); - toolRoot.eraseComponent(); // Strip off executable so we have a directory path - - llvm::sys::Path libDir; - - if ( strcmp(toolRoot.c_str(), KLEE_INSTALL_BIN_DIR ) == 0) - { - DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << - "Using installed KLEE library runtime: "); - libDir = llvm::sys::Path( KLEE_INSTALL_LIB_DIR ); - } - else - { - DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << - "Using build directory KLEE library runtime :"); - libDir = llvm::sys::Path(KLEE_DIR "/" RUNTIME_CONFIGURATION "/lib"); - } - - DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() << - libDir.c_str() << "\n"); - return libDir; -#endif } //===----------------------------------------------------------------------===// @@ -1162,20 +1036,10 @@ static void replaceOrRenameFunction(llvm::Module *module, } } } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) { -#else -static llvm::Module *linkWithUclibc(llvm::Module *mainModule, llvm::sys::Path libDir) { -#endif - // Ensure that klee-uclibc exists -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) SmallString<128> uclibcBCA(libDir); llvm::sys::path::append(uclibcBCA, KLEE_UCLIBC_BCA_NAME); -#else - llvm::sys::Path uclibcBCA(libDir); - uclibcBCA.appendComponent(KLEE_UCLIBC_BCA_NAME); -#endif bool uclibcExists=false; llvm::sys::fs::exists(uclibcBCA.c_str(), uclibcExists); @@ -1401,13 +1265,8 @@ int main(int argc, char **argv, char **envp) { return r; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) std::string LibraryDir = KleeHandler::getRunTimeLibraryPath(argv[0], reinterpret_cast(main)); -#else - llvm::sys::Path LibraryDir = KleeHandler::getRunTimeLibraryPath(argv[0], - reinterpret_cast(main)); -#endif Interpreter::ModuleOptions Opts(LibraryDir.c_str(), /*Optimize=*/OptimizeModule, /*CheckDivZero=*/CheckDivZero, @@ -1419,16 +1278,11 @@ int main(int argc, char **argv, char **envp) { case KleeLibc: { // FIXME: Find a reasonable solution for this. -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) SmallString<128> Path(Opts.LibraryDir); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3,3) llvm::sys::path::append(Path, "klee-libc.bc"); #else - llvm::sys::Path Path(Opts.LibraryDir); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) - Path.appendComponent("klee-libc.bc"); -#else - Path.appendComponent("libklee-libc.bca"); -#endif + llvm::sys::path::append(Path, "libklee-libc.bca"); #endif mainModule = klee::linkWithLibrary(mainModule, Path.c_str()); assert(mainModule && "unable to link with klee-libc"); @@ -1441,13 +1295,8 @@ int main(int argc, char **argv, char **envp) { } if (WithPOSIXRuntime) { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) SmallString<128> Path(Opts.LibraryDir); llvm::sys::path::append(Path, "libkleeRuntimePOSIX.bca"); -#else - llvm::sys::Path Path(Opts.LibraryDir); - Path.appendComponent("libkleeRuntimePOSIX.bca"); -#endif klee_message("NOTE: Using model: %s", Path.c_str()); mainModule = klee::linkWithLibrary(mainModule, Path.c_str()); assert(mainModule && "unable to link with simple model"); -- cgit 1.4.1 From f8f8da3c374ac926e8d0eca4cca83d8a8a095b26 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 3 Apr 2014 15:30:52 +0100 Subject: Do not add SimplifyLibCallsPass for LLVM 3.4 and newer because it has been removed. From the LLVM 3.4 release notes: " The library call simplification pass has been removed. Its functionality has been integrated into the instruction combiner and function attribute marking passes. " --- lib/Module/Optimize.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/Module') diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index 41a106f1..9c200bc8 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -124,7 +124,9 @@ static void AddStandardCompilePasses(PassManager &PM) { addPass(PM, createFunctionInliningPass()); // Inline small functions addPass(PM, createArgumentPromotionPass()); // Scalarize uninlined fn args +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 4) addPass(PM, createSimplifyLibCallsPass()); // Library Call Optimizations +#endif addPass(PM, createInstructionCombiningPass()); // Cleanup for scalarrepl. addPass(PM, createJumpThreadingPass()); // Thread jumps. addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs -- cgit 1.4.1