[llvm] [LLVM] Change Intrinsic::ID to encode target and intrinsic index (PR #113576)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 16:12:47 PDT 2024


================
@@ -33,8 +33,54 @@
 #include "llvm/IR/IntrinsicsXCore.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/Support/IntrinsicID.h"
 
 using namespace llvm;
+using namespace Intrinsic;
+
+/// Table of per-target intrinsic name tables.
+#define GET_INTRINSIC_TARGET_DATA
+#include "llvm/IR/IntrinsicImpl.inc"
+#undef GET_INTRINSIC_TARGET_DATA
+size_t constexpr NumTargets = sizeof(TargetInfos) / sizeof(TargetInfos[0]);
+
+// Returns true if the given intrinsic ID is valid, that is, its value is one
+// of the enum values defined for this intrinsic (including not_intrinsic).
+bool Intrinsic::IsIntrinsicIDValid(ID ID) {
+  if (ID == Intrinsic::not_intrinsic)
+    return true;
+  auto Decoded = DecodeIntrinsicIDNoFail(ID);
+  if (!Decoded)
+    return false;
----------------
jurahul wrote:

Yeah, so in some cases we really just want to return 0 or false if decoding failed, and in other cases we want to assert of fail in different ways, so the nofail variant just reports failure without an assert. Maybe we just have one version that return std::optional and if it has failed, dereferencing the std::optional will fail in cases where `decodeIntrinsicID` is used? So we don't have 2 variants

https://github.com/llvm/llvm-project/pull/113576


More information about the llvm-commits mailing list