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