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// ConditionallySpeculatable
102//===---------------------------------------------------------------------===//
103
104/// Enum representing the speculatability of an operation.
105typedef enum {
106 /// The operation is not speculatable.
108 /// The operation is speculatable.
110 /// The operation is speculatable if all nested operations are speculatable.
113
114/// Returns the interface TypeID of the ConditionallySpeculatable interface.
115MLIR_CAPI_EXPORTED MlirTypeID
117
118/// Callbacks for implementing ConditionallySpeculatable from external code.
119typedef struct {
120 /// Optional constructor for user data. Set to nullptr to disable it.
122 /// Optional destructor for user data. Set to nullptr to disable it.
124 /// Returns the speculatability of the given operation.
126 void *userData;
128
129/// Attach a new FallbackModel for the ConditionallySpeculatable interface to
130/// the named operation. The FallbackModel will call the provided callbacks.
133 MlirContext ctx, MlirStringRef opName,
135
136/// Returns the speculatability of the given operation.
137///
138/// The operation must implement the ConditionallySpeculatable interface.
141 MlirOperation operation);
142
143//===---------------------------------------------------------------------===//
144// MemoryEffectsOpInterface
145//===---------------------------------------------------------------------===//
146
147/// Returns the interface TypeID of the MemoryEffectsOpInterface.
149
150/// Callbacks for implementing MemoryEffectsOpInterface from external code.
151typedef struct {
152 /// Optional constructor for user data. Set to nullptr to disable it.
154 /// Optional destructor for user data. Set to nullptr to disable it.
156 /// Get memory effects callback.
157 void (*getEffects)(MlirOperation op, MlirMemoryEffectInstancesList effects,
158 void *userData);
159 void *userData;
161
162/// Attach a new FallbackModel for the MemoryEffectsOpInterface to the named
163/// operation. The FallbackModel will call the provided callbacks.
165 MlirContext ctx, MlirStringRef opName,
167
168#ifdef __cplusplus
169}
170#endif
171
172#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 MlirSpeculatability mlirConditionallySpeculatableOpInterfaceGetSpeculatability(MlirOperation operation)
Returns the speculatability of the given 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 MlirTypeID mlirConditionallySpeculatableOpInterfaceTypeID(void)
Returns the interface TypeID of the ConditionallySpeculatable interface.
MLIR_CAPI_EXPORTED void mlirConditionallySpeculatableOpInterfaceAttachFallbackModel(MlirContext ctx, MlirStringRef opName, MlirConditionallySpeculatableOpInterfaceCallbacks callbacks)
Attach a new FallbackModel for the ConditionallySpeculatable interface to the named operation.
MlirSpeculatability
Enum representing the speculatability of an operation.
Definition Interfaces.h:105
@ MlirSpeculatabilityRecursivelySpeculatable
The operation is speculatable if all nested operations are speculatable.
Definition Interfaces.h:111
@ MlirSpeculatabilitySpeculatable
The operation is speculatable.
Definition Interfaces.h:109
@ MlirSpeculatabilityNotSpeculatable
The operation is not speculatable.
Definition Interfaces.h:107
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
Callbacks for implementing ConditionallySpeculatable from external code.
Definition Interfaces.h:119
void(* destruct)(void *userData)
Optional destructor for user data. Set to nullptr to disable it.
Definition Interfaces.h:123
void(* construct)(void *userData)
Optional constructor for user data. Set to nullptr to disable it.
Definition Interfaces.h:121
MlirSpeculatability(* getSpeculatability)(MlirOperation op, void *userData)
Returns the speculatability of the given operation.
Definition Interfaces.h:125
A logical result value, essentially a boolean with named states.
Definition Support.h:121
Callbacks for implementing MemoryEffectsOpInterface from external code.
Definition Interfaces.h:151
void(* construct)(void *userData)
Optional constructor for user data. Set to nullptr to disable it.
Definition Interfaces.h:153
void(* getEffects)(MlirOperation op, MlirMemoryEffectInstancesList effects, void *userData)
Get memory effects callback.
Definition Interfaces.h:157
void(* destruct)(void *userData)
Optional destructor for user data. Set to nullptr to disable it.
Definition Interfaces.h:155
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78