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 Type *Ty,
const bool val) {
619 dbgs() <<
"Don't know how to handle this FCmp predicate!\n-->" <<
I;
676 dbgs() <<
"Unhandled Cmp predicate\n";
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;
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));
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');
987 if (I.
getOpcode() == Instruction::Alloca)
988 ECStack.back().Allocas.add(Memory);
997 "Cannot getElementOffset of a nonpointer type!");
1001 for (; I !=
E; ++
I) {
1019 assert(BitWidth == 64 &&
"Invalid index type for getelementptr");
1028 DEBUG(
dbgs() <<
"GEP Index " << Total <<
" bytes.\n");
1046 dbgs() <<
"Volatile load " <<
I;
1056 dbgs() <<
"Volatile store: " <<
I;
1072 case Intrinsic::vastart: {
1079 case Intrinsic::vaend:
1081 case Intrinsic::vacopy:
1090 bool atBegin(Parent->begin() == me);
1108 std::vector<GenericValue> ArgVals;
1110 ArgVals.reserve(NumArgs);
1115 ArgVals.push_back(getOperandValue(V, SF));
1128 if (orgShiftAmount < (uint64_t)valueWidth)
1129 return orgShiftAmount;
1132 return (
NextPowerOf2(valueWidth-1) - 1) & orgShiftAmount;
1145 assert(src1Size == Src2.AggregateVal.size());
1146 for (
unsigned i = 0; i < src1Size; i++) {
1148 uint64_t shiftAmount = Src2.
AggregateVal[
i].IntVal.getZExtValue();
1151 Dest.AggregateVal.push_back(Result);
1172 assert(src1Size == Src2.AggregateVal.size());
1173 for (
unsigned i = 0; i < src1Size; i++) {
1175 uint64_t shiftAmount = Src2.
AggregateVal[
i].IntVal.getZExtValue();
1178 Dest.AggregateVal.push_back(Result);
1199 assert(src1Size == Src2.AggregateVal.size());
1200 for (
unsigned i = 0; i < src1Size; i++) {
1202 uint64_t shiftAmount = Src2.
AggregateVal[
i].IntVal.getZExtValue();
1205 Dest.AggregateVal.push_back(Result);
1223 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1227 for (
unsigned i = 0; i < NumElts; i++)
1243 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1247 for (
unsigned i = 0; i < size; i++)
1250 auto *DITy = cast<IntegerType>(DstTy);
1263 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1268 for (
unsigned i = 0; i < size; i++)
1271 auto *DITy = cast<IntegerType>(DstTy);
1285 "Invalid FPTrunc instruction");
1290 for (
unsigned i = 0; i < size; i++)
1294 "Invalid FPTrunc instruction");
1312 for (
unsigned i = 0; i < size; i++)
1316 "Invalid FPExt instruction");
1338 for (
unsigned i = 0; i < size; i++)
1342 for (
unsigned i = 0; i < size; i++)
1376 for (
unsigned i = 0; i < size; i++)
1380 for (
unsigned i = 0; i < size; i++)
1386 unsigned DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1410 for (
unsigned i = 0; i < size; i++)
1414 for (
unsigned i = 0; i < size; i++)
1442 for (
unsigned i = 0; i < size; i++)
1446 for (
unsigned i = 0; i < size; i++)
1503 unsigned SrcBitSize;
1504 unsigned DstBitSize;
1524 DstNum = (SrcNum * SrcBitSize) / DstBitSize;
1531 if (SrcNum * SrcBitSize != DstNum * DstBitSize)
1537 for (
unsigned i = 0; i < SrcNum; i++)
1542 for (
unsigned i = 0; i < SrcNum; i++)
1546 for (
unsigned i = 0; i < SrcNum; i++)
1554 if (DstNum < SrcNum) {
1556 unsigned Ratio = SrcNum / DstNum;
1557 unsigned SrcElt = 0;
1558 for (
unsigned i = 0; i < DstNum; i++) {
1562 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize * (Ratio - 1);
1563 for (
unsigned j = 0; j < Ratio; j++) {
1565 Tmp = Tmp.
zext(SrcBitSize);
1567 Tmp = Tmp.
zext(DstBitSize);
1568 Tmp = Tmp.
shl(ShiftAmt);
1569 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
1576 unsigned Ratio = DstNum / SrcNum;
1577 for (
unsigned i = 0; i < SrcNum; i++) {
1578 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize * (Ratio - 1);
1579 for (
unsigned j = 0; j < Ratio; j++) {
1585 if (DstBitSize < SrcBitSize)
1587 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
1597 for (
unsigned i = 0; i < DstNum; i++)
1602 for (
unsigned i = 0; i < DstNum; i++)
1714 #define IMPLEMENT_VAARG(TY) \
1715 case Type::TY##TyID: Dest.TY##Val = Src.TY##Val; break
1729 Dest.IntVal = Src.
IntVal;
1735 dbgs() <<
"Unhandled dest type for vaarg instruction: " << *Ty <<
"\n";
1753 const unsigned indx =
unsigned(Src2.IntVal.getZExtValue());
1758 dbgs() <<
"Unhandled destination type for extractelement instruction: "
1773 dbgs() <<
"Invalid index in extractelement instruction\n";
1793 const unsigned indx =
unsigned(Src3.IntVal.getZExtValue());
1802 Dest.AggregateVal[indx].IntVal = Src2.IntVal;
1805 Dest.AggregateVal[indx].FloatVal = Src2.FloatVal;
1808 Dest.AggregateVal[indx].DoubleVal = Src2.DoubleVal;
1832 unsigned src2Size = (
unsigned)Src2.AggregateVal.size();
1833 unsigned src3Size = (
unsigned)Src3.AggregateVal.size();
1835 Dest.AggregateVal.resize(src3Size);
1842 for(
unsigned i=0; i<src3Size; i++) {
1843 unsigned j = Src3.AggregateVal[
i].IntVal.getZExtValue();
1846 else if(j < src1Size + src2Size)
1847 Dest.AggregateVal[
i].IntVal = Src2.AggregateVal[j-src1Size].IntVal;
1858 for(
unsigned i=0; i<src3Size; i++) {
1859 unsigned j = Src3.AggregateVal[
i].IntVal.getZExtValue();
1861 Dest.AggregateVal[
i].FloatVal = Src1.
AggregateVal[j].FloatVal;
1862 else if(j < src1Size + src2Size)
1863 Dest.AggregateVal[
i].FloatVal = Src2.AggregateVal[j-src1Size].FloatVal;
1869 for(
unsigned i=0; i<src3Size; i++) {
1870 unsigned j = Src3.AggregateVal[
i].IntVal.getZExtValue();
1872 Dest.AggregateVal[
i].DoubleVal = Src1.
AggregateVal[j].DoubleVal;
1873 else if(j < src1Size + src2Size)
1874 Dest.AggregateVal[
i].DoubleVal =
1875 Src2.AggregateVal[j-src1Size].DoubleVal;
1894 for (
unsigned i = 0 ; i < Num; ++
i) {
1939 for (
unsigned i = 0 ; i < Num; ++
i) {
1976 case Instruction::Trunc:
1978 case Instruction::ZExt:
1980 case Instruction::SExt:
1982 case Instruction::FPTrunc:
1984 case Instruction::FPExt:
1986 case Instruction::UIToFP:
1988 case Instruction::SIToFP:
1990 case Instruction::FPToUI:
1992 case Instruction::FPToSI:
1994 case Instruction::PtrToInt:
1996 case Instruction::IntToPtr:
1998 case Instruction::BitCast:
2000 case Instruction::GetElementPtr:
2003 case Instruction::FCmp:
2004 case Instruction::ICmp:
2026 case Instruction::Sub: Dest.IntVal = Op0.
IntVal - Op1.IntVal;
break;
2027 case Instruction::Mul: Dest.IntVal = Op0.
IntVal * Op1.IntVal;
break;
2033 case Instruction::SDiv: Dest.IntVal = Op0.
IntVal.
sdiv(Op1.IntVal);
break;
2034 case Instruction::UDiv: Dest.IntVal = Op0.
IntVal.
udiv(Op1.IntVal);
break;
2035 case Instruction::URem: Dest.IntVal = Op0.
IntVal.
urem(Op1.IntVal);
break;
2036 case Instruction::SRem: Dest.IntVal = Op0.
IntVal.
srem(Op1.IntVal);
break;
2040 case Instruction::Shl:
2041 Dest.IntVal = Op0.
IntVal.
shl(Op1.IntVal.getZExtValue());
2043 case Instruction::LShr:
2044 Dest.IntVal = Op0.
IntVal.
lshr(Op1.IntVal.getZExtValue());
2046 case Instruction::AShr:
2047 Dest.IntVal = Op0.
IntVal.
ashr(Op1.IntVal.getZExtValue());
2050 dbgs() <<
"Unhandled ConstantExpr: " << *CE <<
"\n";
2058 return getConstantExprValue(CE, SF);
2059 }
else if (
Constant *CPV = dyn_cast<Constant>(V)) {
2061 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2076 assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() ||
2077 ECStack.back().Caller.arg_size() == ArgVals.
size()) &&
2078 "Incorrect number of arguments passed into function call!");
2080 ECStack.emplace_back();
2088 popStackAndReturnValueToCaller (F->
getReturnType (), Result);
2099 "Invalid number of values passed to function invocation!");
2105 SetValue(&*AI, ArgVals[i], StackFrame);
2113 while (!ECStack.empty()) {
2121 DEBUG(
dbgs() <<
"About to interpret: " << I);
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
Return a value (possibly void), from a function.
void visitVAArgInst(VAArgInst &I)
APInt ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
Type * getIndexedType() const
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")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isVolatile() const
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
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 the 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
This instruction constructs a fixed permutation of two input vectors.
bool isDoubleTy() const
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
Returns the type of the ret val.
unsigned getNumIndices() const
void visitShl(BinaryOperator &I)
This class represents a sign extension of integer types.
An instruction for reading from memory.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
#define IMPLEMENT_VECTOR_FCMP(OP)
Type * getElementType() const
static GenericValue executeFCMP_OLT(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
unsigned arg_size() const
const DataLayout & getDataLayout() const
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 urem(const APInt &RHS) const
Unsigned remainder operation.
void visitFCmpInst(FCmpInst &I)
StructType * getStructTypeOrNull() const
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
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.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
void * getPointerToGlobal(const GlobalValue *GV)
getPointerToGlobal - This returns the address of the specified global value.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
void visitSelectInst(SelectInst &I)
#define IMPLEMENT_BINARY_OPERATOR(OP, TY)
ValTy * getCalledValue() const
getCalledValue - Return the pointer to function that is being called.
APInt 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)
APInt shl(unsigned shiftAmt) const
Left-shift function.
void visitInsertElementInst(InsertElementInst &I)
A constant value that is initialized with an expression using other constant values.
void visitFPTruncInst(FPTruncInst &I)
VectorType * getType() const
Overload to return most specific vector type.
#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)
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
Return the type id for the type.
APInt sdiv(const APInt &LHS, const APInt &RHS)
Signed division function for APInt.
bool isFloatingPointTy() const
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.
An instruction for storing to memory.
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)
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
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.
size_t size() const
size - Get the array size.
#define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, FUNC)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
#define IMPLEMENT_VAARG(TY)
uint64_t getElementOffset(unsigned Idx) const
11: Arbitrary bit width integers
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
void visitLShr(BinaryOperator &I)
static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2, Type *Ty)
void visitICmpInst(ICmpInst &I)
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 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...
Conditional or Unconditional Branch instruction.
void visitCallSite(CallSite CS)
bool isVectorTy() const
True if this is an instance of VectorType.
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
This function has undefined behavior.
This is an important base class in LLVM.
PointerType * getType() const
Overload to return most specific pointer type.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Indirect Branch Instruction.
static GenericValue executeFCMP_UNE(GenericValue Src1, GenericValue Src2, Type *Ty)
bool isFloatTy() const
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 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 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
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
True if this is an instance of PointerType.
Type * getType() const
getType - Return the type of the instruction that generated this call site
uint64_t NextPowerOf2(uint64_t A)
NextPowerOf2 - Returns the next power of two (in 64-bits) that is strictly greater than A...
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
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
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static GenericValue executeFCMP_OGE(GenericValue Src1, GenericValue Src2, Type *Ty)
APInt 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)
0 0 1 0 True if ordered and greater than
idx_iterator idx_begin() const
BinaryOps getOpcode() const
Iterator for intrusive lists based on ilist_node.
void visitShuffleVectorInst(ShuffleVectorInst &I)
std::vector< GenericValue > VarArgs
This is the shared class of boolean and integer constants.
InstrTy * getInstruction() const
void visitReturnInst(ReturnInst &I)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
16: 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
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
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
Return true if this is a load from a volatile memory location.
This class represents a cast from floating point to unsigned integer.
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
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.
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
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, GenericValue Src3, Type *Ty)
APInt 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
#define IMPLEMENT_INTEGER_ICMP(OP, TY)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
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)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void visitBinaryOperator(BinaryOperator &I)
VectorType * getType() const
Overload to return most specific vector type.
static GenericValue executeFCMP_BOOL(GenericValue Src1, GenericValue Src2, Type *Ty, const bool val)
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const BasicBlock & front() const
This class represents a truncation of floating point types.
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
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
Returns a member of one of the enums like Instruction::Add.
void visitUIToFPInst(UIToFPInst &I)
#define INTEGER_VECTOR_FUNCTION(OP)
GenericValue callExternalFunction(Function *F, ArrayRef< GenericValue > ArgVals)
void visitSwitchInst(SwitchInst &I)
APInt 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
static APInt floatToBits(float V)
Converts a float to APInt bits.
Value * getPointerOperand()
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
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
Return true if this is 'void'.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
gep_type_iterator gep_type_begin(const User *GEP)