summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-05 05:54:46 +0000
committerChris Lattner <sabre@nondot.org>2009-10-05 05:54:46 +0000
commitcf0fe8d813727383d630055bb9d1cde21b00b7e7 (patch)
tree4ed7b0bdfe761ae52997a152437d00ddaae10360 /lib/ExecutionEngine
parent5f7962c1b6574e6d834925158886d7c0a1bab5dc (diff)
downloadllvm-cf0fe8d813727383d630055bb9d1cde21b00b7e7.tar.gz
llvm-cf0fe8d813727383d630055bb9d1cde21b00b7e7.tar.bz2
llvm-cf0fe8d813727383d630055bb9d1cde21b00b7e7.tar.xz
strength reduce a ton of type equality tests to check the typeid (Through
the new predicates I added) instead of going through a context and doing a pointer comparison. Besides being cheaper, this allows a smart compiler to turn the if sequence into a switch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83297 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp22
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp20
2 files changed, 20 insertions, 22 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index 335d4deff8..d3430a376a 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -539,11 +539,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
}
case Instruction::UIToFP: {
GenericValue GV = getConstantValue(Op0);
- if (CE->getType() == Type::getFloatTy(CE->getContext()))
+ if (CE->getType()->isFloatTy())
GV.FloatVal = float(GV.IntVal.roundToDouble());
- else if (CE->getType() == Type::getDoubleTy(CE->getContext()))
+ else if (CE->getType()->isDoubleTy())
GV.DoubleVal = GV.IntVal.roundToDouble();
- else if (CE->getType() == Type::getX86_FP80Ty(Op0->getContext())) {
+ else if (CE->getType()->isX86_FP80Ty()) {
const uint64_t zero[] = {0, 0};
APFloat apf = APFloat(APInt(80, 2, zero));
(void)apf.convertFromAPInt(GV.IntVal,
@@ -555,11 +555,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
}
case Instruction::SIToFP: {
GenericValue GV = getConstantValue(Op0);
- if (CE->getType() == Type::getFloatTy(CE->getContext()))
+ if (CE->getType()->isFloatTy())
GV.FloatVal = float(GV.IntVal.signedRoundToDouble());
- else if (CE->getType() == Type::getDoubleTy(CE->getContext()))
+ else if (CE->getType()->isDoubleTy())
GV.DoubleVal = GV.IntVal.signedRoundToDouble();
- else if (CE->getType() == Type::getX86_FP80Ty(CE->getContext())) {
+ else if (CE->getType()->isX86_FP80Ty()) {
const uint64_t zero[] = { 0, 0};
APFloat apf = APFloat(APInt(80, 2, zero));
(void)apf.convertFromAPInt(GV.IntVal,
@@ -573,11 +573,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
case Instruction::FPToSI: {
GenericValue GV = getConstantValue(Op0);
uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
- if (Op0->getType() == Type::getFloatTy(Op0->getContext()))
+ if (Op0->getType()->isFloatTy())
GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth);
- else if (Op0->getType() == Type::getDoubleTy(Op0->getContext()))
+ else if (Op0->getType()->isDoubleTy())
GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth);
- else if (Op0->getType() == Type::getX86_FP80Ty(Op0->getContext())) {
+ else if (Op0->getType()->isX86_FP80Ty()) {
APFloat apf = APFloat(GV.IntVal);
uint64_t v;
bool ignored;
@@ -610,9 +610,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
default: llvm_unreachable("Invalid bitcast operand");
case Type::IntegerTyID:
assert(DestTy->isFloatingPoint() && "invalid bitcast");
- if (DestTy == Type::getFloatTy(Op0->getContext()))
+ if (DestTy->isFloatTy())
GV.FloatVal = GV.IntVal.bitsToFloat();
- else if (DestTy == Type::getDoubleTy(DestTy->getContext()))
+ else if (DestTy->isDoubleTy())
GV.DoubleVal = GV.IntVal.bitsToDouble();
break;
case Type::FloatTyID:
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index bb45b2c441..f8c775ee7c 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -365,7 +365,7 @@ static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2,
}
#define IMPLEMENT_UNORDERED(TY, X,Y) \
- if (TY == Type::getFloatTy(Ty->getContext())) { \
+ if (TY->isFloatTy()) { \
if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \
Dest.IntVal = APInt(1,true); \
return Dest; \
@@ -421,7 +421,7 @@ static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2,
static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2,
const Type *Ty) {
GenericValue Dest;
- if (Ty == Type::getFloatTy(Ty->getContext()))
+ if (Ty->isFloatTy())
Dest.IntVal = APInt(1,(Src1.FloatVal == Src1.FloatVal &&
Src2.FloatVal == Src2.FloatVal));
else
@@ -433,7 +433,7 @@ static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2,
static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2,
const Type *Ty) {
GenericValue Dest;
- if (Ty == Type::getFloatTy(Ty->getContext()))
+ if (Ty->isFloatTy())
Dest.IntVal = APInt(1,(Src1.FloatVal != Src1.FloatVal ||
Src2.FloatVal != Src2.FloatVal));
else
@@ -970,8 +970,7 @@ GenericValue Interpreter::executeZExtInst(Value *SrcVal, const Type *DstTy,
GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy,
ExecutionContext &SF) {
GenericValue Dest, Src = getOperandValue(SrcVal, SF);
- assert(SrcVal->getType() == Type::getDoubleTy(SrcVal->getContext()) &&
- DstTy == Type::getFloatTy(SrcVal->getContext()) &&
+ assert(SrcVal->getType()->isDoubleTy() && DstTy->isFloatTy() &&
"Invalid FPTrunc instruction");
Dest.FloatVal = (float) Src.DoubleVal;
return Dest;
@@ -980,8 +979,7 @@ GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy,
GenericValue Interpreter::executeFPExtInst(Value *SrcVal, const Type *DstTy,
ExecutionContext &SF) {
GenericValue Dest, Src = getOperandValue(SrcVal, SF);
- assert(SrcVal->getType() == Type::getFloatTy(SrcVal->getContext()) &&
- DstTy == Type::getDoubleTy(SrcVal->getContext()) &&
+ assert(SrcVal->getType()->isFloatTy() && DstTy->isDoubleTy() &&
"Invalid FPTrunc instruction");
Dest.DoubleVal = (double) Src.FloatVal;
return Dest;
@@ -1072,22 +1070,22 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy,
assert(isa<PointerType>(SrcTy) && "Invalid BitCast");
Dest.PointerVal = Src.PointerVal;
} else if (DstTy->isInteger()) {
- if (SrcTy == Type::getFloatTy(SrcVal->getContext())) {
+ if (SrcTy->isFloatTy()) {
Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT);
Dest.IntVal.floatToBits(Src.FloatVal);
- } else if (SrcTy == Type::getDoubleTy(SrcVal->getContext())) {
+ } else if (SrcTy->isDoubleTy()) {
Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT);
Dest.IntVal.doubleToBits(Src.DoubleVal);
} else if (SrcTy->isInteger()) {
Dest.IntVal = Src.IntVal;
} else
llvm_unreachable("Invalid BitCast");
- } else if (DstTy == Type::getFloatTy(SrcVal->getContext())) {
+ } else if (DstTy->isFloatTy()) {
if (SrcTy->isInteger())
Dest.FloatVal = Src.IntVal.bitsToFloat();
else
Dest.FloatVal = Src.FloatVal;
- } else if (DstTy == Type::getDoubleTy(SrcVal->getContext())) {
+ } else if (DstTy->isDoubleTy()) {
if (SrcTy->isInteger())
Dest.DoubleVal = Src.IntVal.bitsToDouble();
else