[llvm-commits] [llvm] r53713 - in /llvm/trunk: include/llvm/CodeGen/RuntimeLibcalls.h lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/TargetLowering.cpp

Duncan Sands baldrick at free.fr
Wed Jul 16 19:36:29 PDT 2008


Author: baldrick
Date: Wed Jul 16 21:36:29 2008
New Revision: 53713

URL: http://llvm.org/viewvc/llvm-project?rev=53713&view=rev
Log:
Factorize some code for determining which libcall to use.

Modified:
    llvm/trunk/include/llvm/CodeGen/RuntimeLibcalls.h
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Modified: llvm/trunk/include/llvm/CodeGen/RuntimeLibcalls.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/RuntimeLibcalls.h?rev=53713&r1=53712&r2=53713&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/RuntimeLibcalls.h (original)
+++ llvm/trunk/include/llvm/CodeGen/RuntimeLibcalls.h Wed Jul 16 21:36:29 2008
@@ -8,13 +8,15 @@
 //===----------------------------------------------------------------------===//
 //
 // This file defines the enum representing the list of runtime library calls
-// the backend may emit during code generation.
+// the backend may emit during code generation, and also some helper functions.
 //
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_CODEGEN_RUNTIMELIBCALLS_H
 #define LLVM_CODEGEN_RUNTIMELIBCALLS_H
 
+#include "llvm/CodeGen/ValueTypes.h"
+
 namespace llvm {
 namespace RTLIB {
   /// RTLIB::Libcall enum - This enum defines all of the runtime library calls
@@ -168,6 +170,30 @@
 
     UNKNOWN_LIBCALL
   };
+
+  /// getFPEXT - Return the FPEXT_*_* value for the given types, or
+  /// UNKNOWN_LIBCALL if there is none.
+  Libcall getFPEXT(MVT OpVT, MVT RetVT);
+
+  /// getFPROUND - Return the FPROUND_*_* value for the given types, or
+  /// UNKNOWN_LIBCALL if there is none.
+  Libcall getFPROUND(MVT OpVT, MVT RetVT);
+
+  /// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
+  /// UNKNOWN_LIBCALL if there is none.
+  Libcall getFPTOSINT(MVT OpVT, MVT RetVT);
+
+  /// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
+  /// UNKNOWN_LIBCALL if there is none.
+  Libcall getFPTOUINT(MVT OpVT, MVT RetVT);
+
+  /// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
+  /// UNKNOWN_LIBCALL if there is none.
+  Libcall getSINTTOFP(MVT OpVT, MVT RetVT);
+
+  /// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
+  /// UNKNOWN_LIBCALL if there is none.
+  Libcall getUINTTOFP(MVT OpVT, MVT RetVT);
 }
 }
 

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=53713&r1=53712&r2=53713&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Wed Jul 16 21:36:29 2008
@@ -3764,86 +3764,9 @@
         break;
       }
       // Convert f32 / f64 to i32 / i64 / i128.
