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
17namespace llvm {
18
19using namespace MIPatternMatch;
20
21template <>
22DenormalMode
23MachineFloatingPointPredicateUtils::queryDenormalMode(const MachineFunction &MF,
24 Register Val) {
25 const MachineRegisterInfo &MRI = MF.getRegInfo();
26 LLT Ty = MRI.getType(Reg: Val).getScalarType();
27 return MF.getDenormalMode(FPType: getFltSemanticForLLT(Ty));
28}
29
30template <>
31bool MachineFloatingPointPredicateUtils::lookThroughFAbs(
32 const MachineFunction &MF, Register LHS, Register &Src) {
33 const MachineRegisterInfo &MRI = MF.getRegInfo();
34 return mi_match(R: LHS, MRI, P: m_GFabs(Src: m_Reg(R&: Src)));
35}
36
37template <>
38std::optional<APFloat> MachineFloatingPointPredicateUtils::matchConstantFloat(
39 const MachineFunction &MF, Register Val) {
40 const MachineRegisterInfo &MRI = MF.getRegInfo();
41 const ConstantFP *ConstVal;
42 if (mi_match(R: Val, MRI, P: m_GFCst(C&: ConstVal)))
43 return ConstVal->getValueAPF();
44
45 return std::nullopt;
46}
47
48} // namespace llvm
49