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_FLOATINGPOINT_H
16 #define LLVM_IR_FLOATINGPOINT_H
17 
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/StringRef.h"
20 #include <stdint.h>
21 
22 namespace llvm {
23 
24 namespace fp {
25 
26 /// Rounding mode used for floating point operations.
27 ///
28 /// Each of these values correspond to some metadata argument value of a
29 /// constrained floating point intrinsic. See the LLVM Language Reference Manual
30 /// for details.
31 enum RoundingMode : uint8_t {
32   rmDynamic,   ///< This corresponds to "fpround.dynamic".
33   rmToNearest, ///< This corresponds to "fpround.tonearest".
34   rmDownward,  ///< This corresponds to "fpround.downward".
35   rmUpward,    ///< This corresponds to "fpround.upward".
36   rmTowardZero ///< This corresponds to "fpround.tozero".
37 };
38 
39 /// Exception behavior used for floating point operations.
40 ///
41 /// Each of these values correspond to some metadata argument value of a
42 /// constrained floating point intrinsic. See the LLVM Language Reference Manual
43 /// for details.
44 enum ExceptionBehavior : uint8_t {
45   ebIgnore,  ///< This corresponds to "fpexcept.ignore".
46   ebMayTrap, ///< This corresponds to "fpexcept.maytrap".
47   ebStrict   ///< This corresponds to "fpexcept.strict".
48 };
49 
50 }
51 
52 /// Returns a valid RoundingMode enumerator when given a string
53 /// that is valid as input in constrained intrinsic rounding mode
54 /// metadata.
55 Optional<fp::RoundingMode> StrToRoundingMode(StringRef);
56 
57 /// For any RoundingMode enumerator, returns a string valid as input in
58 /// constrained intrinsic rounding mode metadata.
59 Optional<StringRef> RoundingModeToStr(fp::RoundingMode);
60 
61 /// Returns a valid ExceptionBehavior enumerator when given a string
62 /// valid as input in constrained intrinsic exception behavior metadata.
63 Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef);
64 
65 /// For any ExceptionBehavior enumerator, returns a string valid as
66 /// input in constrained intrinsic exception behavior metadata.
67 Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior);
68 
69 }
70 #endif
71