xref: /freebsd/contrib/llvm-project/llvm/lib/CodeGen/GlobalISel/MachineFloatingPointPredicateUtils.cpp (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- MachineFloatingPointPredicateUtils.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/CodeGen/GlobalISel/MachineFloatingPointPredicateUtils.h"
10 #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
11 #include "llvm/CodeGen/LowLevelTypeUtils.h"
12 #include "llvm/CodeGen/MachineRegisterInfo.h"
13 #include "llvm/CodeGen/MachineSSAContext.h"
14 #include "llvm/IR/Constants.h"
15 #include <optional>
16 
17 namespace llvm {
18 
19 using namespace MIPatternMatch;
20 
21 template <>
22 DenormalMode
queryDenormalMode(const MachineFunction & MF,Register Val)23 MachineFloatingPointPredicateUtils::queryDenormalMode(const MachineFunction &MF,
24                                                       Register Val) {
25   const MachineRegisterInfo &MRI = MF.getRegInfo();
26   LLT Ty = MRI.getType(Val).getScalarType();
27   return MF.getDenormalMode(getFltSemanticForLLT(Ty));
28 }
29 
30 template <>
lookThroughFAbs(const MachineFunction & MF,Register LHS,Register & Src)31 bool MachineFloatingPointPredicateUtils::lookThroughFAbs(
32     const MachineFunction &MF, Register LHS, Register &Src) {
33   const MachineRegisterInfo &MRI = MF.getRegInfo();
34   return mi_match(LHS, MRI, m_GFabs(m_Reg(Src)));
35 }
36 
37 template <>
matchConstantFloat(const MachineFunction & MF,Register Val)38 std::optional<APFloat> MachineFloatingPointPredicateUtils::matchConstantFloat(
39     const MachineFunction &MF, Register Val) {
40   const MachineRegisterInfo &MRI = MF.getRegInfo();
41   const ConstantFP *ConstVal;
42   if (mi_match(Val, MRI, m_GFCst(ConstVal)))
43     return ConstVal->getValueAPF();
44 
45   return std::nullopt;
46 }
47 
48 } // namespace llvm
49