IR: Add ConstantFP::getNaN()
authorTom Stellard <thomas.stellard@amd.com>
Mon, 20 Apr 2015 19:38:24 +0000 (19:38 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 20 Apr 2015 19:38:24 +0000 (19:38 +0000)
This is a wrapper around APFloat::getNaN().

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

include/llvm/IR/Constants.h
lib/IR/Constants.cpp

index 70437e66cbf29dbfb53b187770737c777d0c3b2d..a16bf1ff09215b4fa6190ba23972fb85f164c77f 100644 (file)
@@ -251,6 +251,7 @@ public:
   static Constant *get(Type* Ty, double V);
   static Constant *get(Type* Ty, StringRef Str);
   static ConstantFP *get(LLVMContext &Context, const APFloat &V);
+  static Constant *getNaN(Type *Ty, bool Negative = false, unsigned type = 0);
   static Constant *getNegativeZero(Type *Ty);
   static Constant *getInfinity(Type *Ty, bool Negative = false);
 
index 3f8d1f1ca6a5370c3d2b7c7d16d490d981ca5c7e..20a5206c2300716c94f40d84b5a5bddcf3dbac7a 100644 (file)
@@ -663,6 +663,17 @@ Constant *ConstantFP::get(Type *Ty, StringRef Str) {
   return C; 
 }
 
+Constant *ConstantFP::getNaN(Type *Ty, bool Negative, unsigned Type) {
+  const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
+  APFloat NaN = APFloat::getNaN(Semantics, Negative, Type);
+  Constant *C = get(Ty->getContext(), NaN);
+
+  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
+    return ConstantVector::getSplat(VTy->getNumElements(), C);
+
+  return C;
+}
+
 Constant *ConstantFP::getNegativeZero(Type *Ty) {
   const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
   APFloat NegZero = APFloat::getZero(Semantics, /*Negative=*/true);