diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-09 00:45:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-09 00:45:01 +0000 |
commit | 4592230265384bebc2879303310f89dee4d9d7a8 (patch) | |
tree | 5c2d918cf5f15eee6609e9be6b0ea5b51461c864 /lib/VMCore/Constants.cpp | |
parent | 77d00b0cea5ff46d2b8bc14069b9548ffd74e3ac (diff) | |
download | external_llvm-4592230265384bebc2879303310f89dee4d9d7a8.zip external_llvm-4592230265384bebc2879303310f89dee4d9d7a8.tar.gz external_llvm-4592230265384bebc2879303310f89dee4d9d7a8.tar.bz2 |
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
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index ed34a50..74e30f6 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<PointerType>(Ty)); case Type::StructTyID: @@ -270,7 +270,7 @@ bool ConstantFP::isNullValue() const { ConstantFP *ConstantFP::getNegativeZero(const Type *Ty) { APFloat apf = cast <ConstantFP>(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<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, static ManagedStatic<FPMapTy> 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); } |