diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-13 23:16:26 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-13 23:16:26 +0000 |
commit | fd70726ee103e1e7a352f2033376441a48253f2b (patch) | |
tree | b05ea1cfb920c9acc7017963dde0a396b37168bb /lib/VMCore/LLVMContext.cpp | |
parent | 58773c745409bd5826f0d2f04e8a72ad150ba78a (diff) | |
download | external_llvm-fd70726ee103e1e7a352f2033376441a48253f2b.zip external_llvm-fd70726ee103e1e7a352f2033376441a48253f2b.tar.gz external_llvm-fd70726ee103e1e7a352f2033376441a48253f2b.tar.bz2 |
Move a bit more functionality to LLVMContext, which apparently wasn't being used anyways.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75546 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContext.cpp')
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index a7df2af..8d57d2c 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -442,8 +442,36 @@ ConstantFP* LLVMContext::getConstantFP(const APFloat& V) { return ConstantFP::get(V); } +static const fltSemantics *TypeToFloatSemantics(const Type *Ty) { + if (Ty == Type::FloatTy) + return &APFloat::IEEEsingle; + if (Ty == Type::DoubleTy) + return &APFloat::IEEEdouble; + if (Ty == Type::X86_FP80Ty) + return &APFloat::x87DoubleExtended; + else if (Ty == Type::FP128Ty) + return &APFloat::IEEEquad; + + assert(Ty == Type::PPC_FP128Ty && "Unknown FP format"); + return &APFloat::PPCDoubleDouble; +} + +/// get() - This returns a constant fp for the specified value in the +/// specified type. This should only be used for simple constant values like +/// 2.0/1.0 etc, that are known-valid both as double and as the target format. Constant* LLVMContext::getConstantFP(const Type* Ty, double V) { - return ConstantFP::get(Ty, V); + APFloat FV(V); + bool ignored; + FV.convert(*TypeToFloatSemantics(Ty->getScalarType()), + APFloat::rmNearestTiesToEven, &ignored); + Constant *C = getConstantFP(FV); + + // For vectors, broadcast the value. + if (const VectorType *VTy = dyn_cast<VectorType>(Ty)) + return + getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C)); + + return C; } ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) { |