MLIR 23.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
22extern "C" {
23#endif
24
25#define DEFINE_C_API_STRUCT(name, storage) \
26 struct name { \
27 storage *ptr; \
28 }; \
29 typedef struct name name
30
31DEFINE_C_API_STRUCT(MlirMemoryEffectInstancesList, void);
32
33#undef DEFINE_C_API_STRUCT
34
35/// Returns `true` if the given operation implements an interface identified by
36/// its TypeID.
38mlirOperationImplementsInterface(MlirOperation operation,
39 MlirTypeID interfaceTypeID);
40
41/// Returns `true` if the operation identified by its canonical string name
42/// implements the interface identified by its TypeID in the given context.
43/// Note that interfaces may be attached to operations in some contexts and not
44/// others.
47 MlirContext context,
48 MlirTypeID interfaceTypeID);
49
50//===----------------------------------------------------------------------===//
51// InferTypeOpInterface.
52//===----------------------------------------------------------------------===//
53
54/// Returns the interface TypeID of the InferTypeOpInterface.
56
57/// These callbacks are used to return multiple types from functions while
58/// transferring ownership to the caller. The first argument is the number of
59/// consecutive elements pointed to by the second argument. The third argument
60/// is an opaque pointer forwarded to the callback by the caller.
61typedef void (*MlirTypesCallback)(intptr_t, MlirType *, void *);
62
63/// Infers the return types of the operation identified by its canonical given
64/// the arguments that will be supplied to its generic builder. Calls `callback`
65/// with the types of inferred arguments, potentially several times, on success.
66/// Returns failure otherwise.
68 MlirStringRef opName, MlirContext context, MlirLocation location,
69 intptr_t nOperands, MlirValue *operands, MlirAttribute attributes,
70 void *properties, intptr_t nRegions, MlirRegion *regions,
71 MlirTypesCallback callback, void *userData);
72
73//===----------------------------------------------------------------------===//
74// InferShapedTypeOpInterface.
75//===----------------------------------------------------------------------===//
76
77/// Returns the interface TypeID of the InferShapedTypeOpInterface.
79
80/// These callbacks are used to return multiple shaped type components from
81/// functions while transferring ownership to the caller. The first argument is
82/// the has rank boolean followed by the the rank and a pointer to the shape
83/// (if applicable). The next argument is the element type, then the attribute.
84/// The last argument is an opaque pointer forwarded to the callback by the
85/// caller. This callback will be called potentially multiple times for each
86/// shaped type components.
88 const int64_t *, MlirType,
89 MlirAttribute, void *);
90
91/// Infers the return shaped type components of the operation. Calls `callback`
92/// with the types of inferred arguments on success. Returns failure otherwise.
95 MlirStringRef opName, MlirContext context, MlirLocation location,
96 intptr_t nOperands, MlirValue *operands, MlirAttribute attributes,
97 void *properties, intptr_t nRegions, MlirRegion *regions,
98 MlirShapedTypeComponentsCallback callback, void *userData);
99
100//===---------------------------------------------------------------------===//
101// MemoryEffectsOpInterface
102//===---------------------------------------------------------------------===//
103
104/// Returns the interface TypeID of the MemoryEffectsOpInterface.
106
107/// Callbacks for implementing MemoryEffectsOpInterface from external code.
108typedef struct {
109 /// Optional constructor for user data. Set to nullptr to disable it.
111 /// Optional destructor for user data. Set to nullptr to disable it.
113 /// Get memory effects callback.
114 void (*getEffects)(MlirOperation op, MlirMemoryEffectInstancesList effects,
115 void *userData);
116 void *userData;
118
119/// Attach a new FallbackModel for the MemoryEffectsOpInterface to the named
120/// operation. The FallbackModel will call the provided callbacks.
122 MlirContext ctx, MlirStringRef opName,
124
125#ifdef __cplusplus
126}
127#endif
128
129#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.
MLIR_CAPI_EXPORTED MlirTypeID mlirInferTypeOpInterfaceTypeID(void)
Returns the interface TypeID of the InferTypeOpInterface.
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...
MLIR_CAPI_EXPORTED bool mlirOperationImplementsInterface(MlirOperation operation, MlirTypeID interfaceTypeID)
Returns true if the given operation implements an interface identified by its TypeID.
#define DEFINE_C_API_STRUCT(name, storage)
Definition Interfaces.h:25
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:87
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...
MLIR_CAPI_EXPORTED MlirTypeID mlirMemoryEffectsOpInterfaceTypeID(void)
Returns the interface TypeID of the MemoryEffectsOpInterface.
void(* MlirTypesCallback)(intptr_t, MlirType *, void *)
These callbacks are used to return multiple types from functions while transferring ownership to the ...
Definition Interfaces.h:61
MLIR_CAPI_EXPORTED MlirTypeID mlirInferShapedTypeOpInterfaceTypeID(void)
Returns the interface TypeID of the InferShapedTypeOpInterface.
MLIR_CAPI_EXPORTED void mlirMemoryEffectsOpInterfaceAttachFallbackModel(MlirContext ctx, MlirStringRef opName, MlirMemoryEffectsOpInterfaceCallbacks callbacks)
Attach a new FallbackModel for the MemoryEffectsOpInterface to the named operation.
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
A logical result value, essentially a boolean with named states.
Definition Support.h:121
Callbacks for implementing MemoryEffectsOpInterface from external code.
Definition Interfaces.h:108
void(* construct)(void *userData)
Optional constructor for user data. Set to nullptr to disable it.
Definition Interfaces.h:110
void(* getEffects)(MlirOperation op, MlirMemoryEffectInstancesList effects, void *userData)
Get memory effects callback.
Definition Interfaces.h:114
void(* destruct)(void *userData)
Optional destructor for user data. Set to nullptr to disable it.
Definition Interfaces.h:112
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78