1*700637cbSDimitry Andric //===- FloatingPointPredicateUtils.cpp ------------------------------------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric
9*700637cbSDimitry Andric #include "llvm/Analysis/FloatingPointPredicateUtils.h"
10*700637cbSDimitry Andric #include "llvm/IR/PatternMatch.h"
11*700637cbSDimitry Andric #include <optional>
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric namespace llvm {
14*700637cbSDimitry Andric
15*700637cbSDimitry Andric using namespace PatternMatch;
16*700637cbSDimitry Andric
17*700637cbSDimitry Andric template <>
queryDenormalMode(const Function & F,Value * Val)18*700637cbSDimitry Andric DenormalMode FloatingPointPredicateUtils::queryDenormalMode(const Function &F,
19*700637cbSDimitry Andric Value *Val) {
20*700637cbSDimitry Andric Type *Ty = Val->getType()->getScalarType();
21*700637cbSDimitry Andric return F.getDenormalMode(Ty->getFltSemantics());
22*700637cbSDimitry Andric }
23*700637cbSDimitry Andric
24*700637cbSDimitry Andric template <>
lookThroughFAbs(const Function & F,Value * LHS,Value * & Src)25*700637cbSDimitry Andric bool FloatingPointPredicateUtils::lookThroughFAbs(const Function &F, Value *LHS,
26*700637cbSDimitry Andric Value *&Src) {
27*700637cbSDimitry Andric return match(LHS, m_FAbs(m_Value(Src)));
28*700637cbSDimitry Andric }
29*700637cbSDimitry Andric
30*700637cbSDimitry Andric template <>
31*700637cbSDimitry Andric std::optional<APFloat>
matchConstantFloat(const Function & F,Value * Val)32*700637cbSDimitry Andric FloatingPointPredicateUtils::matchConstantFloat(const Function &F, Value *Val) {
33*700637cbSDimitry Andric const APFloat *ConstVal;
34*700637cbSDimitry Andric
35*700637cbSDimitry Andric if (!match(Val, m_APFloatAllowPoison(ConstVal)))
36*700637cbSDimitry Andric return std::nullopt;
37*700637cbSDimitry Andric
38*700637cbSDimitry Andric return *ConstVal;
39*700637cbSDimitry Andric }
40*700637cbSDimitry Andric
41*700637cbSDimitry Andric } // namespace llvm
42