diff options
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 166 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Execution.cpp | 526 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp | 96 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 56 |
4 files changed, 346 insertions, 498 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 83e94828b7..6903541e06 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -157,7 +157,7 @@ static void *CreateArgv(ExecutionEngine *EE, char *Result = new char[(InputArgv.size()+1)*PtrSize]; DOUT << "ARGV = " << (void*)Result << "\n"; - const Type *SBytePtr = PointerType::get(Type::SByteTy); + const Type *SBytePtr = PointerType::get(Type::Int8Ty); for (unsigned i = 0; i != InputArgv.size(); ++i) { unsigned Size = InputArgv[i].size()+1; @@ -228,7 +228,7 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, const char * const * envp) { std::vector<GenericValue> GVArgs; GenericValue GVArgc; - GVArgc.IntVal = argv.size(); + GVArgc.Int32Val = argv.size(); unsigned NumArgs = Fn->getFunctionType()->getNumParams(); if (NumArgs) { GVArgs.push_back(GVArgc); // Arg #0 = argc. @@ -244,7 +244,7 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, } } } - return runFunction(Fn, GVArgs).IntVal; + return runFunction(Fn, GVArgs).Int32Val; } /// If possible, create a JIT, unless the caller specifically requests an @@ -317,9 +317,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes); if (getTargetData()->getPointerSize() == 4) - Result.IntVal += Offset; + Result.Int32Val += Offset; else - Result.LongVal += Offset; + Result.Int64Val += Offset; return Result; } case Instruction::Trunc: @@ -352,14 +352,10 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { GenericValue GV = getConstantValue(Op); switch (Op->getType()->getTypeID()) { case Type::BoolTyID: return PTOGV((void*)(uintptr_t)GV.BoolVal); - case Type::SByteTyID: return PTOGV((void*)( intptr_t)GV.SByteVal); - case Type::UByteTyID: return PTOGV((void*)(uintptr_t)GV.UByteVal); - case Type::ShortTyID: return PTOGV((void*)( intptr_t)GV.ShortVal); - case Type::UShortTyID: return PTOGV((void*)(uintptr_t)GV.UShortVal); - case Type::IntTyID: return PTOGV((void*)( intptr_t)GV.IntVal); - case Type::UIntTyID: return PTOGV((void*)(uintptr_t)GV.UIntVal); - case Type::LongTyID: return PTOGV((void*)( intptr_t)GV.LongVal); - case Type::ULongTyID: return PTOGV((void*)(uintptr_t)GV.ULongVal); + case Type::Int8TyID: return PTOGV((void*)(uintptr_t)GV.Int8Val); + case Type::Int16TyID: return PTOGV((void*)(uintptr_t)GV.Int16Val); + case Type::Int32TyID: return PTOGV((void*)(uintptr_t)GV.Int32Val); + case Type::Int64TyID: return PTOGV((void*)(uintptr_t)GV.Int64Val); default: assert(0 && "Unknown integral type!"); } break; @@ -367,25 +363,21 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Instruction::Add: switch (CE->getOperand(0)->getType()->getTypeID()) { default: assert(0 && "Bad add type!"); abort(); - case Type::LongTyID: - case Type::ULongTyID: - Result.LongVal = getConstantValue(CE->getOperand(0)).LongVal + - getConstantValue(CE->getOperand(1)).LongVal; + case Type::Int64TyID: + Result.Int64Val = getConstantValue(CE->getOperand(0)).Int64Val + + getConstantValue(CE->getOperand(1)).Int64Val; break; - case Type::IntTyID: - case Type::UIntTyID: - Result.IntVal = getConstantValue(CE->getOperand(0)).IntVal + - getConstantValue(CE->getOperand(1)).IntVal; + case Type::Int32TyID: + Result.Int32Val = getConstantValue(CE->getOperand(0)).Int32Val + + getConstantValue(CE->getOperand(1)).Int32Val; break; - case Type::ShortTyID: - case Type::UShortTyID: - Result.ShortVal = getConstantValue(CE->getOperand(0)).ShortVal + - getConstantValue(CE->getOperand(1)).ShortVal; + case Type::Int16TyID: + Result.Int16Val = getConstantValue(CE->getOperand(0)).Int16Val + + getConstantValue(CE->getOperand(1)).Int16Val; break; - case Type::SByteTyID: - case Type::UByteTyID: - Result.SByteVal = getConstantValue(CE->getOperand(0)).SByteVal + - getConstantValue(CE->getOperand(1)).SByteVal; + case Type::Int8TyID: + Result.Int8Val = getConstantValue(CE->getOperand(0)).Int8Val + + getConstantValue(CE->getOperand(1)).Int8Val; break; case Type::FloatTyID: Result.FloatVal = getConstantValue(CE->getOperand(0)).FloatVal + @@ -407,17 +399,13 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { switch (C->getType()->getTypeID()) { #define GET_CONST_VAL(TY, CTY, CLASS, GETMETH) \ case Type::TY##TyID: Result.TY##Val = (CTY)cast<CLASS>(C)->GETMETH(); break - GET_CONST_VAL(Bool , bool , ConstantBool, getValue); - GET_CONST_VAL(UByte , unsigned char , ConstantInt, getZExtValue); - GET_CONST_VAL(SByte , signed char , ConstantInt, getSExtValue); - GET_CONST_VAL(UShort , unsigned short, ConstantInt, getZExtValue); - GET_CONST_VAL(Short , signed short , ConstantInt, getSExtValue); - GET_CONST_VAL(UInt , unsigned int , ConstantInt, getZExtValue); - GET_CONST_VAL(Int , signed int , ConstantInt, getSExtValue); - GET_CONST_VAL(ULong , uint64_t , ConstantInt, getZExtValue); - GET_CONST_VAL(Long , int64_t , ConstantInt, getSExtValue); - GET_CONST_VAL(Float , float , ConstantFP, getValue); - GET_CONST_VAL(Double , double , ConstantFP, getValue); + GET_CONST_VAL(Bool , bool , ConstantBool, getValue); + GET_CONST_VAL(Int8 , unsigned char , ConstantInt, getZExtValue); + GET_CONST_VAL(Int16 , unsigned short, ConstantInt, getZExtValue); + GET_CONST_VAL(Int32 , unsigned int , ConstantInt, getZExtValue); + GET_CONST_VAL(Int64 , uint64_t , ConstantInt, getZExtValue); + GET_CONST_VAL(Float , float , ConstantFP, getValue); + GET_CONST_VAL(Double, double , ConstantFP, getValue); #undef GET_CONST_VAL case Type::PointerTyID: if (isa<ConstantPointerNull>(C)) @@ -446,33 +434,29 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr, if (getTargetData()->isLittleEndian()) { switch (Ty->getTypeID()) { case Type::BoolTyID: - case Type::UByteTyID: - case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break; - case Type::UShortTyID: - case Type::ShortTyID: Ptr->Untyped[0] = Val.UShortVal & 255; - Ptr->Untyped[1] = (Val.UShortVal >> 8) & 255; + case Type::Int8TyID: Ptr->Untyped[0] = Val.Int8Val; break; + case Type::Int16TyID: Ptr->Untyped[0] = Val.Int16Val & 255; + Ptr->Untyped[1] = (Val.Int16Val >> 8) & 255; break; Store4BytesLittleEndian: case Type::FloatTyID: - case Type::UIntTyID: - case Type::IntTyID: Ptr->Untyped[0] = Val.UIntVal & 255; - Ptr->Untyped[1] = (Val.UIntVal >> 8) & 255; - Ptr->Untyped[2] = (Val.UIntVal >> 16) & 255; - Ptr->Untyped[3] = (Val.UIntVal >> 24) & 255; + case Type::Int32TyID: Ptr->Untyped[0] = Val.Int32Val & 255; + Ptr->Untyped[1] = (Val.Int32Val >> 8) & 255; + Ptr->Untyped[2] = (Val.Int32Val >> 16) & 255; + Ptr->Untyped[3] = (Val.Int32Val >> 24) & 255; break; case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4) goto Store4BytesLittleEndian; case Type::DoubleTyID: - case Type::ULongTyID: - case Type::LongTyID: - Ptr->Untyped[0] = (unsigned char)(Val.ULongVal ); - Ptr->Untyped[1] = (unsigned char)(Val.ULongVal >> 8); - Ptr->Untyped[2] = (unsigned char)(Val.ULongVal >> 16); - Ptr->Untyped[3] = (unsigned char)(Val.ULongVal >> 24); - Ptr->Untyped[4] = (unsigned char)(Val.ULongVal >> 32); - Ptr->Untyped[5] = (unsigned char)(Val.ULongVal >> 40); - Ptr->Untyped[6] = (unsigned char)(Val.ULongVal >> 48); - Ptr->Untyped[7] = (unsigned char)(Val.ULongVal >> 56); + case Type::Int64TyID: + Ptr->Untyped[0] = (unsigned char)(Val.Int64Val ); + Ptr->Untyped[1] = (unsigned char)(Val.Int64Val >> 8); + Ptr->Untyped[2] = (unsigned char)(Val.Int64Val >> 16); + Ptr->Untyped[3] = (unsigned char)(Val.Int64Val >> 24); + Ptr->Untyped[4] = (unsigned char)(Val.Int64Val >> 32); + Ptr->Untyped[5] = (unsigned char)(Val.Int64Val >> 40); + Ptr->Untyped[6] = (unsigned char)(Val.Int64Val >> 48); + Ptr->Untyped[7] = (unsigned char)(Val.Int64Val >> 56); break; default: cerr << "Cannot store value of type " << *Ty << "!\n"; @@ -480,33 +464,29 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr, } else { switch (Ty->getTypeID()) { case Type::BoolTyID: - case Type::UByteTyID: - case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break; - case Type::UShortTyID: - case Type::ShortTyID: Ptr->Untyped[1] = Val.UShortVal & 255; - Ptr->Untyped[0] = (Val.UShortVal >> 8) & 255; + case Type::Int8TyID: Ptr->Untyped[0] = Val.Int8Val; break; + case Type::Int16TyID: Ptr->Untyped[1] = Val.Int16Val & 255; + Ptr->Untyped[0] = (Val.Int16Val >> 8) & 255; break; Store4BytesBigEndian: case Type::FloatTyID: - case Type::UIntTyID: - case Type::IntTyID: Ptr->Untyped[3] = Val.UIntVal & 255; - Ptr->Untyped[2] = (Val.UIntVal >> 8) & 255; - Ptr->Untyped[1] = (Val.UIntVal >> 16) & 255; - Ptr->Untyped[0] = (Val.UIntVal >> 24) & 255; + case Type::Int32TyID: Ptr->Untyped[3] = Val.Int32Val & 255; + Ptr->Untyped[2] = (Val.Int32Val >> 8) & 255; + Ptr->Untyped[1] = (Val.Int32Val >> 16) & 255; + Ptr->Untyped[0] = (Val.Int32Val >> 24) & 255; break; case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4) goto Store4BytesBigEndian; case Type::DoubleTyID: - case Type::ULongTyID: - case Type::LongTyID: - Ptr->Untyped[7] = (unsigned char)(Val.ULongVal ); - Ptr->Untyped[6] = (unsigned char)(Val.ULongVal >> 8); - Ptr->Untyped[5] = (unsigned char)(Val.ULongVal >> 16); - Ptr->Untyped[4] = (unsigned char)(Val.ULongVal >> 24); - Ptr->Untyped[3] = (unsigned char)(Val.ULongVal >> 32); - Ptr->Untyped[2] = (unsigned char)(Val.ULongVal >> 40); - Ptr->Untyped[1] = (unsigned char)(Val.ULongVal >> 48); - Ptr->Untyped[0] = (unsigned char)(Val.ULongVal >> 56); + case Type::Int64TyID: + Ptr->Untyped[7] = (unsigned char)(Val.Int64Val ); + Ptr->Untyped[6] = (unsigned char)(Val.Int64Val >> 8); + Ptr->Untyped[5] = (unsigned char)(Val.Int64Val >> 16); + Ptr->Untyped[4] = (unsigned char)(Val.Int64Val >> 24); + Ptr->Untyped[3] = (unsigned char)(Val.Int64Val >> 32); + Ptr->Untyped[2] = (unsigned char)(Val.Int64Val >> 40); + Ptr->Untyped[1] = (unsigned char)(Val.Int64Val >> 48); + Ptr->Untyped[0] = (unsigned char)(Val.Int64Val >> 56); break; default: cerr << "Cannot store value of type " << *Ty << "!\n"; @@ -522,16 +502,13 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr, if (getTargetData()->isLittleEndian()) { switch (Ty->getTypeID()) { case Type::BoolTyID: - case Type::UByteTyID: - case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break; - case Type::UShortTyID: - case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[0] | + case Type::Int8TyID: Result.Int8Val = Ptr->Untyped[0]; break; + case Type::Int16TyID: Result.Int16Val = (unsigned)Ptr->Untyped[0] | ((unsigned)Ptr->Untyped[1] << 8); break; Load4BytesLittleEndian: case Type::FloatTyID: - case Type::UIntTyID: - case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[0] | + case Type::Int32TyID: Result.Int32Val = (unsigned)Ptr->Untyped[0] | ((unsigned)Ptr->Untyped[1] << 8) | ((unsigned)Ptr->Untyped[2] << 16) | ((unsigned)Ptr->Untyped[3] << 24); @@ -539,8 +516,7 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr, case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4) goto Load4BytesLittleEndian; case Type::DoubleTyID: - case Type::ULongTyID: - case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[0] | + case Type::Int64TyID: Result.Int64Val = (uint64_t)Ptr->Untyped[0] | ((uint64_t)Ptr->Untyped[1] << 8) | ((uint64_t)Ptr->Untyped[2] << 16) | ((uint64_t)Ptr->Untyped[3] << 24) | @@ -556,16 +532,13 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr, } else { switch (Ty->getTypeID()) { case Type::BoolTyID: - case Type::UByteTyID: - case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break; - case Type::UShortTyID: - case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[1] | - ((unsigned)Ptr->Untyped[0] << 8); + case Type::Int8TyID: Result.Int8Val = Ptr->Untyped[0]; break; + case Type::Int16TyID: Result.Int16Val = (unsigned)Ptr->Untyped[1] | + ((unsigned)Ptr->Untyped[0] << 8); break; Load4BytesBigEndian: case Type::FloatTyID: - case Type::UIntTyID: - case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[3] | + case Type::Int32TyID: Result.Int32Val =(unsigned)Ptr->Untyped[3] | ((unsigned)Ptr->Untyped[2] << 8) | ((unsigned)Ptr->Untyped[1] << 16) | ((unsigned)Ptr->Untyped[0] << 24); @@ -573,8 +546,7 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr, case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4) goto Load4BytesBigEndian; case Type::DoubleTyID: - case Type::ULongTyID: - case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[7] | + case Type::Int64TyID: Result.Int64Val = (uint64_t)Ptr->Untyped[7] | ((uint64_t)Ptr->Untyped[6] << 8) | ((uint64_t)Ptr->Untyped[5] << 16) | ((uint64_t)Ptr->Untyped[4] << 24) | diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 3ca5682c05..97411d3943 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -194,14 +194,10 @@ static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_BINARY_OPERATOR(+, UByte); - IMPLEMENT_BINARY_OPERATOR(+, SByte); - IMPLEMENT_BINARY_OPERATOR(+, UShort); - IMPLEMENT_BINARY_OPERATOR(+, Short); - IMPLEMENT_BINARY_OPERATOR(+, UInt); - IMPLEMENT_BINARY_OPERATOR(+, Int); - IMPLEMENT_BINARY_OPERATOR(+, ULong); - IMPLEMENT_BINARY_OPERATOR(+, Long); + IMPLEMENT_BINARY_OPERATOR(+, Int8); + IMPLEMENT_BINARY_OPERATOR(+, Int16); + IMPLEMENT_BINARY_OPERATOR(+, Int32); + IMPLEMENT_BINARY_OPERATOR(+, Int64); IMPLEMENT_BINARY_OPERATOR(+, Float); IMPLEMENT_BINARY_OPERATOR(+, Double); default: @@ -215,14 +211,10 @@ static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_BINARY_OPERATOR(-, UByte); - IMPLEMENT_BINARY_OPERATOR(-, SByte); - IMPLEMENT_BINARY_OPERATOR(-, UShort); - IMPLEMENT_BINARY_OPERATOR(-, Short); - IMPLEMENT_BINARY_OPERATOR(-, UInt); - IMPLEMENT_BINARY_OPERATOR(-, Int); - IMPLEMENT_BINARY_OPERATOR(-, ULong); - IMPLEMENT_BINARY_OPERATOR(-, Long); + IMPLEMENT_BINARY_OPERATOR(-, Int8); + IMPLEMENT_BINARY_OPERATOR(-, Int16); + IMPLEMENT_BINARY_OPERATOR(-, Int32); + IMPLEMENT_BINARY_OPERATOR(-, Int64); IMPLEMENT_BINARY_OPERATOR(-, Float); IMPLEMENT_BINARY_OPERATOR(-, Double); default: @@ -236,14 +228,10 @@ static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_BINARY_OPERATOR(*, UByte); - IMPLEMENT_BINARY_OPERATOR(*, SByte); - IMPLEMENT_BINARY_OPERATOR(*, UShort); - IMPLEMENT_BINARY_OPERATOR(*, Short); - IMPLEMENT_BINARY_OPERATOR(*, UInt); - IMPLEMENT_BINARY_OPERATOR(*, Int); - IMPLEMENT_BINARY_OPERATOR(*, ULong); - IMPLEMENT_BINARY_OPERATOR(*, Long); + IMPLEMENT_BINARY_OPERATOR(*, Int8); + IMPLEMENT_BINARY_OPERATOR(*, Int16); + IMPLEMENT_BINARY_OPERATOR(*, Int32); + IMPLEMENT_BINARY_OPERATOR(*, Int64); IMPLEMENT_BINARY_OPERATOR(*, Float); IMPLEMENT_BINARY_OPERATOR(*, Double); default: @@ -253,17 +241,18 @@ static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2, return Dest; } -#define IMPLEMENT_SIGNLESS_BINOP(OP, TY1, TY2) \ - case Type::TY2##TyID: IMPLEMENT_BINARY_OPERATOR(OP, TY1) +#define IMPLEMENT_SIGNLESS_BINOP(OP, TY, CAST) \ + case Type::TY##TyID: Dest.TY##Val = \ + ((CAST)Src1.TY##Val) OP ((CAST)Src2.TY##Val); break static GenericValue executeUDivInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SIGNLESS_BINOP(/, UByte, SByte); - IMPLEMENT_SIGNLESS_BINOP(/, UShort, Short); - IMPLEMENT_SIGNLESS_BINOP(/, UInt, Int); - IMPLEMENT_SIGNLESS_BINOP(/, ULong, Long); + IMPLEMENT_SIGNLESS_BINOP(/, Int8, uint8_t); + IMPLEMENT_SIGNLESS_BINOP(/, Int16, uint16_t); + IMPLEMENT_SIGNLESS_BINOP(/, Int32, uint32_t); + IMPLEMENT_SIGNLESS_BINOP(/, Int64, uint64_t); default: cerr << "Unhandled type for UDiv instruction: " << *Ty << "\n"; abort(); @@ -275,10 +264,10 @@ static GenericValue executeSDivInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SIGNLESS_BINOP(/, SByte, UByte); - IMPLEMENT_SIGNLESS_BINOP(/, Short, UShort); - IMPLEMENT_SIGNLESS_BINOP(/, Int, UInt); - IMPLEMENT_SIGNLESS_BINOP(/, Long, ULong); + IMPLEMENT_SIGNLESS_BINOP(/, Int8, int8_t); + IMPLEMENT_SIGNLESS_BINOP(/, Int16, int16_t); + IMPLEMENT_SIGNLESS_BINOP(/, Int32, int32_t); + IMPLEMENT_SIGNLESS_BINOP(/, Int64, int64_t); default: cerr << "Unhandled type for SDiv instruction: " << *Ty << "\n"; abort(); @@ -303,10 +292,10 @@ static GenericValue executeURemInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SIGNLESS_BINOP(%, UByte, SByte); - IMPLEMENT_SIGNLESS_BINOP(%, UShort, Short); - IMPLEMENT_SIGNLESS_BINOP(%, UInt, Int); - IMPLEMENT_SIGNLESS_BINOP(%, ULong, Long); + IMPLEMENT_SIGNLESS_BINOP(%, Int8, uint8_t); + IMPLEMENT_SIGNLESS_BINOP(%, Int16, uint16_t); + IMPLEMENT_SIGNLESS_BINOP(%, Int32, uint32_t); + IMPLEMENT_SIGNLESS_BINOP(%, Int64, uint64_t ); default: cerr << "Unhandled type for URem instruction: " << *Ty << "\n"; abort(); @@ -318,10 +307,10 @@ static GenericValue executeSRemInst(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SIGNLESS_BINOP(%, SByte, UByte); - IMPLEMENT_SIGNLESS_BINOP(%, Short, UShort); - IMPLEMENT_SIGNLESS_BINOP(%, Int, UInt); - IMPLEMENT_SIGNLESS_BINOP(%, Long, ULong); + IMPLEMENT_SIGNLESS_BINOP(%, Int8, int8_t); + IMPLEMENT_SIGNLESS_BINOP(%, Int16, int16_t); + IMPLEMENT_SIGNLESS_BINOP(%, Int32, int32_t); + IMPLEMENT_SIGNLESS_BINOP(%, Int64, int64_t); default: cerr << "Unhandled type for Rem instruction: " << *Ty << "\n"; abort(); @@ -351,14 +340,10 @@ static GenericValue executeAndInst(GenericValue Src1, GenericValue Src2, GenericValue Dest; switch (Ty->getTypeID()) { IMPLEMENT_BINARY_OPERATOR(&, Bool); - IMPLEMENT_BINARY_OPERATOR(&, UByte); - IMPLEMENT_BINARY_OPERATOR(&, SByte); - IMPLEMENT_BINARY_OPERATOR(&, UShort); - IMPLEMENT_BINARY_OPERATOR(&, Short); - IMPLEMENT_BINARY_OPERATOR(&, UInt); - IMPLEMENT_BINARY_OPERATOR(&, Int); - IMPLEMENT_BINARY_OPERATOR(&, ULong); - IMPLEMENT_BINARY_OPERATOR(&, Long); + IMPLEMENT_BINARY_OPERATOR(&, Int8); + IMPLEMENT_BINARY_OPERATOR(&, Int16); + IMPLEMENT_BINARY_OPERATOR(&, Int32); + IMPLEMENT_BINARY_OPERATOR(&, Int64); default: cerr << "Unhandled type for And instruction: " << *Ty << "\n"; abort(); @@ -371,14 +356,10 @@ static GenericValue executeOrInst(GenericValue Src1, GenericValue Src2, GenericValue Dest; switch (Ty->getTypeID()) { IMPLEMENT_BINARY_OPERATOR(|, Bool); - IMPLEMENT_BINARY_OPERATOR(|, UByte); - IMPLEMENT_BINARY_OPERATOR(|, SByte); - IMPLEMENT_BINARY_OPERATOR(|, UShort); - IMPLEMENT_BINARY_OPERATOR(|, Short); - IMPLEMENT_BINARY_OPERATOR(|, UInt); - IMPLEMENT_BINARY_OPERATOR(|, Int); - IMPLEMENT_BINARY_OPERATOR(|, ULong); - IMPLEMENT_BINARY_OPERATOR(|, Long); + IMPLEMENT_BINARY_OPERATOR(|, Int8); + IMPLEMENT_BINARY_OPERATOR(|, Int16); + IMPLEMENT_BINARY_OPERATOR(|, Int32); + IMPLEMENT_BINARY_OPERATOR(|, Int64); default: cerr << "Unhandled type for Or instruction: " << *Ty << "\n"; abort(); @@ -391,14 +372,10 @@ static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2, GenericValue Dest; switch (Ty->getTypeID()) { IMPLEMENT_BINARY_OPERATOR(^, Bool); - IMPLEMENT_BINARY_OPERATOR(^, UByte); - IMPLEMENT_BINARY_OPERATOR(^, SByte); - IMPLEMENT_BINARY_OPERATOR(^, UShort); - IMPLEMENT_BINARY_OPERATOR(^, Short); - IMPLEMENT_BINARY_OPERATOR(^, UInt); - IMPLEMENT_BINARY_OPERATOR(^, Int); - IMPLEMENT_BINARY_OPERATOR(^, ULong); - IMPLEMENT_BINARY_OPERATOR(^, Long); + IMPLEMENT_BINARY_OPERATOR(^, Int8); + IMPLEMENT_BINARY_OPERATOR(^, Int16); + IMPLEMENT_BINARY_OPERATOR(^, Int32); + IMPLEMENT_BINARY_OPERATOR(^, Int64); default: cerr << "Unhandled type for Xor instruction: " << *Ty << "\n"; abort(); @@ -406,8 +383,9 @@ static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2, return Dest; } -#define IMPLEMENT_CMP(OP, TY1, TY2) \ - case Type::TY1##TyID: Dest.BoolVal = Src1.TY2##Val OP Src2.TY2##Val; break +#define IMPLEMENT_ICMP(OP, TY, CAST) \ + case Type::TY##TyID: Dest.BoolVal = \ + ((CAST)Src1.TY##Val) OP ((CAST)Src2.TY##Val); break // Handle pointers specially because they must be compared with only as much // width as the host has. We _do not_ want to be comparing 64 bit values when @@ -422,14 +400,10 @@ static GenericValue executeICMP_EQ(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(==, UByte, UByte); - IMPLEMENT_CMP(==, SByte, SByte); - IMPLEMENT_CMP(==, UShort, UShort); - IMPLEMENT_CMP(==, Short, Short); - IMPLEMENT_CMP(==, UInt, UInt); - IMPLEMENT_CMP(==, Int, Int); - IMPLEMENT_CMP(==, ULong, ULong); - IMPLEMENT_CMP(==, Long, Long); + IMPLEMENT_ICMP(==, Int8, uint8_t); + IMPLEMENT_ICMP(==, Int16, uint16_t); + IMPLEMENT_ICMP(==, Int32, uint32_t); + IMPLEMENT_ICMP(==, Int64, uint64_t); IMPLEMENT_POINTERCMP(==); default: cerr << "Unhandled type for ICMP_EQ predicate: " << *Ty << "\n"; @@ -442,14 +416,10 @@ static GenericValue executeICMP_NE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(!=, UByte, UByte); - IMPLEMENT_CMP(!=, SByte, SByte); - IMPLEMENT_CMP(!=, UShort,UShort); - IMPLEMENT_CMP(!=, Short, Short); - IMPLEMENT_CMP(!=, UInt, UInt); - IMPLEMENT_CMP(!=, Int, Int); - IMPLEMENT_CMP(!=, ULong, ULong); - IMPLEMENT_CMP(!=, Long, Long); + IMPLEMENT_ICMP(!=, Int8, uint8_t); + IMPLEMENT_ICMP(!=, Int16, uint16_t); + IMPLEMENT_ICMP(!=, Int32, uint32_t); + IMPLEMENT_ICMP(!=, Int64, uint64_t); IMPLEMENT_POINTERCMP(!=); default: cerr << "Unhandled type for ICMP_NE predicate: " << *Ty << "\n"; @@ -462,14 +432,10 @@ static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(<, SByte, UByte); - IMPLEMENT_CMP(<, Short, UShort); - IMPLEMENT_CMP(<, Int, UInt); - IMPLEMENT_CMP(<, Long, ULong); - IMPLEMENT_CMP(<, UByte, UByte); - IMPLEMENT_CMP(<, UShort, UShort); - IMPLEMENT_CMP(<, UInt, UInt); - IMPLEMENT_CMP(<, ULong, ULong); + IMPLEMENT_ICMP(<, Int8, uint8_t); + IMPLEMENT_ICMP(<, Int16, uint16_t); + IMPLEMENT_ICMP(<, Int32, uint32_t); + IMPLEMENT_ICMP(<, Int64, uint64_t); IMPLEMENT_POINTERCMP(<); default: cerr << "Unhandled type for ICMP_ULT predicate: " << *Ty << "\n"; @@ -482,14 +448,10 @@ static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(<, SByte, SByte); - IMPLEMENT_CMP(<, Short, Short); - IMPLEMENT_CMP(<, Int, Int); - IMPLEMENT_CMP(<, Long, Long); - IMPLEMENT_CMP(<, UByte, SByte); - IMPLEMENT_CMP(<, UShort, Short); - IMPLEMENT_CMP(<, UInt, Int); - IMPLEMENT_CMP(<, ULong, Long); + IMPLEMENT_ICMP(<, Int8, int8_t); + IMPLEMENT_ICMP(<, Int16, int16_t); + IMPLEMENT_ICMP(<, Int32, int32_t); + IMPLEMENT_ICMP(<, Int64, int64_t); IMPLEMENT_POINTERCMP(<); default: cerr << "Unhandled type for ICMP_SLT predicate: " << *Ty << "\n"; @@ -502,14 +464,10 @@ static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(>, SByte, UByte); - IMPLEMENT_CMP(>, Short, UShort); - IMPLEMENT_CMP(>, Int, UInt); - IMPLEMENT_CMP(>, Long, ULong); - IMPLEMENT_CMP(>, UByte, UByte); - IMPLEMENT_CMP(>, UShort, UShort); - IMPLEMENT_CMP(>, UInt, UInt); - IMPLEMENT_CMP(>, ULong, ULong); + IMPLEMENT_ICMP(>, Int8, uint8_t); + IMPLEMENT_ICMP(>, Int16, uint16_t); + IMPLEMENT_ICMP(>, Int32, uint32_t); + IMPLEMENT_ICMP(>, Int64, uint64_t); IMPLEMENT_POINTERCMP(>); default: cerr << "Unhandled type for ICMP_UGT predicate: " << *Ty << "\n"; @@ -522,14 +480,10 @@ static GenericValue executeICMP_SGT(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(>, SByte, SByte); - IMPLEMENT_CMP(>, Short, Short); - IMPLEMENT_CMP(>, Int, Int); - IMPLEMENT_CMP(>, Long, Long); - IMPLEMENT_CMP(>, UByte, SByte); - IMPLEMENT_CMP(>, UShort, Short); - IMPLEMENT_CMP(>, UInt, Int); - IMPLEMENT_CMP(>, ULong, Long); + IMPLEMENT_ICMP(>, Int8, int8_t); + IMPLEMENT_ICMP(>, Int16, int16_t); + IMPLEMENT_ICMP(>, Int32, int32_t); + IMPLEMENT_ICMP(>, Int64, int64_t); IMPLEMENT_POINTERCMP(>); default: cerr << "Unhandled type for ICMP_SGT predicate: " << *Ty << "\n"; @@ -542,14 +496,10 @@ static GenericValue executeICMP_ULE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(<=, SByte, UByte); - IMPLEMENT_CMP(<=, Short, UShort); - IMPLEMENT_CMP(<=, Int, UInt); - IMPLEMENT_CMP(<=, Long, ULong); - IMPLEMENT_CMP(<=, UByte, UByte); - IMPLEMENT_CMP(<=, UShort, UShort); - IMPLEMENT_CMP(<=, UInt, UInt); - IMPLEMENT_CMP(<=, ULong, ULong); + IMPLEMENT_ICMP(<=, Int8, uint8_t); + IMPLEMENT_ICMP(<=, Int16, uint16_t); + IMPLEMENT_ICMP(<=, Int32, uint32_t); + IMPLEMENT_ICMP(<=, Int64, uint64_t); IMPLEMENT_POINTERCMP(<=); default: cerr << "Unhandled type for ICMP_ULE predicate: " << *Ty << "\n"; @@ -562,14 +512,10 @@ static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(<=, SByte, SByte); - IMPLEMENT_CMP(<=, Short, Short); - IMPLEMENT_CMP(<=, Int, Int); - IMPLEMENT_CMP(<=, Long, Long); - IMPLEMENT_CMP(<=, UByte, SByte); - IMPLEMENT_CMP(<=, UShort, Short); - IMPLEMENT_CMP(<=, UInt, Int); - IMPLEMENT_CMP(<=, ULong, Long); + IMPLEMENT_ICMP(<=, Int8, int8_t); + IMPLEMENT_ICMP(<=, Int16, int16_t); + IMPLEMENT_ICMP(<=, Int32, int32_t); + IMPLEMENT_ICMP(<=, Int64, int64_t); IMPLEMENT_POINTERCMP(<=); default: cerr << "Unhandled type for ICMP_SLE predicate: " << *Ty << "\n"; @@ -582,14 +528,10 @@ static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(>=, SByte, UByte); - IMPLEMENT_CMP(>=, Short, UShort); - IMPLEMENT_CMP(>=, Int, UInt); - IMPLEMENT_CMP(>=, Long, ULong); - IMPLEMENT_CMP(>=, UByte, UByte); - IMPLEMENT_CMP(>=, UShort, UShort); - IMPLEMENT_CMP(>=, UInt, UInt); - IMPLEMENT_CMP(>=, ULong, ULong); + IMPLEMENT_ICMP(>=, Int8, uint8_t); + IMPLEMENT_ICMP(>=, Int16, uint16_t); + IMPLEMENT_ICMP(>=, Int32, uint32_t); + IMPLEMENT_ICMP(>=, Int64, uint64_t); IMPLEMENT_POINTERCMP(>=); default: cerr << "Unhandled type for ICMP_UGE predicate: " << *Ty << "\n"; @@ -602,14 +544,10 @@ static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_CMP(>=, SByte, SByte); - IMPLEMENT_CMP(>=, Short, Short); - IMPLEMENT_CMP(>=, Int, Int); - IMPLEMENT_CMP(>=, Long, Long); - IMPLEMENT_CMP(>=, UByte, SByte); - IMPLEMENT_CMP(>=, UShort, Short); - IMPLEMENT_CMP(>=, UInt, Int); - IMPLEMENT_CMP(>=, ULong, Long); + IMPLEMENT_ICMP(>=, Int8, int8_t); + IMPLEMENT_ICMP(>=, Int16, int16_t); + IMPLEMENT_ICMP(>=, Int32, int32_t); + IMPLEMENT_ICMP(>=, Int64, int64_t); IMPLEMENT_POINTERCMP(>=); default: cerr << "Unhandled type for ICMP_SGE predicate: " << *Ty << "\n"; @@ -618,15 +556,41 @@ static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2, return Dest; } -#define IMPLEMENT_SETCC(OP, TY) \ +void Interpreter::visitICmpInst(ICmpInst &I) { + ExecutionContext &SF = ECStack.back(); + const Type *Ty = I.getOperand(0)->getType(); + GenericValue Src1 = getOperandValue(I.getOperand(0), SF); + GenericValue Src2 = getOperandValue(I.getOperand(1), SF); + GenericValue R; // Result + + switch (I.getPredicate()) { + case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break; + case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break; + case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break; + case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break; + case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break; + case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break; + case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break; + case ICmpInst::ICMP_SLE: R = executeICMP_SLE(Src1, Src2, Ty); break; + case ICmpInst::ICMP_UGE: R = executeICMP_UGE(Src1, Src2, Ty); break; + case ICmpInst::ICMP_SGE: R = executeICMP_SGE(Src1, Src2, Ty); break; + default: + cerr << "Don't know how to handle this ICmp predicate!\n-->" << I; + abort(); + } + + SetValue(&I, R, SF); +} + +#define IMPLEMENT_FCMP(OP, TY) \ case Type::TY##TyID: Dest.BoolVal = Src1.TY##Val OP Src2.TY##Val; break static GenericValue executeFCMP_EQ(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SETCC(==, Float); - IMPLEMENT_SETCC(==, Double); + IMPLEMENT_FCMP(==, Float); + IMPLEMENT_FCMP(==, Double); default: cerr << "Unhandled type for SetEQ instruction: " << *Ty << "\n"; abort(); @@ -638,8 +602,8 @@ static GenericValue executeFCMP_NE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SETCC(!=, Float); - IMPLEMENT_SETCC(!=, Double); + IMPLEMENT_FCMP(!=, Float); + IMPLEMENT_FCMP(!=, Double); default: cerr << "Unhandled type for SetNE instruction: " << *Ty << "\n"; @@ -652,8 +616,8 @@ static GenericValue executeFCMP_LE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SETCC(<=, Float); - IMPLEMENT_SETCC(<=, Double); + IMPLEMENT_FCMP(<=, Float); + IMPLEMENT_FCMP(<=, Double); default: cerr << "Unhandled type for SetLE instruction: " << *Ty << "\n"; abort(); @@ -665,8 +629,8 @@ static GenericValue executeFCMP_GE(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SETCC(>=, Float); - IMPLEMENT_SETCC(>=, Double); + IMPLEMENT_FCMP(>=, Float); + IMPLEMENT_FCMP(>=, Double); default: cerr << "Unhandled type for SetGE instruction: " << *Ty << "\n"; abort(); @@ -678,8 +642,8 @@ static GenericValue executeFCMP_LT(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SETCC(<, Float); - IMPLEMENT_SETCC(<, Double); + IMPLEMENT_FCMP(<, Float); + IMPLEMENT_FCMP(<, Double); default: cerr << "Unhandled type for SetLT instruction: " << *Ty << "\n"; abort(); @@ -691,8 +655,8 @@ static GenericValue executeFCMP_GT(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; switch (Ty->getTypeID()) { - IMPLEMENT_SETCC(>, Float); - IMPLEMENT_SETCC(>, Double); + IMPLEMENT_FCMP(>, Float); + IMPLEMENT_FCMP(>, Double); default: cerr << "Unhandled type for SetGT instruction: " << *Ty << "\n"; abort(); @@ -732,32 +696,6 @@ void Interpreter::visitFCmpInst(FCmpInst &I) { SetValue(&I, R, SF); } -void Interpreter::visitICmpInst(ICmpInst &I) { - ExecutionContext &SF = ECStack.back(); - const Type *Ty = I.getOperand(0)->getType(); - GenericValue Src1 = getOperandValue(I.getOperand(0), SF); - GenericValue Src2 = getOperandValue(I.getOperand(1), SF); - GenericValue R; // Result - - switch (I.getPredicate()) { - case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break; - case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break; - case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break; |