49 lines · cpp
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-exception6//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 <>22DenormalMode23MachineFloatingPointPredicateUtils::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 30template <>31bool 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 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(Val, MRI, m_GFCst(ConstVal)))43 return ConstVal->getValueAPF();44 45 return std::nullopt;46}47 48} // namespace llvm49