aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-09 00:45:01 +0000
committerChris Lattner <sabre@nondot.org>2008-04-09 00:45:01 +0000
commit4592230265384bebc2879303310f89dee4d9d7a8 (patch)
tree5c2d918cf5f15eee6609e9be6b0ea5b51461c864 /lib/VMCore/Constants.cpp
parent77d00b0cea5ff46d2b8bc14069b9548ffd74e3ac (diff)
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.cpp43
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index ed34a50165..74e30f6f96 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);
}