1//===- llvm/Support/FloatingPointMode.h -------------------------*- 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// Utilities for dealing with flags related to floating point mode controls. 10// 11//===----------------------------------------------------------------------===/ 12 13#ifndef LLVM_FLOATINGPOINTMODE_H 14#define LLVM_FLOATINGPOINTMODE_H 15 16#include "llvm/ADT/StringSwitch.h" 17 18namespace llvm { 19 20/// Represent handled modes for denormal (aka subnormal) modes in the floating 21/// point environment. 22enum class DenormalMode { 23 Invalid = -1, 24 25 /// IEEE-754 denormal numbers preserved. 26 IEEE, 27 28 /// The sign of a flushed-to-zero number is preserved in the sign of 0 29 PreserveSign, 30 31 /// Denormals are flushed to positive zero. 32 PositiveZero 33}; 34 35/// Parse the expected names from the denormal-fp-math attribute. 36inline 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); 43} 44 45/// Return the name used for the denormal handling mode used by the the 46/// expected names from the denormal-fp-math attribute. 47inline StringRef denormalModeName(DenormalMode Mode) { 48 switch (Mode) { 49 case DenormalMode::IEEE: 50 return "ieee"; 51 case DenormalMode::PreserveSign: 52 return "preserve-sign"; 53 case DenormalMode::PositiveZero: 54 return "positive-zero"; 55 default: 56 return ""; 57 } 58} 59 60} 61 62#endif // LLVM_FLOATINGPOINTMODE_H 63