90 lines · c
1//===- transform.c - Test of Transform dialect C API ----------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM4// Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10// RUN: mlir-capi-transform-test 2>&1 | FileCheck %s11 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: testAnyOpType21void testAnyOpType(MlirContext ctx) {22 fprintf(stderr, "testAnyOpType\n");23 24 MlirType parsedType = mlirTypeParseGet(25 ctx, mlirStringRefCreateFromCString("!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: 132 fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));33 34 // CHECK: parsedType isa AnyOpType: 135 fprintf(stderr, "parsedType isa AnyOpType: %d\n",36 mlirTypeIsATransformAnyOpType(parsedType));37 // CHECK: parsedType isa OperationType: 038 fprintf(stderr, "parsedType isa OperationType: %d\n",39 mlirTypeIsATransformOperationType(parsedType));40 41 // CHECK: !transform.any_op42 mlirTypeDump(constructedType);43 44 fprintf(stderr, "\n\n");45}46 47// CHECK-LABEL: testOperationType48void testOperationType(MlirContext ctx) {49 fprintf(stderr, "testOperationType\n");50 51 MlirType parsedType = mlirTypeParseGet(52 ctx, mlirStringRefCreateFromCString("!transform.op<\"foo.bar\">"));53 MlirType constructedType = mlirTransformOperationTypeGet(54 ctx, mlirStringRefCreateFromCString("foo.bar"));55 56 assert(!mlirTypeIsNull(parsedType) && "couldn't parse AnyOpType");57 assert(!mlirTypeIsNull(constructedType) && "couldn't construct AnyOpType");58 59 // CHECK: equal: 160 fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));61 62 // CHECK: parsedType isa AnyOpType: 063 fprintf(stderr, "parsedType isa AnyOpType: %d\n",64 mlirTypeIsATransformAnyOpType(parsedType));65 // CHECK: parsedType isa OperationType: 166 fprintf(stderr, "parsedType isa OperationType: %d\n",67 mlirTypeIsATransformOperationType(parsedType));68 69 // CHECK: operation name equal: 170 MlirStringRef operationName =71 mlirTransformOperationTypeGetOperationName(constructedType);72 fprintf(stderr, "operation name equal: %d\n",73 mlirStringRefEqual(operationName,74 mlirStringRefCreateFromCString("foo.bar")));75 76 // CHECK: !transform.op<"foo.bar">77 mlirTypeDump(constructedType);78 79 fprintf(stderr, "\n\n");80}81 82int main(void) {83 MlirContext ctx = mlirContextCreate();84 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__transform__(), ctx);85 testAnyOpType(ctx);86 testOperationType(ctx);87 mlirContextDestroy(ctx);88 return EXIT_SUCCESS;89}90