#include "Interpreter.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/IntrinsicLowering.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cmath>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(NumDynamicInsts, "Number of dynamic instructions executed");
static cl::opt<bool> PrintVolatile("interpreter-print-volatile", cl::Hidden,
cl::desc("make the interpreter print every volatile load and store"));
static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) { … }
static void executeFNegInst(GenericValue &Dest, GenericValue Src, Type *Ty) { … }
void Interpreter::visitUnaryOperator(UnaryOperator &I) { … }
#define IMPLEMENT_BINARY_OPERATOR(OP, TY) …
static void executeFAddInst(GenericValue &Dest, GenericValue Src1,
GenericValue Src2, Type *Ty) { … }
static void executeFSubInst(GenericValue &Dest, GenericValue Src1,
GenericValue Src2, Type *Ty) { … }
static void executeFMulInst(GenericValue &Dest, GenericValue Src1,
GenericValue Src2, Type *Ty) { … }
static void executeFDivInst(GenericValue &Dest, GenericValue Src1,
GenericValue Src2, Type *Ty) { … }
static void executeFRemInst(GenericValue &Dest, GenericValue Src1,
GenericValue Src2, Type *Ty) { … }
#define IMPLEMENT_INTEGER_ICMP(OP, TY) …
#define IMPLEMENT_VECTOR_INTEGER_ICMP(OP, TY) …
#define IMPLEMENT_POINTER_ICMP(OP) …
static GenericValue executeICMP_EQ(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_NE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_SGT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_ULE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
void Interpreter::visitICmpInst(ICmpInst &I) { … }
#define IMPLEMENT_FCMP(OP, TY) …
#define IMPLEMENT_VECTOR_FCMP_T(OP, TY) …
#define IMPLEMENT_VECTOR_FCMP(OP) …
static GenericValue executeFCMP_OEQ(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
#define IMPLEMENT_SCALAR_NANS(TY, X,Y) …
#define MASK_VECTOR_NANS_T(X,Y, TZ, FLAG) …
#define MASK_VECTOR_NANS(TY, X,Y, FLAG) … \
static GenericValue executeFCMP_ONE(GenericValue Src1, GenericValue Src2,
Type *Ty)
{ … }
static GenericValue executeFCMP_OLE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_OGE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_OLT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
#define IMPLEMENT_UNORDERED(TY, X,Y) …
#define IMPLEMENT_VECTOR_UNORDERED(TY, X, Y, FUNC) …
static GenericValue executeFCMP_UEQ(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_UNE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_ULE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_UGE(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_ULT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2,
Type *Ty) { … }
static GenericValue executeFCMP_BOOL(GenericValue Src1, GenericValue Src2,
Type *Ty, const bool val) { … }
void Interpreter::visitFCmpInst(FCmpInst &I) { … }
void Interpreter::visitBinaryOperator(BinaryOperator &I) { … }
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2,
GenericValue Src3, Type *Ty) { … }
void Interpreter::visitSelectInst(SelectInst &I) { … }
void Interpreter::exitCalled(GenericValue GV) { … }
void Interpreter::popStackAndReturnValueToCaller(Type *RetTy,
GenericValue Result) { … }
void Interpreter::visitReturnInst(ReturnInst &I) { … }
void Interpreter::visitUnreachableInst(UnreachableInst &I) { … }
void Interpreter::visitBranchInst(BranchInst &I) { … }
void Interpreter::visitSwitchInst(SwitchInst &I) { … }
void Interpreter::visitIndirectBrInst(IndirectBrInst &I) { … }
void Interpreter::SwitchToNewBasicBlock(BasicBlock *Dest, ExecutionContext &SF){ … }
void Interpreter::visitAllocaInst(AllocaInst &I) { … }
GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I,
gep_type_iterator E,
ExecutionContext &SF) { … }
void Interpreter::visitGetElementPtrInst(GetElementPtrInst &I) { … }
void Interpreter::visitLoadInst(LoadInst &I) { … }
void Interpreter::visitStoreInst(StoreInst &I) { … }
void Interpreter::visitVAStartInst(VAStartInst &I) { … }
void Interpreter::visitVAEndInst(VAEndInst &I) { … }
void Interpreter::visitVACopyInst(VACopyInst &I) { … }
void Interpreter::visitIntrinsicInst(IntrinsicInst &I) { … }
void Interpreter::visitCallBase(CallBase &I) { … }
static unsigned getShiftAmount(uint64_t orgShiftAmount,
llvm::APInt valueToShift) { … }
void Interpreter::visitShl(BinaryOperator &I) { … }
void Interpreter::visitLShr(BinaryOperator &I) { … }
void Interpreter::visitAShr(BinaryOperator &I) { … }
GenericValue Interpreter::executeTruncInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeSExtInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeZExtInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeFPExtInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeFPToUIInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeFPToSIInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeUIToFPInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeSIToFPInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executePtrToIntInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeIntToPtrInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
GenericValue Interpreter::executeBitCastInst(Value *SrcVal, Type *DstTy,
ExecutionContext &SF) { … }
void Interpreter::visitTruncInst(TruncInst &I) { … }
void Interpreter::visitSExtInst(SExtInst &I) { … }
void Interpreter::visitZExtInst(ZExtInst &I) { … }
void Interpreter::visitFPTruncInst(FPTruncInst &I) { … }
void Interpreter::visitFPExtInst(FPExtInst &I) { … }
void Interpreter::visitUIToFPInst(UIToFPInst &I) { … }
void Interpreter::visitSIToFPInst(SIToFPInst &I) { … }
void Interpreter::visitFPToUIInst(FPToUIInst &I) { … }
void Interpreter::visitFPToSIInst(FPToSIInst &I) { … }
void Interpreter::visitPtrToIntInst(PtrToIntInst &I) { … }
void Interpreter::visitIntToPtrInst(IntToPtrInst &I) { … }
void Interpreter::visitBitCastInst(BitCastInst &I) { … }
#define IMPLEMENT_VAARG(TY) …
void Interpreter::visitVAArgInst(VAArgInst &I) { … }
void Interpreter::visitExtractElementInst(ExtractElementInst &I) { … }
void Interpreter::visitInsertElementInst(InsertElementInst &I) { … }
void Interpreter::visitShuffleVectorInst(ShuffleVectorInst &I){ … }
void Interpreter::visitExtractValueInst(ExtractValueInst &I) { … }
void Interpreter::visitInsertValueInst(InsertValueInst &I) { … }
GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
ExecutionContext &SF) { … }
GenericValue Interpreter::getOperandValue(Value *V, ExecutionContext &SF) { … }
void Interpreter::callFunction(Function *F, ArrayRef<GenericValue> ArgVals) { … }
void Interpreter::run() { … }