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;
782 case Instruction::And: R.IntVal = Src1.
IntVal & Src2.IntVal;
break;
783 case Instruction::Or: R.IntVal = Src1.
IntVal | Src2.IntVal;
break;
784 case Instruction::Xor: R.IntVal = Src1.
IntVal ^ 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);
902 for (
auto Case : I.
cases()) {
903 GenericValue CaseVal = getOperandValue(Case.getCaseValue(), SF);
905 Dest = cast<BasicBlock>(Case.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);
979 LLVM_DEBUG(
dbgs() <<
"Allocated Type: " << *Ty <<
" (" << TypeSize
980 <<
" bytes) x " << NumElements <<
" (Total: " << MemToAlloc
981 <<
") at " << 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");
1046 dbgs() <<
"Volatile load " <<
I;
1056 dbgs() <<
"Volatile store: " <<
I;
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);
1251 unsigned DBitWidth = DITy->getBitWidth();
1263 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1268 for (
unsigned i = 0; i <
size; i++)
1271 auto *DITy = cast<IntegerType>(DstTy);
1272 unsigned DBitWidth = DITy->getBitWidth();
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);
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";
1790 const unsigned indx =
unsigned(Src3.IntVal.getZExtValue());
1791 Dest.AggregateVal = Src1.AggregateVal;
1793 if(Src1.AggregateVal.size() <= indx)
1799 Dest.AggregateVal[indx].IntVal = Src2.IntVal;
1802 Dest.AggregateVal[indx].FloatVal = Src2.FloatVal;
1805 Dest.AggregateVal[indx].DoubleVal = Src2.DoubleVal;
1826 unsigned src1Size = (
unsigned)Src1.AggregateVal.size();
1827 unsigned src2Size = (
unsigned)Src2.AggregateVal.size();
1828 unsigned src3Size = (
unsigned)Src3.AggregateVal.size();
1830 Dest.AggregateVal.resize(src3Size);
1837 for(
unsigned i=0; i<src3Size; i++) {
1838 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1840 Dest.AggregateVal[i].IntVal = Src1.AggregateVal[j].IntVal;
1841 else if(j < src1Size + src2Size)
1842 Dest.AggregateVal[i].IntVal = Src2.AggregateVal[j-src1Size].IntVal;
1853 for(
unsigned i=0; i<src3Size; i++) {
1854 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1856 Dest.AggregateVal[i].FloatVal = Src1.AggregateVal[j].FloatVal;
1857 else if(j < src1Size + src2Size)
1858 Dest.AggregateVal[i].FloatVal = Src2.AggregateVal[j-src1Size].FloatVal;
1864 for(
unsigned i=0; i<src3Size; i++) {
1865 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1867 Dest.AggregateVal[i].DoubleVal = Src1.AggregateVal[j].DoubleVal;
1868 else if(j < src1Size + src2Size)
1869 Dest.AggregateVal[i].DoubleVal =
1870 Src2.AggregateVal[j-src1Size].DoubleVal;
1889 for (
unsigned i = 0 ; i < Num; ++i) {
1934 for (
unsigned i = 0 ; i < Num; ++i) {
1971 case Instruction::Trunc:
1973 case Instruction::ZExt:
1975 case Instruction::SExt:
1977 case Instruction::FPTrunc:
1979 case Instruction::FPExt:
1981 case Instruction::UIToFP:
1983 case Instruction::SIToFP:
1985 case Instruction::FPToUI:
1987 case Instruction::FPToSI:
1989 case Instruction::PtrToInt:
1991 case Instruction::IntToPtr:
1993 case Instruction::BitCast:
1995 case Instruction::GetElementPtr:
1998 case Instruction::FCmp:
1999 case Instruction::ICmp:
2021 case Instruction::Sub: Dest.IntVal = Op0.
IntVal - Op1.IntVal;
break;
2022 case Instruction::Mul: Dest.IntVal = Op0.
IntVal * Op1.IntVal;
break;
2028 case Instruction::SDiv: Dest.IntVal = Op0.
IntVal.
sdiv(Op1.IntVal);
break;
2029 case Instruction::UDiv: Dest.IntVal = Op0.
IntVal.
udiv(Op1.IntVal);
break;
2030 case Instruction::URem: Dest.IntVal = Op0.
IntVal.
urem(Op1.IntVal);
break;
2031 case Instruction::SRem: Dest.IntVal = Op0.
IntVal.
srem(Op1.IntVal);
break;
2032 case Instruction::And: Dest.IntVal = Op0.
IntVal & Op1.IntVal;
break;
2033 case Instruction::Or: Dest.IntVal = Op0.
IntVal | Op1.IntVal;
break;
2034 case Instruction::Xor: Dest.IntVal = Op0.
IntVal ^ Op1.IntVal;
break;
2035 case Instruction::Shl:
2036 Dest.IntVal = Op0.
IntVal.
shl(Op1.IntVal.getZExtValue());
2038 case Instruction::LShr:
2039 Dest.IntVal = Op0.
IntVal.
lshr(Op1.IntVal.getZExtValue());
2041 case Instruction::AShr:
2042 Dest.IntVal = Op0.
IntVal.
ashr(Op1.IntVal.getZExtValue());
2045 dbgs() <<
"Unhandled ConstantExpr: " << *CE <<
"\n";
2053 return getConstantExprValue(CE, SF);
2054 }
else if (
Constant *CPV = dyn_cast<Constant>(V)) {
2056 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2071 assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() ||
2072 ECStack.back().Caller.arg_size() == ArgVals.
size()) &&
2073 "Incorrect number of arguments passed into function call!");
2075 ECStack.emplace_back();
2083 popStackAndReturnValueToCaller (F->
getReturnType (), Result);
2094 "Invalid number of values passed to function invocation!");
2100 SetValue(&*AI, ArgVals[i], StackFrame);
2108 while (!ECStack.empty()) {
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Return a value (possibly void), from a function.
void visitVAArgInst(VAArgInst &I)
Value * getPointerOperand()
std::vector< GenericValue > AggregateVal
static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2, Type *Ty)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
uint64_t getZExtValue() const
Get zero extended value.
APInt sext(unsigned width) const
Sign extend to a new width.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
This class represents an incoming formal argument to a Function.
Value * getAggregateOperand()
unsigned arg_size() const
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
static GenericValue executeFCMP_ULT(GenericValue Src1, GenericValue Src2, Type *Ty)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
BinaryOps getOpcode() const
void visitAllocaInst(AllocaInst &I)
void visitStoreInst(StoreInst &I)
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float vlalue.
unsigned getNumIndices() const
static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF)
2: 32-bit floating point type
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
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.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
void visitGetElementPtrInst(GetElementPtrInst &I)
APInt zext(unsigned width) const
Zero extend to a new width.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
BasicBlock::iterator CurInst
#define MASK_VECTOR_NANS(TY, X, Y, FLAG)
Value * getCondition() const
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
This instruction constructs a fixed permutation of two input vectors.
LLVMContext & getContext() const
All values hold a context through their type.
1 1 1 0 True if unordered or not equal
void visitExtractElementInst(ExtractElementInst &I)
BasicBlock * getSuccessor(unsigned i) const
APInt trunc(unsigned width) const
Truncate to new width.
void visitShl(BinaryOperator &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 ...
STATISTIC(NumFunctions, "Total number of functions")
This class represents a sign extension of integer types.
An instruction for reading from memory.
const DataLayout & getDataLayout() const
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Value * getCondition() const
bool isVectorTy() const
True if this is an instance of VectorType.
#define IMPLEMENT_VECTOR_FCMP(OP)
static GenericValue executeFCMP_OLT(GenericValue Src1, GenericValue Src2, Type *Ty)
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
unsigned getBitWidth() const
Return the number of bits in the APInt.
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
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 isVolatile() const
Return true if this is a load from a volatile memory location.
This class represents the LLVM 'select' instruction.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
TypeID getTypeID() const
Return the type id for the type.
PointerType * getType() const
Overload to return most specific pointer type.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
APInt shl(unsigned shiftAmt) const
Left-shift function.
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)
bool isIntegerTy() const
True if this is an instance of IntegerType.
0 1 0 1 True if ordered and less than or equal
InstrTy * getInstruction() const
static cl::opt< bool > PrintVolatile("interpreter-print-volatile", cl::Hidden, cl::desc("make the interpreter print every volatile load and store"))
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
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.
#define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY)
static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, Type *Ty)
void visit(Iterator Start, Iterator End)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
void visitInsertElementInst(InsertElementInst &I)
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
void visitFPTruncInst(FPTruncInst &I)
#define IMPLEMENT_SCALAR_NANS(TY, X, Y)
static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2, Type *Ty)
void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, Type *Ty)
FIXME: document.
This instruction compares its operands according to the predicate given to the constructor.
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)
bool isLittleEndian() const
Layout endianness...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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)
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
void visitBitCastInst(BitCastInst &I)
VectorType * getType() const
Overload to return most specific vector type.
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.
Value * getOperand(unsigned i) const
#define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, FUNC)
#define IMPLEMENT_VAARG(TY)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
11: Arbitrary bit width integers
bool isVoidTy() const
Return true if this is 'void'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
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)
Type * getReturnType() const
Returns the type of the ret val.
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)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2, Type *Ty)
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)
size_t size() const
size - Get the array size.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
Indirect Branch Instruction.
static GenericValue executeFCMP_UNE(GenericValue Src1, GenericValue Src2, Type *Ty)
void visitIndirectBrInst(IndirectBrInst &I)
BasicBlock * getDefaultDest() const
void visitZExtInst(ZExtInst &I)
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.
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.
void visitExtractValueInst(ExtractValueInst &I)
This class represents a cast from an integer to a pointer.
1 1 1 1 Always true (always folded)
void visitFPToSIInst(FPToSIInst &I)
void visitIntToPtrInst(IntToPtrInst &I)
void visitFPExtInst(FPExtInst &I)
Type * getIndexedType() const
uint64_t NextPowerOf2(uint64_t A)
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...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
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 lshr(unsigned shiftAmt) const
Logical right-shift function.
void * GVTOP(const GenericValue &GV)
idx_iterator idx_begin() const
static void executeFRemInst(GenericValue &Dest, GenericValue Src1, GenericValue Src2, Type *Ty)
0 0 1 0 True if ordered and greater than
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
Iterator for intrusive lists based on ilist_node.
void visitShuffleVectorInst(ShuffleVectorInst &I)
StructType * getStructTypeOrNull() const
unsigned getNumOperands() const
std::vector< GenericValue > VarArgs
This is the shared class of boolean and integer constants.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
void visitReturnInst(ReturnInst &I)
16: SIMD 'packed' format, or other vector type
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
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.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Class to represent vector types.
GenericValue PTOGV(void *P)
Class for arbitrary precision integers.
void visitPtrToIntInst(PtrToIntInst &I)
void runAtExitHandlers()
runAtExitHandlers - Run any functions registered by the program's calls to atexit(3), which we intercept and store in AtExitHandlers.
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
void visitBranchInst(BranchInst &I)
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
#define FLOAT_VECTOR_OP(OP)
Predicate getPredicate() const
Return the predicate for this instruction.
void visitAShr(BinaryOperator &I)
bool isVolatile() const
Return true if this is a store to a volatile memory location.
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, GenericValue Src3, Type *Ty)
uint64_t getElementOffset(unsigned Idx) const
void LowerIntrinsicCall(CallInst *CI)
Replace a call to the specified intrinsic function.
Value * getOperand() const
static GenericValue executeFCMP_ULE(GenericValue Src1, GenericValue Src2, Type *Ty)
unsigned greater or equal
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
#define IMPLEMENT_INTEGER_ICMP(OP, TY)
void visitSIToFPInst(SIToFPInst &I)
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)
static GenericValue executeFCMP_BOOL(GenericValue Src1, GenericValue Src2, Type *Ty, const bool val)
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
bool isUnconditional() const
1 0 1 0 True if unordered or greater than
void visitLoadInst(LoadInst &I)
Type * getType() const
Return the type of the instruction that generated this call site.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
float bitsToFloat() const
Converts APInt bits to a double.
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.
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)
ArrayRef< unsigned > getIndices() const
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
void visitUIToFPInst(UIToFPInst &I)
#define INTEGER_VECTOR_FUNCTION(OP)
GenericValue callExternalFunction(Function *F, ArrayRef< GenericValue > ArgVals)
Type * getElementType() const
void visitSwitchInst(SwitchInst &I)
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.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
double bitsToDouble() const
Converts APInt bits to a double.
VectorType * getType() const
Overload to return most specific vector type.
Value * getPointerOperand()
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
Type * getElementType() const
0 0 0 0 Always false (always folded)
static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, Type *Ty)
const BasicBlock * getParent() const
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)