diff --git a/mlir/include/mlir/Support/StorageUniquer.h b/mlir/include/mlir/Support/StorageUniquer.h --- a/mlir/include/mlir/Support/StorageUniquer.h +++ b/mlir/include/mlir/Support/StorageUniquer.h @@ -294,45 +294,32 @@ //===--------------------------------------------------------------------===// /// Used to construct an instance of 'ImplTy::KeyTy' if there is an - /// 'ImplTy::getKey' function for the provided arguments. + /// 'ImplTy::getKey' function for the provided arguments. Otherwise, then we + /// try to directly construct the 'ImplTy::KeyTy' with the provided arguments. template - static std::enable_if_t< - llvm::is_detected::value, - typename ImplTy::KeyTy> - getKey(Args &&...args) { - return ImplTy::getKey(args...); - } - /// If there is no 'ImplTy::getKey' method, then we try to directly construct - /// the 'ImplTy::KeyTy' with the provided arguments. - template - static std::enable_if_t< - !llvm::is_detected::value, - typename ImplTy::KeyTy> - getKey(Args &&...args) { - return typename ImplTy::KeyTy(args...); + static typename ImplTy::KeyTy getKey(Args &&...args) { + if constexpr (llvm::is_detected::value) + return ImplTy::getKey(args...); + else + return typename ImplTy::KeyTy(args...); } //===--------------------------------------------------------------------===// // Key Hashing //===--------------------------------------------------------------------===// - /// Used to generate a hash for the 'ImplTy::KeyTy' of a storage instance if - /// there is an 'ImplTy::hashKey' overload for 'DerivedKey'. - template - static std::enable_if_t< - llvm::is_detected::value, - ::llvm::hash_code> - getHash(const DerivedKey &derivedKey) { - return ImplTy::hashKey(derivedKey); - } - /// If there is no 'ImplTy::hashKey' default to using the 'llvm::DenseMapInfo' - /// definition for 'DerivedKey' for generating a hash. + /// Used to generate a hash for the `ImplTy` of a storage instance if + /// there is a `ImplTy::hashKey. Otherwise, if there is no `ImplTy::hashKey` + /// then default to using the 'llvm::DenseMapInfo' definition for + /// 'DerivedKey' for generating a hash. template - static std::enable_if_t::value, - ::llvm::hash_code> - getHash(const DerivedKey &derivedKey) { - return DenseMapInfo::getHashValue(derivedKey); + static ::llvm::hash_code getHash(const DerivedKey &derivedKey) { + if constexpr (llvm::is_detected::value) + return ImplTy::hashKey(derivedKey); + else + return DenseMapInfo::getHashValue(derivedKey); } }; } // namespace mlir