forked from OSchip/llvm-project
				
			Move a bit more functionality to LLVMContext, which apparently wasn't being used anyways.
llvm-svn: 75546
This commit is contained in:
		
							parent
							
								
									56523ceba1
								
							
						
					
					
						commit
						13c240a4c1
					
				| 
						 | 
				
			
			@ -256,12 +256,6 @@ public:
 | 
			
		|||
  /// get() - Static factory methods - Return objects of the specified value
 | 
			
		||||
  static ConstantFP *get(const APFloat &V);
 | 
			
		||||
 | 
			
		||||
  /// get() - This returns a ConstantFP, or a vector containing a splat of a
 | 
			
		||||
  /// ConstantFP, 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 host double and as the target format.
 | 
			
		||||
  static Constant *get(const Type *Ty, double V);
 | 
			
		||||
 | 
			
		||||
  /// isValueValidForType - return true if Ty is big enough to represent V.
 | 
			
		||||
  static bool isValueValidForType(const Type *Ty, const APFloat& V);
 | 
			
		||||
  inline const APFloat& getValueAPF() const { return Val; }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -183,6 +183,11 @@ public:
 | 
			
		|||
  
 | 
			
		||||
  // ConstantFP accessors
 | 
			
		||||
  ConstantFP* getConstantFP(const APFloat& V);
 | 
			
		||||
  
 | 
			
		||||
  /// get() - This returns a ConstantFP, or a vector containing a splat of a
 | 
			
		||||
  /// ConstantFP, 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 host double and as the target format.
 | 
			
		||||
  Constant* getConstantFP(const Type* Ty, double V);
 | 
			
		||||
  ConstantFP* getConstantFPNegativeZero(const Type* Ty);
 | 
			
		||||
  
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -382,24 +382,6 @@ ConstantFP *ConstantFP::get(const APFloat &V) {
 | 
			
		|||
  return Slot;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// 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 *ConstantFP::get(const Type *Ty, double V) {
 | 
			
		||||
  APFloat FV(V);
 | 
			
		||||
  bool ignored;
 | 
			
		||||
  FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
 | 
			
		||||
             APFloat::rmNearestTiesToEven, &ignored);
 | 
			
		||||
  Constant *C = get(FV);
 | 
			
		||||
 | 
			
		||||
  // For vectors, broadcast the value.
 | 
			
		||||
  if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
 | 
			
		||||
    return
 | 
			
		||||
      ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
 | 
			
		||||
 | 
			
		||||
  return C;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//===----------------------------------------------------------------------===//
 | 
			
		||||
//                            ConstantXXX Classes
 | 
			
		||||
//===----------------------------------------------------------------------===//
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue