[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp SelectionDAG.cpp SelectionDAGISel.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Jan 8 00:09:09 PST 2005
Changes in directory llvm/lib/CodeGen/SelectionDAG:
LegalizeDAG.cpp updated: 1.11 -> 1.12
SelectionDAG.cpp updated: 1.14 -> 1.15
SelectionDAGISel.cpp updated: 1.3 -> 1.4
---
Log message:
Add support for FP->INT conversions and back.
---
Diffs of the changes: (+42 -17)
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.11 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.12
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.11 Sat Jan 8 00:25:56 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Sat Jan 8 02:08:56 2005
@@ -575,6 +575,11 @@
case ISD::TRUNCATE:
case ISD::FP_EXTEND:
case ISD::FP_ROUND:
+ case ISD::FP_TO_SINT:
+ case ISD::FP_TO_UINT:
+ case ISD::SINT_TO_FP:
+ case ISD::UINT_TO_FP:
+
switch (getTypeAction(Node->getOperand(0).getValueType())) {
case Legal:
Tmp1 = LegalizeOp(Node->getOperand(0));
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.14 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.15
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.14 Sat Jan 8 00:24:30 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Jan 8 02:08:56 2005
@@ -396,6 +396,8 @@
case ISD::SIGN_EXTEND: return getConstant(C->getSignExtended(), VT);
case ISD::ZERO_EXTEND: return getConstant(Val, VT);
case ISD::TRUNCATE: return getConstant(Val, VT);
+ case ISD::SINT_TO_FP: return getConstantFP(C->getSignExtended(), VT);
+ case ISD::UINT_TO_FP: return getConstantFP(C->getValue(), VT);
}
}
@@ -404,6 +406,10 @@
case ISD::FP_ROUND:
case ISD::FP_EXTEND:
return getConstantFP(C->getValue(), VT);
+ case ISD::FP_TO_SINT:
+ return getConstant((int64_t)C->getValue(), VT);
+ case ISD::FP_TO_UINT:
+ return getConstant((uint64_t)C->getValue(), VT);
}
unsigned OpOpcode = Operand.Val->getOpcode();
@@ -821,6 +827,11 @@
case ISD::FP_ROUND: std::cerr << "fp_round"; break;
case ISD::FP_EXTEND: std::cerr << "fp_extend"; break;
+ case ISD::SINT_TO_FP: std::cerr << "sint_to_fp"; break;
+ case ISD::UINT_TO_FP: std::cerr << "uint_to_fp"; break;
+ case ISD::FP_TO_SINT: std::cerr << "fp_to_sint"; break;
+ case ISD::FP_TO_UINT: std::cerr << "fp_to_uint"; break;
+
// Control flow instructions
case ISD::BR: std::cerr << "br"; break;
case ISD::BRCOND: std::cerr << "brcond"; break;
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.3 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.4
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.3 Fri Jan 7 15:56:57 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Sat Jan 8 02:08:56 2005
@@ -434,24 +434,33 @@
if (N.getValueType() == DestTy) {
setValue(&I, N); // noop cast.
- return;
- } else if (isInteger(SrcTy) && isInteger(DestTy)) {
- if (DestTy < SrcTy) // Truncating cast?
- setValue(&I, DAG.getNode(ISD::TRUNCATE, DestTy, N));
- else if (I.getOperand(0)->getType()->isSigned())
- setValue(&I, DAG.getNode(ISD::SIGN_EXTEND, DestTy, N));
- else
- setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, DestTy, N));
- return;
- } else if (isFloatingPoint(SrcTy) && isFloatingPoint(DestTy)) {
- if (DestTy < SrcTy) // Rounding cast?
- setValue(&I, DAG.getNode(ISD::FP_ROUND, DestTy, N));
- else
- setValue(&I, DAG.getNode(ISD::FP_EXTEND, DestTy, N));
+ } else if (isInteger(SrcTy)) {
+ if (isInteger(DestTy)) { // Int -> Int cast
+ if (DestTy < SrcTy) // Truncating cast?
+ setValue(&I, DAG.getNode(ISD::TRUNCATE, DestTy, N));
+ else if (I.getOperand(0)->getType()->isSigned())
+ setValue(&I, DAG.getNode(ISD::SIGN_EXTEND, DestTy, N));
+ else
+ setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, DestTy, N));
+ } else { // Int -> FP cast
+ if (I.getOperand(0)->getType()->isSigned())
+ setValue(&I, DAG.getNode(ISD::SINT_TO_FP, DestTy, N));
+ else
+ setValue(&I, DAG.getNode(ISD::UINT_TO_FP, DestTy, N));
+ }
} else {
- // F->I or I->F
- // FIXME: implement integer/fp conversions!
- assert(0 && "This CAST is not yet implemented!\n");
+ assert(isFloatingPoint(SrcTy) && "Unknown value type!");
+ if (isFloatingPoint(DestTy)) { // FP -> FP cast
+ if (DestTy < SrcTy) // Rounding cast?
+ setValue(&I, DAG.getNode(ISD::FP_ROUND, DestTy, N));
+ else
+ setValue(&I, DAG.getNode(ISD::FP_EXTEND, DestTy, N));
+ } else { // FP -> Int cast.
+ if (I.getType()->isSigned())
+ setValue(&I, DAG.getNode(ISD::FP_TO_SINT, DestTy, N));
+ else
+ setValue(&I, DAG.getNode(ISD::FP_TO_UINT, DestTy, N));
+ }
}
}
More information about the llvm-commits
mailing list