Implement necessary bits for flt_rounds gcc builtin.
authorAnton Korobeynikov <asl@math.spbu.ru>
Thu, 15 Nov 2007 23:25:33 +0000 (23:25 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Thu, 15 Nov 2007 23:25:33 +0000 (23:25 +0000)
Codegen bits and llvm-gcc support will follow.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44182 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAGNodes.h
include/llvm/Intrinsics.td
lib/CodeGen/IntrinsicLowering.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 56f85f4b741c1f903625bb457756795c7e503628..5407de5b49b9dae96ce140a891d240cb78e062cd 100644 (file)
@@ -390,6 +390,14 @@ namespace ISD {
     // precision down to the specified precision (currently always 64->32).
     FP_ROUND,
 
+    // FLT_ROUNDS - Returns current rounding mode:
+    // -1 Undefined
+    //  0 Round to 0
+    //  1 Round to nearest
+    //  2 Round to +inf
+    //  3 Round to -inf
+    FLT_ROUNDS,
+
     // FP_ROUND_INREG - This operator takes a floating point register, and
     // rounds it to a floating point value.  It then promotes it and returns it
     // in a register of the same size.  This operation effectively just discards
index 4ede06d4083976e39c60469c00cc6397884f7ced..08d82588aa1f8a68be46b6f397468380d98d96e2 100644 (file)
@@ -262,6 +262,11 @@ def int_init_trampoline : Intrinsic<[llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty,
                                      llvm_ptr_ty], []>,
                           GCCBuiltin<"__builtin_init_trampoline">;
 
+//===-------------------------- Other Intrinsics --------------------------===//
+//
+def int_flt_rounds : Intrinsic<[llvm_i32_ty]>,
+                     GCCBuiltin<"__builtin_flt_rounds">;
+
 //===----------------------------------------------------------------------===//
 // Target-specific intrinsics
 //===----------------------------------------------------------------------===//
index bd3d74d27ac82203590d07e42b49abea3c9e5733..0d1da867ed0d339ff921dbfbe1a931cbf2181439 100644 (file)
@@ -856,6 +856,11 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
     }
     break;
   }
+  case Intrinsic::flt_rounds:
+     // Lower to "round to the nearest"
+     if (CI->getType() != Type::VoidTy)
+       CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
+     break;
   }
 
   assert(CI->use_empty() &&
index 9c0c845932f7ac8edc3d58274b2b3aad21443614..d17fbea77431da68bf83103fa4827176f1fbf357 100644 (file)
@@ -3676,6 +3676,20 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
     AddLegalizedOperand(SDOperand(Node, 0), Result);
     AddLegalizedOperand(SDOperand(Node, 1), Tmp1);
     return Op.ResNo ? Tmp1 : Result;
+  }
+   case ISD::FLT_ROUNDS: {
+    MVT::ValueType VT = Node->getValueType(0);
+    switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
+    default: assert(0 && "This action not supported for this op yet!");
+    case TargetLowering::Custom:
+      Result = TLI.LowerOperation(Op, DAG);
+      if (Result.Val) break;
+      // Fall Thru
+    case TargetLowering::Legal:
+      // If this operation is not supported, lower it to constant 1
+      Result = DAG.getConstant(1, VT);
+      break;
+    }
   }
   }
   
index d92bb9cbd282ce1c2719b30db6a5732376cf231a..38987d9faada73e96c561699f660f36563d8b9e8 100644 (file)
@@ -3739,6 +3739,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
   case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
   case ISD::TRUNCATE:    return "truncate";
   case ISD::FP_ROUND:    return "fp_round";
+  case ISD::FLT_ROUNDS:  return "flt_rounds";
   case ISD::FP_ROUND_INREG: return "fp_round_inreg";
   case ISD::FP_EXTEND:   return "fp_extend";
 
index c078f23c20e861fc672f78f76dd3988f7b701bff..ade0a2860b5584fa2dbc657bd76ee637ab48bfe5 100644 (file)
@@ -2930,6 +2930,10 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     DAG.setRoot(Tmp.getValue(1));
     return 0;
   }
+  case Intrinsic::flt_rounds: {
+    setValue(&I, DAG.getNode(ISD::FLT_ROUNDS, MVT::i32));
+    return 0;
+  }
   }
 }