From 225866469fa5a69f240fa67e0aa270c1b32fd35b Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 17 Dec 2006 20:24:50 +0000 Subject: [PATCH] Use a predicate function to identify bitcast of fp and integer instead of repeating the logic in two different parts of the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32643 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 22 +++++++++++----------- lib/Target/CBackend/Writer.cpp | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index a4d5483f2a3..13fd574e0cd 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1676,6 +1676,15 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) { printType(Out, RetTy, FunctionInnards.str()); } +static inline bool isFPIntBitCast(const Instruction &I) { + if (!isa(I)) + return false; + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DstTy = I.getType(); + return (SrcTy->isFloatingPoint() && DstTy->isInteger()) || + (DstTy->isFloatingPoint() && SrcTy->isInteger()); +} + void CWriter::printFunction(Function &F) { printFunctionSignature(&F, false); Out << " {\n"; @@ -1718,11 +1727,7 @@ void CWriter::printFunction(Function &F) { // We need a temporary for the BitCast to use so it can pluck a value out // of a uniont to do the BitCast. This is separate from the need for a // variable to hold the result of the BitCast. - if (isa(*I) && - ((I->getType()->isFloatingPoint() && - I->getOperand(0)->getType()->isInteger()) || - (I->getType()->isInteger() && - I->getOperand(0)->getType()->isFloatingPoint()))) { + if (isFPIntBitCast(*I)) { Out << " llvmBitCastUnion " << Mang->getValueName(&*I) << "__BITCAST_TEMPORARY;\n"; PrintedVar = true; @@ -2025,12 +2030,7 @@ void CWriter::visitCastInst(CastInst &I) { const Type *DstTy = I.getType(); const Type *SrcTy = I.getOperand(0)->getType(); Out << '('; - if (isa(I) && - ((I.getType()->isFloatingPoint() && - I.getOperand(0)->getType()->isInteger()) || - (I.getType()->isInteger() && - I.getOperand(0)->getType()->isFloatingPoint()))) { - + if (isFPIntBitCast(I)) { // These int<->float and long<->double casts need to be handled specially Out << Mang->getValueName(&I) << "__BITCAST_TEMPORARY." << getFloatBitCastField(I.getOperand(0)->getType()) << " = "; diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index a4d5483f2a3..13fd574e0cd 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -1676,6 +1676,15 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) { printType(Out, RetTy, FunctionInnards.str()); } +static inline bool isFPIntBitCast(const Instruction &I) { + if (!isa(I)) + return false; + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DstTy = I.getType(); + return (SrcTy->isFloatingPoint() && DstTy->isInteger()) || + (DstTy->isFloatingPoint() && SrcTy->isInteger()); +} + void CWriter::printFunction(Function &F) { printFunctionSignature(&F, false); Out << " {\n"; @@ -1718,11 +1727,7 @@ void CWriter::printFunction(Function &F) { // We need a temporary for the BitCast to use so it can pluck a value out // of a uniont to do the BitCast. This is separate from the need for a // variable to hold the result of the BitCast. - if (isa(*I) && - ((I->getType()->isFloatingPoint() && - I->getOperand(0)->getType()->isInteger()) || - (I->getType()->isInteger() && - I->getOperand(0)->getType()->isFloatingPoint()))) { + if (isFPIntBitCast(*I)) { Out << " llvmBitCastUnion " << Mang->getValueName(&*I) << "__BITCAST_TEMPORARY;\n"; PrintedVar = true; @@ -2025,12 +2030,7 @@ void CWriter::visitCastInst(CastInst &I) { const Type *DstTy = I.getType(); const Type *SrcTy = I.getOperand(0)->getType(); Out << '('; - if (isa(I) && - ((I.getType()->isFloatingPoint() && - I.getOperand(0)->getType()->isInteger()) || - (I.getType()->isInteger() && - I.getOperand(0)->getType()->isFloatingPoint()))) { - + if (isFPIntBitCast(I)) { // These int<->float and long<->double casts need to be handled specially Out << Mang->getValueName(&I) << "__BITCAST_TEMPORARY." << getFloatBitCastField(I.getOperand(0)->getType()) << " = "; -- 2.34.1