LLVM 23.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"
17#include "llvm/IR/Instruction.h"
19#include "llvm/IR/Intrinsics.h"
20#include <optional>
21
22using namespace llvm;
23
24std::optional<RoundingMode>
26 // For dynamic rounding mode, we use round to nearest but we will set the
27 // 'exact' SDNodeFlag so that the value will not be rounded.
29 .Case("round.dynamic", RoundingMode::Dynamic)
30 .Case("round.tonearest", RoundingMode::NearestTiesToEven)
31 .Case("round.tonearestaway", RoundingMode::NearestTiesToAway)
32 .Case("round.downward", RoundingMode::TowardNegative)
33 .Case("round.upward", RoundingMode::TowardPositive)
34 .Case("round.towardzero", RoundingMode::TowardZero)
35 .Default(std::nullopt);
36}
37
38std::optional<StringRef>
40 switch (UseRounding) {
42 return "round.dynamic";
44 return "round.tonearest";
46 return "round.tonearestaway";
48 return "round.downward";
50 return "round.upward";
52 return "round.towardzero";
53 default:
54 return std::nullopt;
55 }
56}
57
58std::optional<fp::ExceptionBehavior>
61 .Case("fpexcept.ignore", fp::ebIgnore)
62 .Case("fpexcept.maytrap", fp::ebMayTrap)
63 .Case("fpexcept.strict", fp::ebStrict)
64 .Default(std::nullopt);
65}
66
67std::optional<StringRef>
69 switch (UseExcept) {
70 case fp::ebStrict:
71 return "fpexcept.strict";
72 case fp::ebIgnore:
73 return "fpexcept.ignore";
74 case fp::ebMayTrap:
75 return "fpexcept.maytrap";
76 }
77 return std::nullopt;
78}
79
82 switch (Instr.getOpcode()) {
83 case Instruction::FCmp:
84 // Unlike other instructions FCmp can be mapped to one of two intrinsic
85 // functions. We choose the non-signaling variant.
86 IID = Intrinsic::experimental_constrained_fcmp;
87 break;
88
89 // Instructions
90#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
91 case Instruction::NAME: \
92 IID = Intrinsic::INTRINSIC; \
93 break;
94#define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
95#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
96#include "llvm/IR/ConstrainedOps.def"
97
98 // Intrinsic calls.
99 case Instruction::Call:
100 if (auto *IntrinCall = dyn_cast<IntrinsicInst>(&Instr)) {
101 switch (IntrinCall->getIntrinsicID()) {
102#define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
103 case Intrinsic::NAME: \
104 IID = Intrinsic::INTRINSIC; \
105 break;
106#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
107#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
108#include "llvm/IR/ConstrainedOps.def"
109 default:
110 break;
111 }
112 }
113 break;
114 default:
115 break;
116 }
117
118 return IID;
119}
This file contains the declarations of entities that describe floating point environment and related ...
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
ExceptionBehavior
Exception behavior used for floating point operations.
Definition FPEnv.h:39
@ ebStrict
This corresponds to "fpexcept.strict".
Definition FPEnv.h:42
@ ebMayTrap
This corresponds to "fpexcept.maytrap".
Definition FPEnv.h:41
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition FPEnv.h:40
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI std::optional< StringRef > convertRoundingModeToStr(RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition FPEnv.cpp:39
LLVM_ABI std::optional< StringRef > convertExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition FPEnv.cpp:68
LLVM_ABI Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)
Returns constrained intrinsic id to represent the given instruction in strictfp function.
Definition FPEnv.cpp:80
LLVM_ABI std::optional< fp::ExceptionBehavior > convertStrToExceptionBehavior(StringRef)
Returns a valid ExceptionBehavior enumerator when given a string valid as input in constrained intrin...
Definition FPEnv.cpp:59
RoundingMode
Rounding mode.
@ TowardZero
roundTowardZero.
@ NearestTiesToEven
roundTiesToEven.
@ Dynamic
Denotes mode unknown at compile time.
@ TowardPositive
roundTowardPositive.
@ NearestTiesToAway
roundTiesToAway.
@ TowardNegative
roundTowardNegative.
LLVM_ABI std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition FPEnv.cpp:25