mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-17 18:24:34 +00:00
add a simplified accessor for creating an fp constant of a
particular value but variable type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49416 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -246,21 +246,24 @@ ConstantInt *ConstantInt::get(const APInt& V) {
|
|||||||
// ConstantFP
|
// ConstantFP
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
ConstantFP::ConstantFP(const Type *Ty, const APFloat& V)
|
ConstantFP::ConstantFP(const Type *Ty, const APFloat& V)
|
||||||
: Constant(Ty, ConstantFPVal, 0, 0), Val(V) {
|
: Constant(Ty, ConstantFPVal, 0, 0), Val(V) {
|
||||||
// temporary
|
assert(&V.getSemantics() == TypeToFloatSemantics(Ty) &&
|
||||||
if (Ty==Type::FloatTy)
|
"FP type Mismatch");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConstantFP::isNullValue() const {
|
bool ConstantFP::isNullValue() const {
|
||||||
@@ -335,6 +338,15 @@ ConstantFP *ConstantFP::get(const APFloat &V) {
|
|||||||
return Slot = new ConstantFP(Ty, V);
|
return Slot = new ConstantFP(Ty, V);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
ConstantFP *ConstantFP::get(const Type *Ty, double V) {
|
||||||
|
APFloat FV(V);
|
||||||
|
FV.convert(*TypeToFloatSemantics(Ty), APFloat::rmNearestTiesToEven);
|
||||||
|
return get(FV);
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// ConstantXXX Classes
|
// ConstantXXX Classes
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Reference in New Issue
Block a user