From 8cbe371c28a30ca5b0775b095a754702e57aa7ea Mon Sep 17 00:00:00 2001 From: River Riddle Date: Tue, 14 Apr 2020 14:52:52 -0700 Subject: [PATCH] [llvm][STLExtras] Add various type_trait utilities currently present in MLIR This revision moves several type_trait utilities from MLIR into LLVM. Namely, this revision adds: is_detected - This matches the experimental std::is_detected is_invocable - This matches the c++17 std::is_invocable function_traits - A utility traits class for getting the argument and result types of a callable type Differential Revision: https://reviews.llvm.org/D78059 --- llvm/include/llvm/ADT/STLExtras.h | 73 +++++++++++++++++++++ llvm/unittests/ADT/CMakeLists.txt | 1 + llvm/unittests/ADT/TypeTraitsTest.cpp | 80 ++++++++++++++++++++++++ mlir/include/mlir/ADT/TypeSwitch.h | 20 +++--- mlir/include/mlir/IR/Matchers.h | 14 +++-- mlir/include/mlir/IR/OpDefinition.h | 8 +-- mlir/include/mlir/Pass/AnalysisManager.h | 4 +- mlir/include/mlir/Support/STLExtras.h | 72 --------------------- mlir/include/mlir/Support/StorageUniquer.h | 12 ++-- mlir/include/mlir/Transforms/DialectConversion.h | 12 ++-- mlir/lib/IR/SymbolTable.cpp | 8 +-- 11 files changed, 196 insertions(+), 108 deletions(-) create mode 100644 llvm/unittests/ADT/TypeTraitsTest.cpp diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 215bc5a..53457f0 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -75,6 +75,79 @@ template struct make_const_ref { typename std::add_const::type>::type; }; +/// Utilities for detecting if a given trait holds for some set of arguments +/// 'Args'. For example, the given trait could be used to detect if a given type +/// has a copy assignment operator: +/// template +/// using has_copy_assign_t = decltype(std::declval() +/// = std::declval()); +/// bool fooHasCopyAssign = is_detected::value; +namespace detail { +template using void_t = void; +template class Op, class... Args> struct detector { + using value_t = std::false_type; +}; +template