diff --git a/mlir/include/mlir-c/SCFDialect.h b/mlir/include/mlir-c/SCFDialect.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir-c/SCFDialect.h @@ -0,0 +1,42 @@ +//===-- mlir-c/SCFDialect.h - C API for SCF dialect -----*- C -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This header declares the C interface for registering and accessing the +// SCF dialect. A dialect should be registered with a context to make it +// available to users of the context. These users must load the dialect +// before using any of its attributes, operations or types. Parser and pass +// manager can load registered dialects automatically. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_C_SCFDIALECT_H +#define MLIR_C_SCFDIALECT_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Registers the SCF dialect with the given context. This allows the + * dialect to be loaded dynamically if needed when parsing. */ +MLIR_CAPI_EXPORTED void mlirContextRegisterSCFDialect(MlirContext context); + +/** Loads the SCF dialect into the given context. The dialect does _not_ + * have to be registered in advance. */ +MLIR_CAPI_EXPORTED MlirDialect mlirContextLoadSCFDialect(MlirContext context); + +/// Returns the namespace of the SCF dialect, suitable for loading it. +MLIR_CAPI_EXPORTED MlirStringRef mlirSCFDialectGetNamespace(); + +#ifdef __cplusplus +} +#endif + +#endif // MLIR_C_SCFDIALECT_H diff --git a/mlir/lib/CAPI/CMakeLists.txt b/mlir/lib/CAPI/CMakeLists.txt --- a/mlir/lib/CAPI/CMakeLists.txt +++ b/mlir/lib/CAPI/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(IR) add_subdirectory(Registration) +add_subdirectory(SCF) add_subdirectory(Standard) add_subdirectory(Transforms) diff --git a/mlir/lib/CAPI/SCF/CMakeLists.txt b/mlir/lib/CAPI/SCF/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/CAPI/SCF/CMakeLists.txt @@ -0,0 +1,7 @@ +add_mlir_public_c_api_library(MLIRCAPISCF + SCFDialect.cpp + + LINK_LIBS PUBLIC + MLIRCAPIIR + MLIRSCF +) diff --git a/mlir/lib/CAPI/SCF/SCFDialect.cpp b/mlir/lib/CAPI/SCF/SCFDialect.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/CAPI/SCF/SCFDialect.cpp @@ -0,0 +1,25 @@ +//===- SCFDialect.cpp - C Interface for SCF dialect -------------===// +// +// 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-c/SCFDialect.h" +#include "mlir-c/IR.h" +#include "mlir/CAPI/IR.h" +#include "mlir/CAPI/Support.h" +#include "mlir/Dialect/SCF/SCF.h" + +void mlirContextRegisterSCFDialect(MlirContext context) { + unwrap(context)->getDialectRegistry().insert(); +} + +MlirDialect mlirContextLoadSCFDialect(MlirContext context) { + return wrap(unwrap(context)->getOrLoadDialect()); +} + +MlirStringRef mlirSCFDialectGetNamespace() { + return wrap(mlir::scf::SCFDialect::getDialectNamespace()); +}