MLIR  20.0.0git
Registry.h
Go to the documentation of this file.
1 //===--- Registry.h - Matcher Registry --------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Registry class to manage the registry of matchers using a map.
10 //
11 // This class provides a convenient interface for registering and accessing
12 // matcher constructors using a string-based map.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRY_H
17 #define MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRY_H
18 
19 #include "Marshallers.h"
20 #include "llvm/ADT/StringMap.h"
21 #include <string>
22 
23 namespace mlir::query::matcher {
24 
26  llvm::StringMap<std::unique_ptr<const internal::MatcherDescriptor>>;
27 
28 class Registry {
29 public:
30  Registry() = default;
31  ~Registry() = default;
32 
33  const ConstructorMap &constructors() const { return constructorMap; }
34 
35  template <typename MatcherType>
36  void registerMatcher(const std::string &name, MatcherType matcher) {
37  registerMatcherDescriptor(name,
38  internal::makeMatcherAutoMarshall(matcher, name));
39  }
40 
41 private:
42  void registerMatcherDescriptor(
43  llvm::StringRef matcherName,
44  std::unique_ptr<internal::MatcherDescriptor> callback);
45 
46  ConstructorMap constructorMap;
47 };
48 
49 } // namespace mlir::query::matcher
50 
51 #endif // MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRY_H
void registerMatcher(const std::string &name, MatcherType matcher)
Definition: Registry.h:36
const ConstructorMap & constructors() const
Definition: Registry.h:33
std::unique_ptr< MatcherDescriptor > makeMatcherAutoMarshall(ReturnType(*matcherFunc)(ArgTypes...), llvm::StringRef matcherName)
Definition: Marshallers.h:188
llvm::StringMap< std::unique_ptr< const internal::MatcherDescriptor > > ConstructorMap
Definition: Registry.h:26