14 #define DEBUG_TYPE "interpreter"
31 STATISTIC(NumDynamicInsts,
"Number of dynamic instructions executed");
34 cl::desc(
"make the interpreter print every volatile load and store"));
48 #define IMPLEMENT_BINARY_OPERATOR(OP, TY) \
49 case Type::TY##TyID: \
50 Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; \
59 dbgs() <<
"Unhandled type for FAdd instruction: " << *Ty <<
"\n";
70 dbgs() <<
"Unhandled type for FSub instruction: " << *Ty <<
"\n";
81 dbgs() <<
"Unhandled type for FMul instruction: " << *Ty <<
"\n";
92 dbgs() <<
"Unhandled type for FDiv instruction: " << *Ty <<
"\n";
107 dbgs() <<
"Unhandled type for Rem instruction: " << *Ty <<
"\n";
112 #define IMPLEMENT_INTEGER_ICMP(OP, TY) \
113 case Type::IntegerTyID: \
114 Dest.IntVal = APInt(1,Src1.IntVal.OP(Src2.IntVal)); \
117 #define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY) \
118 case Type::VectorTyID: { \
119 assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \
120 Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \
121 for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \
122 Dest.AggregateVal[_i].IntVal = APInt(1, \
123 Src1.AggregateVal[_i].IntVal.OP(Src2.AggregateVal[_i].IntVal));\
130 #define IMPLEMENT_POINTER_ICMP(OP) \
131 case Type::PointerTyID: \
132 Dest.IntVal = APInt(1,(void*)(intptr_t)Src1.PointerVal OP \
133 (void*)(intptr_t)Src2.PointerVal); \
144 dbgs() <<
"Unhandled type for ICMP_EQ predicate: " << *Ty <<
"\n";
158 dbgs() <<
"Unhandled type for ICMP_NE predicate: " << *Ty <<
"\n";
172 dbgs() <<
"Unhandled type for ICMP_ULT predicate: " << *Ty <<
"\n";
186 dbgs() <<
"Unhandled type for ICMP_SLT predicate: " << *Ty <<
"\n";
200 dbgs() <<
"Unhandled type for ICMP_UGT predicate: " << *Ty <<
"\n";
214 dbgs() <<
"Unhandled type for ICMP_SGT predicate: " << *Ty <<
"\n";
228 dbgs() <<
"Unhandled type for ICMP_ULE predicate: " << *Ty <<
"\n";
242 dbgs() <<
"Unhandled type for ICMP_SLE predicate: " << *Ty <<
"\n";
256 dbgs() <<
"Unhandled type for ICMP_UGE predicate: " << *Ty <<
"\n";
270 dbgs() <<
"Unhandled type for ICMP_SGE predicate: " << *Ty <<
"\n";
295 dbgs() <<
"Don't know how to handle this ICmp predicate!\n-->" <<
I;
302 #define IMPLEMENT_FCMP(OP, TY) \
303 case Type::TY##TyID: \
304 Dest.IntVal = APInt(1,Src1.TY##Val OP Src2.TY##Val); \
307 #define IMPLEMENT_VECTOR_FCMP_T(OP, TY) \
308 assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \
309 Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \
310 for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \
311 Dest.AggregateVal[_i].IntVal = APInt(1, \
312 Src1.AggregateVal[_i].TY##Val OP Src2.AggregateVal[_i].TY##Val);\
315 #define IMPLEMENT_VECTOR_FCMP(OP) \
316 case Type::VectorTyID: \
317 if(dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) { \
318 IMPLEMENT_VECTOR_FCMP_T(OP, Float); \
320 IMPLEMENT_VECTOR_FCMP_T(OP, Double); \
331 dbgs() <<
"Unhandled type for FCmp EQ instruction: " << *Ty <<
"\n";
337 #define IMPLEMENT_SCALAR_NANS(TY, X,Y) \
338 if (TY->isFloatTy()) { \
339 if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \
340 Dest.IntVal = APInt(1,false); \
344 if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \
345 Dest.IntVal = APInt(1,false); \
350 #define MASK_VECTOR_NANS_T(X,Y, TZ, FLAG) \
351 assert(X.AggregateVal.size() == Y.AggregateVal.size()); \
352 Dest.AggregateVal.resize( X.AggregateVal.size() ); \
353 for( uint32_t _i=0;_i<X.AggregateVal.size();_i++) { \
354 if (X.AggregateVal[_i].TZ##Val != X.AggregateVal[_i].TZ##Val || \
355 Y.AggregateVal[_i].TZ##Val != Y.AggregateVal[_i].TZ##Val) \
356 Dest.AggregateVal[_i].IntVal = APInt(1,FLAG); \
358 Dest.AggregateVal[_i].IntVal = APInt(1,!FLAG); \
362 #define MASK_VECTOR_NANS(TY, X,Y, FLAG) \
363 if (TY->isVectorTy()) { \
364 if (dyn_cast<VectorType>(TY)->getElementType()->isFloatTy()) { \
365 MASK_VECTOR_NANS_T(X, Y, Float, FLAG) \
367 MASK_VECTOR_NANS_T(X, Y, Double, FLAG) \
387 dbgs() <<
"Unhandled type for FCmp NE instruction: " << *Ty <<
"\n";
407 dbgs() <<
"Unhandled type for FCmp LE instruction: " << *Ty <<
"\n";
421 dbgs() <<
"Unhandled type for FCmp GE instruction: " << *Ty <<
"\n";
435 dbgs() <<
"Unhandled type for FCmp LT instruction: " << *Ty <<
"\n";
449 dbgs() <<
"Unhandled type for FCmp GT instruction: " << *Ty <<
"\n";
455 #define IMPLEMENT_UNORDERED(TY, X,Y) \
456 if (TY->isFloatTy()) { \
457 if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \
458 Dest.IntVal = APInt(1,true); \
461 } else if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \
462 Dest.IntVal = APInt(1,true); \
466 #define IMPLEMENT_VECTOR_UNORDERED(TY, X,Y, _FUNC) \
467 if (TY->isVectorTy()) { \
468 GenericValue DestMask = Dest; \
469 Dest = _FUNC(Src1, Src2, Ty); \
470 for( size_t _i=0; _i<Src1.AggregateVal.size(); _i++) \
471 if (DestMask.AggregateVal[_i].IntVal == true) \
472 Dest.AggregateVal[_i].IntVal = APInt(1,true); \
537 if(dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
568 if(dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
594 const Type *Ty,
const bool val) {
617 dbgs() <<
"Don't know how to handle this FCmp predicate!\n-->" <<
I;
674 dbgs() <<
"Unhandled Cmp predicate\n";
688 assert(Src1.
AggregateVal.size() == Src2.AggregateVal.size());
692 #define INTEGER_VECTOR_OPERATION(OP) \
693 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \
694 R.AggregateVal[i].IntVal = \
695 Src1.AggregateVal[i].IntVal OP Src2.AggregateVal[i].IntVal;
699 #define INTEGER_VECTOR_FUNCTION(OP) \
700 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \
701 R.AggregateVal[i].IntVal = \
702 Src1.AggregateVal[i].IntVal.OP(Src2.AggregateVal[i].IntVal);
706 #define FLOAT_VECTOR_FUNCTION(OP, TY) \
707 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \
708 R.AggregateVal[i].TY = \
709 Src1.AggregateVal[i].TY OP Src2.AggregateVal[i].TY;
713 #define FLOAT_VECTOR_OP(OP) { \
714 if (dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy()) \
715 FLOAT_VECTOR_FUNCTION(OP, FloatVal) \
717 if (dyn_cast<VectorType>(Ty)->getElementType()->isDoubleTy()) \
718 FLOAT_VECTOR_FUNCTION(OP, DoubleVal) \
720 dbgs() << "Unhandled type for OP instruction: " << *Ty << "\n"; \
721 llvm_unreachable(0); \
728 dbgs() <<
"Don't know how to handle this binary operator!\n-->" <<
I;
745 case Instruction::FRem:
746 if (dyn_cast<VectorType>(Ty)->getElementType()->isFloatTy())
747 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
748 R.AggregateVal[i].FloatVal =
751 if (dyn_cast<VectorType>(Ty)->getElementType()->isDoubleTy())
752 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
753 R.AggregateVal[i].DoubleVal =
756 dbgs() <<
"Unhandled type for Rem instruction: " << *Ty <<
"\n";
765 dbgs() <<
"Don't know how to handle this binary operator!\n-->" <<
I;
768 case Instruction::Add: R.IntVal = Src1.
IntVal + Src2.IntVal;
break;
769 case Instruction::Sub: R.IntVal = Src1.
IntVal - Src2.IntVal;
break;
770 case Instruction::Mul: R.IntVal = Src1.
IntVal * Src2.IntVal;
break;
776 case Instruction::UDiv: R.IntVal = Src1.
IntVal.
udiv(Src2.IntVal);
break;
777 case Instruction::SDiv: R.IntVal = Src1.
IntVal.
sdiv(Src2.IntVal);
break;
778 case Instruction::URem: R.IntVal = Src1.
IntVal.
urem(Src2.IntVal);
break;
779 case Instruction::SRem: R.IntVal = Src1.
IntVal.
srem(Src2.IntVal);
break;
799 Dest = (Src1.
IntVal == 0) ? Src3 : Src2;
835 void Interpreter::popStackAndReturnValueToCaller(
Type *RetTy,
840 if (ECStack.empty()) {
855 SwitchToNewBasicBlock (II->getNormalDest (), CallingSF);
872 popStackAndReturnValueToCaller(RetTy, Result);
886 if (getOperandValue(Cond, SF).
IntVal == 0)
889 SwitchToNewBasicBlock(Dest, SF);
901 GenericValue CaseVal = getOperandValue(i.getCaseValue(), SF);
903 Dest = cast<BasicBlock>(i.getCaseSuccessor());
908 SwitchToNewBasicBlock(Dest, SF);
933 if (!isa<PHINode>(SF.
CurInst))
return;
936 std::vector<GenericValue> ResultValues;
941 assert(i != -1 &&
"PHINode doesn't contain entry for predecessor??");
945 ResultValues.push_back(getOperandValue(IncomingValue, SF));
950 for (
unsigned i = 0; isa<PHINode>(SF.
CurInst); ++SF.
CurInst, ++i) {
966 unsigned NumElements =
972 unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
977 DEBUG(
dbgs() <<
"Allocated Type: " << *Ty <<
" (" << TypeSize <<
" bytes) x "
978 << NumElements <<
" (Total: " << MemToAlloc <<
") at "
979 << uintptr_t(Memory) <<
'\n');
982 assert(Result.
PointerVal != 0 &&
"Null pointer returned by malloc!");
985 if (I.
getOpcode() == Instruction::Alloca)
986 ECStack.back().Allocas.add(Memory);
995 "Cannot getElementOffset of a nonpointer type!");
999 for (; I != E; ++
I) {
1000 if (
StructType *STy = dyn_cast<StructType>(*I)) {
1010 GenericValue IdxGV = getOperandValue(I.getOperand(), SF);
1014 cast<IntegerType>(I.getOperand()->getType())->
getBitWidth();
1018 assert(BitWidth == 64 &&
"Invalid index type for getelementptr");
1027 DEBUG(
dbgs() <<
"GEP Index " << Total <<
" bytes.\n");
1045 dbgs() <<
"Volatile load " <<
I;
1055 dbgs() <<
"Volatile store: " <<
I;
1089 bool atBegin(Parent->begin() == me);
1107 std::vector<GenericValue> ArgVals;
1109 ArgVals.reserve(NumArgs);
1114 ArgVals.push_back(getOperandValue(V, SF));
1127 if (orgShiftAmount < (uint64_t)valueWidth)
1128 return orgShiftAmount;
1131 return (
NextPowerOf2(valueWidth-1) - 1) & orgShiftAmount;
1143 uint32_t src1Size = uint32_t(Src1.
AggregateVal.size());
1144 assert(src1Size == Src2.AggregateVal.size());
1145 for (
unsigned i = 0; i < src1Size; i++) {
1147 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1150 Dest.AggregateVal.push_back(Result);
1170 uint32_t src1Size = uint32_t(Src1.
AggregateVal.size());
1171 assert(src1Size == Src2.AggregateVal.size());
1172 for (
unsigned i = 0; i < src1Size; i++) {
1174 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1177 Dest.AggregateVal.push_back(Result);
1198 assert(src1Size == Src2.AggregateVal.size());
1199 for (
unsigned i = 0; i < src1Size; i++) {
1201 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1204 Dest.AggregateVal.push_back(Result);
1222 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1226 for (
unsigned i = 0; i < NumElts; i++)
1242 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1246 for (
unsigned i = 0; i < size; i++)
1249 const IntegerType *DITy = cast<IntegerType>(DstTy);
1262 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1267 for (
unsigned i = 0; i < size; i++)
1270 const IntegerType *DITy = cast<IntegerType>(DstTy);
1284 "Invalid FPTrunc instruction");
1289 for (
unsigned i = 0; i < size; i++)
1293 "Invalid FPTrunc instruction");
1311 for (
unsigned i = 0; i < size; i++)
1315 "Invalid FPExt instruction");
1330 uint32_t DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1337 for (
unsigned i = 0; i < size; i++)
1341 for (
unsigned i = 0; i < size; i++)
1347 uint32_t DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1368 uint32_t DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1375 for (
unsigned i = 0; i < size; i++)
1379 for (
unsigned i = 0; i < size; i++)
1385 unsigned DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1409 for (
unsigned i = 0; i < size; i++)
1413 for (
unsigned i = 0; i < size; i++)
1441 for (
unsigned i = 0; i < size; i++)
1445 for (
unsigned i = 0; i < size; i++)
1465 uint32_t DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1476 assert(DstTy->
isPointerTy() &&
"Invalid PtrToInt instruction");
1500 const Type *SrcElemTy;
1501 const Type *DstElemTy;
1502 unsigned SrcBitSize;
1503 unsigned DstBitSize;
1523 DstNum = (SrcNum * SrcBitSize) / DstBitSize;
1530 if (SrcNum * SrcBitSize != DstNum * DstBitSize)
1536 for (
unsigned i = 0; i < SrcNum; i++)
1541 for (
unsigned i = 0; i < SrcNum; i++)
1545 for (
unsigned i = 0; i < SrcNum; i++)
1553 if (DstNum < SrcNum) {
1555 unsigned Ratio = SrcNum / DstNum;
1556 unsigned SrcElt = 0;
1557 for (
unsigned i = 0; i < DstNum; i++) {
1561 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize * (Ratio - 1);
1562 for (
unsigned j = 0; j < Ratio; j++) {
1564 Tmp = Tmp.
zext(SrcBitSize);
1566 Tmp = Tmp.
zext(DstBitSize);
1567 Tmp = Tmp.
shl(ShiftAmt);
1568 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
1575 unsigned Ratio = DstNum / SrcNum;
1576 for (
unsigned i = 0; i < SrcNum; i++) {
1577 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize * (Ratio - 1);
1578 for (
unsigned j = 0; j < Ratio; j++) {
1584 if (DstBitSize < SrcBitSize)
1586 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
1596 for (
unsigned i = 0; i < DstNum; i++)
1601 for (
unsigned i = 0; i < DstNum; i++)
1621 assert(SrcTy->
isPointerTy() &&
"Invalid BitCast");
1713 #define IMPLEMENT_VAARG(TY) \
1714 case Type::TY##TyID: Dest.TY##Val = Src.TY##Val; break
1728 Dest.IntVal = Src.
IntVal;
1734 dbgs() <<
"Unhandled dest type for vaarg instruction: " << *Ty <<
"\n";
1752 const unsigned indx =
unsigned(Src2.IntVal.getZExtValue());
1757 dbgs() <<
"Unhandled destination type for extractelement instruction: "
1772 dbgs() <<
"Invalid index in extractelement instruction\n";
1792 const unsigned indx =
unsigned(Src3.IntVal.getZExtValue());
1801 Dest.AggregateVal[indx].IntVal = Src2.IntVal;
1804 Dest.AggregateVal[indx].FloatVal = Src2.FloatVal;
1807 Dest.AggregateVal[indx].DoubleVal = Src2.DoubleVal;
1831 unsigned src2Size = (
unsigned)Src2.AggregateVal.size();
1832 unsigned src3Size = (
unsigned)Src3.AggregateVal.size();
1834 Dest.AggregateVal.resize(src3Size);
1841 for(
unsigned i=0; i<src3Size; i++) {
1842 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1844 Dest.AggregateVal[i].IntVal = Src1.
AggregateVal[j].IntVal;
1845 else if(j < src1Size + src2Size)
1846 Dest.AggregateVal[i].IntVal = Src2.AggregateVal[j-src1Size].IntVal;
1857 for(
unsigned i=0; i<src3Size; i++) {
1858 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1860 Dest.AggregateVal[i].FloatVal = Src1.
AggregateVal[j].FloatVal;
1861 else if(j < src1Size + src2Size)
1862 Dest.AggregateVal[i].FloatVal = Src2.AggregateVal[j-src1Size].FloatVal;
1868 for(
unsigned i=0; i<src3Size; i++) {
1869 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1871 Dest.AggregateVal[i].DoubleVal = Src1.
AggregateVal[j].DoubleVal;
1872 else if(j < src1Size + src2Size)
1873 Dest.AggregateVal[i].DoubleVal =
1874 Src2.AggregateVal[j-src1Size].DoubleVal;
1893 for (
unsigned i = 0 ; i < Num; ++i) {
1938 for (
unsigned i = 0 ; i < Num; ++i) {
1975 case Instruction::Trunc:
1977 case Instruction::ZExt:
1979 case Instruction::SExt:
1981 case Instruction::FPTrunc:
1983 case Instruction::FPExt:
1985 case Instruction::UIToFP:
1987 case Instruction::SIToFP:
1989 case Instruction::FPToUI:
1991 case Instruction::FPToSI:
1993 case Instruction::PtrToInt:
1995 case Instruction::IntToPtr:
1997 case Instruction::BitCast:
1999 case Instruction::GetElementPtr:
2002 case Instruction::FCmp:
2003 case Instruction::ICmp:
2024 case Instruction::Add: Dest.IntVal = Op0.
IntVal + Op1.IntVal;
break;
2025 case Instruction::Sub: Dest.IntVal = Op0.
IntVal - Op1.IntVal;
break;
2026 case Instruction::Mul: Dest.IntVal = Op0.
IntVal * Op1.IntVal;
break;
2032 case Instruction::SDiv: Dest.IntVal = Op0.
IntVal.
sdiv(Op1.IntVal);
break;
2033 case Instruction::UDiv: Dest.IntVal = Op0.
IntVal.
udiv(Op1.IntVal);
break;
2034 case Instruction::URem: Dest.IntVal = Op0.
IntVal.
urem(Op1.IntVal);
break;
2035 case Instruction::SRem: Dest.IntVal = Op0.
IntVal.
srem(Op1.IntVal);
break;
2039 case Instruction::Shl:
2040 Dest.IntVal = Op0.
IntVal.
shl(Op1.IntVal.getZExtValue());
2042 case Instruction::LShr:
2043 Dest.IntVal = Op0.
IntVal.
lshr(Op1.IntVal.getZExtValue());
2045 case Instruction::AShr:
2046 Dest.IntVal = Op0.
IntVal.
ashr(Op1.IntVal.getZExtValue());
2049 dbgs() <<
"Unhandled ConstantExpr: " << *CE <<
"\n";
2057 return getConstantExprValue(CE, SF);
2058 }
else if (
Constant *CPV = dyn_cast<Constant>(V)) {
2060 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2075 const std::vector<GenericValue> &ArgVals) {
2076 assert((ECStack.empty() || ECStack.back().Caller.getInstruction() == 0 ||
2077 ECStack.back().Caller.arg_size() == ArgVals.size()) &&
2078 "Incorrect number of arguments passed into function call!");
2088 popStackAndReturnValueToCaller (F->
getReturnType (), Result);
2097 assert((ArgVals.size() == F->
arg_size() ||
2099 "Invalid number of values passed to function invocation!");
2105 SetValue(AI, ArgVals[i], StackFrame);
2108 StackFrame.
VarArgs.assign(ArgVals.begin()+i, ArgVals.end());
2113 while (!ECStack.empty()) {
2121 DEBUG(
dbgs() <<
"About to interpret: " << I);
2126 if (!isa<CallInst>(I) && !isa<InvokeInst>(I) &&
2127 I.
getType() != Type::VoidTy) {
void visitVAArgInst(VAArgInst &I)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
Value * getPointerOperand()
std::vector< GenericValue > AggregateVal
static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2, Type *Ty)
#define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, _FUNC)
Value * getAggregateOperand()
uint64_t getZExtValue() const
Get zero extended value.
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
GenericValue callExternalFunction(Function *F, const std::vector< GenericValue > &ArgVals)
static GenericValue executeFCMP_ULT(GenericValue Src1, GenericValue Src2, Type *Ty)
ArrayRef< unsigned > getIndices() const
void visitAllocaInst(AllocaInst &I)
void visitStoreInst(StoreInst &I)
unsigned getScalarSizeInBits()
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
void visitTruncInst(TruncInst &I)
void visitFPToUIInst(FPToUIInst &I)
static void executeFDivInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
unsigned arg_size() const
An abstraction for memory operations.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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)
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
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.
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
STATISTIC(NumDynamicInsts,"Number of dynamic instructions executed")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
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)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
bool isUnconditional() const
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
const StructLayout * getStructLayout(StructType *Ty) const
APInt urem(const APInt &LHS, const APInt &RHS)
Function for unsigned remainder operation.
void * getPointerToGlobal(const GlobalValue *GV)
#define llvm_unreachable(msg)
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"))
void callFunction(Function *F, const std::vector< GenericValue > &ArgVals)
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 zero extended value.
#define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY)
static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, Type *Ty)
static const APInt srem(const SCEVConstant *C1, const SCEVConstant *C2)
void visit(Iterator Start, Iterator End)
void visitInsertElementInst(InsertElementInst &I)
void visitFPTruncInst(FPTruncInst &I)
VectorType * getType() const
#define IMPLEMENT_SCALAR_NANS(TY, X, Y)
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)
Represents a floating point comparison operator.
BasicBlock * getSuccessor(unsigned i) const
This class represents a no-op cast from one type to another.
double fmod(double x, double y);
void visitInsertValueInst(InsertValueInst &I)
bool isFloatingPointTy() const
bool isLittleEndian() const
Layout endianness...
GenericValue getConstantValue(const Constant *C)
Converts a Constant* into a GenericValue, including handling of ConstantExpr values.
ValTy * getCalledValue() const
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)
static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2, Type *Ty)
This class represents a truncation of integer types.
Type * getElementType() const
#define IMPLEMENT_VAARG(TY)
uint64_t getElementOffset(unsigned Idx) const
10: Arbitrary bit width integers
void visitLShr(BinaryOperator &I)
static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2, Type *Ty)
void visitICmpInst(ICmpInst &I)
static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, Type *Ty)
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.
InstrTy * getInstruction() const
void visitCallSite(CallSite CS)
unsigned getIntrinsicID() const LLVM_READONLY
Type * getContainedType(unsigned i) const
LLVM Constant Representation.
PointerType * getType() const
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)
Represent an integer comparison operator.
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
Integer representation type.
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
1 1 1 1 Always true (always folded)
void visitFPToSIInst(FPToSIInst &I)
void visitIntToPtrInst(IntToPtrInst &I)
void visitFPExtInst(FPExtInst &I)
uint64_t NextPowerOf2(uint64_t A)
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 const APInt sdiv(const SCEVConstant *C1, const SCEVConstant *C2)
static void executeFRemInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
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.
Class for constant integers.
void visitReturnInst(ReturnInst &I)
Value * getIncomingValue(unsigned i) const
15: SIMD 'packed' format, or other vector type
uint64_t getTypeAllocSize(Type *Ty) const
void visitSExtInst(SExtInst &I)
1 1 0 0 True if unordered or less than
This class represents a cast from floating point to unsigned integer.
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, GenericValue Src3, const Type *Ty)
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 - Return a circular-buffered debug stream.
GenericValue PTOGV(void *P)
Class for arbitrary precision integers.
void visitPtrToIntInst(PtrToIntInst &I)
Value * getCondition() const
double bitsToDouble() const
Converts APInt bits to a double.
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
void *malloc(size_t size);
APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const
Unsigned division operation.
void LowerIntrinsicCall(CallInst *CI)
bool isDeclaration() const
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
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
const Type * getScalarType() const
unsigned getPrimitiveSizeInBits() const
1 0 1 0 True if unordered or greater than
void visitLoadInst(LoadInst &I)
3: 64-bit floating point type
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.
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)
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
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'.
FunTy * getCalledFunction() const
gep_type_iterator gep_type_begin(const User *GEP)