MLIR  20.0.0git
Registration.h
Go to the documentation of this file.
1 //===- Registration.h - C API Registration implementation ------*- 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 #ifndef MLIR_CAPI_REGISTRATION_H
10 #define MLIR_CAPI_REGISTRATION_H
11 
12 #include "mlir-c/IR.h"
13 #include "mlir/CAPI/IR.h"
14 #include "mlir/CAPI/Support.h"
15 
16 //===----------------------------------------------------------------------===//
17 // Corrolary to MLIR_DECLARE_CAPI_DIALECT_REGISTRATION that defines an impl.
18 // Takes the same name passed to the above and the fully qualified class name
19 // of the dialect class.
20 //===----------------------------------------------------------------------===//
21 
22 /// Hooks for dynamic discovery of dialects.
24  MlirDialectRegistry registry);
25 typedef MlirDialect (*MlirContextLoadDialectHook)(MlirContext context);
27 
28 /// Structure of dialect registration hooks.
33 };
35 
36 #define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName) \
37  static void mlirDialectRegistryInsert##Name##Dialect( \
38  MlirDialectRegistry registry) { \
39  unwrap(registry)->insert<ClassName>(); \
40  } \
41  static MlirDialect mlirContextLoad##Name##Dialect(MlirContext context) { \
42  return wrap(unwrap(context)->getOrLoadDialect<ClassName>()); \
43  } \
44  static MlirStringRef mlir##Name##DialectGetNamespace() { \
45  return wrap(ClassName::getDialectNamespace()); \
46  } \
47  MlirDialectHandle mlirGetDialectHandle__##Namespace##__() { \
48  static MlirDialectRegistrationHooks hooks = { \
49  mlirDialectRegistryInsert##Name##Dialect, \
50  mlirContextLoad##Name##Dialect, mlir##Name##DialectGetNamespace}; \
51  return MlirDialectHandle{&hooks}; \
52  }
53 
54 #endif // MLIR_CAPI_REGISTRATION_H
MlirStringRef(* MlirDialectGetNamespaceHook)()
Definition: Registration.h:26
MlirDialect(* MlirContextLoadDialectHook)(MlirContext context)
Definition: Registration.h:25
void(* MlirDialectRegistryInsertDialectHook)(MlirDialectRegistry registry)
Hooks for dynamic discovery of dialects.
Definition: Registration.h:23
struct MlirStringRef MlirStringRef
Definition: Support.h:77
Structure of dialect registration hooks.
Definition: Registration.h:29
MlirDialectGetNamespaceHook getNamespaceHook
Definition: Registration.h:32
MlirContextLoadDialectHook loadHook
Definition: Registration.h:31
MlirDialectRegistryInsertDialectHook insertHook
Definition: Registration.h:30