1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/include/llvm/ADT/FloatingPointMode.h
Matt Arsenault 00e1bbce35 Work on cleaning up denormal mode handling
Cleanup handling of the denormal-fp-math attribute. Consolidate places
checking the allowed names in one place.

This is in preparation for introducing FP type specific variants of
the denormal-fp-mode attribute. AMDGPU will switch to using this in
place of the current hacky use of subtarget features for the denormal
mode.

Introduce a new header for dealing with FP modes. The constrained
intrinsic classes define related enums that should also be moved into
this header for uses in other contexts.

The verifier could use a check to make sure the denorm-fp-mode
attribute is sane, but there currently isn't one.

Currently, DAGCombiner incorrectly asssumes non-IEEE behavior by
default in the one current user. Clang must be taught to start
emitting this attribute by default to avoid regressions when this is
switched to assume ieee behavior if the attribute isn't present.
2019-11-19 22:01:14 +05:30

63 lines
1.8 KiB
C++

//===- llvm/Support/FloatingPointMode.h -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Utilities for dealing with flags related to floating point mode controls.
//
//===----------------------------------------------------------------------===/
#ifndef LLVM_FLOATINGPOINTMODE_H
#define LLVM_FLOATINGPOINTMODE_H
#include "llvm/ADT/StringSwitch.h"
namespace llvm {
/// Represent handled modes for denormal (aka subnormal) modes in the floating
/// point environment.
enum class DenormalMode {
Invalid = -1,
/// IEEE-754 denormal numbers preserved.
IEEE,
/// The sign of a flushed-to-zero number is preserved in the sign of 0
PreserveSign,
/// Denormals are flushed to positive zero.
PositiveZero
};
/// Parse the expected names from the denormal-fp-math attribute.
inline DenormalMode parseDenormalFPAttribute(StringRef Str) {
// Assume ieee on unspecified attribute.
return StringSwitch<DenormalMode>(Str)
.Cases("", "ieee", DenormalMode::IEEE)
.Case("preserve-sign", DenormalMode::PreserveSign)
.Case("positive-zero", DenormalMode::PositiveZero)
.Default(DenormalMode::Invalid);
}
/// Return the name used for the denormal handling mode used by the the
/// expected names from the denormal-fp-math attribute.
inline StringRef denormalModeName(DenormalMode Mode) {
switch (Mode) {
case DenormalMode::IEEE:
return "ieee";
case DenormalMode::PreserveSign:
return "preserve-sign";
case DenormalMode::PositiveZero:
return "positive-zero";
default:
return "";
}
}
}
#endif // LLVM_FLOATINGPOINTMODE_H