Fix GCC build problem with 288f05f related to SmallVector. (#116958)
[llvm-project.git] / mlir / test / CAPI / transform_interpreter.c
bloba849b2f245264695906b21c0f3fe557dd3c7673a
1 //===- transform_interpreter.c - Test of the Transform interpreter 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 //===----------------------------------------------------------------------===//
10 // RUN: mlir-capi-transform-interpreter-test 2>&1 | FileCheck %s
12 #include "mlir-c/Dialect/Transform.h"
13 #include "mlir-c/Dialect/Transform/Interpreter.h"
14 #include "mlir-c/IR.h"
15 #include "mlir-c/Support.h"
17 #include <stdio.h>
18 #include <stdlib.h>
20 int testApplyNamedSequence(MlirContext ctx) {
21 fprintf(stderr, "%s\n", __func__);
23 const char module[] =
24 "module attributes {transform.with_named_sequence} {"
25 " transform.named_sequence @__transform_main(%root: !transform.any_op) {"
26 " transform.print %root { name = \"from interpreter\" }: "
27 "!transform.any_op"
28 " transform.yield"
29 " }"
30 "}";
32 MlirStringRef moduleStringRef = mlirStringRefCreateFromCString(module);
33 MlirStringRef nameStringRef = mlirStringRefCreateFromCString("inline-module");
35 MlirOperation root =
36 mlirOperationCreateParse(ctx, moduleStringRef, nameStringRef);
37 if (mlirOperationIsNull(root))
38 return 1;
39 MlirBlock body = mlirRegionGetFirstBlock(mlirOperationGetRegion(root, 0));
40 MlirOperation entry = mlirBlockGetFirstOperation(body);
42 MlirTransformOptions options = mlirTransformOptionsCreate();
43 mlirTransformOptionsEnableExpensiveChecks(options, true);
44 mlirTransformOptionsEnforceSingleTopLevelTransformOp(options, true);
46 MlirLogicalResult result =
47 mlirTransformApplyNamedSequence(root, entry, root, options);
48 mlirTransformOptionsDestroy(options);
49 mlirOperationDestroy(root);
50 if (mlirLogicalResultIsFailure(result))
51 return 2;
53 return 0;
55 // CHECK-LABEL: testApplyNamedSequence
56 // CHECK: from interpreter
57 // CHECK: transform.named_sequence @__transform_main
58 // CHECK: transform.print %arg0
59 // CHECK: transform.yield
61 int main(void) {
62 MlirContext ctx = mlirContextCreate();
63 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__transform__(), ctx);
64 int result = testApplyNamedSequence(ctx);
65 mlirContextDestroy(ctx);
66 if (result)
67 return result;
69 return EXIT_SUCCESS;