-      RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-      switch (Node->getOpcode()) {
-      case ISD::FP_TO_SINT: {
-        if (VT == MVT::i32) {
-          if (OVT == MVT::f32)
-            LC = RTLIB::FPTOSINT_F32_I32;
-          else if (OVT == MVT::f64)
-            LC = RTLIB::FPTOSINT_F64_I32;
-          else if (OVT == MVT::f80)
-            LC = RTLIB::FPTOSINT_F80_I32;
-          else if (OVT == MVT::ppcf128)
-            LC = RTLIB::FPTOSINT_PPCF128_I32;
-          else
-            assert(0 && "Unexpected i32-to-fp conversion!");
-        } else if (VT == MVT::i64) {
-          if (OVT == MVT::f32)
-            LC = RTLIB::FPTOSINT_F32_I64;
-          else if (OVT == MVT::f64)
-            LC = RTLIB::FPTOSINT_F64_I64;
-          else if (OVT == MVT::f80)
-            LC = RTLIB::FPTOSINT_F80_I64;
-          else if (OVT == MVT::ppcf128)
-            LC = RTLIB::FPTOSINT_PPCF128_I64;
-          else
-            assert(0 && "Unexpected i64-to-fp conversion!");
-        } else if (VT == MVT::i128) {
-          if (OVT == MVT::f32)
-            LC = RTLIB::FPTOSINT_F32_I128;
-          else if (OVT == MVT::f64)
-            LC = RTLIB::FPTOSINT_F64_I128;
-          else if (OVT == MVT::f80)
-            LC = RTLIB::FPTOSINT_F80_I128;
-          else if (OVT == MVT::ppcf128)
-            LC = RTLIB::FPTOSINT_PPCF128_I128;
-          else
-            assert(0 && "Unexpected i128-to-fp conversion!");
-        } else {
-          assert(0 && "Unexpectd int-to-fp conversion!");
-        }
-        break;
-      }
-      case ISD::FP_TO_UINT: {
-        if (VT == MVT::i32) {
-          if (OVT == MVT::f32)
-            LC = RTLIB::FPTOUINT_F32_I32;
-          else if (OVT == MVT::f64)
-            LC = RTLIB::FPTOUINT_F64_I32;
-          else if (OVT == MVT::f80)
-            LC = RTLIB::FPTOUINT_F80_I32;
-          else
-            assert(0 && "Unexpected i32-to-fp conversion!");
-        } else if (VT == MVT::i64) {
-          if (OVT == MVT::f32)
-            LC = RTLIB::FPTOUINT_F32_I64;
-          else if (OVT == MVT::f64)
-            LC = RTLIB::FPTOUINT_F64_I64;
-          else if (OVT == MVT::f80)
-            LC = RTLIB::FPTOUINT_F80_I64;
-          else if (OVT == MVT::ppcf128)
-            LC = RTLIB::FPTOUINT_PPCF128_I64;
-          else
-            assert(0 && "Unexpected i64-to-fp conversion!");
-        } else if (VT == MVT::i128) {
-          if (OVT == MVT::f32)
-            LC = RTLIB::FPTOUINT_F32_I128;
-          else if (OVT == MVT::f64)
-            LC = RTLIB::FPTOUINT_F64_I128;
-          else if (OVT == MVT::f80)
-            LC = RTLIB::FPTOUINT_F80_I128;
-          else if (OVT == MVT::ppcf128)
-            LC = RTLIB::FPTOUINT_PPCF128_I128;
-          else
-            assert(0 && "Unexpected i128-to-fp conversion!");
-        } else {
-          assert(0 && "Unexpectd int-to-fp conversion!");
-        }
-        break;
-      }
-      default: assert(0 && "Unreachable!");
-      }
+      RTLIB::Libcall LC = (Node->getOpcode() == ISD::FP_TO_SINT) ?
+        RTLIB::getFPTOSINT(OVT, VT) : RTLIB::getFPTOUINT(OVT, VT);
+      assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!");
       SDOperand Dummy;
       Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
       break;
@@ -5412,41 +5335,11 @@
     Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi);
   }
 
-  RTLIB::Libcall LC;
-  if (SourceVT == MVT::i32) {
-    if (DestTy == MVT::f32)
-      LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32;
-    else {
-      assert(DestTy == MVT::f64 && "Unknown fp value type!");
-      LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64;
-    }
-  } else if (SourceVT == MVT::i64) {
-    if (DestTy == MVT::f32)
-      LC = RTLIB::SINTTOFP_I64_F32;
-    else if (DestTy == MVT::f64)
-      LC = RTLIB::SINTTOFP_I64_F64;
-    else if (DestTy == MVT::f80)
-      LC = RTLIB::SINTTOFP_I64_F80;
-    else {
-      assert(DestTy == MVT::ppcf128 && "Unknown fp value type!");
-      LC = RTLIB::SINTTOFP_I64_PPCF128;
-    }
-  } else if (SourceVT == MVT::i128) {
-    if (DestTy == MVT::f32)
-      LC = RTLIB::SINTTOFP_I128_F32;
-    else if (DestTy == MVT::f64)
-      LC = RTLIB::SINTTOFP_I128_F64;
-    else if (DestTy == MVT::f80)
-      LC = RTLIB::SINTTOFP_I128_F80;
-    else {
-      assert(DestTy == MVT::ppcf128 && "Unknown fp value type!");
-      LC = RTLIB::SINTTOFP_I128_PPCF128;
-    }
-  } else {
-    assert(0 && "Unknown int value type");
-  }
-  
-  assert(TLI.getLibcallName(LC) && "Don't know how to expand this SINT_TO_FP!");
+  RTLIB::Libcall LC = isSigned ?
+    RTLIB::getSINTTOFP(SourceVT, DestTy) :
+    RTLIB::getUINTTOFP(SourceVT, DestTy);
+  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unknown int value type");
+
   Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source);
   SDOperand HiPart;
   SDOperand Result = ExpandLibCall(LC, Source.Val, isSigned, HiPart);
@@ -6196,30 +6089,10 @@
       }
     }
 
