diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2011-07-20 18:36:48 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2011-07-20 18:36:48 +0000 |
commit | b640fcf217c848ad051977018c6dc8f3a5a37e1f (patch) | |
tree | 70c49e15714efdd13bfa096352701638c3b23db1 /lib | |
parent | ed9ea0cf9dc856920afc6813fa1bea0ec7660ba1 (diff) | |
download | klee-b640fcf217c848ad051977018c6dc8f3a5a37e1f.tar.gz |
Updates for LLVM 3.0. Based on changes by arrowdodger, thanks!
git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@135598 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Core/Executor.cpp | 30 | ||||
-rw-r--r-- | lib/Core/Executor.h | 8 | ||||
-rw-r--r-- | lib/Core/ExecutorUtil.cpp | 6 | ||||
-rw-r--r-- | lib/Core/ExternalDispatcher.cpp | 14 | ||||
-rw-r--r-- | lib/Module/KModule.cpp | 15 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 2 | ||||
-rw-r--r-- | lib/Module/Passes.h | 4 | ||||
-rw-r--r-- | lib/Module/RaiseAsm.cpp | 11 |
8 files changed, 56 insertions, 34 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index e46ff9b0..48a8b57a 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -376,10 +376,10 @@ Executor::~Executor() { /***/ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os, - Constant *c, + const Constant *c, unsigned offset) { TargetData *targetData = kmodule->targetData; - if (ConstantVector *cp = dyn_cast<ConstantVector>(c)) { + if (const ConstantVector *cp = dyn_cast<ConstantVector>(c)) { unsigned elementSize = targetData->getTypeStoreSize(cp->getType()->getElementType()); for (unsigned i=0, e=cp->getNumOperands(); i != e; ++i) @@ -389,13 +389,13 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os, unsigned i, size = targetData->getTypeStoreSize(c->getType()); for (i=0; i<size; i++) os->write8(offset+i, (uint8_t) 0); - } else if (ConstantArray *ca = dyn_cast<ConstantArray>(c)) { + } else if (const ConstantArray *ca = dyn_cast<ConstantArray>(c)) { unsigned elementSize = targetData->getTypeStoreSize(ca->getType()->getElementType()); for (unsigned i=0, e=ca->getNumOperands(); i != e; ++i) initializeGlobalObject(state, os, ca->getOperand(i), offset + i*elementSize); - } else if (ConstantStruct *cs = dyn_cast<ConstantStruct>(c)) { + } else if (const ConstantStruct *cs = dyn_cast<ConstantStruct>(c)) { const StructLayout *sl = targetData->getStructLayout(cast<StructType>(cs->getType())); for (unsigned i=0, e=cs->getNumOperands(); i != e; ++i) @@ -501,7 +501,7 @@ void Executor::initializeGlobals(ExecutionState &state) { // better we could support user definition, or use the EXE style // hack where we check the object file information. - const Type *ty = i->getType()->getElementType(); + LLVM_TYPE_Q Type *ty = i->getType()->getElementType(); uint64_t size = kmodule->targetData->getTypeStoreSize(ty); // XXX - DWD - hardcode some things until we decide how to fix. @@ -544,7 +544,7 @@ void Executor::initializeGlobals(ExecutionState &state) { os->write8(offset, ((unsigned char*)addr)[offset]); } } else { - const Type *ty = i->getType()->getElementType(); + LLVM_TYPE_Q Type *ty = i->getType()->getElementType(); uint64_t size = kmodule->targetData->getTypeStoreSize(ty); MemoryObject *mo = 0; @@ -931,8 +931,8 @@ void Executor::addConstraint(ExecutionState &state, ref<Expr> condition) { ConstantExpr::alloc(1, Expr::Bool)); } -ref<klee::ConstantExpr> Executor::evalConstant(Constant *c) { - if (llvm::ConstantExpr *ce = dyn_cast<llvm::ConstantExpr>(c)) { +ref<klee::ConstantExpr> Executor::evalConstant(const Constant *c) { + if (const llvm::ConstantExpr *ce = dyn_cast<llvm::ConstantExpr>(c)) { return evalConstantExpr(ce); } else { if (const ConstantInt *ci = dyn_cast<ConstantInt>(c)) { @@ -1375,7 +1375,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { } if (!isVoidReturn) { - const Type *t = caller->getType(); + LLVM_TYPE_Q Type *t = caller->getType(); if (t != Type::getVoidTy(getGlobalContext())) { // may need to do coercion due to bitcasts Expr::Width from = result->getWidth(); @@ -1462,7 +1462,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(cond)) { // Somewhat gross to create these all the time, but fine till we // switch to an internal rep. - const llvm::IntegerType *Ty = + LLVM_TYPE_Q llvm::IntegerType *Ty = cast<IntegerType>(si->getCondition()->getType()); ConstantInt *ci = ConstantInt::get(Ty, CE->getZExtValue()); unsigned index = si->findCaseValue(ci); @@ -1627,7 +1627,11 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { break; } case Instruction::PHI: { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) + ref<Expr> result = eval(ki, state.incomingBBIndex, state).value; +#else ref<Expr> result = eval(ki, state.incomingBBIndex * 2, state).value; +#endif bindLocal(ki, state, result); break; } @@ -2303,7 +2307,7 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) { ConstantExpr::alloc(0, Context::get().getPointerWidth()); uint64_t index = 1; for (TypeIt ii = ib; ii != ie; ++ii) { - if (const StructType *st = dyn_cast<StructType>(*ii)) { + if (LLVM_TYPE_Q StructType *st = dyn_cast<StructType>(*ii)) { const StructLayout *sl = kmodule->targetData->getStructLayout(st); const ConstantInt *ci = cast<ConstantInt>(ii.getOperand()); uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue()); @@ -2713,7 +2717,7 @@ void Executor::callExternalFunction(ExecutionState &state, return; } - const Type *resultType = target->inst->getType(); + LLVM_TYPE_Q Type *resultType = target->inst->getType(); if (resultType != Type::getVoidTy(getGlobalContext())) { ref<Expr> e = ConstantExpr::fromMemory((void*) args, getWidthForLLVMType(resultType)); @@ -3360,7 +3364,7 @@ void Executor::doImpliedValueConcretization(ExecutionState &state, } } -Expr::Width Executor::getWidthForLLVMType(const llvm::Type *type) const { +Expr::Width Executor::getWidthForLLVMType(LLVM_TYPE_Q llvm::Type *type) const { return kmodule->targetData->getTypeSizeInBits(type); } diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h index 3a0fa139..3df4cc88 100644 --- a/lib/Core/Executor.h +++ b/lib/Core/Executor.h @@ -184,7 +184,7 @@ private: unsigned size, bool isReadOnly); void initializeGlobalObject(ExecutionState &state, ObjectState *os, - llvm::Constant *c, + const llvm::Constant *c, unsigned offset); void initializeGlobals(ExecutionState &state); @@ -309,7 +309,7 @@ private: ExecutionState &state, ref<Expr> value); - ref<klee::ConstantExpr> evalConstantExpr(llvm::ConstantExpr *ce); + ref<klee::ConstantExpr> evalConstantExpr(const llvm::ConstantExpr *ce); /// Return a unique constant value for the given expression in the /// given state, if it has one (i.e. it provably only has a single @@ -390,7 +390,7 @@ public: } // XXX should just be moved out to utility module - ref<klee::ConstantExpr> evalConstant(llvm::Constant *c); + ref<klee::ConstantExpr> evalConstant(const llvm::Constant *c); virtual void setPathWriter(TreeStreamWriter *tsw) { pathWriter = tsw; @@ -452,7 +452,7 @@ public: virtual void getCoveredLines(const ExecutionState &state, std::map<const std::string*, std::set<unsigned> > &res); - Expr::Width getWidthForLLVMType(const llvm::Type *type) const; + Expr::Width getWidthForLLVMType(LLVM_TYPE_Q llvm::Type *type) const; }; } // End klee namespace diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp index 02f18bb4..6ab021c1 100644 --- a/lib/Core/ExecutorUtil.cpp +++ b/lib/Core/ExecutorUtil.cpp @@ -37,8 +37,8 @@ using namespace llvm; namespace klee { - ref<ConstantExpr> Executor::evalConstantExpr(llvm::ConstantExpr *ce) { - const llvm::Type *type = ce->getType(); + ref<ConstantExpr> Executor::evalConstantExpr(const llvm::ConstantExpr *ce) { + LLVM_TYPE_Q llvm::Type *type = ce->getType(); ref<ConstantExpr> op1(0), op2(0), op3(0); int numOperands = ce->getNumOperands(); @@ -87,7 +87,7 @@ namespace klee { ref<ConstantExpr> addend = ConstantExpr::alloc(0, Context::get().getPointerWidth()); - if (const StructType *st = dyn_cast<StructType>(*ii)) { + if (LLVM_TYPE_Q StructType *st = dyn_cast<StructType>(*ii)) { const StructLayout *sl = kmodule->targetData->getStructLayout(st); const ConstantInt *ci = cast<ConstantInt>(ii.getOperand()); diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp index 5c03e42d..c876685e 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -209,7 +209,7 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in Value **args = new Value*[cs.arg_size()]; - std::vector<const Type*> nullary; + std::vector<LLVM_TYPE_Q Type*> nullary; Function *dispatcher = Function::Create(FunctionType::get(Type::getVoidTy(getGlobalContext()), nullary, false), @@ -229,7 +229,7 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in Instruction *argI64s = new LoadInst(argI64sp, "args", dBB); // Get the target function type. - const FunctionType *FTy = + LLVM_TYPE_Q FunctionType *FTy = cast<FunctionType>(cast<PointerType>(target->getType())->getElementType()); // Each argument will be passed by writing it into gTheArgsP[i]. @@ -239,8 +239,8 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in // Determine the type the argument will be passed as. This accomodates for // the corresponding code in Executor.cpp for handling calls to bitcasted // functions. - const Type *argTy = (i < FTy->getNumParams() ? FTy->getParamType(i) : - (*ai)->getType()); + LLVM_TYPE_Q Type *argTy = (i < FTy->getNumParams() ? FTy->getParamType(i) : + (*ai)->getType()); Instruction *argI64p = GetElementPtrInst::Create(argI64s, ConstantInt::get(Type::getInt32Ty(getGlobalContext()), @@ -258,7 +258,13 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in Constant *dispatchTarget = dispatchModule->getOrInsertFunction(target->getName(), FTy, target->getAttributes()); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) + Instruction *result = CallInst::Create(dispatchTarget, + llvm::ArrayRef<Value *>(args, args+i), + "", dBB); +#else Instruction *result = CallInst::Create(dispatchTarget, args, args+i, "", dBB); +#endif if (result->getType() != Type::getVoidTy(getGlobalContext())) { Instruction *resp = new BitCastInst(argI64s, PointerType::getUnqual(result->getType()), diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 94c3d05b..a569242e 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -122,7 +122,7 @@ static Function *getStubFunctionForCtorList(Module *m, assert(!gv->isDeclaration() && !gv->hasInternalLinkage() && "do not support old LLVM style constructor/destructor lists"); - std::vector<const Type*> nullary; + std::vector<LLVM_TYPE_Q Type*> nullary; Function *fn = Function::Create(FunctionType::get(Type::getVoidTy(getGlobalContext()), nullary, false), @@ -181,7 +181,8 @@ static void injectStaticConstructorsAndDestructors(Module *m) { } } -static void forceImport(Module *m, const char *name, const Type *retType, ...) { +static void forceImport(Module *m, const char *name, LLVM_TYPE_Q Type *retType, + ...) { // If module lacks an externally visible symbol for the name then we // need to create one. We have to look in the symbol table because // we want to check everything (global variables, functions, and @@ -194,8 +195,8 @@ static void forceImport(Module *m, const char *name, const Type *retType, ...) { va_list ap; va_start(ap, retType); - std::vector<const Type *> argTypes; - while (const Type *t = va_arg(ap, const Type*)) + std::vector<LLVM_TYPE_Q Type *> argTypes; + while (LLVM_TYPE_Q Type *t = va_arg(ap, LLVM_TYPE_Q Type*)) argTypes.push_back(t); va_end(ap); @@ -208,9 +209,9 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, if (!MergeAtExit.empty()) { Function *mergeFn = module->getFunction("klee_merge"); if (!mergeFn) { - const llvm::FunctionType *Ty = + LLVM_TYPE_Q llvm::FunctionType *Ty = FunctionType::get(Type::getVoidTy(getGlobalContext()), - std::vector<const Type*>(), false); + std::vector<LLVM_TYPE_Q Type*>(), false); mergeFn = Function::Create(Ty, GlobalVariable::ExternalLinkage, "klee_merge", module); @@ -280,7 +281,7 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, // by name. We only add them if such a function doesn't exist to // avoid creating stale uses. - const llvm::Type *i8Ty = Type::getInt8Ty(getGlobalContext()); + LLVM_TYPE_Q llvm::Type *i8Ty = Type::getInt8Ty(getGlobalContext()); forceImport(module, "memcpy", PointerType::getUnqual(i8Ty), PointerType::getUnqual(i8Ty), PointerType::getUnqual(i8Ty), diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index e0ae4d99..524f80e2 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -158,7 +158,9 @@ static void AddStandardCompilePasses(PassManager &PM) { addPass(PM, createAggressiveDCEPass()); // Delete dead instructions addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs addPass(PM, createStripDeadPrototypesPass()); // Get rid of dead prototypes +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0) addPass(PM, createDeadTypeEliminationPass()); // Eliminate dead types +#endif addPass(PM, createConstantMergePass()); // Merge dup global constants } diff --git a/lib/Module/Passes.h b/lib/Module/Passes.h index 480fbde6..6257da8f 100644 --- a/lib/Module/Passes.h +++ b/lib/Module/Passes.h @@ -40,11 +40,11 @@ class RaiseAsmPass : public llvm::ModulePass { llvm::Function *getIntrinsic(llvm::Module &M, unsigned IID, - const llvm::Type **Tys, + LLVM_TYPE_Q llvm::Type **Tys, unsigned NumTys); llvm::Function *getIntrinsic(llvm::Module &M, unsigned IID, - const llvm::Type *Ty0) { + LLVM_TYPE_Q llvm::Type *Ty0) { return getIntrinsic(M, IID, &Ty0, 1); } diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp index 8f862ffa..6f6a5c90 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -28,9 +28,14 @@ char RaiseAsmPass::ID = 0; Function *RaiseAsmPass::getIntrinsic(llvm::Module &M, unsigned IID, - const Type **Tys, + LLVM_TYPE_Q Type **Tys, unsigned NumTys) { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) + return Intrinsic::getDeclaration(&M, (llvm::Intrinsic::ID) IID, + llvm::ArrayRef<llvm::Type*>(Tys, NumTys)); +#else return Intrinsic::getDeclaration(&M, (llvm::Intrinsic::ID) IID, Tys, NumTys); +#endif } // FIXME: This should just be implemented as a patch to @@ -87,7 +92,11 @@ bool RaiseAsmPass::runOnModule(Module &M) { llvm::errs() << "Warning: unable to select native target: " << Err << "\n"; TLI = 0; } else { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) + TargetMachine *TM = NativeTarget->createTargetMachine(HostTriple, "", ""); +#else TargetMachine *TM = NativeTarget->createTargetMachine(HostTriple, ""); +#endif TLI = TM->getTargetLowering(); } #endif |