annotate llvm/lib/IR/FPEnv.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 0572611fdcc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- FPEnv.cpp ---- FP Environment -------------------------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 /// @file
anatofuz
parents:
diff changeset
10 /// This file contains the implementations of entities that describe floating
anatofuz
parents:
diff changeset
11 /// point environment.
anatofuz
parents:
diff changeset
12 //
anatofuz
parents:
diff changeset
13 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 #include "llvm/ADT/StringSwitch.h"
anatofuz
parents:
diff changeset
16 #include "llvm/IR/FPEnv.h"
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 namespace llvm {
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 Optional<fp::RoundingMode> StrToRoundingMode(StringRef RoundingArg) {
anatofuz
parents:
diff changeset
21 // For dynamic rounding mode, we use round to nearest but we will set the
anatofuz
parents:
diff changeset
22 // 'exact' SDNodeFlag so that the value will not be rounded.
anatofuz
parents:
diff changeset
23 return StringSwitch<Optional<fp::RoundingMode>>(RoundingArg)
anatofuz
parents:
diff changeset
24 .Case("round.dynamic", fp::rmDynamic)
anatofuz
parents:
diff changeset
25 .Case("round.tonearest", fp::rmToNearest)
anatofuz
parents:
diff changeset
26 .Case("round.downward", fp::rmDownward)
anatofuz
parents:
diff changeset
27 .Case("round.upward", fp::rmUpward)
anatofuz
parents:
diff changeset
28 .Case("round.towardzero", fp::rmTowardZero)
anatofuz
parents:
diff changeset
29 .Default(None);
anatofuz
parents:
diff changeset
30 }
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 Optional<StringRef> RoundingModeToStr(fp::RoundingMode UseRounding) {
anatofuz
parents:
diff changeset
33 Optional<StringRef> RoundingStr = None;
anatofuz
parents:
diff changeset
34 switch (UseRounding) {
anatofuz
parents:
diff changeset
35 case fp::rmDynamic:
anatofuz
parents:
diff changeset
36 RoundingStr = "round.dynamic";
anatofuz
parents:
diff changeset
37 break;
anatofuz
parents:
diff changeset
38 case fp::rmToNearest:
anatofuz
parents:
diff changeset
39 RoundingStr = "round.tonearest";
anatofuz
parents:
diff changeset
40 break;
anatofuz
parents:
diff changeset
41 case fp::rmDownward:
anatofuz
parents:
diff changeset
42 RoundingStr = "round.downward";
anatofuz
parents:
diff changeset
43 break;
anatofuz
parents:
diff changeset
44 case fp::rmUpward:
anatofuz
parents:
diff changeset
45 RoundingStr = "round.upward";
anatofuz
parents:
diff changeset
46 break;
anatofuz
parents:
diff changeset
47 case fp::rmTowardZero:
anatofuz
parents:
diff changeset
48 RoundingStr = "round.towardzero";
anatofuz
parents:
diff changeset
49 break;
anatofuz
parents:
diff changeset
50 }
anatofuz
parents:
diff changeset
51 return RoundingStr;
anatofuz
parents:
diff changeset
52 }
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) {
anatofuz
parents:
diff changeset
55 return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg)
anatofuz
parents:
diff changeset
56 .Case("fpexcept.ignore", fp::ebIgnore)
anatofuz
parents:
diff changeset
57 .Case("fpexcept.maytrap", fp::ebMayTrap)
anatofuz
parents:
diff changeset
58 .Case("fpexcept.strict", fp::ebStrict)
anatofuz
parents:
diff changeset
59 .Default(None);
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
anatofuz
parents:
diff changeset
63 Optional<StringRef> ExceptStr = None;
anatofuz
parents:
diff changeset
64 switch (UseExcept) {
anatofuz
parents:
diff changeset
65 case fp::ebStrict:
anatofuz
parents:
diff changeset
66 ExceptStr = "fpexcept.strict";
anatofuz
parents:
diff changeset
67 break;
anatofuz
parents:
diff changeset
68 case fp::ebIgnore:
anatofuz
parents:
diff changeset
69 ExceptStr = "fpexcept.ignore";
anatofuz
parents:
diff changeset
70 break;
anatofuz
parents:
diff changeset
71 case fp::ebMayTrap:
anatofuz
parents:
diff changeset
72 ExceptStr = "fpexcept.maytrap";
anatofuz
parents:
diff changeset
73 break;
anatofuz
parents:
diff changeset
74 }
anatofuz
parents:
diff changeset
75 return ExceptStr;
anatofuz
parents:
diff changeset
76 }
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 }