-    RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-    if (VT == MVT::i64) {
-      if (Node->getOperand(0).getValueType() == MVT::f32)
-        LC = RTLIB::FPTOSINT_F32_I64;
-      else if (Node->getOperand(0).getValueType() == MVT::f64)
-        LC = RTLIB::FPTOSINT_F64_I64;
-      else if (Node->getOperand(0).getValueType() == MVT::f80)
-        LC = RTLIB::FPTOSINT_F80_I64;
-      else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
-        LC = RTLIB::FPTOSINT_PPCF128_I64;
-      Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
-    } else if (VT == MVT::i128) {
-      if (Node->getOperand(0).getValueType() == MVT::f32)
-        LC = RTLIB::FPTOSINT_F32_I128;
-      else if (Node->getOperand(0).getValueType() == MVT::f64)
-        LC = RTLIB::FPTOSINT_F64_I128;
-      else if (Node->getOperand(0).getValueType() == MVT::f80)
-        LC = RTLIB::FPTOSINT_F80_I128;
-      else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
-        LC = RTLIB::FPTOSINT_PPCF128_I128;
-      Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
-    } else {
-      assert(0 && "Unexpected uint-to-fp conversion!");
-    }
+    RTLIB::Libcall LC = RTLIB::getFPTOSINT(Node->getOperand(0).getValueType(),
+                                           VT);
+    assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected uint-to-fp conversion!");
+    Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
     break;
   }
 
@@ -6241,30 +6114,10 @@
       }
     }
 
-    RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-    if (VT == MVT::i64) {
-      if (Node->getOperand(0).getValueType() == MVT::f32)
-        LC = RTLIB::FPTOUINT_F32_I64;
-      else if (Node->getOperand(0).getValueType() == MVT::f64)
-        LC = RTLIB::FPTOUINT_F64_I64;
-      else if (Node->getOperand(0).getValueType() == MVT::f80)
-        LC = RTLIB::FPTOUINT_F80_I64;
-      else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
-        LC = RTLIB::FPTOUINT_PPCF128_I64;
-      Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
-    } else if (VT == MVT::i128) {
-      if (Node->getOperand(0).getValueType() == MVT::f32)
-        LC = RTLIB::FPTOUINT_F32_I128;
-      else if (Node->getOperand(0).getValueType() == MVT::f64)
-        LC = RTLIB::FPTOUINT_F64_I128;
-      else if (Node->getOperand(0).getValueType() == MVT::f80)
-        LC = RTLIB::FPTOUINT_F80_I128;
-      else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
-        LC = RTLIB::FPTOUINT_PPCF128_I128;
-      Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
-    } else {
-      assert(0 && "Unexpected uint-to-fp conversion!");
-    }
+    RTLIB::Libcall LC = RTLIB::getFPTOUINT(Node->getOperand(0).getValueType(),
+                                           VT);
+    assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!");
+    Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
     break;
   }
 
@@ -6579,7 +6432,7 @@
                                         RTLIB::DIV_PPCF128),
                        Node, false, Hi);
     break;
