LLVM 20.0.0git
FPEnv.h
Go to the documentation of this file.
1//===- FPEnv.h ---- FP Environment ------------------------------*- 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//
9/// @file
10/// This file contains the declarations of entities that describe floating
11/// point environment and related functions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_FPENV_H
16#define LLVM_IR_FPENV_H
17
19#include "llvm/IR/FMF.h"
20#include <optional>
21
22namespace llvm {
23class StringRef;
24
25namespace Intrinsic {
26typedef unsigned ID;
27}
28
29class Instruction;
30
31namespace fp {
32
33/// Exception behavior used for floating point operations.
34///
35/// Each of these values correspond to some metadata argument value of a
36/// constrained floating point intrinsic. See the LLVM Language Reference Manual
37/// for details.
38enum ExceptionBehavior : uint8_t {
39 ebIgnore, ///< This corresponds to "fpexcept.ignore".
40 ebMayTrap, ///< This corresponds to "fpexcept.maytrap".
41 ebStrict ///< This corresponds to "fpexcept.strict".
42};
43
44}
45
46/// Returns a valid RoundingMode enumerator when given a string
47/// that is valid as input in constrained intrinsic rounding mode
48/// metadata.
49std::optional<RoundingMode> convertStrToRoundingMode(StringRef);
50
51/// For any RoundingMode enumerator, returns a string valid as input in
52/// constrained intrinsic rounding mode metadata.
53std::optional<StringRef> convertRoundingModeToStr(RoundingMode);
54
55/// Returns a valid ExceptionBehavior enumerator when given a string
56/// valid as input in constrained intrinsic exception behavior metadata.
57std::optional<fp::ExceptionBehavior> convertStrToExceptionBehavior(StringRef);
58
59/// For any ExceptionBehavior enumerator, returns a string valid as
60/// input in constrained intrinsic exception behavior metadata.
62
63/// Returns true if the exception handling behavior and rounding mode
64/// match what is used in the default floating point environment.
67}
68
69/// Returns constrained intrinsic id to represent the given instruction in
70/// strictfp function. If the instruction is already a constrained intrinsic or
71/// does not have a constrained intrinsic counterpart, the function returns
72/// zero.
73Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr);
74
75/// Returns true if the rounding mode RM may be QRM at compile time or
76/// at run time.
78 return RM == QRM || RM == RoundingMode::Dynamic;
79}
80
81/// Returns true if the possibility of a signaling NaN can be safely
82/// ignored.
84 return (EB == fp::ebIgnore || FMF.noNaNs());
85}
86}
87#endif
Utilities for dealing with flags related to floating point properties and mode controls.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
bool noNaNs() const
Definition: FMF.h:66
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:38
@ ebStrict
This corresponds to "fpexcept.strict".
Definition: FPEnv.h:41
@ ebMayTrap
This corresponds to "fpexcept.maytrap".
Definition: FPEnv.h:40
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:39
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool isDefaultFPEnvironment(fp::ExceptionBehavior EB, RoundingMode RM)
Returns true if the exception handling behavior and rounding mode match what is used in the default f...
Definition: FPEnv.h:65
std::optional< StringRef > convertRoundingModeToStr(RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition: FPEnv.cpp:37
bool canRoundingModeBe(RoundingMode RM, RoundingMode QRM)
Returns true if the rounding mode RM may be QRM at compile time or at run time.
Definition: FPEnv.h:77
std::optional< StringRef > convertExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition: FPEnv.cpp:74
Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)
Returns constrained intrinsic id to represent the given instruction in strictfp function.
Definition: FPEnv.cpp:90
std::optional< fp::ExceptionBehavior > convertStrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition: FPEnv.cpp:65
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
@ Dynamic
Denotes mode unknown at compile time.
std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition: FPEnv.cpp:24
bool canIgnoreSNaN(fp::ExceptionBehavior EB, FastMathFlags FMF)
Returns true if the possibility of a signaling NaN can be safely ignored.
Definition: FPEnv.h:83