mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
Next round of APFloat changes.
Use APFloat in UpgradeParser and AsmParser. Change all references to ConstantFP to use the APFloat interface rather than double. Remove the ConstantFP double interfaces. Use APFloat functions for constant folding arithmetic and comparisons. (There are still way too many places APFloat is just a wrapper around host float/double, but we're getting there.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41747 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -159,7 +159,7 @@ struct ValID {
|
||||
char *Name; // If it's a named reference. Memory must be free'd.
|
||||
int64_t ConstPool64; // Constant pool reference. This is the value
|
||||
uint64_t UConstPool64;// Unsigned constant pool reference.
|
||||
double ConstPoolFP; // Floating point constant pool reference
|
||||
APFloat *ConstPoolFP; // Floating point constant pool reference
|
||||
Constant *ConstantValue; // Fully resolved constant for ConstantVal case.
|
||||
InlineAsmDescriptor *IAD;
|
||||
};
|
||||
@@ -187,7 +187,7 @@ struct ValID {
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID create(double Val) {
|
||||
static ValID create(APFloat* Val) {
|
||||
ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val;
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
@@ -245,7 +245,7 @@ struct ValID {
|
||||
switch (Type) {
|
||||
case NumberVal : return std::string("#") + itostr(Num);
|
||||
case NameVal : return Name;
|
||||
case ConstFPVal : return ftostr(ConstPoolFP);
|
||||
case ConstFPVal : return ftostr(*ConstPoolFP);
|
||||
case ConstNullVal : return "null";
|
||||
case ConstUndefVal : return "undef";
|
||||
case ConstZeroVal : return "zeroinitializer";
|
||||
@@ -271,7 +271,8 @@ struct ValID {
|
||||
case NameVal: return strcmp(Name, V.Name) < 0;
|
||||
case ConstSIntVal: return ConstPool64 < V.ConstPool64;
|
||||
case ConstUIntVal: return UConstPool64 < V.UConstPool64;
|
||||
case ConstFPVal: return ConstPoolFP < V.ConstPoolFP;
|
||||
case ConstFPVal: return ConstPoolFP->compare(*V.ConstPoolFP) ==
|
||||
APFloat::cmpLessThan;
|
||||
case ConstNullVal: return false;
|
||||
case ConstUndefVal: return false;
|
||||
case ConstZeroVal: return false;
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -410,8 +410,10 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVectorOp, SHUFFLEVECTOR); }
|
||||
return SINTVAL;
|
||||
}
|
||||
|
||||
{FPConstant} { Upgradelval.FPVal = atof(yytext); return FPVAL; }
|
||||
{HexFPConstant} { Upgradelval.FPVal = HexToFP(yytext); return FPVAL; }
|
||||
{FPConstant} { Upgradelval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
|
||||
{HexFPConstant} { Upgradelval.FPVal = new APFloat(HexToFP(yytext));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
<<EOF>> {
|
||||
/* Make sure to free the internal buffers for flex when we are
|
||||
|
@@ -410,8 +410,10 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVectorOp, SHUFFLEVECTOR); }
|
||||
return SINTVAL;
|
||||
}
|
||||
|
||||
{FPConstant} { Upgradelval.FPVal = atof(yytext); return FPVAL; }
|
||||
{HexFPConstant} { Upgradelval.FPVal = HexToFP(yytext); return FPVAL; }
|
||||
{FPConstant} { Upgradelval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
|
||||
{HexFPConstant} { Upgradelval.FPVal = new APFloat(HexToFP(yytext));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
<<EOF>> {
|
||||
/* Make sure to free the internal buffers for flex when we are
|
||||
|
@@ -533,9 +533,13 @@ static Value *getExistingValue(const Type *Ty, const ValID &D) {
|
||||
return ConstantInt::get(Ty, D.UConstPool64);
|
||||
|
||||
case ValID::ConstFPVal: // Is it a floating point const pool reference?
|
||||
if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
|
||||
if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
|
||||
error("FP constant invalid for type");
|
||||
return ConstantFP::get(Ty, D.ConstPoolFP);
|
||||
// Lexer has no type info, so builds all FP constants as double.
|
||||
// Fix this here.
|
||||
if (Ty==Type::FloatTy)
|
||||
D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
|
||||
return ConstantFP::get(Ty, *D.ConstPoolFP);
|
||||
|
||||
case ValID::ConstNullVal: // Is it a null value?
|
||||
if (!isa<PointerType>(Ty))
|
||||
@@ -1773,7 +1777,7 @@ using namespace llvm;
|
||||
uint64_t UInt64Val;
|
||||
int SIntVal;
|
||||
unsigned UIntVal;
|
||||
double FPVal;
|
||||
llvm::APFloat *FPVal;
|
||||
bool BoolVal;
|
||||
|
||||
char *StrVal; // This memory is strdup'd!
|
||||
@@ -2514,9 +2518,13 @@ ConstVal
|
||||
$$.S.makeUnsigned();
|
||||
}
|
||||
| FPType FPVAL { // Float & Double constants
|
||||
if (!ConstantFP::isValueValidForType($1.T, $2))
|
||||
if (!ConstantFP::isValueValidForType($1.T, *$2))
|
||||
error("Floating point constant invalid for type");
|
||||
$$.C = ConstantFP::get($1.T, $2);
|
||||
// Lexer has no type info, so builds all FP constants as double.
|
||||
// Fix this here.
|
||||
if ($1.T==Type::FloatTy)
|
||||
$2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
|
||||
$$.C = ConstantFP::get($1.T, *$2);
|
||||
$$.S.makeSignless();
|
||||
}
|
||||
;
|
||||
|
@@ -533,9 +533,13 @@ static Value *getExistingValue(const Type *Ty, const ValID &D) {
|
||||
return ConstantInt::get(Ty, D.UConstPool64);
|
||||
|
||||
case ValID::ConstFPVal: // Is it a floating point const pool reference?
|
||||
if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
|
||||
if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
|
||||
error("FP constant invalid for type");
|
||||
return ConstantFP::get(Ty, D.ConstPoolFP);
|
||||
// Lexer has no type info, so builds all FP constants as double.
|
||||
// Fix this here.
|
||||
if (Ty==Type::FloatTy)
|
||||
D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
|
||||
return ConstantFP::get(Ty, *D.ConstPoolFP);
|
||||
|
||||
case ValID::ConstNullVal: // Is it a null value?
|
||||
if (!isa<PointerType>(Ty))
|
||||
@@ -1773,7 +1777,7 @@ using namespace llvm;
|
||||
uint64_t UInt64Val;
|
||||
int SIntVal;
|
||||
unsigned UIntVal;
|
||||
double FPVal;
|
||||
llvm::APFloat *FPVal;
|
||||
bool BoolVal;
|
||||
|
||||
char *StrVal; // This memory is strdup'd!
|
||||
@@ -2514,9 +2518,13 @@ ConstVal
|
||||
$$.S.makeUnsigned();
|
||||
}
|
||||
| FPType FPVAL { // Float & Double constants
|
||||
if (!ConstantFP::isValueValidForType($1.T, $2))
|
||||
if (!ConstantFP::isValueValidForType($1.T, *$2))
|
||||
error("Floating point constant invalid for type");
|
||||
$$.C = ConstantFP::get($1.T, $2);
|
||||
// Lexer has no type info, so builds all FP constants as double.
|
||||
// Fix this here.
|
||||
if ($1.T==Type::FloatTy)
|
||||
$2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
|
||||
$$.C = ConstantFP::get($1.T, *$2);
|
||||
$$.S.makeSignless();
|
||||
}
|
||||
;
|
||||
|
@@ -209,25 +209,30 @@ CppWriter::error(const std::string& msg) {
|
||||
// result so that we don't lose precision.
|
||||
void
|
||||
CppWriter::printCFP(const ConstantFP *CFP) {
|
||||
APFloat APF = APFloat(CFP->getValueAPF()); // copy
|
||||
if (CFP->getType() == Type::FloatTy)
|
||||
APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
|
||||
Out << "ConstantFP::get(";
|
||||
if (CFP->getType() == Type::DoubleTy)
|
||||
Out << "Type::DoubleTy, ";
|
||||
else
|
||||
Out << "Type::FloatTy, ";
|
||||
Out << "APFloat(";
|
||||
#if HAVE_PRINTF_A
|
||||
char Buffer[100];
|
||||
sprintf(Buffer, "%A", CFP->getValue());
|
||||
sprintf(Buffer, "%A", APF.convertToDouble());
|
||||
if ((!strncmp(Buffer, "0x", 2) ||
|
||||
!strncmp(Buffer, "-0x", 3) ||
|
||||
!strncmp(Buffer, "+0x", 3)) &&
|
||||
(atof(Buffer) == CFP->getValue()))
|
||||
APF.bitwiseIsEqual(APFloat(atof(Buffer)))) {
|
||||
if (CFP->getType() == Type::DoubleTy)
|
||||
Out << "BitsToDouble(" << Buffer << ")";
|
||||
else
|
||||
Out << "BitsToFloat(" << Buffer << ")";
|
||||
else {
|
||||
Out << "BitsToFloat((float)" << Buffer << ")";
|
||||
Out << ")";
|
||||
} else {
|
||||
#endif
|
||||
std::string StrVal = ftostr(CFP->getValue());
|
||||
std::string StrVal = ftostr(CFP->getValueAPF());
|
||||
|
||||
while (StrVal[0] == ' ')
|
||||
StrVal.erase(StrVal.begin());
|
||||
@@ -237,17 +242,21 @@ CppWriter::printCFP(const ConstantFP *CFP) {
|
||||
if (((StrVal[0] >= '0' && StrVal[0] <= '9') ||
|
||||
((StrVal[0] == '-' || StrVal[0] == '+') &&
|
||||
(StrVal[1] >= '0' && StrVal[1] <= '9'))) &&
|
||||
(atof(StrVal.c_str()) == CFP->getValue()))
|
||||
(CFP->isExactlyValue(atof(StrVal.c_str())))) {
|
||||
if (CFP->getType() == Type::DoubleTy)
|
||||
Out << StrVal;
|
||||
else
|
||||
Out << StrVal;
|
||||
Out << StrVal << "f";
|
||||
}
|
||||
else if (CFP->getType() == Type::DoubleTy)
|
||||
Out << "BitsToDouble(0x" << std::hex << DoubleToBits(CFP->getValue())
|
||||
Out << "BitsToDouble(0x" << std::hex
|
||||
<< DoubleToBits(CFP->getValueAPF().convertToDouble())
|
||||
<< std::dec << "ULL) /* " << StrVal << " */";
|
||||
else
|
||||
Out << "BitsToFloat(0x" << std::hex << FloatToBits(CFP->getValue())
|
||||
Out << "BitsToFloat(0x" << std::hex
|
||||
<< FloatToBits(CFP->getValueAPF().convertToFloat())
|
||||
<< std::dec << "U) /* " << StrVal << " */";
|
||||
Out << ")";
|
||||
#if HAVE_PRINTF_A
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user