diff options
Diffstat (limited to 'lib/Module')
-rw-r--r-- | lib/Module/Checks.cpp | 1 | ||||
-rw-r--r-- | lib/Module/InstructionInfoTable.cpp | 50 | ||||
-rw-r--r-- | lib/Module/KModule.cpp | 56 | ||||
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 15 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 19 |
5 files changed, 65 insertions, 76 deletions
diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp index e1076d43..7d9b7284 100644 --- a/lib/Module/Checks.cpp +++ b/lib/Module/Checks.cpp @@ -45,7 +45,6 @@ #include "llvm/Pass.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" -#include "llvm/Support/CallSite.h" using namespace llvm; using namespace klee; diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp index 8d27e426..7e9a9e26 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -21,17 +21,28 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" #endif -#include "llvm/Linker.h" + +# if LLVM_VERSION_CODE < LLVM_VERSION(3,5) #include "llvm/Assembly/AssemblyAnnotationWriter.h" -#include "llvm/Support/FormattedStream.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/InstIterator.h" +#include "llvm/Linker.h" +#else +#include "llvm/IR/AssemblyAnnotationWriter.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/Linker/Linker.h" +#endif + +#include "llvm/Support/FormattedStream.h" #include "llvm/Support/raw_ostream.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) + +#if LLVM_VERSION_CODE >= LLVM_VERSION(3,5) +#include "llvm/IR/DebugInfo.h" +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) #include "llvm/DebugInfo.h" #else #include "llvm/Analysis/DebugInfo.h" #endif + #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/ErrorHandling.h" @@ -110,22 +121,31 @@ InstructionInfoTable::InstructionInfoTable(Module *m) for (Module::iterator fnIt = m->begin(), fn_ie = m->end(); fnIt != fn_ie; ++fnIt) { + // We want to ensure that as all instructions have source information, if + // available. Clang sometimes will not write out debug information on the + // initial instructions in a function (correspond to the formal parameters), + // so we first search forward to find the first instruction with debug info, + // if any. + const std::string *initialFile = &dummyString; + unsigned initialLine = 0; + for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; + ++it) { + if (getInstructionDebugInfo(&*it, initialFile, initialLine)) + break; + } + + const std::string *file = initialFile; + unsigned line = initialLine; for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; ++it) { - const std::string *initialFile = &dummyString; - unsigned initialLine = 0; Instruction *instr = &*it; - unsigned assemblyLine = 0; + unsigned assemblyLine = lineTable[instr]; + + // Update our source level debug information. + getInstructionDebugInfo(instr, file, line); - std::map<const Instruction*, unsigned>::const_iterator ltit = - lineTable.find(instr); - if (ltit!=lineTable.end()) - assemblyLine = ltit->second; - getInstructionDebugInfo(instr, initialFile, initialLine); infos.insert(std::make_pair(instr, - InstructionInfo(id++, - *initialFile, - initialLine, + InstructionInfo(id++, *file, line, assemblyLine))); } } diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 57e0c4fe..1334b58c 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -10,6 +10,7 @@ // FIXME: This does not belong here. #include "../Core/Common.h" +#define DEBUG_TYPE "KModule" #include "klee/Internal/Module/KModule.h" #include "Passes.h" @@ -42,8 +43,13 @@ #endif -#include "llvm/PassManager.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) #include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + +#include "llvm/PassManager.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_os_ostream.h" @@ -51,7 +57,6 @@ #include "llvm/Transforms/Scalar.h" #include <llvm/Transforms/Utils/Cloning.h> -#include <llvm/Support/InstIterator.h> #include <sstream> @@ -224,56 +229,11 @@ static void forceImport(Module *m, const char *name, LLVM_TYPE_Q Type *retType, } #endif -/// This function will take try to inline all calls to \p functionName -/// in the module \p module . -/// -/// It is intended that this function be used for inling calls to -/// check functions like <tt>klee_div_zero_check()</tt> -static void inlineChecks(Module *module, const char * functionName) { - std::vector<CallSite> checkCalls; - Function* runtimeCheckCall = module->getFunction(functionName); - if (runtimeCheckCall == 0) - { - KLEE_DEBUG(klee_warning("Failed to inline %s because no calls were made " - "to it in module", functionName)); - return; - } - - for (Value::use_iterator i = runtimeCheckCall->use_begin(), - e = runtimeCheckCall->use_end(); i != e; ++i) - if (isa<InvokeInst>(*i) || isa<CallInst>(*i)) { - CallSite cs(*i); - if (!cs.getCalledFunction()) - continue; - checkCalls.push_back(cs); - } - - unsigned int successCount=0; - unsigned int failCount=0; - InlineFunctionInfo IFI(0,0); - for ( std::vector<CallSite>::iterator ci = checkCalls.begin(), - cie = checkCalls.end(); - ci != cie; ++ci) - { - // Try to inline the function - if (InlineFunction(*ci,IFI)) - ++successCount; - else - { - ++failCount; - klee_warning("Failed to inline function %s", functionName); - } - } - - KLEE_DEBUG(klee_message("Tried to inline calls to %s. %u successes, " - "%u failures", functionName, successCount, - failCount)); -} void KModule::addInternalFunction(const char* functionName){ Function* internalFunction = module->getFunction(functionName); if (!internalFunction) { - KLEE_DEBUG_WITH_TYPE("KModule", klee_warning( + KLEE_DEBUG(klee_warning( "Failed to add internal function %s. Not found.", functionName)); return ; } diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index be1ea4c1..3811003e 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -41,15 +41,24 @@ #include "llvm/Module.h" #endif +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) #include "llvm/Linker.h" #include "llvm/Assembly/AssemblyAnnotationWriter.h" -#include "llvm/Support/CFG.h" -#include "llvm/Support/CallSite.h" -#include "llvm/Support/InstIterator.h" +#else +#include "llvm/Linker/Linker.h" +#include "llvm/IR/AssemblyAnnotationWriter.h" +#endif + #include "llvm/Support/raw_ostream.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/Path.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <map> #include <set> #include <fstream> diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index ed1e0e34..ce43cd96 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -19,7 +19,6 @@ #include "llvm/PassManager.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/LoopPass.h" -#include "llvm/Analysis/Verifier.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DynamicLibrary.h" @@ -35,19 +34,18 @@ #endif #endif +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#include "llvm/IR/Verifier.h" +#else +#include "llvm/Analysis/Verifier.h" +#endif + #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" -#include "llvm/Support/PassNameParser.h" #include "llvm/Support/PluginLoader.h" using namespace llvm; -#if 0 -// Pass Name Options as generated by the PassNameParser -static cl::list<const PassInfo*, bool, PassNameParser> - OptimizationList(cl::desc("Optimizations available:")); -#endif - // Don't verify at the end static cl::opt<bool> DontVerify("disable-verify", cl::ReallyHidden); @@ -177,9 +175,12 @@ void Optimize(Module* M) { #if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1) // Add an appropriate TargetData instance for this module... addPass(Passes, new TargetData(M)); -#else +#elif LLVM_VERSION_CODE < LLVM_VERSION(3, 5) // Add an appropriate DataLayout instance for this module... addPass(Passes, new DataLayout(M)); +#else + // Add an appropriate DataLayout instance for this module... + addPass(Passes, new DataLayoutPass(M)); #endif // DWD - Run the opt standard pass list as well. |