1 //===-- FPEnv.cpp ---- FP Environment -------------------------------------===//
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 //===----------------------------------------------------------------------===//
10 /// This file contains the implementations of entities that describe floating
11 /// point environment.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/IR/FPEnv.h"
20 Optional<fp::RoundingMode> StrToRoundingMode(StringRef RoundingArg) {
21 // For dynamic rounding mode, we use round to nearest but we will set the
22 // 'exact' SDNodeFlag so that the value will not be rounded.
23 return StringSwitch<Optional<fp::RoundingMode>>(RoundingArg)
24 .Case("round.dynamic", fp::rmDynamic)
25 .Case("round.tonearest", fp::rmToNearest)
26 .Case("round.downward", fp::rmDownward)
27 .Case("round.upward", fp::rmUpward)
28 .Case("round.towardzero", fp::rmTowardZero)
32 Optional<StringRef> RoundingModeToStr(fp::RoundingMode UseRounding) {
33 Optional<StringRef> RoundingStr = None;
34 switch (UseRounding) {
36 RoundingStr = "round.dynamic";
39 RoundingStr = "round.tonearest";
42 RoundingStr = "round.downward";
45 RoundingStr = "round.upward";
47 case fp::rmTowardZero:
48 RoundingStr = "round.towardzero";
54 Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) {
55 return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg)
56 .Case("fpexcept.ignore", fp::ebIgnore)
57 .Case("fpexcept.maytrap", fp::ebMayTrap)
58 .Case("fpexcept.strict", fp::ebStrict)
62 Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
63 Optional<StringRef> ExceptStr = None;
66 ExceptStr = "fpexcept.strict";
69 ExceptStr = "fpexcept.ignore";
72 ExceptStr = "fpexcept.maytrap";