150
|
1 //===-- FPEnv.cpp ---- FP Environment -------------------------------------===//
|
|
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 /// @file
|
|
10 /// This file contains the implementations of entities that describe floating
|
|
11 /// point environment.
|
|
12 //
|
|
13 //===----------------------------------------------------------------------===//
|
|
14
|
|
15 #include "llvm/ADT/StringSwitch.h"
|
|
16 #include "llvm/IR/FPEnv.h"
|
|
17
|
|
18 namespace llvm {
|
|
19
|
|
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)
|
|
29 .Default(None);
|
|
30 }
|
|
31
|
|
32 Optional<StringRef> RoundingModeToStr(fp::RoundingMode UseRounding) {
|
|
33 Optional<StringRef> RoundingStr = None;
|
|
34 switch (UseRounding) {
|
|
35 case fp::rmDynamic:
|
|
36 RoundingStr = "round.dynamic";
|
|
37 break;
|
|
38 case fp::rmToNearest:
|
|
39 RoundingStr = "round.tonearest";
|
|
40 break;
|
|
41 case fp::rmDownward:
|
|
42 RoundingStr = "round.downward";
|
|
43 break;
|
|
44 case fp::rmUpward:
|
|
45 RoundingStr = "round.upward";
|
|
46 break;
|
|
47 case fp::rmTowardZero:
|
|
48 RoundingStr = "round.towardzero";
|
|
49 break;
|
|
50 }
|
|
51 return RoundingStr;
|
|
52 }
|
|
53
|
|
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)
|
|
59 .Default(None);
|
|
60 }
|
|
61
|
|
62 Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
|
|
63 Optional<StringRef> ExceptStr = None;
|
|
64 switch (UseExcept) {
|
|
65 case fp::ebStrict:
|
|
66 ExceptStr = "fpexcept.strict";
|
|
67 break;
|
|
68 case fp::ebIgnore:
|
|
69 ExceptStr = "fpexcept.ignore";
|
|
70 break;
|
|
71 case fp::ebMayTrap:
|
|
72 ExceptStr = "fpexcept.maytrap";
|
|
73 break;
|
|
74 }
|
|
75 return ExceptStr;
|
|
76 }
|
|
77
|
|
78 }
|