diff 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
line wrap: on
line diff
--- a/llvm/lib/IR/FPEnv.cpp	Wed Jul 21 10:27:27 2021 +0900
+++ b/llvm/lib/IR/FPEnv.cpp	Wed Nov 09 17:45:10 2022 +0900
@@ -14,10 +14,13 @@
 
 #include "llvm/IR/FPEnv.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Intrinsics.h"
 
 namespace llvm {
 
-Optional<RoundingMode> StrToRoundingMode(StringRef RoundingArg) {
+Optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) {
   // For dynamic rounding mode, we use round to nearest but we will set the
   // 'exact' SDNodeFlag so that the value will not be rounded.
   return StringSwitch<Optional<RoundingMode>>(RoundingArg)
@@ -30,8 +33,8 @@
       .Default(None);
 }
 
-Optional<StringRef> RoundingModeToStr(RoundingMode UseRounding) {
-  Optional<StringRef> RoundingStr = None;
+Optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
+  Optional<StringRef> RoundingStr;
   switch (UseRounding) {
   case RoundingMode::Dynamic:
     RoundingStr = "round.dynamic";
@@ -57,7 +60,8 @@
   return RoundingStr;
 }
 
-Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) {
+Optional<fp::ExceptionBehavior>
+convertStrToExceptionBehavior(StringRef ExceptionArg) {
   return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg)
       .Case("fpexcept.ignore", fp::ebIgnore)
       .Case("fpexcept.maytrap", fp::ebMayTrap)
@@ -65,8 +69,9 @@
       .Default(None);
 }
 
-Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
-  Optional<StringRef> ExceptStr = None;
+Optional<StringRef>
+convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
+  Optional<StringRef> ExceptStr;
   switch (UseExcept) {
   case fp::ebStrict:
     ExceptStr = "fpexcept.strict";
@@ -80,4 +85,46 @@
   }
   return ExceptStr;
 }
+
+Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr) {
+  Intrinsic::ID IID = Intrinsic::not_intrinsic;
+  switch (Instr.getOpcode()) {
+  case Instruction::FCmp:
+    // Unlike other instructions FCmp can be mapped to one of two intrinsic
+    // functions. We choose the non-signaling variant.
+    IID = Intrinsic::experimental_constrained_fcmp;
+    break;
+
+    // Instructions
+#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)                         \
+  case Instruction::NAME:                                                      \
+    IID = Intrinsic::INTRINSIC;                                                \
+    break;
+#define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
+#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
+#include "llvm/IR/ConstrainedOps.def"
+
+  // Intrinsic calls.
+  case Instruction::Call:
+    if (auto *IntrinCall = dyn_cast<IntrinsicInst>(&Instr)) {
+      switch (IntrinCall->getIntrinsicID()) {
+#define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC)                            \
+  case Intrinsic::NAME:                                                        \
+    IID = Intrinsic::INTRINSIC;                                                \
+    break;
+#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
+#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)
+#include "llvm/IR/ConstrainedOps.def"
+      default:
+        break;
+      }
+    }
+    break;
+  default:
+    break;
+  }
+
+  return IID;
+}
+
 } // namespace llvm