1 //===- transform_interpreter.c - Test of the Transform interpreter 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-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"
20 int testApplyNamedSequence(MlirContext ctx
) {
21 fprintf(stderr
, "%s\n", __func__
);
24 "module attributes {transform.with_named_sequence} {"
25 " transform.named_sequence @__transform_main(%root: !transform.any_op) {"
26 " transform.print %root { name = \"from interpreter\" }: "
32 MlirStringRef moduleStringRef
= mlirStringRefCreateFromCString(module
);
33 MlirStringRef nameStringRef
= mlirStringRefCreateFromCString("inline-module");
36 mlirOperationCreateParse(ctx
, moduleStringRef
, nameStringRef
);
37 if (mlirOperationIsNull(root
))
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
))
55 // CHECK-LABEL: testApplyNamedSequence
56 // CHECK: from interpreter
57 // CHECK: transform.named_sequence @__transform_main
58 // CHECK: transform.print %arg0
59 // CHECK: transform.yield
62 MlirContext ctx
= mlirContextCreate();
63 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__transform__(), ctx
);
64 int result
= testApplyNamedSequence(ctx
);
65 mlirContextDestroy(ctx
);