1a8a2ee63SDenys Shabalin //===- PDL.cpp - C Interface for PDL dialect ------------------------------===//
2a8a2ee63SDenys Shabalin //
3a8a2ee63SDenys Shabalin // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4a8a2ee63SDenys Shabalin // See https://llvm.org/LICENSE.txt for license information.
5a8a2ee63SDenys Shabalin // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a8a2ee63SDenys Shabalin //
7a8a2ee63SDenys Shabalin //===----------------------------------------------------------------------===//
8a8a2ee63SDenys Shabalin 
9a8a2ee63SDenys Shabalin #include "mlir-c/Dialect/PDL.h"
10a8a2ee63SDenys Shabalin #include "mlir/CAPI/Registration.h"
11a8a2ee63SDenys Shabalin #include "mlir/Dialect/PDL/IR/PDL.h"
12a8a2ee63SDenys Shabalin #include "mlir/Dialect/PDL/IR/PDLOps.h"
13a8a2ee63SDenys Shabalin #include "mlir/Dialect/PDL/IR/PDLTypes.h"
14a8a2ee63SDenys Shabalin 
15a8a2ee63SDenys Shabalin using namespace mlir;
16a8a2ee63SDenys Shabalin 
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PDL,pdl,pdl::PDLDialect)17a8a2ee63SDenys Shabalin MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PDL, pdl, pdl::PDLDialect)
18a8a2ee63SDenys Shabalin 
19a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
20a8a2ee63SDenys Shabalin // PDLType
21a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
22a8a2ee63SDenys Shabalin 
23a8a2ee63SDenys Shabalin bool mlirTypeIsAPDLType(MlirType type) {
24a8a2ee63SDenys Shabalin   return unwrap(type).isa<pdl::PDLType>();
25a8a2ee63SDenys Shabalin }
26a8a2ee63SDenys Shabalin 
27a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
28a8a2ee63SDenys Shabalin // AttributeType
29a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
30a8a2ee63SDenys Shabalin 
mlirTypeIsAPDLAttributeType(MlirType type)31a8a2ee63SDenys Shabalin bool mlirTypeIsAPDLAttributeType(MlirType type) {
32a8a2ee63SDenys Shabalin   return unwrap(type).isa<pdl::AttributeType>();
33a8a2ee63SDenys Shabalin }
34a8a2ee63SDenys Shabalin 
mlirPDLAttributeTypeGet(MlirContext ctx)35a8a2ee63SDenys Shabalin MlirType mlirPDLAttributeTypeGet(MlirContext ctx) {
36a8a2ee63SDenys Shabalin   return wrap(pdl::AttributeType::get(unwrap(ctx)));
37a8a2ee63SDenys Shabalin }
38a8a2ee63SDenys Shabalin 
39a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
40a8a2ee63SDenys Shabalin // OperationType
41a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
42a8a2ee63SDenys Shabalin 
mlirTypeIsAPDLOperationType(MlirType type)43a8a2ee63SDenys Shabalin bool mlirTypeIsAPDLOperationType(MlirType type) {
44a8a2ee63SDenys Shabalin   return unwrap(type).isa<pdl::OperationType>();
45a8a2ee63SDenys Shabalin }
46a8a2ee63SDenys Shabalin 
mlirPDLOperationTypeGet(MlirContext ctx)47a8a2ee63SDenys Shabalin MlirType mlirPDLOperationTypeGet(MlirContext ctx) {
48a8a2ee63SDenys Shabalin   return wrap(pdl::OperationType::get(unwrap(ctx)));
49a8a2ee63SDenys Shabalin }
50a8a2ee63SDenys Shabalin 
51a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
52a8a2ee63SDenys Shabalin // RangeType
53a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
54a8a2ee63SDenys Shabalin 
mlirTypeIsAPDLRangeType(MlirType type)55a8a2ee63SDenys Shabalin bool mlirTypeIsAPDLRangeType(MlirType type) {
56a8a2ee63SDenys Shabalin   return unwrap(type).isa<pdl::RangeType>();
57a8a2ee63SDenys Shabalin }
58a8a2ee63SDenys Shabalin 
mlirPDLRangeTypeGet(MlirType elementType)59a8a2ee63SDenys Shabalin MlirType mlirPDLRangeTypeGet(MlirType elementType) {
60a8a2ee63SDenys Shabalin   return wrap(pdl::RangeType::get(unwrap(elementType)));
61a8a2ee63SDenys Shabalin }
62a8a2ee63SDenys Shabalin 
mlirPDLRangeTypeGetElementType(MlirType type)63*ed21c927SDenys Shabalin MlirType mlirPDLRangeTypeGetElementType(MlirType type) {
64*ed21c927SDenys Shabalin   return wrap(unwrap(type).cast<pdl::RangeType>().getElementType());
65*ed21c927SDenys Shabalin }
66*ed21c927SDenys Shabalin 
67a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
68a8a2ee63SDenys Shabalin // TypeType
69a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
70a8a2ee63SDenys Shabalin 
mlirTypeIsAPDLTypeType(MlirType type)71a8a2ee63SDenys Shabalin bool mlirTypeIsAPDLTypeType(MlirType type) {
72a8a2ee63SDenys Shabalin   return unwrap(type).isa<pdl::TypeType>();
73a8a2ee63SDenys Shabalin }
74a8a2ee63SDenys Shabalin 
mlirPDLTypeTypeGet(MlirContext ctx)75a8a2ee63SDenys Shabalin MlirType mlirPDLTypeTypeGet(MlirContext ctx) {
76a8a2ee63SDenys Shabalin   return wrap(pdl::TypeType::get(unwrap(ctx)));
77a8a2ee63SDenys Shabalin }
78a8a2ee63SDenys Shabalin 
79a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
80a8a2ee63SDenys Shabalin // ValueType
81a8a2ee63SDenys Shabalin //===---------------------------------------------------------------------===//
82a8a2ee63SDenys Shabalin 
mlirTypeIsAPDLValueType(MlirType type)83a8a2ee63SDenys Shabalin bool mlirTypeIsAPDLValueType(MlirType type) {
84a8a2ee63SDenys Shabalin   return unwrap(type).isa<pdl::ValueType>();
85a8a2ee63SDenys Shabalin }
86a8a2ee63SDenys Shabalin 
mlirPDLValueTypeGet(MlirContext ctx)87a8a2ee63SDenys Shabalin MlirType mlirPDLValueTypeGet(MlirContext ctx) {
88a8a2ee63SDenys Shabalin   return wrap(pdl::ValueType::get(unwrap(ctx)));
89a8a2ee63SDenys Shabalin }
90