| 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 | |
| 18 | #include "llvm/ADT/FloatingPointMode.h" |
| 19 | #include "llvm/ADT/Optional.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | class StringRef; |
| 23 | |
| 24 | namespace fp { |
| 25 | |
| 26 | /// Exception behavior 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 ExceptionBehavior : uint8_t { |
| 32 | ebIgnore, ///< This corresponds to "fpexcept.ignore". |
| 33 | ebMayTrap, ///< This corresponds to "fpexcept.maytrap". |
| 34 | ebStrict ///< This corresponds to "fpexcept.strict". |
| 35 | }; |
| 36 | |
| 37 | } |
| 38 | |
| 39 | /// Returns a valid RoundingMode enumerator when given a string |
| 40 | /// that is valid as input in constrained intrinsic rounding mode |
| 41 | /// metadata. |
| 42 | Optional<RoundingMode> convertStrToRoundingMode(StringRef); |
| 43 | |
| 44 | /// For any RoundingMode enumerator, returns a string valid as input in |
| 45 | /// constrained intrinsic rounding mode metadata. |
| 46 | Optional<StringRef> convertRoundingModeToStr(RoundingMode); |
| 47 | |
| 48 | /// Returns a valid ExceptionBehavior enumerator when given a string |
| 49 | /// valid as input in constrained intrinsic exception behavior metadata. |
| 50 | Optional<fp::ExceptionBehavior> convertStrToExceptionBehavior(StringRef); |
| 51 | |
| 52 | /// For any ExceptionBehavior enumerator, returns a string valid as |
| 53 | /// input in constrained intrinsic exception behavior metadata. |
| 54 | Optional<StringRef> convertExceptionBehaviorToStr(fp::ExceptionBehavior); |
| 55 | |
| 56 | /// Returns true if the exception handling behavior and rounding mode |
| 57 | /// match what is used in the default floating point environment. |
| 58 | inline bool isDefaultFPEnvironment(fp::ExceptionBehavior EB, RoundingMode RM) { |
| 59 | return EB == fp::ebIgnore && RM == RoundingMode::NearestTiesToEven; |
| 60 | } |
| 61 | |
| 62 | /// Returns true if the rounding mode RM may be QRM at compile time or |
| 63 | /// at run time. |
| 64 | inline bool canRoundingModeBe(RoundingMode RM, RoundingMode QRM) { |
| 65 | return RM == QRM || RM == RoundingMode::Dynamic; |
| 66 | } |
| 67 | } |
| 68 | #endif |