LLVM  14.0.0git
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/IR/FPEnv.h"
16 #include "llvm/ADT/StringSwitch.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<RoundingMode>>(RoundingArg)
24  .Case("round.dynamic", RoundingMode::Dynamic)
25  .Case("round.tonearest", RoundingMode::NearestTiesToEven)
26  .Case("round.tonearestaway", RoundingMode::NearestTiesToAway)
27  .Case("round.downward", RoundingMode::TowardNegative)
28  .Case("round.upward", RoundingMode::TowardPositive)
29  .Case("round.towardzero", RoundingMode::TowardZero)
30  .Default(None);
31 }
32 
34  Optional<StringRef> RoundingStr = None;
35  switch (UseRounding) {
37  RoundingStr = "round.dynamic";
38  break;
40  RoundingStr = "round.tonearest";
41  break;
43  RoundingStr = "round.tonearestaway";
44  break;
46  RoundingStr = "round.downward";
47  break;
49  RoundingStr = "round.upward";
50  break;
52  RoundingStr = "round.towardzero";
53  break;
54  default:
55  break;
56  }
57  return RoundingStr;
58 }
59 
60 Optional<fp::ExceptionBehavior>
63  .Case("fpexcept.ignore", fp::ebIgnore)
64  .Case("fpexcept.maytrap", fp::ebMayTrap)
65  .Case("fpexcept.strict", fp::ebStrict)
66  .Default(None);
67 }
68 
69 Optional<StringRef>
71  Optional<StringRef> ExceptStr = None;
72  switch (UseExcept) {
73  case fp::ebStrict:
74  ExceptStr = "fpexcept.strict";
75  break;
76  case fp::ebIgnore:
77  ExceptStr = "fpexcept.ignore";
78  break;
79  case fp::ebMayTrap:
80  ExceptStr = "fpexcept.maytrap";
81  break;
82  }
83  return ExceptStr;
84 }
85 } // namespace llvm
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::convertRoundingModeToStr
Optional< StringRef > convertRoundingModeToStr(RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition: FPEnv.cpp:33
llvm::Optional
Definition: APInt.h:33
llvm::fp::ebMayTrap
@ ebMayTrap
This corresponds to "fpexcept.maytrap".
Definition: FPEnv.h:33
llvm::RoundingMode
RoundingMode
Rounding mode.
Definition: FloatingPointMode.h:34
llvm::None
const NoneType None
Definition: None.h:23
llvm::convertExceptionBehaviorToStr
Optional< StringRef > convertExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition: FPEnv.cpp:70
llvm::convertStrToExceptionBehavior
Optional< fp::ExceptionBehavior > convertStrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition: FPEnv.cpp:61
llvm::RoundingMode::TowardNegative
@ TowardNegative
roundTowardNegative.
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::convertStrToRoundingMode
Optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition: FPEnv.cpp:20
llvm::RoundingMode::Dynamic
@ Dynamic
Denotes mode unknown at compile time.
llvm::RoundingMode::NearestTiesToAway
@ NearestTiesToAway
roundTiesToAway.
llvm::RoundingMode::TowardZero
@ TowardZero
roundTowardZero.
FPEnv.h
StringSwitch.h
llvm::fp::ebIgnore
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:32
llvm::fp::ExceptionBehavior
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:31
llvm::RoundingMode::TowardPositive
@ TowardPositive
roundTowardPositive.
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
llvm::fp::ebStrict
@ ebStrict
This corresponds to "fpexcept.strict".
Definition: FPEnv.h:34
llvm::RoundingMode::NearestTiesToEven
@ NearestTiesToEven
roundTiesToEven.