1//===- transform.c - Test of Transform dialect C API ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10// RUN: mlir-capi-transform-test 2>&1 | FileCheck %s
11
12#include "mlir-c/Dialect/Transform.h"
13#include "mlir-c/IR.h"
14#include "mlir-c/Support.h"
15
16#include <assert.h>
17#include <stdio.h>
18#include <stdlib.h>
19
20// CHECK-LABEL: testAnyOpType
21void testAnyOpType(MlirContext ctx) {
22 fprintf(stderr, format: "testAnyOpType\n");
23
24 MlirType parsedType = mlirTypeParseGet(
25 context: ctx, type: mlirStringRefCreateFromCString(str: "!transform.any_op"));
26 MlirType constructedType = mlirTransformAnyOpTypeGet(ctx);
27
28 assert(!mlirTypeIsNull(parsedType) && "couldn't parse AnyOpType");
29 assert(!mlirTypeIsNull(constructedType) && "couldn't construct AnyOpType");
30
31 // CHECK: equal: 1
32 fprintf(stderr, format: "equal: %d\n", mlirTypeEqual(t1: parsedType, t2: constructedType));
33
34 // CHECK: parsedType isa AnyOpType: 1
35 fprintf(stderr, format: "parsedType isa AnyOpType: %d\n",
36 mlirTypeIsATransformAnyOpType(type: parsedType));
37 // CHECK: parsedType isa OperationType: 0
38 fprintf(stderr, format: "parsedType isa OperationType: %d\n",
39 mlirTypeIsATransformOperationType(type: parsedType));
40
41 // CHECK: !transform.any_op
42 mlirTypeDump(type: constructedType);
43
44 fprintf(stderr, format: "\n\n");
45}
46
47// CHECK-LABEL: testOperationType
48void testOperationType(MlirContext ctx) {
49 fprintf(stderr, format: "testOperationType\n");
50
51 MlirType parsedType = mlirTypeParseGet(
52 context: ctx, type: mlirStringRefCreateFromCString(str: "!transform.op<\"foo.bar\">"));
53 MlirType constructedType = mlirTransformOperationTypeGet(
54 ctx, operationName: mlirStringRefCreateFromCString(str: "foo.bar"));
55
56 assert(!mlirTypeIsNull(parsedType) && "couldn't parse AnyOpType");
57 assert(!mlirTypeIsNull(constructedType) && "couldn't construct AnyOpType");
58
59 // CHECK: equal: 1
60 fprintf(stderr, format: "equal: %d\n", mlirTypeEqual(t1: parsedType, t2: constructedType));
61
62 // CHECK: parsedType isa AnyOpType: 0
63 fprintf(stderr, format: "parsedType isa AnyOpType: %d\n",
64 mlirTypeIsATransformAnyOpType(type: parsedType));
65 // CHECK: parsedType isa OperationType: 1
66 fprintf(stderr, format: "parsedType isa OperationType: %d\n",
67 mlirTypeIsATransformOperationType(type: parsedType));
68
69 // CHECK: operation name equal: 1
70 MlirStringRef operationName =
71 mlirTransformOperationTypeGetOperationName(type: constructedType);
72 fprintf(stderr, format: "operation name equal: %d\n",
73 mlirStringRefEqual(string: operationName,
74 other: mlirStringRefCreateFromCString(str: "foo.bar")));
75
76 // CHECK: !transform.op<"foo.bar">
77 mlirTypeDump(type: constructedType);
78
79 fprintf(stderr, format: "\n\n");
80}
81
82int main(void) {
83 MlirContext ctx = mlirContextCreate();
84 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__transform__(), ctx);
85 testAnyOpType(ctx);
86 testOperationType(ctx);
87 mlirContextDestroy(context: ctx);
88 return EXIT_SUCCESS;
89}
90

source code of mlir/test/CAPI/transform.c