95 lines · c
1//===-- mlir-c/Interfaces.h - C API to Core MLIR IR interfaces ----*- C -*-===//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// This header declares the C interface to MLIR interface classes. It is11// intended to contain interfaces defined in lib/Interfaces.12//13//===----------------------------------------------------------------------===//14 15#ifndef MLIR_C_INTERFACES_H16#define MLIR_C_INTERFACES_H17 18#include "mlir-c/IR.h"19#include "mlir-c/Support.h"20 21#ifdef __cplusplus22extern "C" {23#endif24 25/// Returns `true` if the given operation implements an interface identified by26/// its TypeID.27MLIR_CAPI_EXPORTED bool28mlirOperationImplementsInterface(MlirOperation operation,29 MlirTypeID interfaceTypeID);30 31/// Returns `true` if the operation identified by its canonical string name32/// implements the interface identified by its TypeID in the given context.33/// Note that interfaces may be attached to operations in some contexts and not34/// others.35MLIR_CAPI_EXPORTED bool36mlirOperationImplementsInterfaceStatic(MlirStringRef operationName,37 MlirContext context,38 MlirTypeID interfaceTypeID);39 40//===----------------------------------------------------------------------===//41// InferTypeOpInterface.42//===----------------------------------------------------------------------===//43 44/// Returns the interface TypeID of the InferTypeOpInterface.45MLIR_CAPI_EXPORTED MlirTypeID mlirInferTypeOpInterfaceTypeID();46 47/// These callbacks are used to return multiple types from functions while48/// transferring ownership to the caller. The first argument is the number of49/// consecutive elements pointed to by the second argument. The third argument50/// is an opaque pointer forwarded to the callback by the caller.51typedef void (*MlirTypesCallback)(intptr_t, MlirType *, void *);52 53/// Infers the return types of the operation identified by its canonical given54/// the arguments that will be supplied to its generic builder. Calls `callback`55/// with the types of inferred arguments, potentially several times, on success.56/// Returns failure otherwise.57MLIR_CAPI_EXPORTED MlirLogicalResult mlirInferTypeOpInterfaceInferReturnTypes(58 MlirStringRef opName, MlirContext context, MlirLocation location,59 intptr_t nOperands, MlirValue *operands, MlirAttribute attributes,60 void *properties, intptr_t nRegions, MlirRegion *regions,61 MlirTypesCallback callback, void *userData);62 63//===----------------------------------------------------------------------===//64// InferShapedTypeOpInterface.65//===----------------------------------------------------------------------===//66 67/// Returns the interface TypeID of the InferShapedTypeOpInterface.68MLIR_CAPI_EXPORTED MlirTypeID mlirInferShapedTypeOpInterfaceTypeID();69 70/// These callbacks are used to return multiple shaped type components from71/// functions while transferring ownership to the caller. The first argument is72/// the has rank boolean followed by the the rank and a pointer to the shape73/// (if applicable). The next argument is the element type, then the attribute.74/// The last argument is an opaque pointer forwarded to the callback by the75/// caller. This callback will be called potentially multiple times for each76/// shaped type components.77typedef void (*MlirShapedTypeComponentsCallback)(bool, intptr_t,78 const int64_t *, MlirType,79 MlirAttribute, void *);80 81/// Infers the return shaped type components of the operation. Calls `callback`82/// with the types of inferred arguments on success. Returns failure otherwise.83MLIR_CAPI_EXPORTED MlirLogicalResult84mlirInferShapedTypeOpInterfaceInferReturnTypes(85 MlirStringRef opName, MlirContext context, MlirLocation location,86 intptr_t nOperands, MlirValue *operands, MlirAttribute attributes,87 void *properties, intptr_t nRegions, MlirRegion *regions,88 MlirShapedTypeComponentsCallback callback, void *userData);89 90#ifdef __cplusplus91}92#endif93 94#endif // MLIR_C_INTERFACES_H95