annotate llvm/lib/IR/FPEnv.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
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
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
15 #include "llvm/IR/FPEnv.h"
150
anatofuz
parents:
diff changeset
16 #include "llvm/ADT/StringSwitch.h"
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
17 #include "llvm/IR/Instruction.h"
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
18 #include "llvm/IR/IntrinsicInst.h"
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
19 #include "llvm/IR/Intrinsics.h"
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
20 #include <optional>
150
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 namespace llvm {
anatofuz
parents:
diff changeset
23
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
24 std::optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) {
150
anatofuz
parents:
diff changeset
25 // For dynamic rounding mode, we use round to nearest but we will set the
anatofuz
parents:
diff changeset
26 // 'exact' SDNodeFlag so that the value will not be rounded.
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
27 return StringSwitch<std::optional<RoundingMode>>(RoundingArg)
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 .Case("round.dynamic", RoundingMode::Dynamic)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 .Case("round.tonearest", RoundingMode::NearestTiesToEven)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
30 .Case("round.tonearestaway", RoundingMode::NearestTiesToAway)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
31 .Case("round.downward", RoundingMode::TowardNegative)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
32 .Case("round.upward", RoundingMode::TowardPositive)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
33 .Case("round.towardzero", RoundingMode::TowardZero)
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
34 .Default(std::nullopt);
150
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
37 std::optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
38 std::optional<StringRef> RoundingStr;
150
anatofuz
parents:
diff changeset
39 switch (UseRounding) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
40 case RoundingMode::Dynamic:
150
anatofuz
parents:
diff changeset
41 RoundingStr = "round.dynamic";
anatofuz
parents:
diff changeset
42 break;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
43 case RoundingMode::NearestTiesToEven:
150
anatofuz
parents:
diff changeset
44 RoundingStr = "round.tonearest";
anatofuz
parents:
diff changeset
45 break;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
46 case RoundingMode::NearestTiesToAway:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
47 RoundingStr = "round.tonearestaway";
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
48 break;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
49 case RoundingMode::TowardNegative:
150
anatofuz
parents:
diff changeset
50 RoundingStr = "round.downward";
anatofuz
parents:
diff changeset
51 break;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
52 case RoundingMode::TowardPositive:
150
anatofuz
parents:
diff changeset
53 RoundingStr = "round.upward";
anatofuz
parents:
diff changeset
54 break;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
55 case RoundingMode::TowardZero:
150
anatofuz
parents:
diff changeset
56 RoundingStr = "round.towardzero";
anatofuz
parents:
diff changeset
57 break;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
58 default:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
59 break;
150
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61 return RoundingStr;
anatofuz
parents:
diff changeset
62 }
anatofuz
parents:
diff changeset
63
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
64 std::optional<fp::ExceptionBehavior>
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
65 convertStrToExceptionBehavior(StringRef ExceptionArg) {
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
66 return StringSwitch<std::optional<fp::ExceptionBehavior>>(ExceptionArg)
150
anatofuz
parents:
diff changeset
67 .Case("fpexcept.ignore", fp::ebIgnore)
anatofuz
parents:
diff changeset
68 .Case("fpexcept.maytrap", fp::ebMayTrap)
anatofuz
parents:
diff changeset
69 .Case("fpexcept.strict", fp::ebStrict)
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
70 .Default(std::nullopt);
150
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
73 std::optional<StringRef>
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
74 convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
75 std::optional<StringRef> ExceptStr;
150
anatofuz
parents:
diff changeset
76 switch (UseExcept) {
anatofuz
parents:
diff changeset
77 case fp::ebStrict:
anatofuz
parents:
diff changeset
78 ExceptStr = "fpexcept.strict";
anatofuz
parents:
diff changeset
79 break;
anatofuz
parents:
diff changeset
80 case fp::ebIgnore:
anatofuz
parents:
diff changeset
81 ExceptStr = "fpexcept.ignore";
anatofuz
parents:
diff changeset
82 break;
anatofuz
parents:
diff changeset
83 case fp::ebMayTrap:
anatofuz
parents:
diff changeset
84 ExceptStr = "fpexcept.maytrap";
anatofuz
parents:
diff changeset
85 break;
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87 return ExceptStr;
anatofuz
parents:
diff changeset
88 }
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
89
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
90 Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
91 Intrinsic::ID IID = Intrinsic::not_intrinsic;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
92 switch (Instr.getOpcode()) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
93 case Instruction::FCmp:
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
94 // Unlike other instructions FCmp can be mapped to one of two intrinsic
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
95 // functions. We choose the non-signaling variant.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
96 IID = Intrinsic::experimental_constrained_fcmp;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
97 break;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
98
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
99 // Instructions
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
100 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
101 case Instruction::NAME: \
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
102 IID = Intrinsic::INTRINSIC; \
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
103 break;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
104 #define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
105 #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
106 #include "llvm/IR/ConstrainedOps.def"
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
107
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
108 // Intrinsic calls.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
109 case Instruction::Call:
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
110 if (auto *IntrinCall = dyn_cast<IntrinsicInst>(&Instr)) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
111 switch (IntrinCall->getIntrinsicID()) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
112 #define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
113 case Intrinsic::NAME: \
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
114 IID = Intrinsic::INTRINSIC; \
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
115 break;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
116 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
117 #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
118 #include "llvm/IR/ConstrainedOps.def"
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
119 default:
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
120 break;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
121 }
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
122 }
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
123 break;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
124 default:
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
125 break;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
126 }
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
127
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
128 return IID;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
129 }
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
130
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
131 } // namespace llvm