LLVM 22.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"
21#include <optional>
22
23namespace llvm {
24class StringRef;
25
26namespace Intrinsic {
27typedef unsigned ID;
28}
29
30class Instruction;
31
32namespace fp {
33
34/// Exception behavior used for floating point operations.
35///
36/// Each of these values correspond to some metadata argument value of a
37/// constrained floating point intrinsic. See the LLVM Language Reference Manual
38/// for details.
40 ebIgnore, ///< This corresponds to "fpexcept.ignore".
41 ebMayTrap, ///< This corresponds to "fpexcept.maytrap".
42 ebStrict ///< This corresponds to "fpexcept.strict".
43};
44
45}
46
47/// Returns a valid RoundingMode enumerator when given a string
48/// that is valid as input in constrained intrinsic rounding mode
49/// metadata.
50LLVM_ABI std::optional<RoundingMode> convertStrToRoundingMode(StringRef);
51
52/// For any RoundingMode enumerator, returns a string valid as input in
53/// constrained intrinsic rounding mode metadata.
54LLVM_ABI std::optional<StringRef> convertRoundingModeToStr(RoundingMode);
55
56/// Returns a valid ExceptionBehavior enumerator when given a string
57/// valid as input in constrained intrinsic exception behavior metadata.
58LLVM_ABI std::optional<fp::ExceptionBehavior>
60
61/// For any ExceptionBehavior enumerator, returns a string valid as
62/// input in constrained intrinsic exception behavior metadata.
63LLVM_ABI std::optional<StringRef>
65
66/// Returns true if the exception handling behavior and rounding mode
67/// match what is used in the default floating point environment.
70}
71
72/// Returns constrained intrinsic id to represent the given instruction in
73/// strictfp function. If the instruction is already a constrained intrinsic or
74/// does not have a constrained intrinsic counterpart, the function returns
75/// zero.
76LLVM_ABI Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr);
77
78/// Returns true if the rounding mode RM may be QRM at compile time or
79/// at run time.
81 return RM == QRM || RM == RoundingMode::Dynamic;
82}
83
84/// Returns true if the possibility of a signaling NaN can be safely
85/// ignored.
87 return (EB == fp::ebIgnore || FMF.noNaNs());
88}
89}
90#endif
#define LLVM_ABI
Definition: Compiler.h:213
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:22
bool noNaNs() const
Definition: FMF.h:65
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:39
@ ebStrict
This corresponds to "fpexcept.strict".
Definition: FPEnv.h:42
@ ebMayTrap
This corresponds to "fpexcept.maytrap".
Definition: FPEnv.h:41
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:40
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:68
LLVM_ABI 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:80
LLVM_ABI std::optional< StringRef > convertExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition: FPEnv.cpp:74
LLVM_ABI Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)
Returns constrained intrinsic id to represent the given instruction in strictfp function.
Definition: FPEnv.cpp:90
LLVM_ABI 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.
LLVM_ABI 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:86