From eb963a5f2ad1a634f4195bcdd4a3bb916f06b482 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 20 Apr 2015 19:38:24 +0000 Subject: [PATCH] IR: Add ConstantFP::getNaN() 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 | 1 + lib/IR/Constants.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/llvm/IR/Constants.h b/include/llvm/IR/Constants.h index 70437e66cbf..a16bf1ff092 100644 --- a/include/llvm/IR/Constants.h +++ b/include/llvm/IR/Constants.h @@ -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); diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index 3f8d1f1ca6a..20a5206c230 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -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(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); -- 2.34.1