1 //===- transform.c - Test of Transform dialect C API ----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // RUN: mlir-capi-transform-test 2>&1 | FileCheck %s
12 #include "mlir-c/Dialect/Transform.h"
13 #include "mlir-c/IR.h"
14 #include "mlir-c/Support.h"
20 // CHECK-LABEL: testAnyOpType
21 void testAnyOpType(MlirContext ctx
) {
22 fprintf(stderr
, "testAnyOpType\n");
24 MlirType parsedType
= mlirTypeParseGet(
25 ctx
, mlirStringRefCreateFromCString("!transform.any_op"));
26 MlirType constructedType
= mlirTransformAnyOpTypeGet(ctx
);
28 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse AnyOpType");
29 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct AnyOpType");
32 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
34 // CHECK: parsedType isa AnyOpType: 1
35 fprintf(stderr
, "parsedType isa AnyOpType: %d\n",
36 mlirTypeIsATransformAnyOpType(parsedType
));
37 // CHECK: parsedType isa OperationType: 0
38 fprintf(stderr
, "parsedType isa OperationType: %d\n",
39 mlirTypeIsATransformOperationType(parsedType
));
41 // CHECK: !transform.any_op
42 mlirTypeDump(constructedType
);
44 fprintf(stderr
, "\n\n");
47 // CHECK-LABEL: testOperationType
48 void testOperationType(MlirContext ctx
) {
49 fprintf(stderr
, "testOperationType\n");
51 MlirType parsedType
= mlirTypeParseGet(
52 ctx
, mlirStringRefCreateFromCString("!transform.op<\"foo.bar\">"));
53 MlirType constructedType
= mlirTransformOperationTypeGet(
54 ctx
, mlirStringRefCreateFromCString("foo.bar"));
56 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse AnyOpType");
57 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct AnyOpType");
60 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
62 // CHECK: parsedType isa AnyOpType: 0
63 fprintf(stderr
, "parsedType isa AnyOpType: %d\n",
64 mlirTypeIsATransformAnyOpType(parsedType
));
65 // CHECK: parsedType isa OperationType: 1
66 fprintf(stderr
, "parsedType isa OperationType: %d\n",
67 mlirTypeIsATransformOperationType(parsedType
));
69 // CHECK: operation name equal: 1
70 MlirStringRef operationName
=
71 mlirTransformOperationTypeGetOperationName(constructedType
);
72 fprintf(stderr
, "operation name equal: %d\n",
73 mlirStringRefEqual(operationName
,
74 mlirStringRefCreateFromCString("foo.bar")));
76 // CHECK: !transform.op<"foo.bar">
77 mlirTypeDump(constructedType
);
79 fprintf(stderr
, "\n\n");
83 MlirContext ctx
= mlirContextCreate();
84 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__transform__(), ctx
);
86 testOperationType(ctx
);
87 mlirContextDestroy(ctx
);