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
13 namespace llvm {
14
15 using namespace PatternMatch;
16
17 template <>
queryDenormalMode(const Function & F,Value * Val)18 DenormalMode FloatingPointPredicateUtils::queryDenormalMode(const Function &F,
19 Value *Val) {
20 Type *Ty = Val->getType()->getScalarType();
21 return F.getDenormalMode(Ty->getFltSemantics());
22 }
23
24 template <>
lookThroughFAbs(const Function & F,Value * LHS,Value * & Src)25 bool FloatingPointPredicateUtils::lookThroughFAbs(const Function &F, Value *LHS,
26 Value *&Src) {
27 return match(LHS, m_FAbs(m_Value(Src)));
28 }
29
30 template <>
31 std::optional<APFloat>
matchConstantFloat(const Function & F,Value * Val)32 FloatingPointPredicateUtils::matchConstantFloat(const Function &F, Value *Val) {
33 const APFloat *ConstVal;
34
35 if (!match(Val, m_APFloatAllowPoison(ConstVal)))
36 return std::nullopt;
37
38 return *ConstVal;
39 }
40
41 } // namespace llvm
42