summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-09-12 03:30:33 +0000
committerDale Johannesen <dalej@apple.com>2007-09-12 03:30:33 +0000
commit9d5f45607793052bf5b4436d1b43013fab9999ac (patch)
treeda064f263b6242adf84ced2a98439707a6114ddd
parent257500db0437b6089f46ccf58bcdf04ad8dae9d9 (diff)
downloadllvm-9d5f45607793052bf5b4436d1b43013fab9999ac.tar.gz
Revise previous patch per review comments.
Next round of x87 long double stuff. Getting close now, basically works. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41875 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AsmParser/Lexer.l12
-rw-r--r--lib/AsmParser/llvmAsmParser.y2
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp1
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp7
-rw-r--r--lib/CodeGen/AsmPrinter.cpp45
-rw-r--r--lib/CodeGen/MachOWriter.cpp8
-rw-r--r--lib/CodeGen/SelectionDAG/DAGCombiner.cpp10
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp15
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp12
-rw-r--r--lib/Target/CBackend/CBackend.cpp6
-rw-r--r--lib/Target/MSIL/MSILWriter.cpp8
-rw-r--r--lib/VMCore/AsmWriter.cpp85
-rw-r--r--lib/VMCore/ConstantFold.cpp13
-rw-r--r--lib/VMCore/Constants.cpp25
-rw-r--r--tools/llvm2cpp/CppWriter.cpp4
15 files changed, 163 insertions, 90 deletions
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l
index 5acbbacf60fd..73e9c5477127 100644
--- a/lib/AsmParser/Lexer.l
+++ b/lib/AsmParser/Lexer.l
@@ -284,8 +284,8 @@ void { RET_TY(Type::VoidTy, VOID); }
float { RET_TY(Type::FloatTy, FLOAT); }
double { RET_TY(Type::DoubleTy,DOUBLE);}
x86_fp80 { RET_TY(Type::X86_FP80Ty, X86_FP80);}
-fp128 { RET_TY(Type::FP128Ty, FP128);}
-ppc_fp128 { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
+fp128 { RET_TY(Type::FP128Ty, FP128);}
+ppc_fp128 { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
label { RET_TY(Type::LabelTy, LABEL); }
type { return TYPE; }
opaque { return OPAQUE; }
@@ -477,21 +477,21 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
}
{FPConstant} { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
-{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext));
+{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext+2));
return FPVAL;
}
{HexFP80Constant} { uint64_t Pair[2];
- HexToIntPair(yytext, Pair);
+ HexToIntPair(yytext+3, Pair);
llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
return FPVAL;
}
{HexFP128Constant} { uint64_t Pair[2];
- HexToIntPair(yytext, Pair);
+ HexToIntPair(yytext+3, Pair);
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
return FPVAL;
}
{HexPPC128Constant} { uint64_t Pair[2];
- HexToIntPair(yytext, Pair);
+ HexToIntPair(yytext+3, Pair);
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
return FPVAL;
}
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index c0374daf3f1c..d2e5256de887 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -1866,7 +1866,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
$$ = ConstantInt::getFalse();
CHECK_FOR_ERROR
}
- | FPType FPVAL { // Float & Double constants
+ | FPType FPVAL { // Floating point constants
if (!ConstantFP::isValueValidForType($1, *$2))
GEN_ERROR("Floating point constant invalid for type");
// Lexer has no type info, so builds all float and double FP constants
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 06429931dbdf..9e4a3dee60f3 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -629,7 +629,6 @@ bool BitcodeReader::ParseConstants() {
V = ConstantFP::get(CurTy, APFloat(APInt(32, (uint32_t)Record[0])));
else if (CurTy == Type::DoubleTy)
V = ConstantFP::get(CurTy, APFloat(APInt(64, Record[0])));
- // FIXME: Make long double constants work. BitsToDouble does not make it.
else if (CurTy == Type::X86_FP80Ty)
V = ConstantFP::get(CurTy, APFloat(APInt(80, 2, &Record[0])));
else if (CurTy == Type::FP128Ty)
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 78a16d8f6273..fdaa9be5bb61 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -526,11 +526,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
Code = bitc::CST_CODE_FLOAT;
const Type *Ty = CFP->getType();
- if (Ty == Type::FloatTy)
- Record.push_back((uint32_t)*CFP->getValueAPF().convertToAPInt().
- getRawData());
- else if (Ty == Type::DoubleTy) {
- Record.push_back(*CFP->getValueAPF().convertToAPInt().getRawData());
+ if (Ty == Type::FloatTy || Ty == Type::DoubleTy) {
+ Record.push_back(CFP->getValueAPF().convertToAPInt().getZExtValue());
} else if (Ty == Type::X86_FP80Ty) {
const uint64_t *p = CFP->getValueAPF().convertToAPInt().getRawData();
Record.push_back(p[0]);
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 49bcba781418..b55310661e60 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -831,7 +831,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
// precision...
if (CFP->getType() == Type::DoubleTy) {
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
- uint64_t i = *CFP->getValueAPF().convertToAPInt().getRawData();
+ uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
if (TAI->getData64bitsDirective())
O << TAI->getData64bitsDirective() << i << "\t"
<< TAI->getCommentString() << " double value: " << Val << "\n";
@@ -851,13 +851,50 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
<< " double most significant word " << Val << "\n";
}
return;
- } else {
+ } else if (CFP->getType() == Type::FloatTy) {
float Val = CFP->getValueAPF().convertToFloat(); // for comment only
O << TAI->getData32bitsDirective()
- << (uint32_t)*CFP->getValueAPF().convertToAPInt().getRawData()
+ << CFP->getValueAPF().convertToAPInt().getZExtValue()
<< "\t" << TAI->getCommentString() << " float " << Val << "\n";
return;
- }
+ } else if (CFP->getType() == Type::X86_FP80Ty) {
+ // all long double variants are printed as hex
+ const uint64_t *p = CFP->getValueAPF().convertToAPInt().getRawData();
+ if (TD->isBigEndian()) {
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
+ << "\t" << TAI->getCommentString()
+ << " long double most significant halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0])
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[1])
+ << "\t" << TAI->getCommentString()
+ << " long double least significant halfword\n";
+ } else {
+ O << TAI->getData16bitsDirective() << uint16_t(p[1])
+ << "\t" << TAI->getCommentString()
+ << " long double least significant halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0])
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
+ << "\t" << TAI->getCommentString()
+ << " long double next halfword\n";
+ O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
+ << "\t" << TAI->getCommentString()
+ << " long double most significant halfword\n";
+ }
+ return;
+ } else assert(0 && "Floating point constant type not handled");
} else if (CV->getType() == Type::Int64Ty) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
uint64_t Val = CI->getZExtValue();
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index 1c9b0feff54e..0c743759da6c 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -861,8 +861,8 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
break;
}
case Type::FloatTyID: {
- uint32_t val = (uint32_t)*cast<ConstantFP>(PC)->
- getValueAPF().convertToAPInt().getRawData();
+ uint32_t val = cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
+ getZExtValue();
if (TD->isBigEndian())
val = ByteSwap_32(val);
ptr[0] = val;
@@ -872,8 +872,8 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
break;
}
case Type::DoubleTyID: {
- uint64_t val = *cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
- getRawData();
+ uint64_t val = cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
+ getZExtValue();
if (TD->isBigEndian())
val = ByteSwap_64(val);
ptr[0] = val;
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 2050d23ad72b..68158be16705 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3800,8 +3800,8 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
default: assert(0 && "Unknown FP type");
case MVT::f32:
if (!AfterLegalize || TLI.isTypeLegal(MVT::i32)) {
- Tmp = DAG.getConstant((uint32_t)*CFP->getValueAPF().
- convertToAPInt().getRawData(), MVT::i32);
+ Tmp = DAG.getConstant((uint32_t)CFP->getValueAPF().
+ convertToAPInt().getZExtValue(), MVT::i32);
return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
ST->getSrcValueOffset(), ST->isVolatile(),
ST->getAlignment());
@@ -3809,8 +3809,8 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
break;
case MVT::f64:
if (!AfterLegalize || TLI.isTypeLegal(MVT::i64)) {
- Tmp = DAG.getConstant(*CFP->getValueAPF().convertToAPInt().
- getRawData(), MVT::i64);
+ Tmp = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
+ getZExtValue(), MVT::i64);
return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
ST->getSrcValueOffset(), ST->isVolatile(),
ST->getAlignment());
@@ -3818,7 +3818,7 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
// Many FP stores are not make apparent until after legalize, e.g. for
// argument passing. Since this is so common, custom legalize the
// 64-bit integer store into two 32-bit stores.
- uint64_t Val = *CFP->getValueAPF().convertToAPInt().getRawData();
+ uint64_t Val = CFP->getValueAPF().convertToAPInt().getZExtValue();
SDOperand Lo = DAG.getConstant(Val & 0xFFFFFFFF, MVT::i32);
SDOperand Hi = DAG.getConstant(Val >> 32, MVT::i32);
if (!TLI.isLittleEndian()) std::swap(Lo, Hi);
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index d7eb85bd8fb0..da55eafdb28a 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -489,11 +489,8 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP,
ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy :
Type::FloatTy, CFP->getValueAPF());
if (!UseCP) {
- const APFloat& Val = LLVMC->getValueAPF();
- return isDouble
- ? DAG.getConstant(*Val.convertToAPInt().getRawData(), MVT::i64)
- : DAG.getConstant((uint32_t )*Val.convertToAPInt().getRawData(),
- MVT::i32);
+ return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt().getZExtValue(),
+ isDouble ? MVT::i64 : MVT::i32);
}
if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) &&
@@ -1981,13 +1978,13 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
// together.
if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) {
if (CFP->getValueType(0) == MVT::f32) {
- Tmp3 = DAG.getConstant((uint32_t)*CFP->getValueAPF().
- convertToAPInt().getRawData(),
+ Tmp3 = DAG.getConstant((uint32_t)CFP->getValueAPF().
+ convertToAPInt().getZExtValue(),
MVT::i32);
} else {
assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!");
- Tmp3 = DAG.getConstant(*CFP->getValueAPF().convertToAPInt().
- getRawData(), MVT::i64);
+ Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
+ getZExtValue(), MVT::i64);
}
Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
SVOffset, isVolatile, Alignment);
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 85a76f436b1b..ed1777e34ad2 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -109,12 +109,12 @@ bool ISD::isBuildVectorAllOnes(const SDNode *N) {
} else if (isa<ConstantFPSDNode>(NotZero)) {
MVT::ValueType VT = NotZero.getValueType();
if (VT== MVT::f64) {
- if (*((cast<ConstantFPSDNode>(NotZero)->getValueAPF().
- convertToAPInt().getRawData())) != (uint64_t)-1)
+ if (((cast<ConstantFPSDNode>(NotZero)->getValueAPF().
+ convertToAPInt().getZExtValue())) != (uint64_t)-1)
return false;
} else {
- if ((uint32_t)*cast<ConstantFPSDNode>(NotZero)->
- getValueAPF().convertToAPInt().getRawData() !=
+ if ((uint32_t)cast<ConstantFPSDNode>(NotZero)->
+ getValueAPF().convertToAPInt().getZExtValue() !=
(uint32_t)-1)
return false;
}
@@ -1697,9 +1697,9 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
}
case ISD::BIT_CONVERT:
if (VT == MVT::i32 && C->getValueType(0) == MVT::f32)
- return getConstant((uint32_t)*V.convertToAPInt().getRawData(), VT);
+ return getConstant((uint32_t)V.convertToAPInt().getZExtValue(), VT);
else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
- return getConstant(*V.convertToAPInt().getRawData(), VT);
+ return getConstant(V.convertToAPInt().getZExtValue(), VT);
break;
}
}
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index f25b1133b24d..9fc30c45da14 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -1715,14 +1715,14 @@ void CWriter::printFloatingPointConstants(Function &F) {
if (FPC->getType() == Type::DoubleTy) {
double Val = FPC->getValueAPF().convertToDouble();
- uint64_t i = *FPC->getValueAPF().convertToAPInt().getRawData();
+ uint64_t i = FPC->getValueAPF().convertToAPInt().getZExtValue();
Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
<< " = 0x" << std::hex << i << std::dec
<< "ULL; /* " << Val << " */\n";
} else if (FPC->getType() == Type::FloatTy) {
float Val = FPC->getValueAPF().convertToFloat();
- uint32_t i = (uint32_t)*FPC->getValueAPF().convertToAPInt().
- getRawData();
+ uint32_t i = (uint32_t)FPC->getValueAPF().convertToAPInt().
+ getZExtValue();
Out << "static const ConstantFloatTy FPConstant" << FPCounter++
<< " = 0x" << std::hex << i << std::dec
<< "U; /* " << Val << " */\n";
diff --git a/lib/Target/MSIL/MSILWriter.cpp b/lib/Target/MSIL/MSILWriter.cpp
index cd67df17a6fb..5d6740bd1e8f 100644
--- a/lib/Target/MSIL/MSILWriter.cpp
+++ b/lib/Target/MSIL/MSILWriter.cpp
@@ -428,10 +428,10 @@ void MSILWriter::printConstLoad(const Constant* C) {
uint64_t X;
unsigned Size;
if (FP->getType()->getTypeID()==Type::FloatTyID) {
- X = (uint32_t)*FP->getValueAPF().convertToAPInt().getRawData();
+ X = (uint32_t)FP->getValueAPF().convertToAPInt().getZExtValue();
Size = 4;
} else {
- X = *FP->getValueAPF().convertToAPInt().getRawData();
+ X = FP->getValueAPF().convertToAPInt().getZExtValue();
Size = 8;
}
Out << "\tldc.r" << Size << "\t( " << utohexstr(X) << ')';
@@ -1473,10 +1473,10 @@ void MSILWriter::printStaticConstant(const Constant* C, uint64_t& Offset) {
const ConstantFP* FP = cast<ConstantFP>(C);
if (Ty->getTypeID() == Type::FloatTyID)
Out << "int32 (" <<
- (uint32_t)*FP->getValueAPF().convertToAPInt().getRawData() << ')';
+ (uint32_t)FP->getValueAPF().convertToAPInt().getZExtValue() << ')';
else
Out << "int64 (" <<
- *FP->getValueAPF().convertToAPInt().getRawData() << ')';
+ FP->getValueAPF().convertToAPInt().getZExtValue() << ')';
break;
}
case Type::ArrayTyID:
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index a7b1239bcf86..b96fbff88cdb 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -481,35 +481,64 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
else
Out << CI->getValue().toStringSigned(10);
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
- // We would like to output the FP constant value in exponential notation,
- // but we cannot do this if doing so will lose precision. Check here to
- // make sure that we only output it in exponential format if we can parse
- // the value back and get the same value.
- //
- bool isDouble = &CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble;
- double Val = (isDouble) ? CFP->getValueAPF().convertToDouble() :
- CFP->getValueAPF().convertToFloat();
- std::string StrVal = ftostr(CFP->getValueAPF());
-
- // Check to make sure that the stringized number is not some string like
- // "Inf" or NaN, that atof will accept, but the lexer will not. Check that
- // the string matches the "[-+]?[0-9]" regex.
- //
- if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
- ((StrVal[0] == '-' || StrVal[0] == '+') &&
- (StrVal[1] >= '0' && StrVal[1] <= '9')))
- // Reparse stringized version!
- if (atof(StrVal.c_str()) == Val) {
- Out << StrVal;
- return;
+ if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble ||
+ &CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) {
+ // We would like to output the FP constant value in exponential notation,
+ // but we cannot do this if doing so will lose precision. Check here to
+ // make sure that we only output it in exponential format if we can parse
+ // the value back and get the same value.
+ //
+ bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
+ double Val = (isDouble) ? CFP->getValueAPF().convertToDouble() :
+ CFP->getValueAPF().convertToFloat();
+ std::string StrVal = ftostr(CFP->getValueAPF());
+
+ // Check to make sure that the stringized number is not some string like
+ // "Inf" or NaN, that atof will accept, but the lexer will not. Check
+ // that the string matches the "[-+]?[0-9]" regex.
+ //
+ if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
+ ((StrVal[0] == '-' || StrVal[0] == '+') &&
+ (StrVal[1] >= '0' && StrVal[1] <= '9'))) {
+ // Reparse stringized version!
+ if (atof(StrVal.c_str()) == Val) {
+ Out << StrVal;
+ return;
+ }
}
-
- // Otherwise we could not reparse it to exactly the same value, so we must
- // output the string in hexadecimal format!
- assert(sizeof(double) == sizeof(uint64_t) &&
- "assuming that double is 64 bits!");
- Out << "0x" << utohexstr(DoubleToBits(Val));
-
+ // Otherwise we could not reparse it to exactly the same value, so we must
+ // output the string in hexadecimal format!
+ assert(sizeof(double) == sizeof(uint64_t) &&
+ "assuming that double is 64 bits!");
+ Out << "0x" << utohexstr(DoubleToBits(Val));
+ } else {
+ // Some form of long double. These appear as a magic letter identifying
+ // the type, then a fixed number of hex digits.
+ Out << "0x";
+ if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended)
+ Out << 'K';
+ else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad)
+ Out << 'L';
+ else
+ assert(0 && "Unsupported floating point type");
+ const uint64_t* p = CFP->getValueAPF().convertToAPInt().getRawData();
+ uint64_t word = *p;
+ int shiftcount=60;
+ int width = CFP->getValueAPF().convertToAPInt().getBitWidth();
+ for (int j=0; j<width; j+=4, shiftcount-=4) {
+ unsigned int nibble = (word>>shiftcount) & 15;
+ if (nibble < 10)
+ Out << (unsigned char)(nibble + '0');
+ else
+ Out << (unsigned char)(nibble - 10 + 'A');
+ if (shiftcount == 0) {
+ word = *(++p);
+ shiftcount = 60;
+ if (width-j-4 < 64)
+ shiftcount = width-j-4;
+ }
+ }
+ }
} else if (isa<ConstantAggregateZero>(CV)) {
Out << "zeroinitializer";
} else if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index e11b749f9be8..5c80a377ba7b 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -87,8 +87,8 @@ static Constant *CastConstantVector(ConstantVector *CV,
if (SrcEltTy->getTypeID() == Type::DoubleTyID) {
for (unsigned i = 0; i != SrcNumElts; ++i) {
- uint64_t V = *cast<ConstantFP>(CV->getOperand(i))->
- getValueAPF().convertToAPInt().getRawData();
+ uint64_t V = cast<ConstantFP>(CV->getOperand(i))->
+ getValueAPF().convertToAPInt().getZExtValue();
Constant *C = ConstantInt::get(Type::Int64Ty, V);
Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
}
@@ -97,8 +97,8 @@ static Constant *CastConstantVector(ConstantVector *CV,
assert(SrcEltTy->getTypeID() == Type::FloatTyID);
for (unsigned i = 0; i != SrcNumElts; ++i) {
- uint32_t V = (uint32_t)*cast<ConstantFP>(CV->getOperand(i))->
- getValueAPF().convertToAPInt().getRawData();
+ uint32_t V = (uint32_t)cast<ConstantFP>(CV->getOperand(i))->
+ getValueAPF().convertToAPInt().getZExtValue();
Constant *C = ConstantInt::get(Type::Int32Ty, V);
Result.push_back(ConstantExpr::getBitCast(C, DstEltTy));
}
@@ -331,9 +331,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
return const_cast<Constant*>(V);
if (DestTy->isFloatingPoint()) {
- if (DestTy == Type::FloatTy)
- return ConstantFP::get(DestTy, APFloat(CI->getValue()));
- assert(DestTy == Type::DoubleTy && "Unknown FP type!");
+ assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) &&
+ "Unknown FP type!");
return ConstantFP::get(DestTy, APFloat(CI->getValue()));
}
// Otherwise, can't fold this (vector?)
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 1708e460795d..c54604545421 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -245,8 +245,14 @@ ConstantFP::ConstantFP(const Type *Ty, const APFloat& V)
// temporary
if (Ty==Type::FloatTy)
assert(&V.getSemantics()==&APFloat::IEEEsingle);
- else
+ 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
+ assert(0);
}
bool ConstantFP::isNullValue() const {
@@ -294,8 +300,14 @@ ConstantFP *ConstantFP::get(const Type *Ty, const APFloat& V) {
// temporary
if (Ty==Type::FloatTy)
assert(&V.getSemantics()==&APFloat::IEEEsingle);
- else
+ 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
+ assert(0);
DenseMapAPFloatKeyInfo::KeyTy Key(V);
ConstantFP *&Slot = (*FPConstants)[Key];
@@ -713,11 +725,14 @@ bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) {
&Val2.getSemantics() == &APFloat::IEEEdouble ||
Val2.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven) ==
APFloat::opOK;
- // TODO: Figure out how to test if we can use a shorter type instead!
case Type::X86_FP80TyID:
- case Type::PPC_FP128TyID:
+ return &Val2.getSemantics() == &APFloat::IEEEsingle ||
+ &Val2.getSemantics() == &APFloat::IEEEdouble ||
+ &Val2.getSemantics() == &APFloat::x87DoubleExtended;
case Type::FP128TyID:
- return true;
+ return &Val2.getSemantics() == &APFloat::IEEEsingle ||
+ &Val2.getSemantics() == &APFloat::IEEEdouble ||
+ &Val2.getSemantics() == &APFloat::IEEEquad;
}
}
diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp
index a56c7cdd41a8..8fae51d10c75 100644
--- a/tools/llvm2cpp/CppWriter.cpp
+++ b/tools/llvm2cpp/CppWriter.cpp
@@ -250,11 +250,11 @@ CppWriter::printCFP(const ConstantFP *CFP) {
}
else if (CFP->getType() == Type::DoubleTy)
Out << "BitsToDouble(0x" << std::hex
- << *CFP->getValueAPF().convertToAPInt().getRawData()
+ << CFP->getValueAPF().convertToAPInt().getZExtValue()
<< std::dec << "ULL) /* " << StrVal << " */";
else
Out << "BitsToFloat(0x" << std::hex
- << (uint32_t)*CFP->getValueAPF().convertToAPInt().getRawData()
+ << (uint32_t)CFP->getValueAPF().convertToAPInt().getZExtValue()
<< std::dec << "U) /* " << StrVal << " */";
Out << ")";
#if HAVE_PRINTF_A