llvm-project/mlir/lib/CAPI/IR/DialectHandle.cpp
George 5099a48a3b [MLIR] Replace dialect registration hooks with dialect handle
Replace MlirDialectRegistrationHooks with MlirDialectHandle, which under-the-hood is an opaque pointer to MlirDialectRegistrationHooks. Then we expose the functionality previously directly on MlirDialectRegistrationHooks, as functions which take the opaque MlirDialectHandle struct. This makes the actual structure of the registration hooks an implementation detail, and happens to avoid this issue: https://llvm.discourse.group/t/strange-swift-issues-with-dialect-registration-hooks/2759/3

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D96229
2021-02-09 09:02:16 -08:00

29 lines
1004 B
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 mlirDialectHandleRegisterDialect(MlirDialectHandle handle,
MlirContext ctx) {
unwrap(handle)->registerHook(ctx);
}
MlirDialect mlirDialectHandleLoadDialect(MlirDialectHandle handle,
MlirContext ctx) {
return unwrap(handle)->loadHook(ctx);
}