-  case ISD::FP_EXTEND:
+  case ISD::FP_EXTEND: {
     if (VT == MVT::ppcf128) {
       assert(Node->getOperand(0).getValueType()==MVT::f32 ||
              Node->getOperand(0).getValueType()==MVT::f64);
@@ -6591,11 +6444,18 @@
       Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
       break;
     }
-    Lo = ExpandLibCall(RTLIB::FPEXT_F32_F64, Node, true, Hi);
+    RTLIB::Libcall LC = RTLIB::getFPEXT(Node->getOperand(0).getValueType(), VT);
+    assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
+    Lo = ExpandLibCall(LC, Node, true, Hi);
     break;
-  case ISD::FP_ROUND:
-    Lo = ExpandLibCall(RTLIB::FPROUND_F64_F32, Node, true, Hi);
+  }
+  case ISD::FP_ROUND: {
+    RTLIB::Libcall LC = RTLIB::getFPROUND(Node->getOperand(0).getValueType(),
+                                          VT);
+    assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!");
+    Lo = ExpandLibCall(LC, Node, true, Hi);
     break;
+  }
   case ISD::FPOWI:
     Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::POWI_F32,
                                         RTLIB::POWI_F64,

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp?rev=53713&r1=53712&r2=53713&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp Wed Jul 16 21:36:29 2008
@@ -161,40 +161,16 @@
 SDOperand DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) {
   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
   SDOperand Op = N->getOperand(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (Op.getValueType().getSimpleVT()) {
-  default:
-    assert(false && "Unsupported FP_EXTEND!");
-  case MVT::f32:
-    switch (N->getValueType(0).getSimpleVT()) {
-    default:
-      assert(false && "Unsupported FP_EXTEND!");
-    case MVT::f64:
-      LC = RTLIB::FPEXT_F32_F64;
-    }
-  }
-
+  RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0));
+  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
   return MakeLibCall(LC, NVT, &Op, 1, false);
 }
 
 SDOperand DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode *N) {
   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
   SDOperand Op = N->getOperand(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (Op.getValueType().getSimpleVT()) {
-  default:
-    assert(false && "Unsupported FP_ROUND!");
-  case MVT::f64:
-    switch (N->getValueType(0).getSimpleVT()) {
-    default:
-      assert(false && "Unsupported FP_ROUND!");
-    case MVT::f32:
-      LC = RTLIB::FPROUND_F64_F32;
-    }
-  }
-
+  RTLIB::Libcall LC = RTLIB::getFPROUND(Op.getValueType(), N->getValueType(0));
+  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!");
   return MakeLibCall(LC, NVT, &Op, 1, false);
 }
 
@@ -267,100 +243,16 @@
 SDOperand DAGTypeLegalizer::SoftenFloatRes_SINT_TO_FP(SDNode *N) {
   SDOperand Op = N->getOperand(0);
   MVT RVT = N->getValueType(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (Op.getValueType().getSimpleVT()) {
-  case MVT::i32:
-    switch (RVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::SINTTOFP_I32_F32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::SINTTOFP_I32_F64;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i64:
-    switch (RVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::SINTTOFP_I64_F32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::SINTTOFP_I64_F64;
-      break;
-    case MVT::f80:
-      LC = RTLIB::SINTTOFP_I64_F80;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::SINTTOFP_I64_PPCF128;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i128:
-    switch (RVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::SINTTOFP_I128_F32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::SINTTOFP_I128_F64;
-      break;
-    case MVT::f80:
-      LC = RTLIB::SINTTOFP_I128_F80;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::SINTTOFP_I128_PPCF128;
-      break;
-    default:
-      break;
-    }
-    break;
-  default:
-    break;
-  }
+  RTLIB::Libcall LC = RTLIB::getSINTTOFP(Op.getValueType(), RVT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SINT_TO_FP!");
-
   return MakeLibCall(LC, TLI.getTypeToTransformTo(RVT), &Op, 1, false);
 }
 
 SDOperand DAGTypeLegalizer::SoftenFloatRes_UINT_TO_FP(SDNode *N) {
   SDOperand Op = N->getOperand(0);
   MVT RVT = N->getValueType(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (Op.getValueType().getSimpleVT()) {
-  case MVT::i32:
-    switch (RVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::UINTTOFP_I32_F32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::UINTTOFP_I32_F64;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i64:
-    switch (RVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::UINTTOFP_I64_F32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::UINTTOFP_I64_F64;
-      break;
-    default:
-      break;
-    }
-    break;
-  default:
-    break;
-  }
+  RTLIB::Libcall LC = RTLIB::getUINTTOFP(Op.getValueType(), RVT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported UINT_TO_FP!");
-
   return MakeLibCall(LC, TLI.getTypeToTransformTo(RVT), &Op, 1, false);
 }
 
@@ -521,139 +413,17 @@
 }
 
 SDOperand DAGTypeLegalizer::SoftenFloatOp_FP_TO_SINT(SDNode *N) {
-  MVT SVT = N->getOperand(0).getValueType();
   MVT RVT = N->getValueType(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (RVT.getSimpleVT()) {
-  case MVT::i32:
-    switch (SVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::FPTOSINT_F32_I32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::FPTOSINT_F64_I32;
-      break;
-    case MVT::f80:
-      LC = RTLIB::FPTOSINT_F80_I32;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::FPTOSINT_PPCF128_I32;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i64:
-    switch (SVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::FPTOSINT_F32_I64;
-      break;
-    case MVT::f64:
-      LC = RTLIB::FPTOSINT_F64_I64;
-      break;
-    case MVT::f80:
-      LC = RTLIB::FPTOSINT_F80_I64;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::FPTOSINT_PPCF128_I64;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i128:
-    switch (SVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::FPTOSINT_F32_I128;
-      break;
-    case MVT::f64:
-      LC = RTLIB::FPTOSINT_F64_I128;
-      break;
-    case MVT::f80:
-      LC = RTLIB::FPTOSINT_F80_I128;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::FPTOSINT_PPCF128_I128;
-      break;
-    default:
-      break;
-    }
-    break;
-  default:
-    break;
-  }
+  RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
-
   SDOperand Op = GetSoftenedFloat(N->getOperand(0));
   return MakeLibCall(LC, RVT, &Op, 1, false);
 }
 
 SDOperand DAGTypeLegalizer::SoftenFloatOp_FP_TO_UINT(SDNode *N) {
-  MVT SVT = N->getOperand(0).getValueType();
   MVT RVT = N->getValueType(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (RVT.getSimpleVT()) {
-  case MVT::i32:
-    switch (SVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::FPTOUINT_F32_I32;
-      break;
-    case MVT::f64:
-      LC = RTLIB::FPTOUINT_F64_I32;
-      break;
-    case MVT::f80:
-      LC = RTLIB::FPTOUINT_F80_I32;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::FPTOUINT_PPCF128_I32;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i64:
-    switch (SVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::FPTOUINT_F32_I64;
-      break;
-    case MVT::f64:
-      LC = RTLIB::FPTOUINT_F64_I64;
-      break;
-    case MVT::f80:
-      LC = RTLIB::FPTOUINT_F80_I64;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::FPTOUINT_PPCF128_I64;
-      break;
-    default:
-      break;
-    }
-    break;
-  case MVT::i128:
-    switch (SVT.getSimpleVT()) {
-    case MVT::f32:
-      LC = RTLIB::FPTOUINT_F32_I128;
-      break;
-    case MVT::f64:
-      LC = RTLIB::FPTOUINT_F64_I128;
-      break;
-    case MVT::f80:
-      LC = RTLIB::FPTOUINT_F80_I128;
-      break;
-    case MVT::ppcf128:
-      LC = RTLIB::FPTOUINT_PPCF128_I128;
-      break;
-    default:
-      break;
-    }
-    break;
-  default:
-    break;
-  }
+  RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
-
   SDOperand Op = GetSoftenedFloat(N->getOperand(0));
   return MakeLibCall(LC, RVT, &Op, 1, false);
 }
@@ -1067,45 +837,16 @@
 }
 
 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode *N) {
-  assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
-         "Unsupported FP_TO_SINT!");
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (N->getValueType(0).getSimpleVT()) {
-  default:
-    assert(false && "Unsupported FP_TO_SINT!");
-  case MVT::i32:
-    LC = RTLIB::FPTOSINT_PPCF128_I32;
-  case MVT::i64:
-    LC = RTLIB::FPTOSINT_PPCF128_I64;
-    break;
-  case MVT::i128:
-    LC = RTLIB::FPTOSINT_PPCF128_I64;
-    break;
-  }
-
-  return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false);
+  MVT RVT = N->getValueType(0);
+  RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
+  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
+  return MakeLibCall(LC, RVT, &N->getOperand(0), 1, false);
 }
 
 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) {
-  assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
-         "Unsupported FP_TO_UINT!");
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  switch (N->getValueType(0).getSimpleVT()) {
-  default:
-    assert(false && "Unsupported FP_TO_UINT!");
-  case MVT::i32:
-    LC = RTLIB::FPTOUINT_PPCF128_I32;
-    break;
-  case MVT::i64:
-    LC = RTLIB::FPTOUINT_PPCF128_I64;
-    break;
-  case MVT::i128:
-    LC = RTLIB::FPTOUINT_PPCF128_I128;
-    break;
-  }
-
+  MVT RVT = N->getValueType(0);
+  RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
+  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
   return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false);
 }
 

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp?rev=53713&r1=53712&r2=53713&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp Wed Jul 16 21:36:29 2008
@@ -1238,36 +1238,7 @@
                                                SDOperand &Hi) {
   MVT VT = N->getValueType(0);
   SDOperand Op = N->getOperand(0);
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-
-  if (VT == MVT::i32) {
-    if (Op.getValueType() == MVT::f32)
-      LC = RTLIB::FPTOSINT_F32_I32;
-    else if (Op.getValueType() == MVT::f64)
-      LC = RTLIB::FPTOSINT_F64_I32;
-    else if (Op.getValueType() == MVT::f80)
-      LC = RTLIB::FPTOSINT_F80_I32;
-    else if (Op.getValueType() == MVT::ppcf128)
-      LC = RTLIB::FPTOSINT_PPCF128_I32;
-  } else if (VT == MVT::i64) {
-    if (Op.getValueType() == MVT::f32)
-      LC = RTLIB::FPTOSINT_F32_I64;
-    else if (Op.getValueType() == MVT::f64)
-      LC = RTLIB::FPTOSINT_F64_I64;
-    else if (Op.getValueType() == MVT::f80)
-      LC = RTLIB::FPTOSINT_F80_I64;
-    else if (Op.getValueType() == MVT::ppcf128)
-      LC = RTLIB::FPTOSINT_PPCF128_I64;
-  } else if (VT == MVT::i128) {
-    if (Op.getValueType() == MVT::f32)
-      LC = RTLIB::FPTOSINT_F32_I128;
-    else if (Op.getValueType() == MVT::f64)
-      LC = RTLIB::FPTOSINT_F64_I128;
-    else if (Op.getValueType() == MVT::f80)
-      LC = RTLIB::FPTOSINT_F80_I128;
-    else if (Op.getValueType() == MVT::ppcf128)
-      LC = RTLIB::FPTOSINT_PPCF128_I128;
-  }
+  RTLIB::Libcall LC = RTLIB::getFPTOSINT(Op.getValueType(), VT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-sint conversion!");
   SplitInteger(MakeLibCall(LC, VT, &Op, 1, true/*sign irrelevant*/), Lo, Hi);
 }
@@ -1276,35 +1247,7 @@
                                                SDOperand &Hi) {
   MVT VT = N->getValueType(0);
   SDOperand Op = N->getOperand(0);
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  if (VT == MVT::i32) {
-    if (Op.getValueType() == MVT::f32)
-      LC = RTLIB::FPTOUINT_F32_I32;
-    else if (Op.getValueType() == MVT::f64)
-      LC = RTLIB::FPTOUINT_F64_I32;
-    else if (Op.getValueType() == MVT::f80)
-      LC = RTLIB::FPTOUINT_F80_I32;
-    else if (Op.getValueType() == MVT::ppcf128)
-      LC = RTLIB::FPTOUINT_PPCF128_I32;
-  } else if (VT == MVT::i64) {
-    if (Op.getValueType() == MVT::f32)
-      LC = RTLIB::FPTOUINT_F32_I64;
-    else if (Op.getValueType() == MVT::f64)
-      LC = RTLIB::FPTOUINT_F64_I64;
-    else if (Op.getValueType() == MVT::f80)
-      LC = RTLIB::FPTOUINT_F80_I64;
-    else if (Op.getValueType() == MVT::ppcf128)
-      LC = RTLIB::FPTOUINT_PPCF128_I64;
-  } else if (VT == MVT::i128) {
-    if (Op.getValueType() == MVT::f32)
-      LC = RTLIB::FPTOUINT_F32_I128;
-    else if (Op.getValueType() == MVT::f64)
-      LC = RTLIB::FPTOUINT_F64_I128;
-    else if (Op.getValueType() == MVT::f80)
-      LC = RTLIB::FPTOUINT_F80_I128;
-    else if (Op.getValueType() == MVT::ppcf128)
-      LC = RTLIB::FPTOUINT_PPCF128_I128;
-  }
+  RTLIB::Libcall LC = RTLIB::getFPTOUINT(Op.getValueType(), VT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!");
   SplitInteger(MakeLibCall(LC, VT, &Op, 1, false/*sign irrelevant*/), Lo, Hi);
 }
@@ -1961,41 +1904,10 @@
 
 SDOperand DAGTypeLegalizer::ExpandIntOp_SINT_TO_FP(SDNode *N) {
   SDOperand Op = N->getOperand(0);
-  MVT SrcVT = Op.getValueType();
   MVT DstVT = N->getValueType(0);
-
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  if (SrcVT == MVT::i32) {
-    if (DstVT == MVT::f32)
-      LC = RTLIB::SINTTOFP_I32_F32;
-    else if (DstVT == MVT::f64)
-      LC = RTLIB::SINTTOFP_I32_F64;
-    else if (DstVT == MVT::f80)
-      LC = RTLIB::SINTTOFP_I32_F80;
-    else if (DstVT == MVT::ppcf128)
-      LC = RTLIB::SINTTOFP_I32_PPCF128;
-  } else if (SrcVT == MVT::i64) {
-    if (DstVT == MVT::f32)
-      LC = RTLIB::SINTTOFP_I64_F32;
-    else if (DstVT == MVT::f64)
-      LC = RTLIB::SINTTOFP_I64_F64;
-    else if (DstVT == MVT::f80)
-      LC = RTLIB::SINTTOFP_I64_F80;
-    else if (DstVT == MVT::ppcf128)
-      LC = RTLIB::SINTTOFP_I64_PPCF128;
-  } else if (SrcVT == MVT::i128) {
-    if (DstVT == MVT::f32)
-      LC = RTLIB::SINTTOFP_I128_F32;
-    else if (DstVT == MVT::f64)
-      LC = RTLIB::SINTTOFP_I128_F64;
-    else if (DstVT == MVT::f80)
-      LC = RTLIB::SINTTOFP_I128_F80;
-    else if (DstVT == MVT::ppcf128)
-      LC = RTLIB::SINTTOFP_I128_PPCF128;
-  }
+  RTLIB::Libcall LC = RTLIB::getSINTTOFP(Op.getValueType(), DstVT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL &&
          "Don't know how to expand this SINT_TO_FP!");
-
   return MakeLibCall(LC, DstVT, &Op, 1, true);
 }
 
@@ -2140,37 +2052,8 @@
   }
 
   // Otherwise, use a libcall.
-  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
-  if (SrcVT == MVT::i32) {
-    if (DstVT == MVT::f32)
-      LC = RTLIB::UINTTOFP_I32_F32;
-    else if (DstVT == MVT::f64)
-      LC = RTLIB::UINTTOFP_I32_F64;
-    else if (DstVT == MVT::f80)
-      LC = RTLIB::UINTTOFP_I32_F80;
-    else if (DstVT == MVT::ppcf128)
-      LC = RTLIB::UINTTOFP_I32_PPCF128;
-  } else if (SrcVT == MVT::i64) {
-    if (DstVT == MVT::f32)
-      LC = RTLIB::UINTTOFP_I64_F32;
-    else if (DstVT == MVT::f64)
-      LC = RTLIB::UINTTOFP_I64_F64;
-    else if (DstVT == MVT::f80)
-      LC = RTLIB::UINTTOFP_I64_F80;
-    else if (DstVT == MVT::ppcf128)
-      LC = RTLIB::UINTTOFP_I64_PPCF128;
-  } else if (SrcVT == MVT::i128) {
-    if (DstVT == MVT::f32)
-      LC = RTLIB::UINTTOFP_I128_F32;
-    else if (DstVT == MVT::f64)
-      LC = RTLIB::UINTTOFP_I128_F64;
-    else if (DstVT == MVT::f80)
-      LC = RTLIB::UINTTOFP_I128_F80;
-    else if (DstVT == MVT::ppcf128)
-      LC = RTLIB::UINTTOFP_I128_PPCF128;
-  }
+  RTLIB::Libcall LC = RTLIB::getUINTTOFP(SrcVT, DstVT);
   assert(LC != RTLIB::UNKNOWN_LIBCALL &&
          "Don't know how to expand this UINT_TO_FP!");
-
   return MakeLibCall(LC, DstVT, &Op, 1, true);
 }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=53713&r1=53712&r2=53713&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Wed Jul 16 21:36:29 2008
@@ -163,6 +163,164 @@
   Names[RTLIB::O_F64] = "__unorddf2";
 }
 
+/// getFPEXT - Return the FPEXT_*_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+RTLIB::Libcall RTLIB::getFPEXT(MVT OpVT, MVT RetVT) {
+  if (OpVT == MVT::f32) {
+    if (RetVT == MVT::f64)
+      return FPEXT_F32_F64;
+  }
+  return UNKNOWN_LIBCALL;
+}
+
+/// getFPROUND - Return the FPROUND_*_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+RTLIB::Libcall RTLIB::getFPROUND(MVT OpVT, MVT RetVT) {
+  if (OpVT == MVT::f64) {
+    if (RetVT == MVT::f32)
+      return FPROUND_F64_F32;
+  }
+  return UNKNOWN_LIBCALL;
+}
+
+/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+RTLIB::Libcall RTLIB::getFPTOSINT(MVT OpVT, MVT RetVT) {
+  if (OpVT == MVT::f32) {
+    if (RetVT == MVT::i32)
+      return FPTOSINT_F32_I32;
+    if (RetVT == MVT::i64)
+      return FPTOSINT_F32_I64;
+    if (RetVT == MVT::i128)
+      return FPTOSINT_F32_I128;
+  } else if (OpVT == MVT::f64) {
+    if (RetVT == MVT::i32)
+      return FPTOSINT_F64_I32;
+    if (RetVT == MVT::i64)
+      return FPTOSINT_F64_I64;
+    if (RetVT == MVT::i128)
+      return FPTOSINT_F64_I128;
+  } else if (OpVT == MVT::f80) {
+    if (RetVT == MVT::i32)
+      return FPTOSINT_F80_I32;
+    if (RetVT == MVT::i64)
+      return FPTOSINT_F80_I64;
+    if (RetVT == MVT::i128)
+      return FPTOSINT_F80_I128;
+  } else if (OpVT == MVT::ppcf128) {
+    if (RetVT == MVT::i32)
+      return FPTOSINT_PPCF128_I32;
+    if (RetVT == MVT::i64)
+      return FPTOSINT_PPCF128_I64;
+    if (RetVT == MVT::i128)
+      return FPTOSINT_PPCF128_I128;
+  }
+  return UNKNOWN_LIBCALL;
+}
+
+/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+RTLIB::Libcall RTLIB::getFPTOUINT(MVT OpVT, MVT RetVT) {
+  if (OpVT == MVT::f32) {
+    if (RetVT == MVT::i32)
+      return FPTOUINT_F32_I32;
+    if (RetVT == MVT::i64)
+      return FPTOUINT_F32_I64;
+    if (RetVT == MVT::i128)
+      return FPTOUINT_F32_I128;
+  } else if (OpVT == MVT::f64) {
+    if (RetVT == MVT::i32)
+      return FPTOUINT_F64_I32;
+    if (RetVT == MVT::i64)
+      return FPTOUINT_F64_I64;
+    if (RetVT == MVT::i128)
+      return FPTOUINT_F64_I128;
+  } else if (OpVT == MVT::f80) {
+    if (RetVT == MVT::i32)
+      return FPTOUINT_F80_I32;
+    if (RetVT == MVT::i64)
+      return FPTOUINT_F80_I64;
+    if (RetVT == MVT::i128)
+      return FPTOUINT_F80_I128;
+  } else if (OpVT == MVT::ppcf128) {
+    if (RetVT == MVT::i32)
+      return FPTOUINT_PPCF128_I32;
+    if (RetVT == MVT::i64)
+      return FPTOUINT_PPCF128_I64;
+    if (RetVT == MVT::i128)
+      return FPTOUINT_PPCF128_I128;
+  }
+  return UNKNOWN_LIBCALL;
+}
+
+/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+RTLIB::Libcall RTLIB::getSINTTOFP(MVT OpVT, MVT RetVT) {
+  if (OpVT == MVT::i32) {
+    if (RetVT == MVT::f32)
+      return SINTTOFP_I32_F32;
+    else if (RetVT == MVT::f64)
+      return SINTTOFP_I32_F64;
+    else if (RetVT == MVT::f80)
+      return SINTTOFP_I32_F80;
+    else if (RetVT == MVT::ppcf128)
+      return SINTTOFP_I32_PPCF128;
+  } else if (OpVT == MVT::i64) {
+    if (RetVT == MVT::f32)
+      return SINTTOFP_I64_F32;
+    else if (RetVT == MVT::f64)
+      return SINTTOFP_I64_F64;
+    else if (RetVT == MVT::f80)
+      return SINTTOFP_I64_F80;
+    else if (RetVT == MVT::ppcf128)
+      return SINTTOFP_I64_PPCF128;
+  } else if (OpVT == MVT::i128) {
+    if (RetVT == MVT::f32)
+      return SINTTOFP_I128_F32;
+    else if (RetVT == MVT::f64)
+      return SINTTOFP_I128_F64;
+    else if (RetVT == MVT::f80)
+      return SINTTOFP_I128_F80;
+    else if (RetVT == MVT::ppcf128)
+      return SINTTOFP_I128_PPCF128;
+  }
+  return UNKNOWN_LIBCALL;
+}
+
+/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+RTLIB::Libcall RTLIB::getUINTTOFP(MVT OpVT, MVT RetVT) {
+  if (OpVT == MVT::i32) {
+    if (RetVT == MVT::f32)
+      return UINTTOFP_I32_F32;
+    else if (RetVT == MVT::f64)
+      return UINTTOFP_I32_F64;
+    else if (RetVT == MVT::f80)
+      return UINTTOFP_I32_F80;
+    else if (RetVT == MVT::ppcf128)
+      return UINTTOFP_I32_PPCF128;
+  } else if (OpVT == MVT::i64) {
+    if (RetVT == MVT::f32)
+      return UINTTOFP_I64_F32;
+    else if (RetVT == MVT::f64)
+      return UINTTOFP_I64_F64;
+    else if (RetVT == MVT::f80)
+      return UINTTOFP_I64_F80;
+    else if (RetVT == MVT::ppcf128)
+      return UINTTOFP_I64_PPCF128;
+  } else if (OpVT == MVT::i128) {
+    if (RetVT == MVT::f32)
+      return UINTTOFP_I128_F32;
+    else if (RetVT == MVT::f64)
+      return UINTTOFP_I128_F64;
+    else if (RetVT == MVT::f80)
+      return UINTTOFP_I128_F80;
+    else if (RetVT == MVT::ppcf128)
+      return UINTTOFP_I128_PPCF128;
+  }
+  return UNKNOWN_LIBCALL;
+}
+
 /// InitCmpLibcallCCs - Set default comparison libcall CC.
 ///
 static void InitCmpLibcallCCs(ISD::CondCode *CCs) {





More information about the llvm-commits mailing list