30 #define DEBUG_TYPE "interpreter" 32 STATISTIC(NumDynamicInsts,
"Number of dynamic instructions executed");
35 cl::desc(
"make the interpreter print every volatile load and store"));
76 case Instruction::FNeg:
77 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
78 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
79 R.AggregateVal[i].FloatVal = -Src.
AggregateVal[i].FloatVal;
80 }
else if (cast<VectorType>(Ty)->getElementType()->isDoubleTy()) {
81 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
82 R.AggregateVal[i].DoubleVal = -Src.
AggregateVal[i].DoubleVal;
103 #define IMPLEMENT_BINARY_OPERATOR(OP, TY) \ 104 case Type::TY##TyID: \ 105 Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; \ 114 dbgs() <<
"Unhandled type for FAdd instruction: " << *Ty <<
"\n";
125 dbgs() <<
"Unhandled type for FSub instruction: " << *Ty <<
"\n";
136 dbgs() <<
"Unhandled type for FMul instruction: " << *Ty <<
"\n";
147 dbgs() <<
"Unhandled type for FDiv instruction: " << *Ty <<
"\n";
162 dbgs() <<
"Unhandled type for Rem instruction: " << *Ty <<
"\n";
167 #define IMPLEMENT_INTEGER_ICMP(OP, TY) \ 168 case Type::IntegerTyID: \ 169 Dest.IntVal = APInt(1,Src1.IntVal.OP(Src2.IntVal)); \ 172 #define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY) \ 173 case Type::VectorTyID: { \ 174 assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \ 175 Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \ 176 for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \ 177 Dest.AggregateVal[_i].IntVal = APInt(1, \ 178 Src1.AggregateVal[_i].IntVal.OP(Src2.AggregateVal[_i].IntVal));\ 185 #define IMPLEMENT_POINTER_ICMP(OP) \ 186 case Type::PointerTyID: \ 187 Dest.IntVal = APInt(1,(void*)(intptr_t)Src1.PointerVal OP \ 188 (void*)(intptr_t)Src2.PointerVal); \ 199 dbgs() <<
"Unhandled type for ICMP_EQ predicate: " << *Ty <<
"\n";
213 dbgs() <<
"Unhandled type for ICMP_NE predicate: " << *Ty <<
"\n";
227 dbgs() <<
"Unhandled type for ICMP_ULT predicate: " << *Ty <<
"\n";
241 dbgs() <<
"Unhandled type for ICMP_SLT predicate: " << *Ty <<
"\n";
255 dbgs() <<
"Unhandled type for ICMP_UGT predicate: " << *Ty <<
"\n";
269 dbgs() <<
"Unhandled type for ICMP_SGT predicate: " << *Ty <<
"\n";
283 dbgs() <<
"Unhandled type for ICMP_ULE predicate: " << *Ty <<
"\n";
297 dbgs() <<
"Unhandled type for ICMP_SLE predicate: " << *Ty <<
"\n";
311 dbgs() <<
"Unhandled type for ICMP_UGE predicate: " << *Ty <<
"\n";
325 dbgs() <<
"Unhandled type for ICMP_SGE predicate: " << *Ty <<
"\n";
350 dbgs() <<
"Don't know how to handle this ICmp predicate!\n-->" <<
I;
357 #define IMPLEMENT_FCMP(OP, TY) \ 358 case Type::TY##TyID: \ 359 Dest.IntVal = APInt(1,Src1.TY##Val OP Src2.TY##Val); \ 362 #define IMPLEMENT_VECTOR_FCMP_T(OP, TY) \ 363 assert(Src1.AggregateVal.size() == Src2.AggregateVal.size()); \ 364 Dest.AggregateVal.resize( Src1.AggregateVal.size() ); \ 365 for( uint32_t _i=0;_i<Src1.AggregateVal.size();_i++) \ 366 Dest.AggregateVal[_i].IntVal = APInt(1, \ 367 Src1.AggregateVal[_i].TY##Val OP Src2.AggregateVal[_i].TY##Val);\ 370 #define IMPLEMENT_VECTOR_FCMP(OP) \ 371 case Type::VectorTyID: \ 372 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) { \ 373 IMPLEMENT_VECTOR_FCMP_T(OP, Float); \ 375 IMPLEMENT_VECTOR_FCMP_T(OP, Double); \ 386 dbgs() <<
"Unhandled type for FCmp EQ instruction: " << *Ty <<
"\n";
392 #define IMPLEMENT_SCALAR_NANS(TY, X,Y) \ 393 if (TY->isFloatTy()) { \ 394 if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ 395 Dest.IntVal = APInt(1,false); \ 399 if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \ 400 Dest.IntVal = APInt(1,false); \ 405 #define MASK_VECTOR_NANS_T(X,Y, TZ, FLAG) \ 406 assert(X.AggregateVal.size() == Y.AggregateVal.size()); \ 407 Dest.AggregateVal.resize( X.AggregateVal.size() ); \ 408 for( uint32_t _i=0;_i<X.AggregateVal.size();_i++) { \ 409 if (X.AggregateVal[_i].TZ##Val != X.AggregateVal[_i].TZ##Val || \ 410 Y.AggregateVal[_i].TZ##Val != Y.AggregateVal[_i].TZ##Val) \ 411 Dest.AggregateVal[_i].IntVal = APInt(1,FLAG); \ 413 Dest.AggregateVal[_i].IntVal = APInt(1,!FLAG); \ 417 #define MASK_VECTOR_NANS(TY, X,Y, FLAG) \ 418 if (TY->isVectorTy()) { \ 419 if (cast<VectorType>(TY)->getElementType()->isFloatTy()) { \ 420 MASK_VECTOR_NANS_T(X, Y, Float, FLAG) \ 422 MASK_VECTOR_NANS_T(X, Y, Double, FLAG) \ 442 dbgs() <<
"Unhandled type for FCmp NE instruction: " << *Ty <<
"\n";
462 dbgs() <<
"Unhandled type for FCmp LE instruction: " << *Ty <<
"\n";
476 dbgs() <<
"Unhandled type for FCmp GE instruction: " << *Ty <<
"\n";
490 dbgs() <<
"Unhandled type for FCmp LT instruction: " << *Ty <<
"\n";
504 dbgs() <<
"Unhandled type for FCmp GT instruction: " << *Ty <<
"\n";
510 #define IMPLEMENT_UNORDERED(TY, X,Y) \ 511 if (TY->isFloatTy()) { \ 512 if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ 513 Dest.IntVal = APInt(1,true); \ 516 } else if (X.DoubleVal != X.DoubleVal || Y.DoubleVal != Y.DoubleVal) { \ 517 Dest.IntVal = APInt(1,true); \ 521 #define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, FUNC) \ 522 if (TY->isVectorTy()) { \ 523 GenericValue DestMask = Dest; \ 524 Dest = FUNC(Src1, Src2, Ty); \ 525 for (size_t _i = 0; _i < Src1.AggregateVal.size(); _i++) \ 526 if (DestMask.AggregateVal[_i].IntVal == true) \ 527 Dest.AggregateVal[_i].IntVal = APInt(1, true); \ 592 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
623 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) {
649 Type *Ty,
const bool val) {
672 dbgs() <<
"Don't know how to handle this FCmp predicate!\n-->" <<
I;
729 dbgs() <<
"Unhandled Cmp predicate\n";
747 #define INTEGER_VECTOR_OPERATION(OP) \ 748 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \ 749 R.AggregateVal[i].IntVal = \ 750 Src1.AggregateVal[i].IntVal OP Src2.AggregateVal[i].IntVal; 754 #define INTEGER_VECTOR_FUNCTION(OP) \ 755 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \ 756 R.AggregateVal[i].IntVal = \ 757 Src1.AggregateVal[i].IntVal.OP(Src2.AggregateVal[i].IntVal); 761 #define FLOAT_VECTOR_FUNCTION(OP, TY) \ 762 for (unsigned i = 0; i < R.AggregateVal.size(); ++i) \ 763 R.AggregateVal[i].TY = \ 764 Src1.AggregateVal[i].TY OP Src2.AggregateVal[i].TY; 768 #define FLOAT_VECTOR_OP(OP) { \ 769 if (cast<VectorType>(Ty)->getElementType()->isFloatTy()) \ 770 FLOAT_VECTOR_FUNCTION(OP, FloatVal) \ 772 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy()) \ 773 FLOAT_VECTOR_FUNCTION(OP, DoubleVal) \ 775 dbgs() << "Unhandled type for OP instruction: " << *Ty << "\n"; \ 776 llvm_unreachable(0); \ 783 dbgs() <<
"Don't know how to handle this binary operator!\n-->" <<
I;
800 case Instruction::FRem:
801 if (cast<VectorType>(Ty)->getElementType()->isFloatTy())
802 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
803 R.AggregateVal[i].FloatVal =
804 fmod(Src1.
AggregateVal[i].FloatVal, Src2.AggregateVal[i].FloatVal);
806 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
807 for (
unsigned i = 0; i < R.AggregateVal.size(); ++i)
808 R.AggregateVal[i].DoubleVal =
809 fmod(Src1.
AggregateVal[i].DoubleVal, Src2.AggregateVal[i].DoubleVal);
811 dbgs() <<
"Unhandled type for Rem instruction: " << *Ty <<
"\n";
820 dbgs() <<
"Don't know how to handle this binary operator!\n-->" <<
I;
824 case Instruction::Sub: R.IntVal = Src1.
IntVal - Src2.IntVal;
break;
825 case Instruction::Mul: R.IntVal = Src1.
IntVal * Src2.IntVal;
break;
831 case Instruction::UDiv: R.IntVal = Src1.
IntVal.
udiv(Src2.IntVal);
break;
832 case Instruction::SDiv: R.IntVal = Src1.
IntVal.
sdiv(Src2.IntVal);
break;
833 case Instruction::URem: R.IntVal = Src1.
IntVal.
urem(Src2.IntVal);
break;
834 case Instruction::SRem: R.IntVal = Src1.
IntVal.
srem(Src2.IntVal);
break;
835 case Instruction::And: R.IntVal = Src1.
IntVal & Src2.IntVal;
break;
836 case Instruction::Or: R.IntVal = Src1.
IntVal | Src2.IntVal;
break;
837 case Instruction::Xor: R.IntVal = Src1.
IntVal ^ Src2.IntVal;
break;
854 Dest = (Src1.
IntVal == 0) ? Src3 : Src2;
890 void Interpreter::popStackAndReturnValueToCaller(
Type *RetTy,
895 if (ECStack.empty()) {
910 SwitchToNewBasicBlock (II->getNormalDest (), CallingSF);
927 popStackAndReturnValueToCaller(RetTy, Result);
941 if (getOperandValue(Cond, SF).
IntVal == 0)
944 SwitchToNewBasicBlock(Dest, SF);
955 for (
auto Case : I.
cases()) {
956 GenericValue CaseVal = getOperandValue(Case.getCaseValue(), SF);
958 Dest = cast<BasicBlock>(Case.getCaseSuccessor());
963 SwitchToNewBasicBlock(Dest, SF);
988 if (!isa<PHINode>(SF.
CurInst))
return;
991 std::vector<GenericValue> ResultValues;
996 assert(i != -1 &&
"PHINode doesn't contain entry for predecessor??");
1000 ResultValues.push_back(getOperandValue(IncomingValue, SF));
1005 for (
unsigned i = 0; isa<PHINode>(SF.
CurInst); ++SF.
CurInst, ++i) {
1021 unsigned NumElements =
1027 unsigned MemToAlloc =
std::max(1U, NumElements * TypeSize);
1032 LLVM_DEBUG(
dbgs() <<
"Allocated Type: " << *Ty <<
" (" << TypeSize
1033 <<
" bytes) x " << NumElements <<
" (Total: " << MemToAlloc
1034 <<
") at " << uintptr_t(Memory) <<
'\n');
1040 if (I.
getOpcode() == Instruction::Alloca)
1041 ECStack.back().Allocas.add(Memory);
1050 "Cannot getElementOffset of a nonpointer type!");
1054 for (; I !=
E; ++
I) {
1072 assert(BitWidth == 64 &&
"Invalid index type for getelementptr");
1099 dbgs() <<
"Volatile load " <<
I;
1109 dbgs() <<
"Volatile store: " <<
I;
1125 case Intrinsic::vastart: {
1132 case Intrinsic::vaend:
1134 case Intrinsic::vacopy:
1143 bool atBegin(Parent->begin() == me);
1161 std::vector<GenericValue> ArgVals;
1163 ArgVals.reserve(NumArgs);
1168 ArgVals.push_back(getOperandValue(V, SF));
1181 if (orgShiftAmount < (uint64_t)valueWidth)
1182 return orgShiftAmount;
1185 return (
NextPowerOf2(valueWidth-1) - 1) & orgShiftAmount;
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);
1225 assert(src1Size == Src2.AggregateVal.size());
1226 for (
unsigned i = 0; i < src1Size; i++) {
1228 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1231 Dest.AggregateVal.push_back(Result);
1252 assert(src1Size == Src2.AggregateVal.size());
1253 for (
unsigned i = 0; i < src1Size; i++) {
1255 uint64_t shiftAmount = Src2.
AggregateVal[i].IntVal.getZExtValue();
1258 Dest.AggregateVal.push_back(Result);
1276 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1280 for (
unsigned i = 0; i < NumElts; i++)
1296 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1300 for (
unsigned i = 0; i <
size; i++)
1303 auto *DITy = cast<IntegerType>(DstTy);
1304 unsigned DBitWidth = DITy->getBitWidth();
1316 unsigned DBitWidth = cast<IntegerType>(DstVecTy)->
getBitWidth();
1321 for (
unsigned i = 0; i <
size; i++)
1324 auto *DITy = cast<IntegerType>(DstTy);
1325 unsigned DBitWidth = DITy->getBitWidth();
1338 "Invalid FPTrunc instruction");
1343 for (
unsigned i = 0; i <
size; i++)
1347 "Invalid FPTrunc instruction");
1365 for (
unsigned i = 0; i <
size; i++)
1369 "Invalid FPExt instruction");
1391 for (
unsigned i = 0; i <
size; i++)
1395 for (
unsigned i = 0; i <
size; i++)
1429 for (
unsigned i = 0; i <
size; i++)
1433 for (
unsigned i = 0; i <
size; i++)
1439 unsigned DBitWidth = cast<IntegerType>(DstTy)->
getBitWidth();
1463 for (
unsigned i = 0; i <
size; i++)
1467 for (
unsigned i = 0; i <
size; i++)
1495 for (
unsigned i = 0; i <
size; i++)
1499 for (
unsigned i = 0; i <
size; i++)
1556 unsigned SrcBitSize;
1557 unsigned DstBitSize;
1577 DstNum = (SrcNum * SrcBitSize) / DstBitSize;
1584 if (SrcNum * SrcBitSize != DstNum * DstBitSize)
1590 for (
unsigned i = 0; i < SrcNum; i++)
1595 for (
unsigned i = 0; i < SrcNum; i++)
1599 for (
unsigned i = 0; i < SrcNum; i++)
1607 if (DstNum < SrcNum) {
1609 unsigned Ratio = SrcNum / DstNum;
1610 unsigned SrcElt = 0;
1611 for (
unsigned i = 0; i < DstNum; i++) {
1615 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize * (Ratio - 1);
1616 for (
unsigned j = 0; j < Ratio; j++) {
1618 Tmp = Tmp.
zext(SrcBitSize);
1620 Tmp = Tmp.
zext(DstBitSize);
1622 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
1629 unsigned Ratio = DstNum / SrcNum;
1630 for (
unsigned i = 0; i < SrcNum; i++) {
1631 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize * (Ratio - 1);
1632 for (
unsigned j = 0; j < Ratio; j++) {
1638 if (DstBitSize < SrcBitSize)
1640 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
1650 for (
unsigned i = 0; i < DstNum; i++)
1655 for (
unsigned i = 0; i < DstNum; i++)
1767 #define IMPLEMENT_VAARG(TY) \ 1768 case Type::TY##TyID: Dest.TY##Val = Src.TY##Val; break 1782 Dest.IntVal = Src.
IntVal;
1788 dbgs() <<
"Unhandled dest type for vaarg instruction: " << *Ty <<
"\n";
1806 const unsigned indx =
unsigned(Src2.IntVal.getZExtValue());
1811 dbgs() <<
"Unhandled destination type for extractelement instruction: " 1826 dbgs() <<
"Invalid index in extractelement instruction\n";
1843 const unsigned indx =
unsigned(Src3.IntVal.getZExtValue());
1844 Dest.AggregateVal = Src1.AggregateVal;
1846 if(Src1.AggregateVal.size() <= indx)
1852 Dest.AggregateVal[indx].IntVal = Src2.IntVal;
1855 Dest.AggregateVal[indx].FloatVal = Src2.FloatVal;
1858 Dest.AggregateVal[indx].DoubleVal = Src2.DoubleVal;
1879 unsigned src1Size = (
unsigned)Src1.AggregateVal.size();
1880 unsigned src2Size = (
unsigned)Src2.AggregateVal.size();
1881 unsigned src3Size = (
unsigned)Src3.AggregateVal.size();
1883 Dest.AggregateVal.resize(src3Size);
1890 for(
unsigned i=0; i<src3Size; i++) {
1891 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1893 Dest.AggregateVal[i].IntVal = Src1.AggregateVal[j].IntVal;
1894 else if(j < src1Size + src2Size)
1895 Dest.AggregateVal[i].IntVal = Src2.AggregateVal[j-src1Size].IntVal;
1906 for(
unsigned i=0; i<src3Size; i++) {
1907 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1909 Dest.AggregateVal[i].FloatVal = Src1.AggregateVal[j].FloatVal;
1910 else if(j < src1Size + src2Size)
1911 Dest.AggregateVal[i].FloatVal = Src2.AggregateVal[j-src1Size].FloatVal;
1917 for(
unsigned i=0; i<src3Size; i++) {
1918 unsigned j = Src3.AggregateVal[i].IntVal.getZExtValue();
1920 Dest.AggregateVal[i].DoubleVal = Src1.AggregateVal[j].DoubleVal;
1921 else if(j < src1Size + src2Size)
1922 Dest.AggregateVal[i].DoubleVal =
1923 Src2.AggregateVal[j-src1Size].DoubleVal;
1942 for (
unsigned i = 0 ; i < Num; ++i) {
1987 for (
unsigned i = 0 ; i < Num; ++i) {
2024 case Instruction::Trunc:
2026 case Instruction::ZExt:
2028 case Instruction::SExt:
2030 case Instruction::FPTrunc:
2032 case Instruction::FPExt:
2034 case Instruction::UIToFP:
2036 case Instruction::SIToFP:
2038 case Instruction::FPToUI:
2040 case Instruction::FPToSI:
2042 case Instruction::PtrToInt:
2044 case Instruction::IntToPtr:
2046 case Instruction::BitCast:
2048 case Instruction::GetElementPtr:
2051 case Instruction::FCmp:
2052 case Instruction::ICmp:
2074 case Instruction::Sub: Dest.IntVal = Op0.
IntVal - Op1.IntVal;
break;
2075 case Instruction::Mul: Dest.IntVal = Op0.
IntVal * Op1.IntVal;
break;
2081 case Instruction::SDiv: Dest.IntVal = Op0.
IntVal.
sdiv(Op1.IntVal);
break;
2082 case Instruction::UDiv: Dest.IntVal = Op0.
IntVal.
udiv(Op1.IntVal);
break;
2083 case Instruction::URem: Dest.IntVal = Op0.
IntVal.
urem(Op1.IntVal);
break;
2084 case Instruction::SRem: Dest.IntVal = Op0.
IntVal.
srem(Op1.IntVal);
break;
2085 case Instruction::And: Dest.IntVal = Op0.
IntVal & Op1.IntVal;
break;
2086 case Instruction::Or: Dest.IntVal = Op0.
IntVal | Op1.IntVal;
break;
2087 case Instruction::Xor: Dest.IntVal = Op0.
IntVal ^ Op1.IntVal;
break;
2088 case Instruction::Shl:
2089 Dest.IntVal = Op0.
IntVal.
shl(Op1.IntVal.getZExtValue());
2091 case Instruction::LShr:
2092 Dest.IntVal = Op0.
IntVal.
lshr(Op1.IntVal.getZExtValue());
2094 case Instruction::AShr:
2095 Dest.IntVal = Op0.
IntVal.
ashr(Op1.IntVal.getZExtValue());
2098 dbgs() <<
"Unhandled ConstantExpr: " << *CE <<
"\n";
2106 return getConstantExprValue(CE, SF);
2107 }
else if (
Constant *CPV = dyn_cast<Constant>(V)) {
2109 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2124 assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() ||
2125 ECStack.back().Caller.arg_size() == ArgVals.
size()) &&
2126 "Incorrect number of arguments passed into function call!");
2128 ECStack.emplace_back();
2136 popStackAndReturnValueToCaller (F->
getReturnType (), Result);
2147 "Invalid number of values passed to function invocation!");
2153 SetValue(&*AI, ArgVals[i], StackFrame);
2161 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.
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
This class represents an incoming formal argument to a Function.
Value * getAggregateOperand()
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)
void visitUnaryOperator(UnaryOperator &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.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
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.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
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
Type * getType() const
Return the type of the instruction that generated this call site.
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)
InstrTy * getInstruction() const
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.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
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)
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
Align max(MaybeAlign Lhs, Align Rhs)
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
unsigned arg_size() const
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)
#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)
UnaryOps getOpcode() const
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)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
float bitsToFloat() const
Converts APInt bits to a float.
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())
static void executeFNegInst(GenericValue &Dest, GenericValue Src, Type *Ty)
const BasicBlock & front() const
This class represents a truncation of floating point types.
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)