diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 70 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 33 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 37 |
6 files changed, 74 insertions, 75 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4491eb2..85ade6f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -916,7 +916,7 @@ SDValue SelectionDAG::getIntPtrConstant(uint64_t Val, bool isTarget) { SDValue SelectionDAG::getConstantFP(const APFloat& V, MVT VT, bool isTarget) { - return getConstantFP(*ConstantFP::get(V), VT, isTarget); + return getConstantFP(*Context->getConstantFP(V), VT, isTarget); } SDValue SelectionDAG::getConstantFP(const ConstantFP& V, MVT VT, bool isTarget){ diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 4f90bb3..3c85118 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -2146,7 +2146,8 @@ void SelectionDAGLowering::visitFSub(User &I) { const VectorType *DestTy = cast<VectorType>(I.getType()); const Type *ElTy = DestTy->getElementType(); unsigned VL = DestTy->getNumElements(); - std::vector<Constant*> NZ(VL, Context->getConstantFPNegativeZero(ElTy)); + std::vector<Constant*> NZ(VL, + DAG.getContext()->getConstantFPNegativeZero(ElTy)); Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size()); if (CV == CNZ) { SDValue Op2 = getValue(I.getOperand(1)); @@ -2158,7 +2159,7 @@ void SelectionDAGLowering::visitFSub(User &I) { } if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0))) if (CFP->isExactlyValue( - Context->getConstantFPNegativeZero(Ty)->getValueAPF())) { + DAG.getContext()->getConstantFPNegativeZero(Ty)->getValueAPF())) { SDValue Op2 = getValue(I.getOperand(1)); setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), Op2.getValueType(), Op2)); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 680aed5..6092eb1 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -222,76 +222,6 @@ bool ConstantFP::isExactlyValue(const APFloat& V) const { return Val.bitwiseIsEqual(V); } -namespace { - struct DenseMapAPFloatKeyInfo { - struct KeyTy { - APFloat val; - KeyTy(const APFloat& V) : val(V){} - KeyTy(const KeyTy& that) : val(that.val) {} - bool operator==(const KeyTy& that) const { - return this->val.bitwiseIsEqual(that.val); - } - bool operator!=(const KeyTy& that) const { - return !this->operator==(that); - } - }; - static inline KeyTy getEmptyKey() { - return KeyTy(APFloat(APFloat::Bogus,1)); - } - static inline KeyTy getTombstoneKey() { - return KeyTy(APFloat(APFloat::Bogus,2)); - } - static unsigned getHashValue(const KeyTy &Key) { - return Key.val.getHashValue(); - } - static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { - return LHS == RHS; - } - static bool isPod() { return false; } - }; -} - -//---- ConstantFP::get() implementation... -// -typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, - DenseMapAPFloatKeyInfo> FPMapTy; - -static ManagedStatic<FPMapTy> FPConstants; - -ConstantFP *ConstantFP::get(const APFloat &V) { - DenseMapAPFloatKeyInfo::KeyTy Key(V); - - ConstantsLock->reader_acquire(); - ConstantFP *&Slot = (*FPConstants)[Key]; - ConstantsLock->reader_release(); - - if (!Slot) { - sys::SmartScopedWriter<true> Writer(*ConstantsLock); - ConstantFP *&NewSlot = (*FPConstants)[Key]; - if (!NewSlot) { - 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; - } - NewSlot = new ConstantFP(Ty, V); - } - - return NewSlot; - } - - return Slot; -} - //===----------------------------------------------------------------------===// // ConstantXXX Classes //===----------------------------------------------------------------------===// diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index 0372f31..c869ab0 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -482,7 +482,7 @@ Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) { // ConstantFP accessors. ConstantFP* LLVMContext::getConstantFP(const APFloat& V) { - return ConstantFP::get(V); + return pImpl->getConstantFP(V); } static const fltSemantics *TypeToFloatSemantics(const Type *Ty) { diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index a92c19f..4c6319e 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -46,3 +46,36 @@ ConstantInt *LLVMContextImpl::getConstantInt(const APInt& V) { } } +ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) { + DenseMapAPFloatKeyInfo::KeyTy Key(V); + + ConstantsLock.reader_acquire(); + ConstantFP *&Slot = FPConstants[Key]; + ConstantsLock.reader_release(); + + if (!Slot) { + sys::SmartScopedWriter<true> Writer(ConstantsLock); + ConstantFP *&NewSlot = FPConstants[Key]; + if (!NewSlot) { + 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; + } + NewSlot = new ConstantFP(Ty, V); + } + + return NewSlot; + } + + return Slot; +}
\ No newline at end of file diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index fbf29fd..27bd451 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -16,12 +16,14 @@ #define LLVM_LLVMCONTEXT_IMPL_H #include "llvm/System/RWMutex.h" +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" namespace llvm { class ConstantInt; +class ConstantFP; class LLVMContext; class Type; @@ -50,6 +52,33 @@ struct DenseMapAPIntKeyInfo { static bool isPod() { return false; } }; +struct DenseMapAPFloatKeyInfo { + struct KeyTy { + APFloat val; + KeyTy(const APFloat& V) : val(V){} + KeyTy(const KeyTy& that) : val(that.val) {} + bool operator==(const KeyTy& that) const { + return this->val.bitwiseIsEqual(that.val); + } + bool operator!=(const KeyTy& that) const { + return !this->operator==(that); + } + }; + static inline KeyTy getEmptyKey() { + return KeyTy(APFloat(APFloat::Bogus,1)); + } + static inline KeyTy getTombstoneKey() { + return KeyTy(APFloat(APFloat::Bogus,2)); + } + static unsigned getHashValue(const KeyTy &Key) { + return Key.val.getHashValue(); + } + static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { + return LHS == RHS; + } + static bool isPod() { return false; } +}; + class LLVMContextImpl { sys::SmartRWMutex<true> ConstantsLock; @@ -57,6 +86,10 @@ class LLVMContextImpl { DenseMapAPIntKeyInfo> IntMapTy; IntMapTy IntConstants; + typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, + DenseMapAPFloatKeyInfo> FPMapTy; + FPMapTy FPConstants; + LLVMContext &Context; LLVMContextImpl(); LLVMContextImpl(const LLVMContextImpl&); @@ -65,7 +98,9 @@ public: /// Return a ConstantInt with the specified value and an implied Type. The /// type is the integer type that corresponds to the bit width of the value. - ConstantInt* getConstantInt(const APInt &V); + ConstantInt *getConstantInt(const APInt &V); + + ConstantFP *getConstantFP(const APFloat &V); }; } |