| 1 | //===- OpenACC.cpp - C Interface for OpenACC dialect ----------------------===// |
|---|---|
| 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 | #include "mlir-c/Dialect/OpenACC.h" |
| 10 | #include "mlir/CAPI/Registration.h" |
| 11 | #include "mlir/Dialect/GPU/IR/GPUDialect.h" |
| 12 | #include "mlir/Dialect/OpenACC/Extensions/AllExtensions.h" |
| 13 | #include "mlir/Dialect/OpenACC/OpenACC.h" |
| 14 | |
| 15 | using namespace mlir; |
| 16 | using namespace mlir::acc; |
| 17 | |
| 18 | namespace { |
| 19 | // Keep the C API's complete registration behavior. Frontends that only need |
| 20 | // OpenACC IR can link MLIROpenACCDialect directly instead. |
| 21 | void registerOpenACC(DialectRegistry ®istry) { |
| 22 | registry.insert<OpenACCDialect, gpu::GPUDialect>(); |
| 23 | acc::registerAllExtensions(registry); |
| 24 | registry.addExtension(extensionFn: +[](MLIRContext *context, OpenACCDialect *) { |
| 25 | context->getOrLoadDialect<gpu::GPUDialect>(); |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | void insertOpenACC(MlirDialectRegistry registry) { |
| 30 | registerOpenACC(registry&: *unwrap(c: registry)); |
| 31 | } |
| 32 | |
| 33 | MlirDialect loadOpenACC(MlirContext context) { |
| 34 | DialectRegistry registry; |
| 35 | registerOpenACC(registry); |
| 36 | unwrap(c: context)->appendDialectRegistry(registry); |
| 37 | return wrap(cpp: unwrap(c: context)->getOrLoadDialect<OpenACCDialect>()); |
| 38 | } |
| 39 | |
| 40 | MlirStringRef getNamespace() { |
| 41 | return wrap(ref: OpenACCDialect::getDialectNamespace()); |
| 42 | } |
| 43 | } // namespace |
| 44 | |
| 45 | MlirDialectHandle mlirGetDialectHandle__acc__() { |
| 46 | static MlirDialectRegistrationHooks hooks = {.insertHook: insertOpenACC, .loadHook: loadOpenACC, |
| 47 | .getNamespaceHook: getNamespace}; |
| 48 | return MlirDialectHandle{.ptr: &hooks}; |
| 49 | } |
| 50 |