From 4592230265384bebc2879303310f89dee4d9d7a8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 9 Apr 2008 00:45:01 +0000 Subject: [PATCH] add a version of ConstantFP::get that doesn't take a redundant Type* value, start migrating code over to use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49413 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constants.h | 5 ++++- lib/VMCore/Constants.cpp | 43 ++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index b7c16e4f8c7..c7a7c14b990 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -232,7 +232,10 @@ protected: } public: /// get() - Static factory methods - Return objects of the specified value - static ConstantFP *get(const Type *Ty, const APFloat& V); + static ConstantFP *get(const APFloat &V); + static ConstantFP *get(const Type *Ty, const APFloat &V) { + return get(V); + } /// isValueValidForType - return true if Ty is big enough to represent V. static bool isValueValidForType(const Type *Ty, const APFloat& V); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index ed34a501659..74e30f6f960 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -108,15 +108,15 @@ Constant *Constant::getNullValue(const Type *Ty) { case Type::IntegerTyID: return ConstantInt::get(Ty, 0); case Type::FloatTyID: - return ConstantFP::get(Ty, APFloat(APInt(32, 0))); + return ConstantFP::get(APFloat(APInt(32, 0))); case Type::DoubleTyID: - return ConstantFP::get(Ty, APFloat(APInt(64, 0))); + return ConstantFP::get(APFloat(APInt(64, 0))); case Type::X86_FP80TyID: - return ConstantFP::get(Ty, APFloat(APInt(80, 2, zero))); + return ConstantFP::get(APFloat(APInt(80, 2, zero))); case Type::FP128TyID: - return ConstantFP::get(Ty, APFloat(APInt(128, 2, zero), true)); + return ConstantFP::get(APFloat(APInt(128, 2, zero), true)); case Type::PPC_FP128TyID: - return ConstantFP::get(Ty, APFloat(APInt(128, 2, zero))); + return ConstantFP::get(APFloat(APInt(128, 2, zero))); case Type::PointerTyID: return ConstantPointerNull::get(cast(Ty)); case Type::StructTyID: @@ -270,7 +270,7 @@ bool ConstantFP::isNullValue() const { ConstantFP *ConstantFP::getNegativeZero(const Type *Ty) { APFloat apf = cast (Constant::getNullValue(Ty))->getValueAPF(); apf.changeSign(); - return ConstantFP::get(Ty, apf); + return ConstantFP::get(apf); } bool ConstantFP::isExactlyValue(const APFloat& V) const { @@ -313,24 +313,25 @@ typedef DenseMap FPConstants; -ConstantFP *ConstantFP::get(const Type *Ty, const APFloat& V) { - // temporary - if (Ty==Type::FloatTy) - assert(&V.getSemantics()==&APFloat::IEEEsingle); - else if (Ty==Type::DoubleTy) - assert(&V.getSemantics()==&APFloat::IEEEdouble); - else if (Ty==Type::X86_FP80Ty) - assert(&V.getSemantics()==&APFloat::x87DoubleExtended); - else if (Ty==Type::FP128Ty) - assert(&V.getSemantics()==&APFloat::IEEEquad); - else if (Ty==Type::PPC_FP128Ty) - assert(&V.getSemantics()==&APFloat::PPCDoubleDouble); - else - assert(0); - +ConstantFP *ConstantFP::get(const APFloat &V) { DenseMapAPFloatKeyInfo::KeyTy Key(V); ConstantFP *&Slot = (*FPConstants)[Key]; if (Slot) return Slot; + + const Type *Ty; + if (&V.getSemantics() == &APFloat::IEEEsingle) + Ty = Type::FloatTy; + else if (&V.getSemantics() == &APFloat::IEEEdouble) + Ty = Type::DoubleTy; + else if (&V.getSemantics() == &APFloat::x87DoubleExtended) + Ty = Type::X86_FP80Ty; + else if (&V.getSemantics() == &APFloat::IEEEquad) + Ty = Type::FP128Ty; + else { + assert(&V.getSemantics() == &APFloat::PPCDoubleDouble&&"Unknown FP format"); + Ty = Type::PPC_FP128Ty; + } + return Slot = new ConstantFP(Ty, V); } -- 2.34.1