1 //===-- mlir-c/IR.h - C API to Core MLIR IR classes ---------------*- C -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // This header declares the C interface to MLIR core IR classes.
12 // Many exotic languages can interoperate with C code but have a harder time
13 // with C++ due to name mangling. So in addition to C, this interface enables
14 // tools written in such languages.
16 //===----------------------------------------------------------------------===//
24 #include "mlir-c/Support.h"
30 //===----------------------------------------------------------------------===//
31 /// Opaque type declarations.
33 /// Types are exposed to C bindings as structs containing opaque pointers. They
34 /// are not supposed to be inspected from C. This allows the underlying
35 /// representation to change without affecting the API users. The use of structs
36 /// instead of typedefs enables some type safety as structs are not implicitly
37 /// convertible to each other.
39 /// Instances of these types may or may not own the underlying object (most
40 /// often only point to an IR fragment without owning it). The ownership
41 /// semantics is defined by how an instance of the type was obtained.
43 //===----------------------------------------------------------------------===//
45 #define DEFINE_C_API_STRUCT(name, storage) \
49 typedef struct name name
51 DEFINE_C_API_STRUCT(MlirAsmState
, void);
52 DEFINE_C_API_STRUCT(MlirBytecodeWriterConfig
, void);
53 DEFINE_C_API_STRUCT(MlirContext
, void);
54 DEFINE_C_API_STRUCT(MlirDialect
, void);
55 DEFINE_C_API_STRUCT(MlirDialectRegistry
, void);
56 DEFINE_C_API_STRUCT(MlirOperation
, void);
57 DEFINE_C_API_STRUCT(MlirOpOperand
, void);
58 DEFINE_C_API_STRUCT(MlirOpPrintingFlags
, void);
59 DEFINE_C_API_STRUCT(MlirBlock
, void);
60 DEFINE_C_API_STRUCT(MlirRegion
, void);
61 DEFINE_C_API_STRUCT(MlirSymbolTable
, void);
63 DEFINE_C_API_STRUCT(MlirAttribute
, const void);
64 DEFINE_C_API_STRUCT(MlirIdentifier
, const void);
65 DEFINE_C_API_STRUCT(MlirLocation
, const void);
66 DEFINE_C_API_STRUCT(MlirModule
, const void);
67 DEFINE_C_API_STRUCT(MlirType
, const void);
68 DEFINE_C_API_STRUCT(MlirValue
, const void);
70 #undef DEFINE_C_API_STRUCT
72 /// Named MLIR attribute.
74 /// A named attribute is essentially a (name, attribute) pair where the name is
76 struct MlirNamedAttribute
{
78 MlirAttribute attribute
;
80 typedef struct MlirNamedAttribute MlirNamedAttribute
;
82 //===----------------------------------------------------------------------===//
84 //===----------------------------------------------------------------------===//
86 /// Creates an MLIR context and transfers its ownership to the caller.
87 /// This sets the default multithreading option (enabled).
88 MLIR_CAPI_EXPORTED MlirContext
mlirContextCreate(void);
90 /// Creates an MLIR context with an explicit setting of the multithreading
91 /// setting and transfers its ownership to the caller.
92 MLIR_CAPI_EXPORTED MlirContext
93 mlirContextCreateWithThreading(bool threadingEnabled
);
95 /// Creates an MLIR context, setting the multithreading setting explicitly and
96 /// pre-loading the dialects from the provided DialectRegistry.
97 MLIR_CAPI_EXPORTED MlirContext
mlirContextCreateWithRegistry(
98 MlirDialectRegistry registry
, bool threadingEnabled
);
100 /// Checks if two contexts are equal.
101 MLIR_CAPI_EXPORTED
bool mlirContextEqual(MlirContext ctx1
, MlirContext ctx2
);
103 /// Checks whether a context is null.
104 static inline bool mlirContextIsNull(MlirContext context
) {
108 /// Takes an MLIR context owned by the caller and destroys it.
109 MLIR_CAPI_EXPORTED
void mlirContextDestroy(MlirContext context
);
111 /// Sets whether unregistered dialects are allowed in this context.
112 MLIR_CAPI_EXPORTED
void
113 mlirContextSetAllowUnregisteredDialects(MlirContext context
, bool allow
);
115 /// Returns whether the context allows unregistered dialects.
116 MLIR_CAPI_EXPORTED
bool
117 mlirContextGetAllowUnregisteredDialects(MlirContext context
);
119 /// Returns the number of dialects registered with the given context. A
120 /// registered dialect will be loaded if needed by the parser.
121 MLIR_CAPI_EXPORTED
intptr_t
122 mlirContextGetNumRegisteredDialects(MlirContext context
);
124 /// Append the contents of the given dialect registry to the registry associated
125 /// with the context.
126 MLIR_CAPI_EXPORTED
void
127 mlirContextAppendDialectRegistry(MlirContext ctx
, MlirDialectRegistry registry
);
129 /// Returns the number of dialects loaded by the context.
131 MLIR_CAPI_EXPORTED
intptr_t
132 mlirContextGetNumLoadedDialects(MlirContext context
);
134 /// Gets the dialect instance owned by the given context using the dialect
135 /// namespace to identify it, loads (i.e., constructs the instance of) the
136 /// dialect if necessary. If the dialect is not registered with the context,
137 /// returns null. Use mlirContextLoad<Name>Dialect to load an unregistered
139 MLIR_CAPI_EXPORTED MlirDialect
mlirContextGetOrLoadDialect(MlirContext context
,
142 /// Set threading mode (must be set to false to mlir-print-ir-after-all).
143 MLIR_CAPI_EXPORTED
void mlirContextEnableMultithreading(MlirContext context
,
146 /// Eagerly loads all available dialects registered with a context, making
147 /// them available for use for IR construction.
148 MLIR_CAPI_EXPORTED
void
149 mlirContextLoadAllAvailableDialects(MlirContext context
);
151 /// Returns whether the given fully-qualified operation (i.e.
152 /// 'dialect.operation') is registered with the context. This will return true
153 /// if the dialect is loaded and the operation is registered within the
155 MLIR_CAPI_EXPORTED
bool mlirContextIsRegisteredOperation(MlirContext context
,
158 /// Sets the thread pool of the context explicitly, enabling multithreading in
159 /// the process. This API should be used to avoid re-creating thread pools in
160 /// long-running applications that perform multiple compilations, see
161 /// the C++ documentation for MLIRContext for details.
162 MLIR_CAPI_EXPORTED
void mlirContextSetThreadPool(MlirContext context
,
163 MlirLlvmThreadPool threadPool
);
165 //===----------------------------------------------------------------------===//
167 //===----------------------------------------------------------------------===//
169 /// Returns the context that owns the dialect.
170 MLIR_CAPI_EXPORTED MlirContext
mlirDialectGetContext(MlirDialect dialect
);
172 /// Checks if the dialect is null.
173 static inline bool mlirDialectIsNull(MlirDialect dialect
) {
177 /// Checks if two dialects that belong to the same context are equal. Dialects
178 /// from different contexts will not compare equal.
179 MLIR_CAPI_EXPORTED
bool mlirDialectEqual(MlirDialect dialect1
,
180 MlirDialect dialect2
);
182 /// Returns the namespace of the given dialect.
183 MLIR_CAPI_EXPORTED MlirStringRef
mlirDialectGetNamespace(MlirDialect dialect
);
185 //===----------------------------------------------------------------------===//
186 // DialectHandle API.
187 // Registration entry-points for each dialect are declared using the common
188 // MLIR_DECLARE_DIALECT_REGISTRATION_CAPI macro, which takes the dialect
189 // API name (i.e. "Func", "Tensor", "Linalg") and namespace (i.e. "func",
190 // "tensor", "linalg"). The following declarations are produced:
192 // /// Gets the above hook methods in struct form for a dialect by namespace.
193 // /// This is intended to facilitate dynamic lookup and registration of
194 // /// dialects via a plugin facility based on shared library symbol lookup.
195 // const MlirDialectHandle *mlirGetDialectHandle__{NAMESPACE}__();
197 // This is done via a common macro to facilitate future expansion to
198 // registration schemes.
199 //===----------------------------------------------------------------------===//
201 struct MlirDialectHandle
{
204 typedef struct MlirDialectHandle MlirDialectHandle
;
206 #define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace) \
207 MLIR_CAPI_EXPORTED MlirDialectHandle mlirGetDialectHandle__##Namespace##__( \
210 /// Returns the namespace associated with the provided dialect handle.
212 MlirStringRef
mlirDialectHandleGetNamespace(MlirDialectHandle
);
214 /// Inserts the dialect associated with the provided dialect handle into the
215 /// provided dialect registry
216 MLIR_CAPI_EXPORTED
void mlirDialectHandleInsertDialect(MlirDialectHandle
,
217 MlirDialectRegistry
);
219 /// Registers the dialect associated with the provided dialect handle.
220 MLIR_CAPI_EXPORTED
void mlirDialectHandleRegisterDialect(MlirDialectHandle
,
223 /// Loads the dialect associated with the provided dialect handle.
224 MLIR_CAPI_EXPORTED MlirDialect
mlirDialectHandleLoadDialect(MlirDialectHandle
,
227 //===----------------------------------------------------------------------===//
228 // DialectRegistry API.
229 //===----------------------------------------------------------------------===//
231 /// Creates a dialect registry and transfers its ownership to the caller.
232 MLIR_CAPI_EXPORTED MlirDialectRegistry
mlirDialectRegistryCreate(void);
234 /// Checks if the dialect registry is null.
235 static inline bool mlirDialectRegistryIsNull(MlirDialectRegistry registry
) {
236 return !registry
.ptr
;
239 /// Takes a dialect registry owned by the caller and destroys it.
240 MLIR_CAPI_EXPORTED
void
241 mlirDialectRegistryDestroy(MlirDialectRegistry registry
);
243 //===----------------------------------------------------------------------===//
245 //===----------------------------------------------------------------------===//
247 /// Returns the underlying location attribute of this location.
248 MLIR_CAPI_EXPORTED MlirAttribute
249 mlirLocationGetAttribute(MlirLocation location
);
251 /// Creates a location from a location attribute.
252 MLIR_CAPI_EXPORTED MlirLocation
253 mlirLocationFromAttribute(MlirAttribute attribute
);
255 /// Creates an File/Line/Column location owned by the given context.
256 MLIR_CAPI_EXPORTED MlirLocation
mlirLocationFileLineColGet(
257 MlirContext context
, MlirStringRef filename
, unsigned line
, unsigned col
);
259 /// Creates an File/Line/Column range location owned by the given context.
260 MLIR_CAPI_EXPORTED MlirLocation
mlirLocationFileLineColRangeGet(
261 MlirContext context
, MlirStringRef filename
, unsigned start_line
,
262 unsigned start_col
, unsigned end_line
, unsigned end_col
);
264 /// Creates a call site location with a callee and a caller.
265 MLIR_CAPI_EXPORTED MlirLocation
mlirLocationCallSiteGet(MlirLocation callee
,
266 MlirLocation caller
);
268 /// Creates a fused location with an array of locations and metadata.
269 MLIR_CAPI_EXPORTED MlirLocation
270 mlirLocationFusedGet(MlirContext ctx
, intptr_t nLocations
,
271 MlirLocation
const *locations
, MlirAttribute metadata
);
273 /// Creates a name location owned by the given context. Providing null location
274 /// for childLoc is allowed and if childLoc is null location, then the behavior
275 /// is the same as having unknown child location.
276 MLIR_CAPI_EXPORTED MlirLocation
mlirLocationNameGet(MlirContext context
,
278 MlirLocation childLoc
);
280 /// Creates a location with unknown position owned by the given context.
281 MLIR_CAPI_EXPORTED MlirLocation
mlirLocationUnknownGet(MlirContext context
);
283 /// Gets the context that a location was created with.
284 MLIR_CAPI_EXPORTED MlirContext
mlirLocationGetContext(MlirLocation location
);
286 /// Checks if the location is null.
287 static inline bool mlirLocationIsNull(MlirLocation location
) {
288 return !location
.ptr
;
291 /// Checks if two locations are equal.
292 MLIR_CAPI_EXPORTED
bool mlirLocationEqual(MlirLocation l1
, MlirLocation l2
);
294 /// Prints a location by sending chunks of the string representation and
295 /// forwarding `userData to `callback`. Note that the callback may be called
296 /// several times with consecutive chunks of the string.
297 MLIR_CAPI_EXPORTED
void mlirLocationPrint(MlirLocation location
,
298 MlirStringCallback callback
,
301 //===----------------------------------------------------------------------===//
303 //===----------------------------------------------------------------------===//
305 /// Creates a new, empty module and transfers ownership to the caller.
306 MLIR_CAPI_EXPORTED MlirModule
mlirModuleCreateEmpty(MlirLocation location
);
308 /// Parses a module from the string and transfers ownership to the caller.
309 MLIR_CAPI_EXPORTED MlirModule
mlirModuleCreateParse(MlirContext context
,
310 MlirStringRef module
);
312 /// Gets the context that a module was created with.
313 MLIR_CAPI_EXPORTED MlirContext
mlirModuleGetContext(MlirModule module
);
315 /// Gets the body of the module, i.e. the only block it contains.
316 MLIR_CAPI_EXPORTED MlirBlock
mlirModuleGetBody(MlirModule module
);
318 /// Checks whether a module is null.
319 static inline bool mlirModuleIsNull(MlirModule module
) { return !module
.ptr
; }
321 /// Takes a module owned by the caller and deletes it.
322 MLIR_CAPI_EXPORTED
void mlirModuleDestroy(MlirModule module
);
324 /// Views the module as a generic operation.
325 MLIR_CAPI_EXPORTED MlirOperation
mlirModuleGetOperation(MlirModule module
);
327 /// Views the generic operation as a module.
328 /// The returned module is null when the input operation was not a ModuleOp.
329 MLIR_CAPI_EXPORTED MlirModule
mlirModuleFromOperation(MlirOperation op
);
331 //===----------------------------------------------------------------------===//
333 //===----------------------------------------------------------------------===//
335 /// An auxiliary class for constructing operations.
337 /// This class contains all the information necessary to construct the
338 /// operation. It owns the MlirRegions it has pointers to and does not own
339 /// anything else. By default, the state can be constructed from a name and
340 /// location, the latter being also used to access the context, and has no other
341 /// components. These components can be added progressively until the operation
342 /// is constructed. Users are not expected to rely on the internals of this
343 /// class and should use mlirOperationState* functions instead.
345 struct MlirOperationState
{
347 MlirLocation location
;
354 intptr_t nSuccessors
;
355 MlirBlock
*successors
;
356 intptr_t nAttributes
;
357 MlirNamedAttribute
*attributes
;
358 bool enableResultTypeInference
;
360 typedef struct MlirOperationState MlirOperationState
;
362 /// Constructs an operation state from a name and a location.
363 MLIR_CAPI_EXPORTED MlirOperationState
mlirOperationStateGet(MlirStringRef name
,
366 /// Adds a list of components to the operation state.
367 MLIR_CAPI_EXPORTED
void mlirOperationStateAddResults(MlirOperationState
*state
,
369 MlirType
const *results
);
370 MLIR_CAPI_EXPORTED
void
371 mlirOperationStateAddOperands(MlirOperationState
*state
, intptr_t n
,
372 MlirValue
const *operands
);
373 MLIR_CAPI_EXPORTED
void
374 mlirOperationStateAddOwnedRegions(MlirOperationState
*state
, intptr_t n
,
375 MlirRegion
const *regions
);
376 MLIR_CAPI_EXPORTED
void
377 mlirOperationStateAddSuccessors(MlirOperationState
*state
, intptr_t n
,
378 MlirBlock
const *successors
);
379 MLIR_CAPI_EXPORTED
void
380 mlirOperationStateAddAttributes(MlirOperationState
*state
, intptr_t n
,
381 MlirNamedAttribute
const *attributes
);
383 /// Enables result type inference for the operation under construction. If
384 /// enabled, then the caller must not have called
385 /// mlirOperationStateAddResults(). Note that if enabled, the
386 /// mlirOperationCreate() call is failable: it will return a null operation
387 /// on inference failure and will emit diagnostics.
388 MLIR_CAPI_EXPORTED
void
389 mlirOperationStateEnableResultTypeInference(MlirOperationState
*state
);
391 //===----------------------------------------------------------------------===//
393 // While many of these are simple settings that could be represented in a
394 // struct, they are wrapped in a heap allocated object and accessed via
395 // functions to maximize the possibility of compatibility over time.
396 //===----------------------------------------------------------------------===//
398 /// Creates new AsmState, as with AsmState the IR should not be mutated
399 /// in-between using this state.
400 /// Must be freed with a call to mlirAsmStateDestroy().
401 // TODO: This should be expanded to handle location & resouce map.
402 MLIR_CAPI_EXPORTED MlirAsmState
403 mlirAsmStateCreateForOperation(MlirOperation op
, MlirOpPrintingFlags flags
);
405 /// Creates new AsmState from value.
406 /// Must be freed with a call to mlirAsmStateDestroy().
407 // TODO: This should be expanded to handle location & resouce map.
408 MLIR_CAPI_EXPORTED MlirAsmState
409 mlirAsmStateCreateForValue(MlirValue value
, MlirOpPrintingFlags flags
);
411 /// Destroys printing flags created with mlirAsmStateCreate.
412 MLIR_CAPI_EXPORTED
void mlirAsmStateDestroy(MlirAsmState state
);
414 //===----------------------------------------------------------------------===//
415 // Op Printing flags API.
416 // While many of these are simple settings that could be represented in a
417 // struct, they are wrapped in a heap allocated object and accessed via
418 // functions to maximize the possibility of compatibility over time.
419 //===----------------------------------------------------------------------===//
421 /// Creates new printing flags with defaults, intended for customization.
422 /// Must be freed with a call to mlirOpPrintingFlagsDestroy().
423 MLIR_CAPI_EXPORTED MlirOpPrintingFlags
mlirOpPrintingFlagsCreate(void);
425 /// Destroys printing flags created with mlirOpPrintingFlagsCreate.
426 MLIR_CAPI_EXPORTED
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags
);
428 /// Enables the elision of large elements attributes by printing a lexically
429 /// valid but otherwise meaningless form instead of the element data. The
430 /// `largeElementLimit` is used to configure what is considered to be a "large"
431 /// ElementsAttr by providing an upper limit to the number of elements.
432 MLIR_CAPI_EXPORTED
void
433 mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags
,
434 intptr_t largeElementLimit
);
436 /// Enables the elision of large resources strings by omitting them from the
437 /// `dialect_resources` section. The `largeResourceLimit` is used to configure
438 /// what is considered to be a "large" resource by providing an upper limit to
440 MLIR_CAPI_EXPORTED
void
441 mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags
,
442 intptr_t largeResourceLimit
);
444 /// Enable or disable printing of debug information (based on `enable`). If
445 /// 'prettyForm' is set to true, debug information is printed in a more readable
446 /// 'pretty' form. Note: The IR generated with 'prettyForm' is not parsable.
447 MLIR_CAPI_EXPORTED
void
448 mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags
, bool enable
,
451 /// Always print operations in the generic form.
452 MLIR_CAPI_EXPORTED
void
453 mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags
);
455 /// Use local scope when printing the operation. This allows for using the
456 /// printer in a more localized and thread-safe setting, but may not
457 /// necessarily be identical to what the IR will look like when dumping
459 MLIR_CAPI_EXPORTED
void
460 mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags
);
462 /// Do not verify the operation when using custom operation printers.
463 MLIR_CAPI_EXPORTED
void
464 mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags
);
466 /// Skip printing regions.
467 MLIR_CAPI_EXPORTED
void
468 mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags
);
470 //===----------------------------------------------------------------------===//
471 // Bytecode printing flags API.
472 //===----------------------------------------------------------------------===//
474 /// Creates new printing flags with defaults, intended for customization.
475 /// Must be freed with a call to mlirBytecodeWriterConfigDestroy().
476 MLIR_CAPI_EXPORTED MlirBytecodeWriterConfig
477 mlirBytecodeWriterConfigCreate(void);
479 /// Destroys printing flags created with mlirBytecodeWriterConfigCreate.
480 MLIR_CAPI_EXPORTED
void
481 mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config
);
483 /// Sets the version to emit in the writer config.
484 MLIR_CAPI_EXPORTED
void
485 mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags
,
488 //===----------------------------------------------------------------------===//
490 //===----------------------------------------------------------------------===//
492 /// Creates an operation and transfers ownership to the caller.
493 /// Note that caller owned child objects are transferred in this call and must
494 /// not be further used. Particularly, this applies to any regions added to
495 /// the state (the implementation may invalidate any such pointers).
497 /// This call can fail under the following conditions, in which case, it will
498 /// return a null operation and emit diagnostics:
499 /// - Result type inference is enabled and cannot be performed.
500 MLIR_CAPI_EXPORTED MlirOperation
mlirOperationCreate(MlirOperationState
*state
);
502 /// Parses an operation, giving ownership to the caller. If parsing fails a null
503 /// operation will be returned, and an error diagnostic emitted.
505 /// `sourceStr` may be either the text assembly format, or binary bytecode
506 /// format. `sourceName` is used as the file name of the source; any IR without
507 /// locations will get a `FileLineColLoc` location with `sourceName` as the file
509 MLIR_CAPI_EXPORTED MlirOperation
mlirOperationCreateParse(
510 MlirContext context
, MlirStringRef sourceStr
, MlirStringRef sourceName
);
512 /// Creates a deep copy of an operation. The operation is not inserted and
513 /// ownership is transferred to the caller.
514 MLIR_CAPI_EXPORTED MlirOperation
mlirOperationClone(MlirOperation op
);
516 /// Takes an operation owned by the caller and destroys it.
517 MLIR_CAPI_EXPORTED
void mlirOperationDestroy(MlirOperation op
);
519 /// Removes the given operation from its parent block. The operation is not
520 /// destroyed. The ownership of the operation is transferred to the caller.
521 MLIR_CAPI_EXPORTED
void mlirOperationRemoveFromParent(MlirOperation op
);
523 /// Checks whether the underlying operation is null.
524 static inline bool mlirOperationIsNull(MlirOperation op
) { return !op
.ptr
; }
526 /// Checks whether two operation handles point to the same operation. This does
527 /// not perform deep comparison.
528 MLIR_CAPI_EXPORTED
bool mlirOperationEqual(MlirOperation op
,
529 MlirOperation other
);
531 /// Gets the context this operation is associated with
532 MLIR_CAPI_EXPORTED MlirContext
mlirOperationGetContext(MlirOperation op
);
534 /// Gets the location of the operation.
535 MLIR_CAPI_EXPORTED MlirLocation
mlirOperationGetLocation(MlirOperation op
);
537 /// Gets the type id of the operation.
538 /// Returns null if the operation does not have a registered operation
540 MLIR_CAPI_EXPORTED MlirTypeID
mlirOperationGetTypeID(MlirOperation op
);
542 /// Gets the name of the operation as an identifier.
543 MLIR_CAPI_EXPORTED MlirIdentifier
mlirOperationGetName(MlirOperation op
);
545 /// Gets the block that owns this operation, returning null if the operation is
547 MLIR_CAPI_EXPORTED MlirBlock
mlirOperationGetBlock(MlirOperation op
);
549 /// Gets the operation that owns this operation, returning null if the operation
551 MLIR_CAPI_EXPORTED MlirOperation
552 mlirOperationGetParentOperation(MlirOperation op
);
554 /// Returns the number of regions attached to the given operation.
555 MLIR_CAPI_EXPORTED
intptr_t mlirOperationGetNumRegions(MlirOperation op
);
557 /// Returns `pos`-th region attached to the operation.
558 MLIR_CAPI_EXPORTED MlirRegion
mlirOperationGetRegion(MlirOperation op
,
561 /// Returns an operation immediately following the given operation it its
563 MLIR_CAPI_EXPORTED MlirOperation
mlirOperationGetNextInBlock(MlirOperation op
);
565 /// Returns the number of operands of the operation.
566 MLIR_CAPI_EXPORTED
intptr_t mlirOperationGetNumOperands(MlirOperation op
);
568 /// Returns `pos`-th operand of the operation.
569 MLIR_CAPI_EXPORTED MlirValue
mlirOperationGetOperand(MlirOperation op
,
572 /// Sets the `pos`-th operand of the operation.
573 MLIR_CAPI_EXPORTED
void mlirOperationSetOperand(MlirOperation op
, intptr_t pos
,
576 /// Replaces the operands of the operation.
577 MLIR_CAPI_EXPORTED
void mlirOperationSetOperands(MlirOperation op
,
579 MlirValue
const *operands
);
581 /// Returns the number of results of the operation.
582 MLIR_CAPI_EXPORTED
intptr_t mlirOperationGetNumResults(MlirOperation op
);
584 /// Returns `pos`-th result of the operation.
585 MLIR_CAPI_EXPORTED MlirValue
mlirOperationGetResult(MlirOperation op
,
588 /// Returns the number of successor blocks of the operation.
589 MLIR_CAPI_EXPORTED
intptr_t mlirOperationGetNumSuccessors(MlirOperation op
);
591 /// Returns `pos`-th successor of the operation.
592 MLIR_CAPI_EXPORTED MlirBlock
mlirOperationGetSuccessor(MlirOperation op
,
595 /// Set `pos`-th successor of the operation.
596 MLIR_CAPI_EXPORTED
void
597 mlirOperationSetSuccessor(MlirOperation op
, intptr_t pos
, MlirBlock block
);
599 /// Returns true if this operation defines an inherent attribute with this name.
600 /// Note: the attribute can be optional, so
601 /// `mlirOperationGetInherentAttributeByName` can still return a null attribute.
602 MLIR_CAPI_EXPORTED
bool
603 mlirOperationHasInherentAttributeByName(MlirOperation op
, MlirStringRef name
);
605 /// Returns an inherent attribute attached to the operation given its name.
606 MLIR_CAPI_EXPORTED MlirAttribute
607 mlirOperationGetInherentAttributeByName(MlirOperation op
, MlirStringRef name
);
609 /// Sets an inherent attribute by name, replacing the existing if it exists.
610 /// This has no effect if "name" does not match an inherent attribute.
611 MLIR_CAPI_EXPORTED
void
612 mlirOperationSetInherentAttributeByName(MlirOperation op
, MlirStringRef name
,
615 /// Returns the number of discardable attributes attached to the operation.
616 MLIR_CAPI_EXPORTED
intptr_t
617 mlirOperationGetNumDiscardableAttributes(MlirOperation op
);
619 /// Return `pos`-th discardable attribute of the operation.
620 MLIR_CAPI_EXPORTED MlirNamedAttribute
621 mlirOperationGetDiscardableAttribute(MlirOperation op
, intptr_t pos
);
623 /// Returns a discardable attribute attached to the operation given its name.
624 MLIR_CAPI_EXPORTED MlirAttribute
mlirOperationGetDiscardableAttributeByName(
625 MlirOperation op
, MlirStringRef name
);
627 /// Sets a discardable attribute by name, replacing the existing if it exists or
628 /// adding a new one otherwise. The new `attr` Attribute is not allowed to be
629 /// null, use `mlirOperationRemoveDiscardableAttributeByName` to remove an
630 /// Attribute instead.
631 MLIR_CAPI_EXPORTED
void
632 mlirOperationSetDiscardableAttributeByName(MlirOperation op
, MlirStringRef name
,
635 /// Removes a discardable attribute by name. Returns false if the attribute was
636 /// not found and true if removed.
637 MLIR_CAPI_EXPORTED
bool
638 mlirOperationRemoveDiscardableAttributeByName(MlirOperation op
,
641 /// Returns the number of attributes attached to the operation.
642 /// Deprecated, please use `mlirOperationGetNumInherentAttributes` or
643 /// `mlirOperationGetNumDiscardableAttributes`.
644 MLIR_CAPI_EXPORTED
intptr_t mlirOperationGetNumAttributes(MlirOperation op
);
646 /// Return `pos`-th attribute of the operation.
647 /// Deprecated, please use `mlirOperationGetInherentAttribute` or
648 /// `mlirOperationGetDiscardableAttribute`.
649 MLIR_CAPI_EXPORTED MlirNamedAttribute
650 mlirOperationGetAttribute(MlirOperation op
, intptr_t pos
);
652 /// Returns an attribute attached to the operation given its name.
653 /// Deprecated, please use `mlirOperationGetInherentAttributeByName` or
654 /// `mlirOperationGetDiscardableAttributeByName`.
655 MLIR_CAPI_EXPORTED MlirAttribute
656 mlirOperationGetAttributeByName(MlirOperation op
, MlirStringRef name
);
658 /// Sets an attribute by name, replacing the existing if it exists or
659 /// adding a new one otherwise.
660 /// Deprecated, please use `mlirOperationSetInherentAttributeByName` or
661 /// `mlirOperationSetDiscardableAttributeByName`.
662 MLIR_CAPI_EXPORTED
void mlirOperationSetAttributeByName(MlirOperation op
,
666 /// Removes an attribute by name. Returns false if the attribute was not found
667 /// and true if removed.
668 /// Deprecated, please use `mlirOperationRemoveInherentAttributeByName` or
669 /// `mlirOperationRemoveDiscardableAttributeByName`.
670 MLIR_CAPI_EXPORTED
bool mlirOperationRemoveAttributeByName(MlirOperation op
,
673 /// Prints an operation by sending chunks of the string representation and
674 /// forwarding `userData to `callback`. Note that the callback may be called
675 /// several times with consecutive chunks of the string.
676 MLIR_CAPI_EXPORTED
void mlirOperationPrint(MlirOperation op
,
677 MlirStringCallback callback
,
680 /// Same as mlirOperationPrint but accepts flags controlling the printing
682 MLIR_CAPI_EXPORTED
void mlirOperationPrintWithFlags(MlirOperation op
,
683 MlirOpPrintingFlags flags
,
684 MlirStringCallback callback
,
687 /// Same as mlirOperationPrint but accepts AsmState controlling the printing
688 /// behavior as well as caching computed names.
689 MLIR_CAPI_EXPORTED
void mlirOperationPrintWithState(MlirOperation op
,
691 MlirStringCallback callback
,
694 /// Same as mlirOperationPrint but writing the bytecode format.
695 MLIR_CAPI_EXPORTED
void mlirOperationWriteBytecode(MlirOperation op
,
696 MlirStringCallback callback
,
699 /// Same as mlirOperationWriteBytecode but with writer config and returns
700 /// failure only if desired bytecode could not be honored.
701 MLIR_CAPI_EXPORTED MlirLogicalResult
mlirOperationWriteBytecodeWithConfig(
702 MlirOperation op
, MlirBytecodeWriterConfig config
,
703 MlirStringCallback callback
, void *userData
);
705 /// Prints an operation to stderr.
706 MLIR_CAPI_EXPORTED
void mlirOperationDump(MlirOperation op
);
708 /// Verify the operation and return true if it passes, false if it fails.
709 MLIR_CAPI_EXPORTED
bool mlirOperationVerify(MlirOperation op
);
711 /// Moves the given operation immediately after the other operation in its
712 /// parent block. The given operation may be owned by the caller or by its
713 /// current block. The other operation must belong to a block. In any case, the
714 /// ownership is transferred to the block of the other operation.
715 MLIR_CAPI_EXPORTED
void mlirOperationMoveAfter(MlirOperation op
,
716 MlirOperation other
);
718 /// Moves the given operation immediately before the other operation in its
719 /// parent block. The given operation may be owner by the caller or by its
720 /// current block. The other operation must belong to a block. In any case, the
721 /// ownership is transferred to the block of the other operation.
722 MLIR_CAPI_EXPORTED
void mlirOperationMoveBefore(MlirOperation op
,
723 MlirOperation other
);
725 /// Operation walk result.
726 typedef enum MlirWalkResult
{
727 MlirWalkResultAdvance
,
728 MlirWalkResultInterrupt
,
732 /// Traversal order for operation walk.
733 typedef enum MlirWalkOrder
{
738 /// Operation walker type. The handler is passed an (opaque) reference to an
739 /// operation and a pointer to a `userData`.
740 typedef MlirWalkResult (*MlirOperationWalkCallback
)(MlirOperation
,
743 /// Walks operation `op` in `walkOrder` and calls `callback` on that operation.
744 /// `*userData` is passed to the callback as well and can be used to tunnel some
745 /// context or other data into the callback.
747 void mlirOperationWalk(MlirOperation op
, MlirOperationWalkCallback callback
,
748 void *userData
, MlirWalkOrder walkOrder
);
750 //===----------------------------------------------------------------------===//
752 //===----------------------------------------------------------------------===//
754 /// Creates a new empty region and transfers ownership to the caller.
755 MLIR_CAPI_EXPORTED MlirRegion
mlirRegionCreate(void);
757 /// Takes a region owned by the caller and destroys it.
758 MLIR_CAPI_EXPORTED
void mlirRegionDestroy(MlirRegion region
);
760 /// Checks whether a region is null.
761 static inline bool mlirRegionIsNull(MlirRegion region
) { return !region
.ptr
; }
763 /// Checks whether two region handles point to the same region. This does not
764 /// perform deep comparison.
765 MLIR_CAPI_EXPORTED
bool mlirRegionEqual(MlirRegion region
, MlirRegion other
);
767 /// Gets the first block in the region.
768 MLIR_CAPI_EXPORTED MlirBlock
mlirRegionGetFirstBlock(MlirRegion region
);
770 /// Takes a block owned by the caller and appends it to the given region.
771 MLIR_CAPI_EXPORTED
void mlirRegionAppendOwnedBlock(MlirRegion region
,
774 /// Takes a block owned by the caller and inserts it at `pos` to the given
775 /// region. This is an expensive operation that linearly scans the region,
776 /// prefer insertAfter/Before instead.
777 MLIR_CAPI_EXPORTED
void
778 mlirRegionInsertOwnedBlock(MlirRegion region
, intptr_t pos
, MlirBlock block
);
780 /// Takes a block owned by the caller and inserts it after the (non-owned)
781 /// reference block in the given region. The reference block must belong to the
782 /// region. If the reference block is null, prepends the block to the region.
783 MLIR_CAPI_EXPORTED
void mlirRegionInsertOwnedBlockAfter(MlirRegion region
,
787 /// Takes a block owned by the caller and inserts it before the (non-owned)
788 /// reference block in the given region. The reference block must belong to the
789 /// region. If the reference block is null, appends the block to the region.
790 MLIR_CAPI_EXPORTED
void mlirRegionInsertOwnedBlockBefore(MlirRegion region
,
794 /// Returns first region attached to the operation.
795 MLIR_CAPI_EXPORTED MlirRegion
mlirOperationGetFirstRegion(MlirOperation op
);
797 /// Returns the region immediately following the given region in its parent
799 MLIR_CAPI_EXPORTED MlirRegion
mlirRegionGetNextInOperation(MlirRegion region
);
801 /// Moves the entire content of the source region to the target region.
802 MLIR_CAPI_EXPORTED
void mlirRegionTakeBody(MlirRegion target
,
805 //===----------------------------------------------------------------------===//
807 //===----------------------------------------------------------------------===//
809 /// Creates a new empty block with the given argument types and transfers
810 /// ownership to the caller.
811 MLIR_CAPI_EXPORTED MlirBlock
mlirBlockCreate(intptr_t nArgs
,
812 MlirType
const *args
,
813 MlirLocation
const *locs
);
815 /// Takes a block owned by the caller and destroys it.
816 MLIR_CAPI_EXPORTED
void mlirBlockDestroy(MlirBlock block
);
818 /// Detach a block from the owning region and assume ownership.
819 MLIR_CAPI_EXPORTED
void mlirBlockDetach(MlirBlock block
);
821 /// Checks whether a block is null.
822 static inline bool mlirBlockIsNull(MlirBlock block
) { return !block
.ptr
; }
824 /// Checks whether two blocks handles point to the same block. This does not
825 /// perform deep comparison.
826 MLIR_CAPI_EXPORTED
bool mlirBlockEqual(MlirBlock block
, MlirBlock other
);
828 /// Returns the closest surrounding operation that contains this block.
829 MLIR_CAPI_EXPORTED MlirOperation
mlirBlockGetParentOperation(MlirBlock
);
831 /// Returns the region that contains this block.
832 MLIR_CAPI_EXPORTED MlirRegion
mlirBlockGetParentRegion(MlirBlock block
);
834 /// Returns the block immediately following the given block in its parent
836 MLIR_CAPI_EXPORTED MlirBlock
mlirBlockGetNextInRegion(MlirBlock block
);
838 /// Returns the first operation in the block.
839 MLIR_CAPI_EXPORTED MlirOperation
mlirBlockGetFirstOperation(MlirBlock block
);
841 /// Returns the terminator operation in the block or null if no terminator.
842 MLIR_CAPI_EXPORTED MlirOperation
mlirBlockGetTerminator(MlirBlock block
);
844 /// Takes an operation owned by the caller and appends it to the block.
845 MLIR_CAPI_EXPORTED
void mlirBlockAppendOwnedOperation(MlirBlock block
,
846 MlirOperation operation
);
848 /// Takes an operation owned by the caller and inserts it as `pos` to the block.
849 /// This is an expensive operation that scans the block linearly, prefer
850 /// insertBefore/After instead.
851 MLIR_CAPI_EXPORTED
void mlirBlockInsertOwnedOperation(MlirBlock block
,
853 MlirOperation operation
);
855 /// Takes an operation owned by the caller and inserts it after the (non-owned)
856 /// reference operation in the given block. If the reference is null, prepends
857 /// the operation. Otherwise, the reference must belong to the block.
858 MLIR_CAPI_EXPORTED
void
859 mlirBlockInsertOwnedOperationAfter(MlirBlock block
, MlirOperation reference
,
860 MlirOperation operation
);
862 /// Takes an operation owned by the caller and inserts it before the (non-owned)
863 /// reference operation in the given block. If the reference is null, appends
864 /// the operation. Otherwise, the reference must belong to the block.
865 MLIR_CAPI_EXPORTED
void
866 mlirBlockInsertOwnedOperationBefore(MlirBlock block
, MlirOperation reference
,
867 MlirOperation operation
);
869 /// Returns the number of arguments of the block.
870 MLIR_CAPI_EXPORTED
intptr_t mlirBlockGetNumArguments(MlirBlock block
);
872 /// Appends an argument of the specified type to the block. Returns the newly
874 MLIR_CAPI_EXPORTED MlirValue
mlirBlockAddArgument(MlirBlock block
,
878 /// Erase the argument at 'index' and remove it from the argument list.
879 MLIR_CAPI_EXPORTED
void mlirBlockEraseArgument(MlirBlock block
, unsigned index
);
881 /// Inserts an argument of the specified type at a specified index to the block.
882 /// Returns the newly added argument.
883 MLIR_CAPI_EXPORTED MlirValue
mlirBlockInsertArgument(MlirBlock block
,
888 /// Returns `pos`-th argument of the block.
889 MLIR_CAPI_EXPORTED MlirValue
mlirBlockGetArgument(MlirBlock block
,
892 /// Prints a block by sending chunks of the string representation and
893 /// forwarding `userData to `callback`. Note that the callback may be called
894 /// several times with consecutive chunks of the string.
895 MLIR_CAPI_EXPORTED
void
896 mlirBlockPrint(MlirBlock block
, MlirStringCallback callback
, void *userData
);
898 //===----------------------------------------------------------------------===//
900 //===----------------------------------------------------------------------===//
902 /// Returns whether the value is null.
903 static inline bool mlirValueIsNull(MlirValue value
) { return !value
.ptr
; }
905 /// Returns 1 if two values are equal, 0 otherwise.
906 MLIR_CAPI_EXPORTED
bool mlirValueEqual(MlirValue value1
, MlirValue value2
);
908 /// Returns 1 if the value is a block argument, 0 otherwise.
909 MLIR_CAPI_EXPORTED
bool mlirValueIsABlockArgument(MlirValue value
);
911 /// Returns 1 if the value is an operation result, 0 otherwise.
912 MLIR_CAPI_EXPORTED
bool mlirValueIsAOpResult(MlirValue value
);
914 /// Returns the block in which this value is defined as an argument. Asserts if
915 /// the value is not a block argument.
916 MLIR_CAPI_EXPORTED MlirBlock
mlirBlockArgumentGetOwner(MlirValue value
);
918 /// Returns the position of the value in the argument list of its block.
919 MLIR_CAPI_EXPORTED
intptr_t mlirBlockArgumentGetArgNumber(MlirValue value
);
921 /// Sets the type of the block argument to the given type.
922 MLIR_CAPI_EXPORTED
void mlirBlockArgumentSetType(MlirValue value
,
925 /// Returns an operation that produced this value as its result. Asserts if the
926 /// value is not an op result.
927 MLIR_CAPI_EXPORTED MlirOperation
mlirOpResultGetOwner(MlirValue value
);
929 /// Returns the position of the value in the list of results of the operation
930 /// that produced it.
931 MLIR_CAPI_EXPORTED
intptr_t mlirOpResultGetResultNumber(MlirValue value
);
933 /// Returns the type of the value.
934 MLIR_CAPI_EXPORTED MlirType
mlirValueGetType(MlirValue value
);
936 /// Set the type of the value.
937 MLIR_CAPI_EXPORTED
void mlirValueSetType(MlirValue value
, MlirType type
);
939 /// Prints the value to the standard error stream.
940 MLIR_CAPI_EXPORTED
void mlirValueDump(MlirValue value
);
942 /// Prints a value by sending chunks of the string representation and
943 /// forwarding `userData to `callback`. Note that the callback may be called
944 /// several times with consecutive chunks of the string.
945 MLIR_CAPI_EXPORTED
void
946 mlirValuePrint(MlirValue value
, MlirStringCallback callback
, void *userData
);
948 /// Prints a value as an operand (i.e., the ValueID).
949 MLIR_CAPI_EXPORTED
void mlirValuePrintAsOperand(MlirValue value
,
951 MlirStringCallback callback
,
954 /// Returns an op operand representing the first use of the value, or a null op
955 /// operand if there are no uses.
956 MLIR_CAPI_EXPORTED MlirOpOperand
mlirValueGetFirstUse(MlirValue value
);
958 /// Replace all uses of 'of' value with the 'with' value, updating anything in
959 /// the IR that uses 'of' to use the other value instead. When this returns
960 /// there are zero uses of 'of'.
961 MLIR_CAPI_EXPORTED
void mlirValueReplaceAllUsesOfWith(MlirValue of
,
964 /// Replace all uses of 'of' value with 'with' value, updating anything in the
965 /// IR that uses 'of' to use 'with' instead, except if the user is listed in
966 /// 'exceptions'. The 'exceptions' parameter is an array of MlirOperation
967 /// pointers with a length of 'numExceptions'.
968 MLIR_CAPI_EXPORTED
void
969 mlirValueReplaceAllUsesExcept(MlirValue of
, MlirValue with
,
970 intptr_t numExceptions
,
971 MlirOperation
*exceptions
);
973 //===----------------------------------------------------------------------===//
975 //===----------------------------------------------------------------------===//
977 /// Returns whether the op operand is null.
978 MLIR_CAPI_EXPORTED
bool mlirOpOperandIsNull(MlirOpOperand opOperand
);
980 /// Returns the value of an op operand.
981 MLIR_CAPI_EXPORTED MlirValue
mlirOpOperandGetValue(MlirOpOperand opOperand
);
983 /// Returns the owner operation of an op operand.
984 MLIR_CAPI_EXPORTED MlirOperation
mlirOpOperandGetOwner(MlirOpOperand opOperand
);
986 /// Returns the operand number of an op operand.
987 MLIR_CAPI_EXPORTED
unsigned
988 mlirOpOperandGetOperandNumber(MlirOpOperand opOperand
);
990 /// Returns an op operand representing the next use of the value, or a null op
991 /// operand if there is no next use.
992 MLIR_CAPI_EXPORTED MlirOpOperand
993 mlirOpOperandGetNextUse(MlirOpOperand opOperand
);
995 //===----------------------------------------------------------------------===//
997 //===----------------------------------------------------------------------===//
999 /// Parses a type. The type is owned by the context.
1000 MLIR_CAPI_EXPORTED MlirType
mlirTypeParseGet(MlirContext context
,
1001 MlirStringRef type
);
1003 /// Gets the context that a type was created with.
1004 MLIR_CAPI_EXPORTED MlirContext
mlirTypeGetContext(MlirType type
);
1006 /// Gets the type ID of the type.
1007 MLIR_CAPI_EXPORTED MlirTypeID
mlirTypeGetTypeID(MlirType type
);
1009 /// Gets the dialect a type belongs to.
1010 MLIR_CAPI_EXPORTED MlirDialect
mlirTypeGetDialect(MlirType type
);
1012 /// Checks whether a type is null.
1013 static inline bool mlirTypeIsNull(MlirType type
) { return !type
.ptr
; }
1015 /// Checks if two types are equal.
1016 MLIR_CAPI_EXPORTED
bool mlirTypeEqual(MlirType t1
, MlirType t2
);
1018 /// Prints a location by sending chunks of the string representation and
1019 /// forwarding `userData to `callback`. Note that the callback may be called
1020 /// several times with consecutive chunks of the string.
1021 MLIR_CAPI_EXPORTED
void
1022 mlirTypePrint(MlirType type
, MlirStringCallback callback
, void *userData
);
1024 /// Prints the type to the standard error stream.
1025 MLIR_CAPI_EXPORTED
void mlirTypeDump(MlirType type
);
1027 //===----------------------------------------------------------------------===//
1029 //===----------------------------------------------------------------------===//
1031 /// Parses an attribute. The attribute is owned by the context.
1032 MLIR_CAPI_EXPORTED MlirAttribute
mlirAttributeParseGet(MlirContext context
,
1033 MlirStringRef attr
);
1035 /// Gets the context that an attribute was created with.
1036 MLIR_CAPI_EXPORTED MlirContext
mlirAttributeGetContext(MlirAttribute attribute
);
1038 /// Gets the type of this attribute.
1039 MLIR_CAPI_EXPORTED MlirType
mlirAttributeGetType(MlirAttribute attribute
);
1041 /// Gets the type id of the attribute.
1042 MLIR_CAPI_EXPORTED MlirTypeID
mlirAttributeGetTypeID(MlirAttribute attribute
);
1044 /// Gets the dialect of the attribute.
1045 MLIR_CAPI_EXPORTED MlirDialect
mlirAttributeGetDialect(MlirAttribute attribute
);
1047 /// Checks whether an attribute is null.
1048 static inline bool mlirAttributeIsNull(MlirAttribute attr
) { return !attr
.ptr
; }
1050 /// Checks if two attributes are equal.
1051 MLIR_CAPI_EXPORTED
bool mlirAttributeEqual(MlirAttribute a1
, MlirAttribute a2
);
1053 /// Prints an attribute by sending chunks of the string representation and
1054 /// forwarding `userData to `callback`. Note that the callback may be called
1055 /// several times with consecutive chunks of the string.
1056 MLIR_CAPI_EXPORTED
void mlirAttributePrint(MlirAttribute attr
,
1057 MlirStringCallback callback
,
1060 /// Prints the attribute to the standard error stream.
1061 MLIR_CAPI_EXPORTED
void mlirAttributeDump(MlirAttribute attr
);
1063 /// Associates an attribute with the name. Takes ownership of neither.
1064 MLIR_CAPI_EXPORTED MlirNamedAttribute
mlirNamedAttributeGet(MlirIdentifier name
,
1065 MlirAttribute attr
);
1067 //===----------------------------------------------------------------------===//
1069 //===----------------------------------------------------------------------===//
1071 /// Gets an identifier with the given string value.
1072 MLIR_CAPI_EXPORTED MlirIdentifier
mlirIdentifierGet(MlirContext context
,
1075 /// Returns the context associated with this identifier
1076 MLIR_CAPI_EXPORTED MlirContext
mlirIdentifierGetContext(MlirIdentifier
);
1078 /// Checks whether two identifiers are the same.
1079 MLIR_CAPI_EXPORTED
bool mlirIdentifierEqual(MlirIdentifier ident
,
1080 MlirIdentifier other
);
1082 /// Gets the string value of the identifier.
1083 MLIR_CAPI_EXPORTED MlirStringRef
mlirIdentifierStr(MlirIdentifier ident
);
1085 //===----------------------------------------------------------------------===//
1086 // Symbol and SymbolTable API.
1087 //===----------------------------------------------------------------------===//
1089 /// Returns the name of the attribute used to store symbol names compatible with
1091 MLIR_CAPI_EXPORTED MlirStringRef
mlirSymbolTableGetSymbolAttributeName(void);
1093 /// Returns the name of the attribute used to store symbol visibility.
1094 MLIR_CAPI_EXPORTED MlirStringRef
1095 mlirSymbolTableGetVisibilityAttributeName(void);
1097 /// Creates a symbol table for the given operation. If the operation does not
1098 /// have the SymbolTable trait, returns a null symbol table.
1099 MLIR_CAPI_EXPORTED MlirSymbolTable
1100 mlirSymbolTableCreate(MlirOperation operation
);
1102 /// Returns true if the symbol table is null.
1103 static inline bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable
) {
1104 return !symbolTable
.ptr
;
1107 /// Destroys the symbol table created with mlirSymbolTableCreate. This does not
1108 /// affect the operations in the table.
1109 MLIR_CAPI_EXPORTED
void mlirSymbolTableDestroy(MlirSymbolTable symbolTable
);
1111 /// Looks up a symbol with the given name in the given symbol table and returns
1112 /// the operation that corresponds to the symbol. If the symbol cannot be found,
1113 /// returns a null operation.
1114 MLIR_CAPI_EXPORTED MlirOperation
1115 mlirSymbolTableLookup(MlirSymbolTable symbolTable
, MlirStringRef name
);
1117 /// Inserts the given operation into the given symbol table. The operation must
1118 /// have the symbol trait. If the symbol table already has a symbol with the
1119 /// same name, renames the symbol being inserted to ensure name uniqueness. Note
1120 /// that this does not move the operation itself into the block of the symbol
1121 /// table operation, this should be done separately. Returns the name of the
1122 /// symbol after insertion.
1123 MLIR_CAPI_EXPORTED MlirAttribute
1124 mlirSymbolTableInsert(MlirSymbolTable symbolTable
, MlirOperation operation
);
1126 /// Removes the given operation from the symbol table and erases it.
1127 MLIR_CAPI_EXPORTED
void mlirSymbolTableErase(MlirSymbolTable symbolTable
,
1128 MlirOperation operation
);
1130 /// Attempt to replace all uses that are nested within the given operation
1131 /// of the given symbol 'oldSymbol' with the provided 'newSymbol'. This does
1132 /// not traverse into nested symbol tables. Will fail atomically if there are
1133 /// any unknown operations that may be potential symbol tables.
1134 MLIR_CAPI_EXPORTED MlirLogicalResult
mlirSymbolTableReplaceAllSymbolUses(
1135 MlirStringRef oldSymbol
, MlirStringRef newSymbol
, MlirOperation from
);
1137 /// Walks all symbol table operations nested within, and including, `op`. For
1138 /// each symbol table operation, the provided callback is invoked with the op
1139 /// and a boolean signifying if the symbols within that symbol table can be
1140 /// treated as if all uses within the IR are visible to the caller.
1141 /// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
1142 /// within `op` are visible.
1143 MLIR_CAPI_EXPORTED
void mlirSymbolTableWalkSymbolTables(
1144 MlirOperation from
, bool allSymUsesVisible
,
1145 void (*callback
)(MlirOperation
, bool, void *userData
), void *userData
);
1151 #endif // MLIR_C_IR_H