LLVM 24.0.0git
FPFold.h
Go to the documentation of this file.
1//===- FPFold.h - Floating-point constant-folding helpers -------*- C++ -*-===//
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/// \file
9/// This file provides fallible floating-point folding operations with explicit
10/// rounding and denormal modes.
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_FPFOLD_H
14#define LLVM_SUPPORT_FPFOLD_H
15
16#include "llvm/ADT/APFloat.h"
17#include "llvm/ADT/ArrayRef.h"
20#include <optional>
21
22namespace llvm {
23
24/// The floating-point operations supported by the folding helpers.
44
45/// A unique floating-point result and the IEEE exceptions raised computing it.
50
51/// Return the value of a successful fold, or std::nullopt.
52LLVM_ABI std::optional<APFloat> getFPValue(std::optional<FPFoldResult> Res);
53
54/// Try to evaluate a floating-point operation with the specified inputs.
55/// Ceil, Floor, Trunc, Round, and RoundEven select their own rounding mode;
56/// Other rounding-dependent operations use RN.
57/// Min/max and FRem do not depend on the rounding mode.
58///
59/// Returns std::nullopt when the modes do not specify one result. In
60/// particular, this occurs when a dynamic denormal mode could change an input
61/// or output value.
62LLVM_ABI std::optional<FPFoldResult>
63tryFoldFP(FPOp Opcode, ArrayRef<APFloat> Args, DenormalMode Denorms);
64
65/// Try to evaluate a floating-point operation with an explicit rounding mode.
66/// Dynamic is evaluated using RN, but folding is declined if evaluation is
67/// inexact. Fixed-rounding operations still select their own rounding mode.
68LLVM_ABI std::optional<FPFoldResult> tryFoldFPWithRM(FPOp Opcode,
70 RoundingMode RM,
71 DenormalMode Denorms);
72
73/// Try to compare two floating-point values.
74///
75/// A comparison has no rounding or output-denormal mode, but is not foldable
76/// when dynamic input-denormal handling could alter an operand.
77LLVM_ABI std::optional<APFloat::cmpResult>
78tryFoldFCmp(const APFloat &LHS, const APFloat &RHS, DenormalMode Denorms);
79
80} // namespace llvm
81
82#endif // LLVM_SUPPORT_FPFOLD_H
This file declares a class to represent arbitrary precision floating point values and provide a varie...
#define LLVM_ABI
Definition Compiler.h:211
Utilities for dealing with flags related to floating point properties and mode controls.
Value * RHS
Value * LHS
opStatus
IEEE-754R 7: Default exception handling.
Definition APFloat.h:377
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::optional< FPFoldResult > tryFoldFP(FPOp Opcode, ArrayRef< APFloat > Args, DenormalMode Denorms)
Try to evaluate a floating-point operation with the specified inputs.
Definition FPFold.cpp:160
FPOp
The floating-point operations supported by the folding helpers.
Definition FPFold.h:25
@ MaximumNum
Definition FPFold.h:36
@ RoundEven
Definition FPFold.h:42
@ Maximum
Definition FPFold.h:34
@ Minimum
Definition FPFold.h:33
@ MinimumNum
Definition FPFold.h:35
LLVM_ABI std::optional< APFloat::cmpResult > tryFoldFCmp(const APFloat &LHS, const APFloat &RHS, DenormalMode Denorms)
Try to compare two floating-point values.
Definition FPFold.cpp:184
@ Mul
Product of integers.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
RoundingMode
Rounding mode.
LLVM_ABI std::optional< APFloat > getFPValue(std::optional< FPFoldResult > Res)
Return the value of a successful fold, or std::nullopt.
Definition FPFold.cpp:18
LLVM_ABI std::optional< FPFoldResult > tryFoldFPWithRM(FPOp Opcode, ArrayRef< APFloat > Args, RoundingMode RM, DenormalMode Denorms)
Try to evaluate a floating-point operation with an explicit rounding mode.
Definition FPFold.cpp:170
Represent subnormal handling kind for floating point instruction inputs and outputs.
A unique floating-point result and the IEEE exceptions raised computing it.
Definition FPFold.h:46
APFloat Value
Definition FPFold.h:47
APFloat::opStatus Status
Definition FPFold.h:48