MLIR  20.0.0git
Interfaces.h
Go to the documentation of this file.
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.
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.
37  MlirContext context,
38  MlirTypeID interfaceTypeID);
39 
40 //===----------------------------------------------------------------------===//
41 // InferTypeOpInterface.
42 //===----------------------------------------------------------------------===//
43 
44 /// Returns the interface TypeID of the InferTypeOpInterface.
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.
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.
69 
70 /// These callbacks are used to return multiple shaped type components from
71 /// functions while transferring ownership to the caller. The first argument is
72 /// the has rank boolean followed by the the rank and a pointer to the shape
73 /// (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 the
75 /// caller. This callback will be called potentially multiple times for each
76 /// shaped type components.
77 typedef 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.
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 __cplusplus
91 }
92 #endif
93 
94 #endif // MLIR_C_INTERFACES_H
MLIR_CAPI_EXPORTED MlirLogicalResult mlirInferShapedTypeOpInterfaceInferReturnTypes(MlirStringRef opName, MlirContext context, MlirLocation location, intptr_t nOperands, MlirValue *operands, MlirAttribute attributes, void *properties, intptr_t nRegions, MlirRegion *regions, MlirShapedTypeComponentsCallback callback, void *userData)
Infers the return shaped type components of the operation.
Definition: Interfaces.cpp:127
MLIR_CAPI_EXPORTED bool mlirOperationImplementsInterfaceStatic(MlirStringRef operationName, MlirContext context, MlirTypeID interfaceTypeID)
Returns true if the operation identified by its canonical string name implements the interface identi...
Definition: Interfaces.cpp:80
MLIR_CAPI_EXPORTED MlirTypeID mlirInferTypeOpInterfaceTypeID()
Returns the interface TypeID of the InferTypeOpInterface.
Definition: Interfaces.cpp:88
MLIR_CAPI_EXPORTED bool mlirOperationImplementsInterface(MlirOperation operation, MlirTypeID interfaceTypeID)
Returns true if the given operation implements an interface identified by its TypeID.
Definition: Interfaces.cpp:73
void(* MlirShapedTypeComponentsCallback)(bool, intptr_t, const int64_t *, MlirType, MlirAttribute, void *)
These callbacks are used to return multiple shaped type components from functions while transferring ...
Definition: Interfaces.h:77
MLIR_CAPI_EXPORTED MlirLogicalResult mlirInferTypeOpInterfaceInferReturnTypes(MlirStringRef opName, MlirContext context, MlirLocation location, intptr_t nOperands, MlirValue *operands, MlirAttribute attributes, void *properties, intptr_t nRegions, MlirRegion *regions, MlirTypesCallback callback, void *userData)
Infers the return types of the operation identified by its canonical given the arguments that will be...
Definition: Interfaces.cpp:92
void(* MlirTypesCallback)(intptr_t, MlirType *, void *)
These callbacks are used to return multiple types from functions while transferring ownership to the ...
Definition: Interfaces.h:51
MLIR_CAPI_EXPORTED MlirTypeID mlirInferShapedTypeOpInterfaceTypeID()
Returns the interface TypeID of the InferShapedTypeOpInterface.
Definition: Interfaces.cpp:123
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
A logical result value, essentially a boolean with named states.
Definition: Support.h:116
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73