[llvm] 3eab094 - [CodeGen] Use llvm::is_detected (NFC) (#137561)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 17:51:57 PDT 2025


Author: Kazu Hirata
Date: 2025-04-27T17:51:54-07:00
New Revision: 3eab094c457c03539854398b47f3f20d85323f5c

URL: https://github.com/llvm/llvm-project/commit/3eab094c457c03539854398b47f3f20d85323f5c
DIFF: https://github.com/llvm/llvm-project/commit/3eab094c457c03539854398b47f3f20d85323f5c.diff

LOG: [CodeGen] Use llvm::is_detected (NFC) (#137561)

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/ByteProvider.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/ByteProvider.h b/llvm/include/llvm/CodeGen/ByteProvider.h
index b97ff5c1aa039..c00335a216458 100644
--- a/llvm/include/llvm/CodeGen/ByteProvider.h
+++ b/llvm/include/llvm/CodeGen/ByteProvider.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CODEGEN_BYTEPROVIDER_H
 #define LLVM_CODEGEN_BYTEPROVIDER_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/DataTypes.h"
 #include <optional>
 #include <type_traits>
@@ -35,22 +36,14 @@ template <typename ISelOp> class ByteProvider {
 
   // TODO -- use constraint in c++20
   // Does this type correspond with an operation in selection DAG
-  template <typename T> class is_op {
-  private:
-    using yes = std::true_type;
-    using no = std::false_type;
+  // Only allow classes with member function getOpcode
+  template <typename U>
+  using check_has_getOpcode =
+      decltype(std::declval<std::remove_pointer_t<U> &>().getOpcode());
 
-    // Only allow classes with member function getOpcode
-    template <typename U>
-    static auto test(int) -> decltype(std::declval<U>().getOpcode(), yes());
-
-    template <typename> static no test(...);
-
-  public:
-    using remove_pointer_t = typename std::remove_pointer<T>::type;
-    static constexpr bool value =
-        std::is_same<decltype(test<remove_pointer_t>(0)), yes>::value;
-  };
+  template <typename U>
+  static constexpr bool has_getOpcode =
+      is_detected<check_has_getOpcode, U>::value;
 
 public:
   // For constant zero providers Src is set to nullopt. For actual providers
@@ -66,7 +59,7 @@ template <typename ISelOp> class ByteProvider {
 
   static ByteProvider getSrc(std::optional<ISelOp> Val, int64_t ByteOffset,
                              int64_t VectorOffset) {
-    static_assert(is_op<ISelOp>().value,
+    static_assert(has_getOpcode<ISelOp>,
                   "ByteProviders must contain an operation in selection DAG.");
     return ByteProvider(Val, ByteOffset, VectorOffset);
   }


        


More information about the llvm-commits mailing list