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 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 //===----------------------------------------------------------------------===// 9 // 10 // This header declares the C interface to MLIR interface classes. It is 11 // intended to contain interfaces defined in lib/Interfaces. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef MLIR_C_INTERFACES_H 16 #define MLIR_C_INTERFACES_H 17 18 #include "mlir-c/IR.h" 19 #include "mlir-c/Support.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /// Returns `true` if the given operation implements an interface identified by 26 /// its TypeID. 27 MLIR_CAPI_EXPORTED bool 28 mlirOperationImplementsInterface(MlirOperation operation, 29 MlirTypeID interfaceTypeID); 30 31 /// Returns `true` if the operation identified by its canonical string name 32 /// implements the interface identified by its TypeID in the given context. 33 /// Note that interfaces may be attached to operations in some contexts and not 34 /// others. 35 MLIR_CAPI_EXPORTED bool 36 mlirOperationImplementsInterfaceStatic(MlirStringRef operationName, 37 MlirContext context, 38 MlirTypeID interfaceTypeID); 39 40 //===----------------------------------------------------------------------===// 41 // InferTypeOpInterface. 42 //===----------------------------------------------------------------------===// 43 44 /// Returns the interface TypeID of the InferTypeOpInterface. 45 MLIR_CAPI_EXPORTED MlirTypeID mlirInferTypeOpInterfaceTypeID(); 46 47 /// These callbacks are used to return multiple types from functions while 48 /// transferring ownership to the caller. The first argument is the number of 49 /// consecutive elements pointed to by the second argument. The third argument 50 /// is an opaque pointer forwarded to the callback by the caller. 51 typedef void (*MlirTypesCallback)(intptr_t, MlirType *, void *); 52 53 /// Infers the return types of the operation identified by its canonical given 54 /// 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. 57 MLIR_CAPI_EXPORTED MlirLogicalResult mlirInferTypeOpInterfaceInferReturnTypes( 58 MlirStringRef opName, MlirContext context, MlirLocation location, 59 intptr_t nOperands, MlirValue *operands, MlirAttribute attributes, 60 intptr_t nRegions, MlirRegion *regions, MlirTypesCallback callback, 61 void *userData); 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif // MLIR_C_INTERFACES_H 68