mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
a91d41c574
This is recommit of commit e6584b2b7b2d, which was reverted in 30e7ee3c4bac together with af57dbf12e54. Original message is below. Enumerations that describe rounding mode and exception behavior were defined inside ConstrainedFPIntrinsic. It makes sense to use the same definitions to represent the same properties in other cases, not only in constrained intrinsics. It was however inconvenient as required to include constrained intrinsics definitions even if they were not needed. Also using long scope prefix reduced readability. This change moves these definitioins to the namespace llvm::fp. No functional changes. Differential Revision: https://reviews.llvm.org/D69552
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
//===-- FPEnv.cpp ---- FP Environment -------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
/// @file
|
|
/// This file contains the implementations of entities that describe floating
|
|
/// point environment.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
#include "llvm/IR/FPEnv.h"
|
|
|
|
namespace llvm {
|
|
|
|
Optional<fp::RoundingMode> StrToRoundingMode(StringRef RoundingArg) {
|
|
// For dynamic rounding mode, we use round to nearest but we will set the
|
|
// 'exact' SDNodeFlag so that the value will not be rounded.
|
|
return StringSwitch<Optional<fp::RoundingMode>>(RoundingArg)
|
|
.Case("round.dynamic", fp::rmDynamic)
|
|
.Case("round.tonearest", fp::rmToNearest)
|
|
.Case("round.downward", fp::rmDownward)
|
|
.Case("round.upward", fp::rmUpward)
|
|
.Case("round.towardzero", fp::rmTowardZero)
|
|
.Default(None);
|
|
}
|
|
|
|
Optional<StringRef> RoundingModeToStr(fp::RoundingMode UseRounding) {
|
|
Optional<StringRef> RoundingStr = None;
|
|
switch (UseRounding) {
|
|
case fp::rmDynamic:
|
|
RoundingStr = "round.dynamic";
|
|
break;
|
|
case fp::rmToNearest:
|
|
RoundingStr = "round.tonearest";
|
|
break;
|
|
case fp::rmDownward:
|
|
RoundingStr = "round.downward";
|
|
break;
|
|
case fp::rmUpward:
|
|
RoundingStr = "round.upward";
|
|
break;
|
|
case fp::rmTowardZero:
|
|
RoundingStr = "round.towardzero";
|
|
break;
|
|
}
|
|
return RoundingStr;
|
|
}
|
|
|
|
Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) {
|
|
return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg)
|
|
.Case("fpexcept.ignore", fp::ebIgnore)
|
|
.Case("fpexcept.maytrap", fp::ebMayTrap)
|
|
.Case("fpexcept.strict", fp::ebStrict)
|
|
.Default(None);
|
|
}
|
|
|
|
Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
|
|
Optional<StringRef> ExceptStr = None;
|
|
switch (UseExcept) {
|
|
case fp::ebStrict:
|
|
ExceptStr = "fpexcept.strict";
|
|
break;
|
|
case fp::ebIgnore:
|
|
ExceptStr = "fpexcept.ignore";
|
|
break;
|
|
case fp::ebMayTrap:
|
|
ExceptStr = "fpexcept.maytrap";
|
|
break;
|
|
}
|
|
return ExceptStr;
|
|
}
|
|
|
|
} |