31 #define DEBUG_TYPE "interpreter"
33 STATISTIC(NumDynamicInsts,
"Number of dynamic instructions executed");
36 cl::desc(
"make the interpreter print every volatile load and store"));
50 #define IMPLEMENT_BINARY_OPERATOR(OP, TY) \
51 case Type::TY##TyID: \
52 Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; \
61 dbgs() <<
"Unhandled type for FAdd instruction: " << *Ty <<
"\n";
72 dbgs() <<
"Unhandled type for FSub instruction: " << *Ty <<
"\n";
83 dbgs() <<
"Unhandled type for FMul instruction: " << *Ty <<
"\n";
94 dbgs() <<
"Unhandled type for FDiv instruction: " << *Ty <<
"\n";
109 dbgs() <<
"Unhandled type for Rem instruction: " << *Ty <<
"\n";
114 #define IMPLEMENT_INTEGER_ICMP(OP, TY) \
115 case Type::IntegerTyID: \
116 Dest.IntVal = APInt(1,Src1.IntVal.OP(Src2.IntVal)); \
119 #define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY) \
120 case Type::VectorTyID: { \
121 assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \
122 Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \
123 for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \
124 Dest.AggregateVal[_i].IntVal = APInt(1, \
125 Src1.AggregateVal[_i].IntVal.OP(Src2.AggregateVal[_i].IntVal));\
132 #define IMPLEMENT_POINTER_ICMP(OP) \
133 case Type::PointerTyID: \
134 Dest.IntVal = APInt(1,(void*)(intptr_t)Src1.PointerVal OP \
135 (void*)(intptr_t)Src2.PointerVal); \
146 dbgs() <<
"Unhandled type for ICMP_EQ predicate: " << *Ty <<
"\n";
160 dbgs() <<
"Unhandled type for ICMP_NE predicate: " << *Ty <<
"\n";
174 dbgs() <<
"Unhandled type for ICMP_ULT predicate: " << *Ty <<
"\n";
188 dbgs() <<
"Unhandled type for ICMP_SLT predicate: " << *Ty <<
"\n";
202 dbgs() <<
"Unhandled type for ICMP_UGT predicate: " << *Ty <<
"\n";
216 dbgs() <<
"Unhandled type for ICMP_SGT predicate: " << *Ty <<
"\n";
230 dbgs() <<
"Unhandled type for ICMP_ULE predicate: " << *Ty <<
"\n";
244 dbgs() <<
"Unhandled type for ICMP_SLE predicate: " << *Ty <<
"\n";
258 dbgs() <<
"Unhandled type for ICMP_UGE predicate: " << *Ty <<
"\n";
272 dbgs() <<
"Unhandled type for ICMP_SGE predicate: " << *Ty <<
"\n";
297 dbgs() <<
"Don't know how to handle this ICmp predicate!\n-->" <<
I;
304 #define IMPLEMENT_FCMP(OP, TY) \
305 case Type::TY##TyID: \
306 Dest.IntVal = APInt(1,Src1.TY##Val OP Src2.TY##Val); \
309 #define IMPLEMENT_VECTOR_FCMP_T(OP, TY) \
310 assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \
311 Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \
312 for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \
313 Dest.AggregateVal[_i].IntVal = APInt(1, \
314 Src1.AggregateVal[_i].TY##Val OP Src2.AggregateVal[_i].TY##Val);\
317 #define IMPLEMENT_VECTOR_FCMP(OP) \
318 case Type::VectorTyID: \
319 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) { \
320 IMPLEMENT_VECTOR_FCMP_T(OP, Float); \
322 IMPLEMENT_VECTOR_FCMP_T(OP, Double); \
333 dbgs() <<
"Unhandled type for FCmp EQ instruction: " << *Ty <<
"\n";
339 #define IMPLEMENT_SCALAR_NANS(TY, X,Y) \
340 if (TY->isFloatTy()) { \
341 if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \
342 Dest.IntVal = APInt(1,false); \
346 if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \
347 Dest.IntVal = APInt(1,false); \
352 #define MASK_VECTOR_NANS_T(X,Y, TZ, FLAG) \
353 assert(X.AggregateVal.size() == Y.AggregateVal.size()); \
354 Dest.AggregateVal.resize( X.AggregateVal.size() ); \
355 for( uint32_t _i=0;_i<X.AggregateVal.size();_i++) { \
356 if (X.AggregateVal[_i].TZ##Val != X.AggregateVal[_i].TZ##Val || \
357 Y.AggregateVal[_i].TZ##Val != Y.AggregateVal[_i].TZ##Val) \
358 Dest.AggregateVal[_i].IntVal = APInt(1,FLAG); \
360 Dest.AggregateVal[_i].IntVal = APInt(1,!FLAG); \
364 #define MASK_VECTOR_NANS(TY, X,Y, FLAG) \
365 if (TY->isVectorTy()) { \
366 if (cast<VectorType>(TY)->getElementType()->isFloatTy()) { \
367 MASK_VECTOR_NANS_T(X, Y, Float, FLAG) \
369 MASK_VECTOR_NANS_T(X, Y, Double, FLAG) \
389 dbgs() <<
"Unhandled type for FCmp NE instruction: " << *Ty <<
"\n";
409 dbgs() <<
"Unhandled type for FCmp LE instruction: " << *Ty <<
"\n";
423 dbgs() <<
"Unhandled type for FCmp GE instruction: " << *Ty <<
"\n";
437 dbgs() <<
"Unhandled type for FCmp LT instruction: " << *Ty <<
"\n";
451 dbgs() <<
"Unhandled type for FCmp GT instruction: " << *Ty <<
"\n";
457 #define IMPLEMENT_UNORDERED(TY, X,Y) \
458 if (TY->isFloatTy()) { \
459 if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \
460 Dest.IntVal = APInt(1,true); \
463 } else if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \
464 Dest.IntVal = APInt(1,true); \
468 #define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, FUNC) \
469 if (TY->isVectorTy()) { \
470 GenericValue DestMask = Dest; \
471 Dest = FUNC(Src1, Src2, Ty); \
472 for (size_t _i = 0; _i < Src1.AggregateVal.size(); _i++) \
473 if (DestMask.AggregateVal[_i].IntVal == true) \
474 Dest.AggregateVal[_i].IntVal = APInt(1, true); \
539 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
570 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
596 const Type *Ty,
const bool val) {
619 dbgs() <<
"Don't know how to handle this FCmp predicate!\n-->" <<
I;
676 dbgs() <<
"Unhandled Cmp predicate\n";
690 assert(Src1.
AggregateVal.size() == Src2.AggregateVal.size());
694 #define INTEGER_VECTOR_OPERATION(OP) \
695 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \
696 R.AggregateVal[i].IntVal = \
697 Src1.AggregateVal[i].IntVal OP Src2.AggregateVal[i].IntVal;
701 #define INTEGER_VECTOR_FUNCTION(OP) \
702 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \
703 R.AggregateVal[i].IntVal = \
704 Src1.AggregateVal[i].IntVal.OP(Src2.AggregateVal[i].IntVal);
708 #define FLOAT_VECTOR_FUNCTION(OP, TY) \
709 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \
710 R.AggregateVal[i].TY = \
711 Src1.AggregateVal[i].TY OP Src2.AggregateVal[i].TY;
715 #define FLOAT_VECTOR_OP(OP) { \
716 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) \
717 FLOAT_VECTOR_FUNCTION(OP, FloatVal) \
719 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy()) \
720 FLOAT_VECTOR_FUNCTION(OP, DoubleVal) \
722 dbgs() << "Unhandled type for OP instruction: " << *Ty << "\n"; \
723 llvm_unreachable(0); \
730 dbgs() <<
"Don't know how to handle this binary operator!\n-->" <<
I;
747 case Instruction::FRem:
748 if (cast<VectorType>(Ty)->getElementType()->isFloatTy())
749 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
750 R.AggregateVal[i].FloatVal =
751 fmod(Src1.
AggregateVal[i].FloatVal, Src2.AggregateVal[i].FloatVal);
753 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
754 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
755 R.AggregateVal[i].DoubleVal =
756 fmod(Src1.
AggregateVal[i].DoubleVal, Src2.AggregateVal[i].DoubleVal);
758 dbgs() <<
"Unhandled type for Rem instruction: " << *Ty <<
"\n";
767 dbgs() <<
"Don't know how to handle this binary operator!\n-->" <<
I;
770 case Instruction::Add: R.IntVal = Src1.
IntVal + Src2.IntVal;
break;
771 case Instruction::Sub: R.IntVal = Src1.
IntVal - Src2.IntVal;
break;
772 case Instruction::Mul: R.IntVal = Src1.
IntVal * Src2.IntVal;
break;
778 case Instruction::UDiv: R.IntVal = Src1.
IntVal.
udiv(Src2.IntVal);
break;
779 case Instruction::SDiv: R.IntVal = Src1.
IntVal.
sdiv(Src2.IntVal);
break;
780 case Instruction::URem: R.IntVal = Src1.
IntVal.
urem(Src2.IntVal);
break;
781 case Instruction::SRem: R.IntVal = Src1.
IntVal.
srem(Src2.IntVal);
break;
801 Dest = (Src1.
IntVal == 0) ? Src3 : Src2;
837 void Interpreter::popStackAndReturnValueToCaller(
Type *RetTy,
842 if (ECStack.empty()) {
857 SwitchToNewBasicBlock (II->getNormalDest (), CallingSF);
874 popStackAndReturnValueToCaller(RetTy, Result);
888 if (getOperandValue(Cond, SF).
IntVal == 0)
891 SwitchToNewBasicBlock(Dest, SF);
903 GenericValue CaseVal = getOperandValue(i.getCaseValue(), SF);
905 Dest = cast<BasicBlock>(i.getCaseSuccessor());
910 SwitchToNewBasicBlock(Dest, SF);
935 if (!isa<PHINode>(SF.
CurInst))
return;
938 std::vector<GenericValue> ResultValues;
943 assert(i != -1 &&
"PHINode doesn't contain entry for predecessor??");
947 ResultValues.push_back(getOperandValue(IncomingValue, SF));
952 for (
unsigned i = 0; isa<PHINode>(SF.
CurInst); ++SF.
CurInst, ++i) {
968 unsigned NumElements =
974 unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
977 void *
Memory = malloc(MemToAlloc);
979 DEBUG(
dbgs() <<
"Allocated Type: " << *Ty <<
" (" << TypeSize <<
" bytes) x "
980 << NumElements <<
" (Total: " << MemToAlloc <<
") at "
981 << uintptr_t(Memory) <<
'\n');
984 assert(Result.
PointerVal &&
"Null pointer returned by malloc!");
987 if (I.
getOpcode() == Instruction::Alloca)
988 ECStack.back().Allocas.add(Memory);
997 "Cannot getElementOffset of a nonpointer type!");
1001 for (; I != E; ++
I) {
1002 if (
StructType *STy = dyn_cast<StructType>(*I)) {
1012 GenericValue IdxGV = getOperandValue(I.getOperand(), SF);
1016 cast<IntegerType>(I.getOperand()->getType())->
getBitWidth();
1020 assert(BitWidth == 64 &&
"Invalid index type for getelementptr");
1029 DEBUG(
dbgs() <<
"GEP Index " << Total <<
" bytes.\n");
1047 dbgs() <<
"Volatile load " <<
I;
1057 dbgs() <<
"Volatile store: " <<
I;
1073 case Intrinsic::vastart: {
1080 case Intrinsic::vaend:
1082 case Intrinsic::vacopy:
1091 bool atBegin(Parent->begin() == me);
1109 std::vector<GenericValue> ArgVals;
1111 ArgVals.reserve(NumArgs);
1116 ArgVals.push_back(getOperandValue(V, SF));
1129 if (orgShiftAmount < (uint64_t)valueWidth)
1130 return orgShiftAmount;
1133 return (
NextPowerOf2(valueWidth-1) - 1) & orgShiftAmount;
1145 uint32_t src1Size = uint32_t(Src1.
AggregateVal.size());
1146 assert(src1Size == Src2.AggregateVal.size());
1147 for (
unsigned i = 0; i < src1Size; i++) {
1149 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1152 Dest.AggregateVal.push_back(Result);
1172 uint32_t src1Size = uint32_t(Src1.
AggregateVal.size());
1173 assert(src1Size == Src2.AggregateVal.size());
1174 for (
unsigned i = 0; i < src1Size; i++) {
1176 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1179 Dest.AggregateVal.push_back(Result);
1200 assert(src1Size == Src2.AggregateVal.size());
1201 for (
unsigned i = 0; i < src1Size; i++) {
1203 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1206 Dest.AggregateVal.push_back(Result);
1224 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1228 for (
unsigned i = 0; i < NumElts; i++)
1244 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1248 for (
unsigned i = 0; i <
size; i++)
1251 const IntegerType *DITy = cast<IntegerType>(DstTy);
1264 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1269 for (
unsigned i = 0; i <
size; i++)
1272 const IntegerType *DITy = cast<IntegerType>(DstTy);
1286 "Invalid FPTrunc instruction");
1291 for (
unsigned i = 0; i <
size; i++)
1295 "Invalid FPTrunc instruction");
1313 for (
unsigned i = 0; i <
size; i++)
1317 "Invalid FPExt instruction");
1332 uint32_t DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1339 for (
unsigned i = 0; i <
size; i++)
1343 for (
unsigned i = 0; i <
size; i++)
1349 uint32_t DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1370 uint32_t DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1377 for (
unsigned i = 0; i <
size; i++)
1381 for (
unsigned i = 0; i <
size; i++)
1387 unsigned DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1411 for (
unsigned i = 0; i <
size; i++)
1415 for (
unsigned i = 0; i <
size; i++)
1443 for (
unsigned i = 0; i <
size; i++)
1447 for (
unsigned i = 0; i <
size; i++)
1467 uint32_t DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1478 assert(DstTy->
isPointerTy() &&
"Invalid PtrToInt instruction");
1502 const Type *SrcElemTy;
1503 const Type *DstElemTy;
1504 unsigned SrcBitSize;
1505 unsigned DstBitSize;
1525 DstNum = (SrcNum * SrcBitSize) / DstBitSize;
1532 if (SrcNum * SrcBitSize != DstNum * DstBitSize)
1538 for (
unsigned i = 0; i < SrcNum; i++)
1543 for (
unsigned i = 0; i < SrcNum; i++)
1547 for (
unsigned i = 0; i < SrcNum; i++)
1555 if (DstNum < SrcNum) {
1557 unsigned Ratio = SrcNum / DstNum;
1558 unsigned SrcElt = 0;
1559 for (
unsigned i = 0; i < DstNum; i++) {
1563 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize * (Ratio - 1);
1564 for (
unsigned j = 0; j < Ratio; j++) {
1566 Tmp = Tmp.
zext(SrcBitSize);
1568 Tmp = Tmp.
zext(DstBitSize);
1569 Tmp = Tmp.
shl(ShiftAmt);
1570 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
1577 unsigned Ratio = DstNum / SrcNum;
1578 for (
unsigned i = 0; i < SrcNum; i++) {
1579 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize * (Ratio - 1);
1580 for (
unsigned j = 0; j < Ratio; j++) {
1586 if (DstBitSize < SrcBitSize)
1588 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
1598 for (
unsigned i = 0; i < DstNum; i++)
1603 for (
unsigned i = 0; i < DstNum; i++)
1623 assert(SrcTy->
isPointerTy() &&
"Invalid BitCast");
1715 #define IMPLEMENT_VAARG(TY) \
1716 case Type::TY##TyID: Dest.TY##Val = Src.TY##Val; break
1730 Dest.IntVal = Src.
IntVal;
1736 dbgs() <<
"Unhandled dest type for vaarg instruction: " << *Ty <<
"\n";
1754 const unsigned indx =
unsigned(Src2.IntVal.getZExtValue());
1759 dbgs() <<
"Unhandled destination type for extractelement instruction: "
1774 dbgs() <<
"Invalid index in extractelement instruction\n";
1794 const unsigned indx =
unsigned(Src3.IntVal.getZExtValue());
1803 Dest.AggregateVal[indx].IntVal = Src2.IntVal;
1806 Dest.AggregateVal[indx].FloatVal = Src2.FloatVal;
1809 Dest.AggregateVal[indx].DoubleVal = Src2.DoubleVal;
1833 unsigned src2Size = (
unsigned)Src2.AggregateVal.size();
1834 unsigned src3Size = (
unsigned)Src3.AggregateVal.size();
1836 Dest.AggregateVal.resize(src3Size);
1843 for(
unsigned i=0; i<src3Size; i++) {
1844 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1846 Dest.AggregateVal[i].IntVal = Src1.
AggregateVal[j].IntVal;
1847 else if(j < src1Size + src2Size)
1848 Dest.AggregateVal[i].IntVal = Src2.AggregateVal[j-src1Size].IntVal;
1859 for(
unsigned i=0; i<src3Size; i++) {
1860 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1862 Dest.AggregateVal[i].FloatVal = Src1.
AggregateVal[j].FloatVal;
1863 else if(j < src1Size + src2Size)
1864 Dest.AggregateVal[i].FloatVal = Src2.AggregateVal[j-src1Size].FloatVal;
1870 for(
unsigned i=0; i<src3Size; i++) {
1871 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1873 Dest.AggregateVal[i].DoubleVal = Src1.
AggregateVal[j].DoubleVal;
1874 else if(j < src1Size + src2Size)
1875 Dest.AggregateVal[i].DoubleVal =
1876 Src2.AggregateVal[j-src1Size].DoubleVal;
1895 for (
unsigned i = 0 ; i < Num; ++i) {
1940 for (
unsigned i = 0 ; i < Num; ++i) {
1977 case Instruction::Trunc:
1979 case Instruction::ZExt:
1981 case Instruction::SExt:
1983 case Instruction::FPTrunc:
1985 case Instruction::FPExt:
1987 case Instruction::UIToFP:
1989 case Instruction::SIToFP:
1991 case Instruction::FPToUI:
1993 case Instruction::FPToSI:
1995 case Instruction::PtrToInt:
1997 case Instruction::IntToPtr:
1999 case Instruction::BitCast:
2001 case Instruction::GetElementPtr:
2004 case Instruction::FCmp:
2005 case Instruction::ICmp:
2026 case Instruction::Add: Dest.IntVal = Op0.
IntVal + Op1.IntVal;
break;
2027 case Instruction::Sub: Dest.IntVal = Op0.
IntVal - Op1.IntVal;
break;
2028 case Instruction::Mul: Dest.IntVal = Op0.
IntVal * Op1.IntVal;
break;
2034 case Instruction::SDiv: Dest.IntVal = Op0.
IntVal.
sdiv(Op1.IntVal);
break;
2035 case Instruction::UDiv: Dest.IntVal = Op0.
IntVal.
udiv(Op1.IntVal);
break;
2036 case Instruction::URem: Dest.IntVal = Op0.
IntVal.
urem(Op1.IntVal);
break;
2037 case Instruction::SRem: Dest.IntVal = Op0.
IntVal.
srem(Op1.IntVal);
break;
2041 case Instruction::Shl:
2042 Dest.IntVal = Op0.
IntVal.
shl(Op1.IntVal.getZExtValue());
2044 case Instruction::LShr:
2045 Dest.IntVal = Op0.
IntVal.
lshr(Op1.IntVal.getZExtValue());
2047 case Instruction::AShr:
2048 Dest.IntVal = Op0.
IntVal.
ashr(Op1.IntVal.getZExtValue());
2051 dbgs() <<
"Unhandled ConstantExpr: " << *CE <<
"\n";
2059 return getConstantExprValue(CE, SF);
2060 }
else if (
Constant *CPV = dyn_cast<Constant>(V)) {
2062 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2077 assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() ||
2078 ECStack.back().Caller.arg_size() == ArgVals.
size()) &&
2079 "Incorrect number of arguments passed into function call!");
2081 ECStack.emplace_back();
2089 popStackAndReturnValueToCaller (F->
getReturnType (), Result);
2100 "Invalid number of values passed to function invocation!");
2106 SetValue(AI, ArgVals[i], StackFrame);
2114 while (!ECStack.empty()) {
2122 DEBUG(
dbgs() <<
"About to interpret: " << I);
2127 if (!isa<CallInst>(I) && !isa<InvokeInst>(I) &&
2128 I.
getType() != Type::VoidTy) {
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
ReturnInst - Return a value (possibly void), from a function.
void visitVAArgInst(VAArgInst &I)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
Value * getPointerOperand()
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
std::vector< GenericValue > AggregateVal
static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2, Type *Ty)
Value * getAggregateOperand()
uint64_t getZExtValue() const
Get zero extended value.
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
static GenericValue executeFCMP_ULT(GenericValue Src1, GenericValue Src2, Type *Ty)
STATISTIC(NumFunctions,"Total number of functions")
bool isVolatile() const
isVolatile - Return true if this is a store to a volatile memory location.
ArrayRef< unsigned > getIndices() const
void visitAllocaInst(AllocaInst &I)
void visitStoreInst(StoreInst &I)
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float vlalue.
static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF)
2: 32-bit floating point type
InstrTy * getInstruction() const
void visitTruncInst(TruncInst &I)
void visitFPToUIInst(FPToUIInst &I)
static void executeFDivInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
This class provides various memory handling functions that manipulate MemoryBlock instances...
This class represents zero extension of integer types.
unsigned getNumOperands() const
void visitGetElementPtrInst(GetElementPtrInst &I)
BasicBlock::iterator CurInst
#define MASK_VECTOR_NANS(TY, X, Y, FLAG)
gep_type_iterator gep_type_end(const User *GEP)
CaseIt case_begin()
Returns a read/write iterator that points to the first case in SwitchInst.
0 1 0 0 True if ordered and less than
static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, Type *Ty)
std::map< Value *, GenericValue > Values
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
1 1 1 0 True if unordered or not equal
void visitExtractElementInst(ExtractElementInst &I)
Type * getReturnType() const
unsigned getNumIndices() const
void visitShl(BinaryOperator &I)
This class represents a sign extension of integer types.
LoadInst - an instruction for reading from memory.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
#define IMPLEMENT_VECTOR_FCMP(OP)
static GenericValue executeFCMP_OLT(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
void toStringUnsigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be unsigned and converts it into a string in the radix given.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
iterator begin()
Instruction iterator methods.
static GenericValue executeICMP_SGT(GenericValue Src1, GenericValue Src2, Type *Ty)
static GenericValue executeFCMP_UEQ(GenericValue Src1, GenericValue Src2, Type *Ty)
1 0 0 1 True if unordered or equal
APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const
Unsigned remainder operation.
void visitFCmpInst(FCmpInst &I)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
bool isUnconditional() const
SelectInst - This class represents the LLVM 'select' instruction.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
APInt urem(const APInt &LHS, const APInt &RHS)
Function for unsigned remainder operation.
void * getPointerToGlobal(const GlobalValue *GV)
getPointerToGlobal - This returns the address of the specified global value.
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
void visitSelectInst(SelectInst &I)
#define IMPLEMENT_BINARY_OPERATOR(OP, TY)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
0 1 0 1 True if ordered and less than or equal
static cl::opt< bool > PrintVolatile("interpreter-print-volatile", cl::Hidden, cl::desc("make the interpreter print every volatile load and store"))
static GenericValue executeICMP_EQ(GenericValue Src1, GenericValue Src2, Type *Ty)
This file implements a class to represent arbitrary precision integral constant values and operations...
This class represents a cast from a pointer to an integer.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
#define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY)
static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, Type *Ty)
void visit(Iterator Start, Iterator End)
void visitInsertElementInst(InsertElementInst &I)
ConstantExpr - a constant value that is initialized with an expression using other constant values...
void visitFPTruncInst(FPTruncInst &I)
VectorType * getType() const
getType - Overload to return most specific vector type.
#define IMPLEMENT_SCALAR_NANS(TY, X, Y)
ValTy * getCalledValue() const
getCalledValue - Return the pointer to function that is being called.
static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt udiv(const APInt &LHS, const APInt &RHS)
Unsigned division function for APInt.
void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, Type *Ty)
FIXME: document.
This instruction compares its operands according to the predicate given to the constructor.
BasicBlock * getSuccessor(unsigned i) const
This class represents a no-op cast from one type to another.
void callFunction(Function *F, ArrayRef< GenericValue > ArgVals)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void visitInsertValueInst(InsertValueInst &I)
TypeID getTypeID() const
getTypeID - Return the type id for the type.
APInt sdiv(const APInt &LHS, const APInt &RHS)
Signed division function for APInt.
bool isFloatingPointTy() const
isFloatingPointTy - Return true if this is one of the six floating point types
bool isLittleEndian() const
Layout endianness...
GenericValue getConstantValue(const Constant *C)
Converts a Constant* into a GenericValue, including handling of ConstantExpr values.
StoreInst - an instruction for storing to memory.
static GenericValue executeFCMP_BOOL(GenericValue Src1, GenericValue Src2, const Type *Ty, const bool val)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const
Left-shift function.
This class represents a cast from floating point to signed integer.
float RoundSignedAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
static GenericValue executeICMP_ULE(GenericValue Src1, GenericValue Src2, Type *Ty)
void visitBitCastInst(BitCastInst &I)
void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, Type *Ty)
StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2, Type *Ty)
This class represents a truncation of integer types.
Type * getElementType() const
size_t size() const
size - Get the array size.
#define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, FUNC)
#define IMPLEMENT_VAARG(TY)
uint64_t getElementOffset(unsigned Idx) const
10: Arbitrary bit width integers
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
void visitLShr(BinaryOperator &I)
static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2, Type *Ty)
void visitICmpInst(ICmpInst &I)
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt srem(const APInt &LHS, const APInt &RHS)
Function for signed remainder operation.
static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
BranchInst - Conditional or Unconditional Branch instruction.
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
void visitCallSite(CallSite CS)
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
Type * getContainedType(unsigned i) const
getContainedType - This method is used to implement the type iterator (defined at the end of the file...
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
PointerType * getType() const
getType - Overload to return most specific pointer type
This file contains the declarations for the subclasses of Constant, which represent the different fla...
IndirectBrInst - Indirect Branch Instruction.
static GenericValue executeFCMP_UNE(GenericValue Src1, GenericValue Src2, Type *Ty)
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
void visitIndirectBrInst(IndirectBrInst &I)
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
void visitZExtInst(ZExtInst &I)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT sext(unsigned width) const
Sign extend to a new width.
static Type * getVoidTy(LLVMContext &C)
static GenericValue executeICMP_NE(GenericValue Src1, GenericValue Src2, Type *Ty)
static GenericValue executeFCMP_ONE(GenericValue Src1, GenericValue Src2, Type *Ty)
void exitCalled(GenericValue GV)
static GenericValue executeFCMP_OLE(GenericValue Src1, GenericValue Src2, Type *Ty)
This instruction compares its operands according to the predicate given to the constructor.
unsigned getBitWidth() const
Return the number of bits in the APInt.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const
Signed division function for APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
Value * getPointerOperand()
static GenericValue executeFCMP_UGE(GenericValue Src1, GenericValue Src2, Type *Ty)
struct IntPair UIntPairVal
Class to represent integer types.
Predicate getPredicate() const
Return the predicate for this instruction.
void visitExtractValueInst(ExtractValueInst &I)
This class represents a cast from an integer to a pointer.
unsigned getPredicate() const
getPredicate - Return the ICMP or FCMP predicate value.
1 1 1 1 Always true (always folded)
void visitFPToSIInst(FPToSIInst &I)
void visitIntToPtrInst(IntToPtrInst &I)
void visitFPExtInst(FPExtInst &I)
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
uint64_t NextPowerOf2(uint64_t A)
NextPowerOf2 - Returns the next power of two (in 64-bits) that is strictly greater than A...
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
LLVMContext & getContext() const
All values hold a context through their type.
void visitUnreachableInst(UnreachableInst &I)
static void executeFAddInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
1 1 0 1 True if unordered, less than, or equal
static GenericValue executeFCMP_OGE(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const
Function for signed remainder operation.
void * GVTOP(const GenericValue &GV)
static void executeFRemInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
SequentialType - This is the superclass of the array, pointer and vector type classes.
0 0 1 0 True if ordered and greater than
idx_iterator idx_begin() const
BinaryOps getOpcode() const
void visitShuffleVectorInst(ShuffleVectorInst &I)
std::vector< GenericValue > VarArgs
static APInt LLVM_ATTRIBUTE_UNUSED_RESULT doubleToBits(double V)
Converts a double to APInt bits.
This is the shared class of boolean and integer constants.
void visitReturnInst(ReturnInst &I)
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
15: SIMD 'packed' format, or other vector type
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
void visitSExtInst(SExtInst &I)
1 1 0 0 True if unordered or less than
Type * getType() const
All values are typed, get the type of this value.
bool isVolatile() const
isVolatile - Return true if this is a load from a volatile memory location.
This class represents a cast from floating point to unsigned integer.
unsigned arg_size() const
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, GenericValue Src3, const Type *Ty)
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
static void executeFSubInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
static void executeFMulInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
static GenericValue executeCmpInst(unsigned predicate, GenericValue Src1, GenericValue Src2, Type *Ty)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
GenericValue PTOGV(void *P)
Class for arbitrary precision integers.
void visitPtrToIntInst(PtrToIntInst &I)
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
void runAtExitHandlers()
runAtExitHandlers - Run any functions registered by the program's calls to atexit(3), which we intercept and store in AtExitHandlers.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * getCondition() const
double bitsToDouble() const
Converts APInt bits to a double.
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
void visitBranchInst(BranchInst &I)
Value * getOperand() const
#define FLOAT_VECTOR_OP(OP)
void visitAShr(BinaryOperator &I)
Value * getCondition() const
BasicBlock * getDefaultDest() const
APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const
Unsigned division operation.
void LowerIntrinsicCall(CallInst *CI)
LowerIntrinsicCall - This method replaces a call with the LLVM function which should be used to imple...
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
static GenericValue executeFCMP_ULE(GenericValue Src1, GenericValue Src2, Type *Ty)
unsigned greater or equal
static APInt LLVM_ATTRIBUTE_UNUSED_RESULT floatToBits(float V)
Converts a float to APInt bits.
#define IMPLEMENT_INTEGER_ICMP(OP, TY)
FunctionType * getFunctionType() const
void visitSIToFPInst(SIToFPInst &I)
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
This class represents a cast unsigned integer to floating point.
#define INTEGER_VECTOR_OPERATION(OP)
0 1 1 0 True if ordered and operands are unequal
static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2, Type *Ty)
void visitBinaryOperator(BinaryOperator &I)
VectorType * getType() const
getType - Overload to return most specific vector type.
1 0 1 0 True if unordered or greater than
void visitLoadInst(LoadInst &I)
Type * getType() const
getType - Return the type of the instruction that generated this call site
3: 64-bit floating point type
SwitchInst - Multiway switch.
This class represents a cast from signed integer to floating point.
#define IMPLEMENT_POINTER_ICMP(OP)
This class represents a truncation of floating point types.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
#define IMPLEMENT_UNORDERED(TY, X, Y)
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
void visitUIToFPInst(UIToFPInst &I)
#define INTEGER_VECTOR_FUNCTION(OP)
InvokeInst - Invoke instruction.
GenericValue callExternalFunction(Function *F, ArrayRef< GenericValue > ArgVals)
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
void visitSwitchInst(SwitchInst &I)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
static unsigned getShiftAmount(uint64_t orgShiftAmount, llvm::APInt valueToShift)
static GenericValue executeFCMP_OEQ(GenericValue Src1, GenericValue Src2, Type *Ty)
#define IMPLEMENT_FCMP(OP, TY)
APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
This class represents an extension of floating point types.
0 0 1 1 True if ordered and greater than or equal
Value * getPointerOperand()
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
int getBasicBlockIndex(const BasicBlock *BB) const
getBasicBlockIndex - Return the first index of the specified basic block in the value list for this P...
const BasicBlock * getParent() const
0 0 0 0 Always false (always folded)
float bitsToFloat() const
Converts APInt bits to a double.
static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, Type *Ty)
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
gep_type_iterator gep_type_begin(const User *GEP)