aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-09-11 18:32:33 +0000
committerDale Johannesen <dalej@apple.com>2007-09-11 18:32:33 +0000
commit3f6eb7419de437436265831fce92f62498556e08 (patch)
treecb752d4a86ec5c5dd783cfc421e30d0cf7600e87 /lib/CodeGen
parent6320260e060ce4fc5d199d757b15a0f43be66029 (diff)
downloadexternal_llvm-3f6eb7419de437436265831fce92f62498556e08.zip
external_llvm-3f6eb7419de437436265831fce92f62498556e08.tar.gz
external_llvm-3f6eb7419de437436265831fce92f62498556e08.tar.bz2
Add APInt interfaces to APFloat (allows directly
access to bits). Use them in place of float and double interfaces where appropriate. First bits of x86 long double constants handling (untested, probably does not work). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41858 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/AsmPrinter.cpp18
-rw-r--r--lib/CodeGen/MachOWriter.cpp8
-rw-r--r--lib/CodeGen/SelectionDAG/DAGCombiner.cpp8
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp14
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp13
5 files changed, 33 insertions, 28 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index e80afd4..49bcba7 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -830,29 +830,31 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
// FP Constants are printed as integer constants to avoid losing
// precision...
if (CFP->getType() == Type::DoubleTy) {
- double Val = CFP->getValueAPF().convertToDouble();
+ double Val = CFP->getValueAPF().convertToDouble(); // for comment only
+ uint64_t i = *CFP->getValueAPF().convertToAPInt().getRawData();
if (TAI->getData64bitsDirective())
- O << TAI->getData64bitsDirective() << DoubleToBits(Val) << "\t"
+ O << TAI->getData64bitsDirective() << i << "\t"
<< TAI->getCommentString() << " double value: " << Val << "\n";
else if (TD->isBigEndian()) {
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
+ O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< "\t" << TAI->getCommentString()
<< " double most significant word " << Val << "\n";
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
+ O << TAI->getData32bitsDirective() << unsigned(i)
<< "\t" << TAI->getCommentString()
<< " double least significant word " << Val << "\n";
} else {
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
+ O << TAI->getData32bitsDirective() << unsigned(i)
<< "\t" << TAI->getCommentString()
<< " double least significant word " << Val << "\n";
- O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
+ O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< "\t" << TAI->getCommentString()
<< " double most significant word " << Val << "\n";
}
return;
} else {
- float Val = CFP->getValueAPF().convertToFloat();
- O << TAI->getData32bitsDirective() << FloatToBits(Val)
+ float Val = CFP->getValueAPF().convertToFloat(); // for comment only
+ O << TAI->getData32bitsDirective()
+ << (uint32_t)*CFP->getValueAPF().convertToAPInt().getRawData()
<< "\t" << TAI->getCommentString() << " float " << Val << "\n";
return;
}
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index af2555d..1c9b0fe 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: {
- uint64_t val = FloatToBits(cast<ConstantFP>(PC)->
- getValueAPF().convertToFloat());
+ uint32_t val = (uint32_t)*cast<ConstantFP>(PC)->
+ getValueAPF().convertToAPInt().getRawData();
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 = DoubleToBits(cast<ConstantFP>(PC)->
- getValueAPF().convertToDouble());
+ uint64_t val = *cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
+ getRawData();
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 32f81d3..2050d23 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3800,7 +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(FloatToBits(CFP->getValueAPF().convertToFloat()), MVT::i32);
+ Tmp = DAG.getConstant((uint32_t)*CFP->getValueAPF().
+ convertToAPInt().getRawData(), MVT::i32);
return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
ST->getSrcValueOffset(), ST->isVolatile(),
ST->getAlignment());
@@ -3808,7 +3809,8 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
break;
case MVT::f64:
if (!AfterLegalize || TLI.isTypeLegal(MVT::i64)) {
- Tmp = DAG.getConstant(DoubleToBits(CFP->getValueAPF().convertToDouble()), MVT::i64);
+ Tmp = DAG.getConstant(*CFP->getValueAPF().convertToAPInt().
+ getRawData(), MVT::i64);
return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
ST->getSrcValueOffset(), ST->isVolatile(),
ST->getAlignment());
@@ -3816,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 = DoubleToBits(CFP->getValueAPF().convertToDouble());
+ uint64_t Val = *CFP->getValueAPF().convertToAPInt().getRawData();
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 31e2947..d7eb85b 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -491,8 +491,9 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP,
if (!UseCP) {
const APFloat& Val = LLVMC->getValueAPF();
return isDouble
- ? DAG.getConstant(DoubleToBits(Val.convertToDouble()), MVT::i64)
- : DAG.getConstant(FloatToBits(Val.convertToFloat()), MVT::i32);
+ ? DAG.getConstant(*Val.convertToAPInt().getRawData(), MVT::i64)
+ : DAG.getConstant((uint32_t )*Val.convertToAPInt().getRawData(),
+ MVT::i32);
}
if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) &&
@@ -1980,12 +1981,13 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
// together.
if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) {
if (CFP->getValueType(0) == MVT::f32) {
- Tmp3 = DAG.getConstant(FloatToBits(CFP->getValueAPF().
- convertToFloat()), MVT::i32);
+ Tmp3 = DAG.getConstant((uint32_t)*CFP->getValueAPF().
+ convertToAPInt().getRawData(),
+ MVT::i32);
} else {
assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!");
- Tmp3 = DAG.getConstant(DoubleToBits(CFP->getValueAPF().
- convertToDouble()), MVT::i64);
+ Tmp3 = DAG.getConstant(*CFP->getValueAPF().convertToAPInt().
+ getRawData(), 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 01ec5c9..85a76f4 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -109,13 +109,12 @@ bool ISD::isBuildVectorAllOnes(const SDNode *N) {
} else if (isa<ConstantFPSDNode>(NotZero)) {
MVT::ValueType VT = NotZero.getValueType();
if (VT== MVT::f64) {
- if (DoubleToBits(cast<ConstantFPSDNode>(NotZero)->
- getValueAPF().convertToDouble()) !=
- (uint64_t)-1)
+ if (*((cast<ConstantFPSDNode>(NotZero)->getValueAPF().
+ convertToAPInt().getRawData())) != (uint64_t)-1)
return false;
} else {
- if (FloatToBits(cast<ConstantFPSDNode>(NotZero)->
- getValueAPF().convertToFloat()) !=
+ if ((uint32_t)*cast<ConstantFPSDNode>(NotZero)->
+ getValueAPF().convertToAPInt().getRawData() !=
(uint32_t)-1)
return false;
}
@@ -1698,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(FloatToBits(V.convertToFloat()), VT);
+ return getConstant((uint32_t)*V.convertToAPInt().getRawData(), VT);
else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
- return getConstant(DoubleToBits(V.convertToDouble()), VT);
+ return getConstant(*V.convertToAPInt().getRawData(), VT);
break;
}
}