about summary refs log tree commit diff homepage
path: root/lib/Core
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2010-06-24 22:12:27 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2010-06-24 22:12:27 +0000
commit717c804da48ee71f4b5aeee3ac0ba6c62a537224 (patch)
tree374dc73d90103069466fd38de753cc3b0bd7ecc4 /lib/Core
parentb2f49b6d8578e4df8d33933fbe5b6c951f9150f1 (diff)
downloadklee-717c804da48ee71f4b5aeee3ac0ba6c62a537224.tar.gz
Use LLVM's TargetData::getTypeSizeInBits to determine type bitwidth instead of our own implementation
git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@106800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/Context.cpp12
-rw-r--r--lib/Core/Executor.cpp36
-rw-r--r--lib/Core/Executor.h2
-rw-r--r--lib/Core/ExecutorUtil.cpp10
4 files changed, 27 insertions, 33 deletions
diff --git a/lib/Core/Context.cpp b/lib/Core/Context.cpp
index 590b2080..45dbdca0 100644
--- a/lib/Core/Context.cpp
+++ b/lib/Core/Context.cpp
@@ -35,18 +35,6 @@ const Context &Context::get() {
 // FIXME: This is a total hack, just to avoid a layering issue until this stuff
 // moves out of Expr.
 
-Expr::Width Expr::getWidthForLLVMType(const llvm::Type *t) {
-  switch (t->getTypeID()) {
-  default:
-    assert(0 && "non-primitive type argument to Expr::getTypeForLLVMType()\n");
-  case llvm::Type::IntegerTyID: return cast<llvm::IntegerType>(t)->getBitWidth();
-  case llvm::Type::FloatTyID: return Expr::Int32;
-  case llvm::Type::DoubleTyID: return Expr::Int64;
-  case llvm::Type::X86_FP80TyID: return 80;
-  case llvm::Type::PointerTyID: return Context::get().getPointerWidth();
-  }
-}
-
 ref<Expr> Expr::createCoerceToPointerType(ref<Expr> e) {
   return ZExtExpr::create(e, Context::get().getPointerWidth());
 }
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 1da91f2a..b12caec0 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -940,7 +940,7 @@ ref<klee::ConstantExpr> Executor::evalConstant(Constant *c) {
     } else if (isa<ConstantPointerNull>(c)) {
       return Expr::createPointer(0);
     } else if (isa<UndefValue>(c)) {
-      return ConstantExpr::create(0, Expr::getWidthForLLVMType(c->getType()));
+      return ConstantExpr::create(0, getWidthForLLVMType(c->getType()));
     } else {
       // Constant{AggregateZero,Array,Struct,Vector}
       assert(0 && "invalid argument to evalConstant()");
@@ -1355,7 +1355,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
         if (t != Type::getVoidTy(getGlobalContext())) {
           // may need to do coercion due to bitcasts
           Expr::Width from = result->getWidth();
-          Expr::Width to = Expr::getWidthForLLVMType(t);
+          Expr::Width to = getWidthForLLVMType(t);
             
           if (from != to) {
             CallSite cs = (isa<InvokeInst>(caller) ? CallSite(cast<InvokeInst>(caller)) : 
@@ -1547,7 +1547,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
           Expr::Width to, from = (*ai)->getWidth();
             
           if (i<fType->getNumParams()) {
-            to = Expr::getWidthForLLVMType(fType->getParamType(i));
+            to = getWidthForLLVMType(fType->getParamType(i));
 
             if (from != to) {
               // XXX need to check other param attrs ?
@@ -1894,35 +1894,35 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
     CastInst *ci = cast<CastInst>(i);
     ref<Expr> result = ExtractExpr::create(eval(ki, 0, state).value,
                                            0,
-                                           Expr::getWidthForLLVMType(ci->getType()));
+                                           getWidthForLLVMType(ci->getType()));
     bindLocal(ki, state, result);
     break;
   }
   case Instruction::ZExt: {
     CastInst *ci = cast<CastInst>(i);
     ref<Expr> result = ZExtExpr::create(eval(ki, 0, state).value,
-                                        Expr::getWidthForLLVMType(ci->getType()));
+                                        getWidthForLLVMType(ci->getType()));
     bindLocal(ki, state, result);
     break;
   }
   case Instruction::SExt: {
     CastInst *ci = cast<CastInst>(i);
     ref<Expr> result = SExtExpr::create(eval(ki, 0, state).value,
-                                        Expr::getWidthForLLVMType(ci->getType()));
+                                        getWidthForLLVMType(ci->getType()));
     bindLocal(ki, state, result);
     break;
   }
 
   case Instruction::IntToPtr: {
     CastInst *ci = cast<CastInst>(i);
-    Expr::Width pType = Expr::getWidthForLLVMType(ci->getType());
+    Expr::Width pType = getWidthForLLVMType(ci->getType());
     ref<Expr> arg = eval(ki, 0, state).value;
     bindLocal(ki, state, ZExtExpr::create(arg, pType));
     break;
   } 
   case Instruction::PtrToInt: {
     CastInst *ci = cast<CastInst>(i);
-    Expr::Width iType = Expr::getWidthForLLVMType(ci->getType());
+    Expr::Width iType = getWidthForLLVMType(ci->getType());
     ref<Expr> arg = eval(ki, 0, state).value;
     bindLocal(ki, state, ZExtExpr::create(arg, iType));
     break;
@@ -2013,7 +2013,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::FPTrunc: {
     FPTruncInst *fi = cast<FPTruncInst>(i);
-    Expr::Width resultType = Expr::getWidthForLLVMType(fi->getType());
+    Expr::Width resultType = getWidthForLLVMType(fi->getType());
     ref<ConstantExpr> arg = toConstant(state, eval(ki, 0, state).value,
                                        "floating point");
     if (!fpWidthToSemantics(arg->getWidth()) || resultType > arg->getWidth())
@@ -2030,7 +2030,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::FPExt: {
     FPExtInst *fi = cast<FPExtInst>(i);
-    Expr::Width resultType = Expr::getWidthForLLVMType(fi->getType());
+    Expr::Width resultType = getWidthForLLVMType(fi->getType());
     ref<ConstantExpr> arg = toConstant(state, eval(ki, 0, state).value,
                                         "floating point");
     if (!fpWidthToSemantics(arg->getWidth()) || arg->getWidth() > resultType)
@@ -2047,7 +2047,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::FPToUI: {
     FPToUIInst *fi = cast<FPToUIInst>(i);
-    Expr::Width resultType = Expr::getWidthForLLVMType(fi->getType());
+    Expr::Width resultType = getWidthForLLVMType(fi->getType());
     ref<ConstantExpr> arg = toConstant(state, eval(ki, 0, state).value,
                                        "floating point");
     if (!fpWidthToSemantics(arg->getWidth()) || resultType > 64)
@@ -2064,7 +2064,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::FPToSI: {
     FPToSIInst *fi = cast<FPToSIInst>(i);
-    Expr::Width resultType = Expr::getWidthForLLVMType(fi->getType());
+    Expr::Width resultType = getWidthForLLVMType(fi->getType());
     ref<ConstantExpr> arg = toConstant(state, eval(ki, 0, state).value,
                                        "floating point");
     if (!fpWidthToSemantics(arg->getWidth()) || resultType > 64)
@@ -2081,7 +2081,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::UIToFP: {
     UIToFPInst *fi = cast<UIToFPInst>(i);
-    Expr::Width resultType = Expr::getWidthForLLVMType(fi->getType());
+    Expr::Width resultType = getWidthForLLVMType(fi->getType());
     ref<ConstantExpr> arg = toConstant(state, eval(ki, 0, state).value,
                                        "floating point");
     const llvm::fltSemantics *semantics = fpWidthToSemantics(resultType);
@@ -2097,7 +2097,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::SIToFP: {
     SIToFPInst *fi = cast<SIToFPInst>(i);
-    Expr::Width resultType = Expr::getWidthForLLVMType(fi->getType());
+    Expr::Width resultType = getWidthForLLVMType(fi->getType());
     ref<ConstantExpr> arg = toConstant(state, eval(ki, 0, state).value,
                                        "floating point");
     const llvm::fltSemantics *semantics = fpWidthToSemantics(resultType);
@@ -2654,7 +2654,7 @@ void Executor::callExternalFunction(ExecutionState &state,
   const Type *resultType = target->inst->getType();
   if (resultType != Type::getVoidTy(getGlobalContext())) {
     ref<Expr> e = ConstantExpr::fromMemory((void*) args, 
-                                           Expr::getWidthForLLVMType(resultType));
+                                           getWidthForLLVMType(resultType));
     bindLocal(target, state, e);
   }
 }
@@ -2883,7 +2883,7 @@ void Executor::executeMemoryOperation(ExecutionState &state,
                                       ref<Expr> value /* undef if read */,
                                       KInstruction *target /* undef if write */) {
   Expr::Width type = (isWrite ? value->getWidth() : 
-                     Expr::getWidthForLLVMType(target->inst->getType()));
+                     getWidthForLLVMType(target->inst->getType()));
   unsigned bytes = Expr::getMinBytesForWidth(type);
 
   if (SimplifySymIndices) {
@@ -3292,6 +3292,10 @@ void Executor::doImpliedValueConcretization(ExecutionState &state,
   }
 }
 
+Expr::Width Executor::getWidthForLLVMType(const llvm::Type *type) const {
+  return kmodule->targetData->getTypeSizeInBits(type);
+}
+
 ///
 
 Interpreter *Interpreter::create(const InterpreterOptions &opts,
diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h
index c8211854..e6f7c63e 100644
--- a/lib/Core/Executor.h
+++ b/lib/Core/Executor.h
@@ -447,6 +447,8 @@ public:
 
   virtual void getCoveredLines(const ExecutionState &state,
                                std::map<const std::string*, std::set<unsigned> > &res);
+
+  Expr::Width getWidthForLLVMType(const llvm::Type *type) const;
 };
   
 } // End klee namespace
diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp
index 5164e927..04264164 100644
--- a/lib/Core/ExecutorUtil.cpp
+++ b/lib/Core/ExecutorUtil.cpp
@@ -53,9 +53,9 @@ namespace klee {
       abort();
 
     case Instruction::Trunc: 
-      return op1->Extract(0, Expr::getWidthForLLVMType(type));
-    case Instruction::ZExt:  return op1->ZExt(Expr::getWidthForLLVMType(type));
-    case Instruction::SExt:  return op1->SExt(Expr::getWidthForLLVMType(type));
+      return op1->Extract(0, getWidthForLLVMType(type));
+    case Instruction::ZExt:  return op1->ZExt(getWidthForLLVMType(type));
+    case Instruction::SExt:  return op1->SExt(getWidthForLLVMType(type));
     case Instruction::Add:   return op1->Add(op2);
     case Instruction::Sub:   return op1->Sub(op2);
     case Instruction::Mul:   return op1->Mul(op2);
@@ -72,10 +72,10 @@ namespace klee {
     case Instruction::BitCast:  return op1;
 
     case Instruction::IntToPtr:
-      return op1->ZExt(Expr::getWidthForLLVMType(type));
+      return op1->ZExt(getWidthForLLVMType(type));
 
     case Instruction::PtrToInt:
-      return op1->ZExt(Expr::getWidthForLLVMType(type));
+      return op1->ZExt(getWidthForLLVMType(type));
 
     case Instruction::GetElementPtr: {
       ref<ConstantExpr> base = op1->ZExt(Context::get().getPointerWidth());