summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorJF Bastien <jfbastien@apple.com>2018-12-10 19:27:38 +0000
committerJF Bastien <jfbastien@apple.com>2018-12-10 19:27:38 +0000
commit69f6098e89312b934ed87e4cd3603401a9b436b4 (patch)
tree58af5357af19893d7f24253b6a419c888be8bf96 /llvm/lib/IR/Constants.cpp
parentce2837f880a519d435be9e220b62c10b6361d798 (diff)
downloadbcm5719-llvm-69f6098e89312b934ed87e4cd3603401a9b436b4.tar.gz
bcm5719-llvm-69f6098e89312b934ed87e4cd3603401a9b436b4.zip
APFloat: allow 64-bit of payload
Summary: The APFloat and Constant APIs taking an APInt allow arbitrary payloads, and that's great. There's a convenience API which takes an unsigned, and that's silly because it then directly creates a 64-bit APInt. Just change it to 64-bits directly. At the same time, add ConstantFP NaN getters which match the APFloat ones (with getQNaN / getSNaN and APInt parameters). Improve the APFloat testing to set more payload bits. Reviewers: scanon, rjmccall Subscribers: jkorous, dexonsmith, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D55460 llvm-svn: 348791
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index aa1d6c909b3..22ffc811511 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -719,9 +719,9 @@ Constant *ConstantFP::get(Type *Ty, StringRef Str) {
return C;
}
-Constant *ConstantFP::getNaN(Type *Ty, bool Negative, unsigned Type) {
+Constant *ConstantFP::getNaN(Type *Ty, bool Negative, uint64_t Payload) {
const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
- APFloat NaN = APFloat::getNaN(Semantics, Negative, Type);
+ APFloat NaN = APFloat::getNaN(Semantics, Negative, Payload);
Constant *C = get(Ty->getContext(), NaN);
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
@@ -730,6 +730,28 @@ Constant *ConstantFP::getNaN(Type *Ty, bool Negative, unsigned Type) {
return C;
}
+Constant *ConstantFP::getQNaN(Type *Ty, bool Negative, APInt *Payload) {
+ const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
+ APFloat NaN = APFloat::getQNaN(Semantics, Negative, Payload);
+ Constant *C = get(Ty->getContext(), NaN);
+
+ if (VectorType *VTy = dyn_cast<VectorType>(Ty))
+ return ConstantVector::getSplat(VTy->getNumElements(), C);
+
+ return C;
+}
+
+Constant *ConstantFP::getSNaN(Type *Ty, bool Negative, APInt *Payload) {
+ const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType());
+ APFloat NaN = APFloat::getSNaN(Semantics, Negative, Payload);
+ 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);
OpenPOWER on IntegriCloud