LLVM  15.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/ADT/Optional.h"
20 #include "llvm/IR/FMF.h"
21 
22 namespace llvm {
23 class StringRef;
24 
25 namespace Intrinsic {
26 typedef unsigned ID;
27 }
28 
29 class Instruction;
30 
31 namespace 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.
38 enum 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.
49 Optional<RoundingMode> convertStrToRoundingMode(StringRef);
50 
51 /// For any RoundingMode enumerator, returns a string valid as input in
52 /// constrained intrinsic rounding mode metadata.
53 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.
57 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.
73 Intrinsic::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
FloatingPointMode.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
FMF.h
Optional.h
llvm::convertRoundingModeToStr
Optional< StringRef > convertRoundingModeToStr(RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition: FPEnv.cpp:36
llvm::FastMathFlags
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:21
llvm::FastMathFlags::noNaNs
bool noNaNs() const
Definition: FMF.h:67
llvm::fp::ebMayTrap
@ ebMayTrap
This corresponds to "fpexcept.maytrap".
Definition: FPEnv.h:40
llvm::getConstrainedIntrinsicID
Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)
Returns constrained intrinsic id to represent the given instruction in strictfp function.
Definition: FPEnv.cpp:89
llvm::RoundingMode
RoundingMode
Rounding mode.
Definition: FloatingPointMode.h:36
llvm::codeview::ClassOptions::Intrinsic
@ Intrinsic
llvm::convertExceptionBehaviorToStr
Optional< StringRef > convertExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition: FPEnv.cpp:73
llvm::convertStrToExceptionBehavior
Optional< fp::ExceptionBehavior > convertStrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition: FPEnv.cpp:64
llvm::canRoundingModeBe
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
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:469
llvm::convertStrToRoundingMode
Optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition: FPEnv.cpp:23
llvm::RoundingMode::Dynamic
@ Dynamic
Denotes mode unknown at compile time.
llvm::isDefaultFPEnvironment
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
llvm::fp::ebIgnore
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:39
llvm::fp::ExceptionBehavior
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:38
llvm::canIgnoreSNaN
bool canIgnoreSNaN(fp::ExceptionBehavior EB, FastMathFlags FMF)
Returns true if the possibility of a signaling NaN can be safely ignored.
Definition: FPEnv.h:83
llvm::fp::ebStrict
@ ebStrict
This corresponds to "fpexcept.strict".
Definition: FPEnv.h:41
llvm::RoundingMode::NearestTiesToEven
@ NearestTiesToEven
roundTiesToEven.
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38