llvm-project/mlir/lib/CAPI/IR/DialectHandle.cpp
Daniel Resnick 97fc568211 [mlir][capi] Add DialectRegistry to MLIR C-API
Exposes mlir::DialectRegistry to the C API as MlirDialectRegistry along with
helper functions. A hook has been added to MlirDialectHandle that inserts
the dialect into a registry.

A future possible change is removing mlirDialectHandleRegisterDialect in
favor of using mlirDialectHandleInsertDialect, which it is now implemented with.

Differential Revision: https://reviews.llvm.org/D118293
2022-02-01 13:42:06 -07:00

36 lines
1.3 KiB
C++

//===- DialectHandle.cpp - C Interface for MLIR Dialect Operations -------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/CAPI/Registration.h"
static inline const MlirDialectRegistrationHooks *
unwrap(MlirDialectHandle handle) {
return (const MlirDialectRegistrationHooks *)handle.ptr;
}
MlirStringRef mlirDialectHandleGetNamespace(MlirDialectHandle handle) {
return unwrap(handle)->getNamespaceHook();
}
void mlirDialectHandleInsertDialect(MlirDialectHandle handle,
MlirDialectRegistry registry) {
unwrap(handle)->insertHook(registry);
}
void mlirDialectHandleRegisterDialect(MlirDialectHandle handle,
MlirContext ctx) {
mlir::DialectRegistry registry;
mlirDialectHandleInsertDialect(handle, wrap(&registry));
unwrap(ctx)->appendDialectRegistry(registry);
}
MlirDialect mlirDialectHandleLoadDialect(MlirDialectHandle handle,
MlirContext ctx) {
return unwrap(handle)->loadHook(ctx);
}