LLVM  10.0.0
FPEnv.cpp
Go to the documentation of this file.
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 
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 
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 
56  .Case("fpexcept.ignore", fp::ebIgnore)
57  .Case("fpexcept.maytrap", fp::ebMayTrap)
58  .Case("fpexcept.strict", fp::ebStrict)
59  .Default(None);
60 }
61 
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 }
const NoneType None
Definition: None.h:23
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This corresponds to "fpround.tonearest".
Definition: FPEnv.h:33
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:44
RoundingMode
Rounding mode used for floating point operations.
Definition: FPEnv.h:31
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
Optional< fp::RoundingMode > StrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition: FPEnv.cpp:20
This corresponds to "fpexcept.maytrap".
Definition: FPEnv.h:46
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
Optional< fp::ExceptionBehavior > StrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition: FPEnv.cpp:54
Optional< StringRef > ExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition: FPEnv.cpp:62
This corresponds to "fpround.dynamic".
Definition: FPEnv.h:32
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:45
This corresponds to "fpround.tozero".
Definition: FPEnv.h:36
This file contains the declarations of entities that describe floating point environment and related ...
Optional< StringRef > RoundingModeToStr(fp::RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition: FPEnv.cpp:32
This corresponds to "fpexcept.strict".
Definition: FPEnv.h:47
This corresponds to "fpround.downward".
Definition: FPEnv.h:34
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
This corresponds to "fpround.upward".
Definition: FPEnv.h:35