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