From: Tom Stellard Date: Mon, 20 Apr 2015 19:38:24 +0000 (+0000) Subject: IR: Add ConstantFP::getNaN() X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=eb963a5f2ad1a634f4195bcdd4a3bb916f06b482;p=oota-llvm.git 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 --- 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);