comparison llvm/lib/IR/FPEnv.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "llvm/IR/FPEnv.h" 15 #include "llvm/IR/FPEnv.h"
16 #include "llvm/ADT/StringSwitch.h" 16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/IR/Instruction.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Intrinsics.h"
17 20
18 namespace llvm { 21 namespace llvm {
19 22
20 Optional<RoundingMode> StrToRoundingMode(StringRef RoundingArg) { 23 Optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) {
21 // For dynamic rounding mode, we use round to nearest but we will set the 24 // 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. 25 // 'exact' SDNodeFlag so that the value will not be rounded.
23 return StringSwitch<Optional<RoundingMode>>(RoundingArg) 26 return StringSwitch<Optional<RoundingMode>>(RoundingArg)
24 .Case("round.dynamic", RoundingMode::Dynamic) 27 .Case("round.dynamic", RoundingMode::Dynamic)
25 .Case("round.tonearest", RoundingMode::NearestTiesToEven) 28 .Case("round.tonearest", RoundingMode::NearestTiesToEven)
28 .Case("round.upward", RoundingMode::TowardPositive) 31 .Case("round.upward", RoundingMode::TowardPositive)
29 .Case("round.towardzero", RoundingMode::TowardZero) 32 .Case("round.towardzero", RoundingMode::TowardZero)
30 .Default(None); 33 .Default(None);
31 } 34 }
32 35
33 Optional<StringRef> RoundingModeToStr(RoundingMode UseRounding) { 36 Optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
34 Optional<StringRef> RoundingStr = None; 37 Optional<StringRef> RoundingStr;
35 switch (UseRounding) { 38 switch (UseRounding) {
36 case RoundingMode::Dynamic: 39 case RoundingMode::Dynamic:
37 RoundingStr = "round.dynamic"; 40 RoundingStr = "round.dynamic";
38 break; 41 break;
39 case RoundingMode::NearestTiesToEven: 42 case RoundingMode::NearestTiesToEven:
55 break; 58 break;
56 } 59 }
57 return RoundingStr; 60 return RoundingStr;
58 } 61 }
59 62
60 Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) { 63 Optional<fp::ExceptionBehavior>
64 convertStrToExceptionBehavior(StringRef ExceptionArg) {
61 return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg) 65 return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg)
62 .Case("fpexcept.ignore", fp::ebIgnore) 66 .Case("fpexcept.ignore", fp::ebIgnore)
63 .Case("fpexcept.maytrap", fp::ebMayTrap) 67 .Case("fpexcept.maytrap", fp::ebMayTrap)
64 .Case("fpexcept.strict", fp::ebStrict) 68 .Case("fpexcept.strict", fp::ebStrict)
65 .Default(None); 69 .Default(None);
66 } 70 }
67 71
68 Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) { 72 Optional<StringRef>
69 Optional<StringRef> ExceptStr = None; 73 convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
74 Optional<StringRef> ExceptStr;
70 switch (UseExcept) { 75 switch (UseExcept) {
71 case fp::ebStrict: 76 case fp::ebStrict:
72 ExceptStr = "fpexcept.strict"; 77 ExceptStr = "fpexcept.strict";
73 break; 78 break;
74 case fp::ebIgnore: 79 case fp::ebIgnore:
78 ExceptStr = "fpexcept.maytrap"; 83 ExceptStr = "fpexcept.maytrap";
79 break; 84 break;
80 } 85 }
81 return ExceptStr; 86 return ExceptStr;
82 } 87 }
88
89 Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr) {
90 Intrinsic::ID IID = Intrinsic::not_intrinsic;
91 switch (Instr.getOpcode()) {
92 case Instruction::FCmp:
93 // Unlike other instructions FCmp can be mapped to one of two intrinsic
94 // functions. We choose the non-signaling variant.
95 IID = Intrinsic::experimental_constrained_fcmp;
96 break;
97
98 // Instructions
99 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
100 case Instruction::NAME: \
101 IID = Intrinsic::INTRINSIC; \
102 break;
103 #define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
104 #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
105 #include "llvm/IR/ConstrainedOps.def"
106
107 // Intrinsic calls.
108 case Instruction::Call:
109 if (auto *IntrinCall = dyn_cast<IntrinsicInst>(&Instr)) {
110 switch (IntrinCall->getIntrinsicID()) {
111 #define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
112 case Intrinsic::NAME: \
113 IID = Intrinsic::INTRINSIC; \
114 break;
115 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
116 #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
117 #include "llvm/IR/ConstrainedOps.def"
118 default:
119 break;
120 }
121 }
122 break;
123 default:
124 break;
125 }
126
127 return IID;
128 }
129
83 } // namespace llvm 130 } // namespace llvm