1 //===- llvm/Support/FloatingPointMode.h -------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Utilities for dealing with flags related to floating point mode controls.
11 //===----------------------------------------------------------------------===/
13 #ifndef LLVM_FLOATINGPOINTMODE_H
14 #define LLVM_FLOATINGPOINTMODE_H
16 #include "llvm/ADT/StringSwitch.h"
20 /// Represent handled modes for denormal (aka subnormal) modes in the floating
21 /// point environment.
22 enum class DenormalMode {
25 /// IEEE-754 denormal numbers preserved.
28 /// The sign of a flushed-to-zero number is preserved in the sign of 0
31 /// Denormals are flushed to positive zero.
35 /// Parse the expected names from the denormal-fp-math attribute.
36 inline DenormalMode parseDenormalFPAttribute(StringRef Str) {
37 // Assume ieee on unspecified attribute.
38 return StringSwitch<DenormalMode>(Str)
39 .Cases("", "ieee", DenormalMode::IEEE)
40 .Case("preserve-sign", DenormalMode::PreserveSign)
41 .Case("positive-zero", DenormalMode::PositiveZero)
42 .Default(DenormalMode::Invalid);
45 /// Return the name used for the denormal handling mode used by the the
46 /// expected names from the denormal-fp-math attribute.
47 inline StringRef denormalModeName(DenormalMode Mode) {
49 case DenormalMode::IEEE:
51 case DenormalMode::PreserveSign:
52 return "preserve-sign";
53 case DenormalMode::PositiveZero:
54 return "positive-zero";
62 #endif // LLVM_FLOATINGPOINTMODE_H