diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-01-18 16:43:06 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-01-18 16:43:06 +0000 |
commit | 5d2ff221f6977f42e6b327ea4466d3bd8642ea59 (patch) | |
tree | 8d2bde39002db2e83bbcfcff0e8b46ca4ad063d5 /llvm/lib/IR/Constants.cpp | |
parent | f170add239e7b0646a8972787e0d175c7b186cfa (diff) | |
download | bcm5719-llvm-5d2ff221f6977f42e6b327ea4466d3bd8642ea59.tar.gz bcm5719-llvm-5d2ff221f6977f42e6b327ea4466d3bd8642ea59.zip |
Upgrade ConstantFP's negative zero and infinity getters to handle vector types.
Will be used soon.
llvm-svn: 199552
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 690ac597b06..dbb3495583b 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -584,23 +584,21 @@ Constant *ConstantFP::get(Type *Ty, StringRef Str) { return C; } +Constant *ConstantFP::getNegativeZero(Type *Ty) { + const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType()); + APFloat NegZero = APFloat::getZero(Semantics, /*Negative=*/true); + Constant *C = get(Ty->getContext(), NegZero); -ConstantFP *ConstantFP::getNegativeZero(Type *Ty) { - LLVMContext &Context = Ty->getContext(); - APFloat apf = cast<ConstantFP>(Constant::getNullValue(Ty))->getValueAPF(); - apf.changeSign(); - return get(Context, apf); + if (VectorType *VTy = dyn_cast<VectorType>(Ty)) + return ConstantVector::getSplat(VTy->getNumElements(), C); + + return C; } Constant *ConstantFP::getZeroValueForNegation(Type *Ty) { - Type *ScalarTy = Ty->getScalarType(); - if (ScalarTy->isFloatingPointTy()) { - Constant *C = getNegativeZero(ScalarTy); - if (VectorType *VTy = dyn_cast<VectorType>(Ty)) - return ConstantVector::getSplat(VTy->getNumElements(), C); - return C; - } + if (Ty->isFPOrFPVectorTy()) + return getNegativeZero(Ty); return Constant::getNullValue(Ty); } @@ -635,10 +633,14 @@ ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) { return Slot; } -ConstantFP *ConstantFP::getInfinity(Type *Ty, bool Negative) { - const fltSemantics &Semantics = *TypeToFloatSemantics(Ty); - return ConstantFP::get(Ty->getContext(), - APFloat::getInf(Semantics, Negative)); +Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) { + const fltSemantics &Semantics = *TypeToFloatSemantics(Ty->getScalarType()); + Constant *C = get(Ty->getContext(), APFloat::getInf(Semantics, Negative)); + + if (VectorType *VTy = dyn_cast<VectorType>(Ty)) + return ConstantVector::getSplat(VTy->getNumElements(), C); + + return C; } ConstantFP::ConstantFP(Type *Ty, const APFloat& V) |