MLIR 23.0.0git
IR.h
Go to the documentation of this file.
1//===-- mlir-c/IR.h - C API to Core MLIR IR classes ---------------*- 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 core IR classes.
11//
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.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef MLIR_C_IR_H
19#define MLIR_C_IR_H
20
21#include <stdbool.h>
22#include <stdint.h>
23
24#include "mlir-c/Support.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30//===----------------------------------------------------------------------===//
31/// Opaque type declarations.
32///
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.
38///
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.
42
43//===----------------------------------------------------------------------===//
44
45#define DEFINE_C_API_STRUCT(name, storage) \
46 struct name { \
47 storage *ptr; \
48 }; \
49 typedef struct name name
50
51DEFINE_C_API_STRUCT(MlirAsmState, void);
52DEFINE_C_API_STRUCT(MlirBytecodeWriterConfig, void);
53DEFINE_C_API_STRUCT(MlirContext, void);
54DEFINE_C_API_STRUCT(MlirDialect, void);
55DEFINE_C_API_STRUCT(MlirDialectRegistry, void);
56DEFINE_C_API_STRUCT(MlirOperation, void);
57DEFINE_C_API_STRUCT(MlirOpOperand, void);
58DEFINE_C_API_STRUCT(MlirOpPrintingFlags, void);
59DEFINE_C_API_STRUCT(MlirBlock, void);
60DEFINE_C_API_STRUCT(MlirRegion, void);
61DEFINE_C_API_STRUCT(MlirSymbolTable, void);
62
63DEFINE_C_API_STRUCT(MlirAttribute, const void);
64DEFINE_C_API_STRUCT(MlirIdentifier, const void);
65DEFINE_C_API_STRUCT(MlirLocation, const void);
66DEFINE_C_API_STRUCT(MlirModule, const void);
67DEFINE_C_API_STRUCT(MlirType, const void);
68DEFINE_C_API_STRUCT(MlirValue, const void);
69
70#undef DEFINE_C_API_STRUCT
71
72/// Named MLIR attribute.
73///
74/// A named attribute is essentially a (name, attribute) pair where the name is
75/// a string.
77 MlirIdentifier name;
78 MlirAttribute attribute;
79};
81
82//===----------------------------------------------------------------------===//
83// Context API.
84//===----------------------------------------------------------------------===//
85
86/// Creates an MLIR context and transfers its ownership to the caller.
87/// This sets the default multithreading option (enabled).
89
90/// Creates an MLIR context with an explicit setting of the multithreading
91/// setting and transfers its ownership to the caller.
92MLIR_CAPI_EXPORTED MlirContext
93mlirContextCreateWithThreading(bool threadingEnabled);
94
95/// Creates an MLIR context, setting the multithreading setting explicitly and
96/// pre-loading the dialects from the provided DialectRegistry.
98 MlirDialectRegistry registry, bool threadingEnabled);
99
100/// Checks if two contexts are equal.
101MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2);
102
103/// Checks whether a context is null.
104static inline bool mlirContextIsNull(MlirContext context) {
105 return !context.ptr;
106}
107
108/// Takes an MLIR context owned by the caller and destroys it.
109MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context);
110
111/// Sets whether unregistered dialects are allowed in this context.
113mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow);
114
115/// Returns whether the context allows unregistered dialects.
117mlirContextGetAllowUnregisteredDialects(MlirContext context);
118
119/// Returns the number of dialects registered with the given context. A
120/// registered dialect will be loaded if needed by the parser.
122mlirContextGetNumRegisteredDialects(MlirContext context);
123
124/// Append the contents of the given dialect registry to the registry associated
125/// with the context.
127mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry);
128
129/// Returns the number of dialects loaded by the context.
130
132mlirContextGetNumLoadedDialects(MlirContext context);
133
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
138/// dialect.
139MLIR_CAPI_EXPORTED MlirDialect mlirContextGetOrLoadDialect(MlirContext context,
141
142/// Set threading mode (must be set to false to mlir-print-ir-after-all).
144 bool enable);
145
146/// Eagerly loads all available dialects registered with a context, making
147/// them available for use for IR construction.
149mlirContextLoadAllAvailableDialects(MlirContext context);
150
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
154/// dialect.
157
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.
162MLIR_CAPI_EXPORTED void mlirContextSetThreadPool(MlirContext context,
163 MlirLlvmThreadPool threadPool);
164
165/// Gets the number of threads of the thread pool of the context when
166/// multithreading is enabled. Returns 1 if no multithreading.
167MLIR_CAPI_EXPORTED unsigned mlirContextGetNumThreads(MlirContext context);
168
169/// Gets the thread pool of the context when enabled multithreading, otherwise
170/// an assertion is raised.
171MLIR_CAPI_EXPORTED MlirLlvmThreadPool
172mlirContextGetThreadPool(MlirContext context);
173
174//===----------------------------------------------------------------------===//
175// Dialect API.
176//===----------------------------------------------------------------------===//
177
178/// Returns the context that owns the dialect.
179MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect);
180
181/// Checks if the dialect is null.
182static inline bool mlirDialectIsNull(MlirDialect dialect) {
183 return !dialect.ptr;
184}
185
186/// Checks if two dialects that belong to the same context are equal. Dialects
187/// from different contexts will not compare equal.
188MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1,
189 MlirDialect dialect2);
190
191/// Returns the namespace of the given dialect.
193
194//===----------------------------------------------------------------------===//
195// DialectHandle API.
196// Registration entry-points for each dialect are declared using the common
197// MLIR_DECLARE_DIALECT_REGISTRATION_CAPI macro, which takes the dialect
198// API name (i.e. "Func", "Tensor", "Linalg") and namespace (i.e. "func",
199// "tensor", "linalg"). The following declarations are produced:
200//
201// /// Gets the above hook methods in struct form for a dialect by namespace.
202// /// This is intended to facilitate dynamic lookup and registration of
203// /// dialects via a plugin facility based on shared library symbol lookup.
204// const MlirDialectHandle *mlirGetDialectHandle__{NAMESPACE}__();
205//
206// This is done via a common macro to facilitate future expansion to
207// registration schemes.
208//===----------------------------------------------------------------------===//
209
211 const void *ptr;
212};
214
215#define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace) \
216 MLIR_CAPI_EXPORTED MlirDialectHandle mlirGetDialectHandle__##Namespace##__( \
217 void)
218
219/// Returns the namespace associated with the provided dialect handle.
222
223/// Inserts the dialect associated with the provided dialect handle into the
224/// provided dialect registry
226 MlirDialectRegistry);
227
228/// Registers the dialect associated with the provided dialect handle.
230 MlirContext);
231
232/// Loads the dialect associated with the provided dialect handle.
234 MlirContext);
235
236//===----------------------------------------------------------------------===//
237// DialectRegistry API.
238//===----------------------------------------------------------------------===//
239
240/// Creates a dialect registry and transfers its ownership to the caller.
241MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void);
242
243/// Checks if the dialect registry is null.
244static inline bool mlirDialectRegistryIsNull(MlirDialectRegistry registry) {
245 return !registry.ptr;
246}
247
248/// Takes a dialect registry owned by the caller and destroys it.
250mlirDialectRegistryDestroy(MlirDialectRegistry registry);
251
252//===----------------------------------------------------------------------===//
253// Location API.
254//===----------------------------------------------------------------------===//
255
256/// Returns the underlying location attribute of this location.
257MLIR_CAPI_EXPORTED MlirAttribute
258mlirLocationGetAttribute(MlirLocation location);
259
260/// Creates a location from a location attribute.
261MLIR_CAPI_EXPORTED MlirLocation
262mlirLocationFromAttribute(MlirAttribute attribute);
263
264/// Creates an File/Line/Column location owned by the given context.
266 MlirContext context, MlirStringRef filename, unsigned line, unsigned col);
267
268/// Creates an File/Line/Column range location owned by the given context.
270 MlirContext context, MlirStringRef filename, unsigned start_line,
271 unsigned start_col, unsigned end_line, unsigned end_col);
272
273/// Getter for filename of FileLineColRange.
274MLIR_CAPI_EXPORTED MlirIdentifier
275mlirLocationFileLineColRangeGetFilename(MlirLocation location);
276
277/// Getter for start_line of FileLineColRange.
279mlirLocationFileLineColRangeGetStartLine(MlirLocation location);
280
281/// Getter for start_column of FileLineColRange.
283mlirLocationFileLineColRangeGetStartColumn(MlirLocation location);
284
285/// Getter for end_line of FileLineColRange.
287mlirLocationFileLineColRangeGetEndLine(MlirLocation location);
288
289/// Getter for end_column of FileLineColRange.
291mlirLocationFileLineColRangeGetEndColumn(MlirLocation location);
292
293/// TypeID Getter for FileLineColRange.
295
296/// Checks whether the given location is an FileLineColRange.
297MLIR_CAPI_EXPORTED bool mlirLocationIsAFileLineColRange(MlirLocation location);
298
299/// Creates a call site location with a callee and a caller.
300MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
301 MlirLocation caller);
302
303/// Getter for callee of CallSite.
304MLIR_CAPI_EXPORTED MlirLocation
305mlirLocationCallSiteGetCallee(MlirLocation location);
306
307/// Getter for caller of CallSite.
308MLIR_CAPI_EXPORTED MlirLocation
309mlirLocationCallSiteGetCaller(MlirLocation location);
310
311/// TypeID Getter for CallSite.
313
314/// Checks whether the given location is an CallSite.
315MLIR_CAPI_EXPORTED bool mlirLocationIsACallSite(MlirLocation location);
316
317/// Creates a fused location with an array of locations and metadata.
318MLIR_CAPI_EXPORTED MlirLocation
319mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
320 MlirLocation const *locations, MlirAttribute metadata);
321
322/// Getter for number of locations fused together.
323MLIR_CAPI_EXPORTED unsigned
324mlirLocationFusedGetNumLocations(MlirLocation location);
325
326/// Getter for locations of Fused. Requires pre-allocated memory of
327/// #fusedLocations X sizeof(MlirLocation).
329mlirLocationFusedGetLocations(MlirLocation location,
330 MlirLocation *locationsCPtr);
331
332/// Getter for metadata of Fused.
333MLIR_CAPI_EXPORTED MlirAttribute
334mlirLocationFusedGetMetadata(MlirLocation location);
335
336/// TypeID Getter for Fused.
338
339/// Checks whether the given location is an Fused.
340MLIR_CAPI_EXPORTED bool mlirLocationIsAFused(MlirLocation location);
341
342/// Creates a name location owned by the given context. Providing null location
343/// for childLoc is allowed and if childLoc is null location, then the behavior
344/// is the same as having unknown child location.
345MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context,
346 MlirStringRef name,
347 MlirLocation childLoc);
348
349/// Getter for name of Name.
350MLIR_CAPI_EXPORTED MlirIdentifier
351mlirLocationNameGetName(MlirLocation location);
352
353/// Getter for childLoc of Name.
354MLIR_CAPI_EXPORTED MlirLocation
355mlirLocationNameGetChildLoc(MlirLocation location);
356
357/// TypeID Getter for Name.
359
360/// Checks whether the given location is an Name.
361MLIR_CAPI_EXPORTED bool mlirLocationIsAName(MlirLocation location);
362
363/// Creates a location with unknown position owned by the given context.
364MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context);
365
366/// Gets the context that a location was created with.
367MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location);
368
369/// Checks if the location is null.
370static inline bool mlirLocationIsNull(MlirLocation location) {
371 return !location.ptr;
372}
373
374/// Checks if two locations are equal.
375MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2);
376
377/// Prints a location by sending chunks of the string representation and
378/// forwarding `userData to `callback`. Note that the callback may be called
379/// several times with consecutive chunks of the string.
380MLIR_CAPI_EXPORTED void mlirLocationPrint(MlirLocation location,
381 MlirStringCallback callback,
382 void *userData);
383
384//===----------------------------------------------------------------------===//
385// Module API.
386//===----------------------------------------------------------------------===//
387
388/// Creates a new, empty module and transfers ownership to the caller.
389MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateEmpty(MlirLocation location);
390
391/// Parses a module from the string and transfers ownership to the caller.
392MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateParse(MlirContext context,
393 MlirStringRef module);
394
395/// Parses a module from file and transfers ownership to the caller.
396MLIR_CAPI_EXPORTED MlirModule
397mlirModuleCreateParseFromFile(MlirContext context, MlirStringRef fileName);
398
399/// Gets the context that a module was created with.
400MLIR_CAPI_EXPORTED MlirContext mlirModuleGetContext(MlirModule module);
401
402/// Gets the body of the module, i.e. the only block it contains.
403MLIR_CAPI_EXPORTED MlirBlock mlirModuleGetBody(MlirModule module);
404
405/// Checks whether a module is null.
406static inline bool mlirModuleIsNull(MlirModule module) { return !module.ptr; }
407
408/// Takes a module owned by the caller and deletes it.
409MLIR_CAPI_EXPORTED void mlirModuleDestroy(MlirModule module);
410
411/// Views the module as a generic operation.
412MLIR_CAPI_EXPORTED MlirOperation mlirModuleGetOperation(MlirModule module);
413
414/// Views the generic operation as a module.
415/// The returned module is null when the input operation was not a ModuleOp.
416MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op);
417
418/// Checks if two modules are equal.
419MLIR_CAPI_EXPORTED bool mlirModuleEqual(MlirModule lhs, MlirModule rhs);
420
421/// Compute a hash for the given module.
422MLIR_CAPI_EXPORTED size_t mlirModuleHashValue(MlirModule mod);
423
424//===----------------------------------------------------------------------===//
425// Operation state.
426//===----------------------------------------------------------------------===//
427
428/// An auxiliary class for constructing operations.
429///
430/// This class contains all the information necessary to construct the
431/// operation. It owns the MlirRegions it has pointers to and does not own
432/// anything else. By default, the state can be constructed from a name and
433/// location, the latter being also used to access the context, and has no other
434/// components. These components can be added progressively until the operation
435/// is constructed. Users are not expected to rely on the internals of this
436/// class and should use mlirOperationState* functions instead.
437
438struct MlirOperationState {
439 MlirStringRef name;
440 MlirLocation location;
441 intptr_t nResults;
442 MlirType *results;
443 intptr_t nOperands;
444 MlirValue *operands;
445 intptr_t nRegions;
446 MlirRegion *regions;
447 intptr_t nSuccessors;
448 MlirBlock *successors;
449 intptr_t nAttributes;
450 MlirNamedAttribute *attributes;
451 bool enableResultTypeInference;
452};
453typedef struct MlirOperationState MlirOperationState;
454
455/// Constructs an operation state from a name and a location.
457 MlirLocation loc);
458
459/// Adds a list of components to the operation state.
460MLIR_CAPI_EXPORTED void mlirOperationStateAddResults(MlirOperationState *state,
461 intptr_t n,
462 MlirType const *results);
464mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n,
465 MlirValue const *operands);
467mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n,
468 MlirRegion const *regions);
470mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n,
471 MlirBlock const *successors);
473mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n,
474 MlirNamedAttribute const *attributes);
475
476/// Enables result type inference for the operation under construction. If
477/// enabled, then the caller must not have called
478/// mlirOperationStateAddResults(). Note that if enabled, the
479/// mlirOperationCreate() call is failable: it will return a null operation
480/// on inference failure and will emit diagnostics.
482mlirOperationStateEnableResultTypeInference(MlirOperationState *state);
483
484//===----------------------------------------------------------------------===//
485// AsmState API.
486// While many of these are simple settings that could be represented in a
487// struct, they are wrapped in a heap allocated object and accessed via
488// functions to maximize the possibility of compatibility over time.
489//===----------------------------------------------------------------------===//
490
491/// Creates new AsmState, as with AsmState the IR should not be mutated
492/// in-between using this state.
493/// Must be freed with a call to mlirAsmStateDestroy().
494// TODO: This should be expanded to handle location & resouce map.
495MLIR_CAPI_EXPORTED MlirAsmState
496mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags);
497
498/// Creates new AsmState from value.
499/// Must be freed with a call to mlirAsmStateDestroy().
500// TODO: This should be expanded to handle location & resouce map.
501MLIR_CAPI_EXPORTED MlirAsmState
502mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags);
503
504/// Destroys printing flags created with mlirAsmStateCreate.
505MLIR_CAPI_EXPORTED void mlirAsmStateDestroy(MlirAsmState state);
506
507//===----------------------------------------------------------------------===//
508// Op Printing flags API.
509// While many of these are simple settings that could be represented in a
510// struct, they are wrapped in a heap allocated object and accessed via
511// functions to maximize the possibility of compatibility over time.
512//===----------------------------------------------------------------------===//
513
514/// Creates new printing flags with defaults, intended for customization.
515/// Must be freed with a call to mlirOpPrintingFlagsDestroy().
516MLIR_CAPI_EXPORTED MlirOpPrintingFlags mlirOpPrintingFlagsCreate(void);
517
518/// Destroys printing flags created with mlirOpPrintingFlagsCreate.
519MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags);
520
521/// Enables the elision of large elements attributes by printing a lexically
522/// valid but otherwise meaningless form instead of the element data. The
523/// `largeElementLimit` is used to configure what is considered to be a "large"
524/// ElementsAttr by providing an upper limit to the number of elements.
526mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
527 intptr_t largeElementLimit);
528
529/// Enables the elision of large resources strings by omitting them from the
530/// `dialect_resources` section. The `largeResourceLimit` is used to configure
531/// what is considered to be a "large" resource by providing an upper limit to
532/// the string size.
534mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags,
535 intptr_t largeResourceLimit);
536
537/// Enable or disable printing of debug information (based on `enable`). If
538/// 'prettyForm' is set to true, debug information is printed in a more readable
539/// 'pretty' form. Note: The IR generated with 'prettyForm' is not parsable.
541mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
542 bool prettyForm);
543
544/// Always print operations in the generic form.
546mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags);
547
548/// Print the name and location, if NamedLoc, as a prefix to the SSA ID.
550mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags);
551
552/// Use local scope when printing the operation. This allows for using the
553/// printer in a more localized and thread-safe setting, but may not
554/// necessarily be identical to what the IR will look like when dumping
555/// the full module.
557mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags);
558
559/// Do not verify the operation when using custom operation printers.
561mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags);
562
563/// Skip printing regions.
565mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags);
566
567//===----------------------------------------------------------------------===//
568// Bytecode printing flags API.
569//===----------------------------------------------------------------------===//
570
571/// Creates new printing flags with defaults, intended for customization.
572/// Must be freed with a call to mlirBytecodeWriterConfigDestroy().
573MLIR_CAPI_EXPORTED MlirBytecodeWriterConfig
575
576/// Destroys printing flags created with mlirBytecodeWriterConfigCreate.
578mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config);
579
580/// Sets the version to emit in the writer config.
582mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags,
583 int64_t version);
584
585//===----------------------------------------------------------------------===//
586// Operation API.
587//===----------------------------------------------------------------------===//
588
589/// Creates an operation and transfers ownership to the caller.
590/// Note that caller owned child objects are transferred in this call and must
591/// not be further used. Particularly, this applies to any regions added to
592/// the state (the implementation may invalidate any such pointers).
593///
594/// This call can fail under the following conditions, in which case, it will
595/// return a null operation and emit diagnostics:
596/// - Result type inference is enabled and cannot be performed.
597MLIR_CAPI_EXPORTED MlirOperation mlirOperationCreate(MlirOperationState *state);
598
599/// Parses an operation, giving ownership to the caller. If parsing fails a null
600/// operation will be returned, and an error diagnostic emitted.
601///
602/// `sourceStr` may be either the text assembly format, or binary bytecode
603/// format. `sourceName` is used as the file name of the source; any IR without
604/// locations will get a `FileLineColLoc` location with `sourceName` as the file
605/// name.
607 MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName);
608
609/// Creates a deep copy of an operation. The operation is not inserted and
610/// ownership is transferred to the caller.
611MLIR_CAPI_EXPORTED MlirOperation mlirOperationClone(MlirOperation op);
612
613/// Takes an operation owned by the caller and destroys it.
614MLIR_CAPI_EXPORTED void mlirOperationDestroy(MlirOperation op);
615
616/// Removes the given operation from its parent block. The operation is not
617/// destroyed. The ownership of the operation is transferred to the caller.
619
620/// Checks whether the underlying operation is null.
621static inline bool mlirOperationIsNull(MlirOperation op) { return !op.ptr; }
622
623/// Checks whether two operation handles point to the same operation. This does
624/// not perform deep comparison.
625MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op,
626 MlirOperation other);
627
628/// Compute a hash for the given operation.
629MLIR_CAPI_EXPORTED size_t mlirOperationHashValue(MlirOperation op);
630
631/// Gets the context this operation is associated with
632MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op);
633
634/// Checks if the operation name has a trait identified by the given type id.
636 MlirTypeID traitTypeID,
637 MlirContext context);
638
639/// Gets the location of the operation.
640MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation(MlirOperation op);
641
642/// Sets the location of the operation.
643MLIR_CAPI_EXPORTED void mlirOperationSetLocation(MlirOperation op,
644 MlirLocation loc);
645
646/// Gets the type id of the operation.
647/// Returns null if the operation does not have a registered operation
648/// description.
649MLIR_CAPI_EXPORTED MlirTypeID mlirOperationGetTypeID(MlirOperation op);
650
651/// Gets the name of the operation as an identifier.
652MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op);
653
654/// Gets the block that owns this operation, returning null if the operation is
655/// not owned.
656MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetBlock(MlirOperation op);
657
658/// Gets the operation that owns this operation, returning null if the operation
659/// is not owned.
660MLIR_CAPI_EXPORTED MlirOperation
661mlirOperationGetParentOperation(MlirOperation op);
662
663/// Returns the number of regions attached to the given operation.
665
666/// Returns `pos`-th region attached to the operation.
667MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op,
668 intptr_t pos);
669
670/// Returns an operation immediately following the given operation it its
671/// enclosing block.
672MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetNextInBlock(MlirOperation op);
673
674/// Returns the number of operands of the operation.
676
677/// Returns `pos`-th operand of the operation.
678MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op,
679 intptr_t pos);
680
681/// Returns `pos`-th OpOperand of the operation.
682MLIR_CAPI_EXPORTED MlirOpOperand mlirOperationGetOpOperand(MlirOperation op,
683 intptr_t pos);
684
685/// Sets the `pos`-th operand of the operation.
686MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
687 MlirValue newValue);
688
689/// Replaces the operands of the operation.
690MLIR_CAPI_EXPORTED void mlirOperationSetOperands(MlirOperation op,
691 intptr_t nOperands,
692 MlirValue const *operands);
693
694/// Returns the number of results of the operation.
696
697/// Returns `pos`-th result of the operation.
698MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op,
699 intptr_t pos);
700
701/// Returns the number of successor blocks of the operation.
703
704/// Returns `pos`-th successor of the operation.
705MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op,
706 intptr_t pos);
707
708/// Set `pos`-th successor of the operation.
710mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block);
711
712/// Returns true if this operation defines an inherent attribute with this name.
713/// Note: the attribute can be optional, so
714/// `mlirOperationGetInherentAttributeByName` can still return a null attribute.
717
718/// Returns an inherent attribute attached to the operation given its name.
719MLIR_CAPI_EXPORTED MlirAttribute
721
722/// Sets an inherent attribute by name, replacing the existing if it exists.
723/// This has no effect if "name" does not match an inherent attribute.
726 MlirAttribute attr);
727
728/// Returns the number of discardable attributes attached to the operation.
731
732/// Return `pos`-th discardable attribute of the operation.
735
736/// Returns a discardable attribute attached to the operation given its name.
738 MlirOperation op, MlirStringRef name);
739
740/// Sets a discardable attribute by name, replacing the existing if it exists or
741/// adding a new one otherwise. The new `attr` Attribute is not allowed to be
742/// null, use `mlirOperationRemoveDiscardableAttributeByName` to remove an
743/// Attribute instead.
746 MlirAttribute attr);
747
748/// Removes a discardable attribute by name. Returns false if the attribute was
749/// not found and true if removed.
752 MlirStringRef name);
753
754/// Returns the number of attributes attached to the operation.
755/// Deprecated, please use `mlirOperationGetNumInherentAttributes` or
756/// `mlirOperationGetNumDiscardableAttributes`.
758
759/// Return `pos`-th attribute of the operation.
760/// Deprecated, please use `mlirOperationGetInherentAttribute` or
761/// `mlirOperationGetDiscardableAttribute`.
763mlirOperationGetAttribute(MlirOperation op, intptr_t pos);
764
765/// Returns an attribute attached to the operation given its name.
766/// Deprecated, please use `mlirOperationGetInherentAttributeByName` or
767/// `mlirOperationGetDiscardableAttributeByName`.
768MLIR_CAPI_EXPORTED MlirAttribute
769mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name);
770
771/// Sets an attribute by name, replacing the existing if it exists or
772/// adding a new one otherwise.
773/// Deprecated, please use `mlirOperationSetInherentAttributeByName` or
774/// `mlirOperationSetDiscardableAttributeByName`.
776 MlirStringRef name,
777 MlirAttribute attr);
778
779/// Removes an attribute by name. Returns false if the attribute was not found
780/// and true if removed.
781/// Deprecated, please use `mlirOperationRemoveInherentAttributeByName` or
782/// `mlirOperationRemoveDiscardableAttributeByName`.
784 MlirStringRef name);
785
786/// Prints an operation by sending chunks of the string representation and
787/// forwarding `userData to `callback`. Note that the callback may be called
788/// several times with consecutive chunks of the string.
789MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op,
790 MlirStringCallback callback,
791 void *userData);
792
793/// Same as mlirOperationPrint but accepts flags controlling the printing
794/// behavior.
796 MlirOpPrintingFlags flags,
797 MlirStringCallback callback,
798 void *userData);
799
800/// Same as mlirOperationPrint but accepts AsmState controlling the printing
801/// behavior as well as caching computed names.
803 MlirAsmState state,
804 MlirStringCallback callback,
805 void *userData);
806
807/// Same as mlirOperationPrint but writing the bytecode format.
809 MlirStringCallback callback,
810 void *userData);
811
812/// Same as mlirOperationWriteBytecode but with writer config and returns
813/// failure only if desired bytecode could not be honored.
815 MlirOperation op, MlirBytecodeWriterConfig config,
816 MlirStringCallback callback, void *userData);
817
818/// Prints an operation to stderr.
819MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op);
820
821/// Verify the operation and return true if it passes, false if it fails.
822MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op);
823
824/// Moves the given operation immediately after the other operation in its
825/// parent block. The given operation may be owned by the caller or by its
826/// current block. The other operation must belong to a block. In any case, the
827/// ownership is transferred to the block of the other operation.
828MLIR_CAPI_EXPORTED void mlirOperationMoveAfter(MlirOperation op,
829 MlirOperation other);
830
831/// Moves the given operation immediately before the other operation in its
832/// parent block. The given operation may be owner by the caller or by its
833/// current block. The other operation must belong to a block. In any case, the
834/// ownership is transferred to the block of the other operation.
835MLIR_CAPI_EXPORTED void mlirOperationMoveBefore(MlirOperation op,
836 MlirOperation other);
837
838/// Given an operation 'other' that is within the same parent block, return
839/// whether the current operation is before 'other' in the operation list
840/// of the parent block.
841/// Note: This function has an average complexity of O(1), but worst case may
842/// take O(N) where N is the number of operations within the parent block.
844 MlirOperation other);
845/// Operation walk result.
851
852/// Traversal order for operation walk.
857
858/// Operation walker type. The handler is passed an (opaque) reference to an
859/// operation and a pointer to a `userData`.
861 void *userData);
862
863/// Walks operation `op` in `walkOrder` and calls `callback` on that operation.
864/// `*userData` is passed to the callback as well and can be used to tunnel some
865/// context or other data into the callback.
867void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback,
868 void *userData, MlirWalkOrder walkOrder);
869
870/// Replace uses of 'of' value with the 'with' value inside the 'op' operation.
872mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with);
873
874//===----------------------------------------------------------------------===//
875// Region API.
876//===----------------------------------------------------------------------===//
877
878/// Creates a new empty region and transfers ownership to the caller.
879MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void);
880
881/// Takes a region owned by the caller and destroys it.
882MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region);
883
884/// Checks whether a region is null.
885static inline bool mlirRegionIsNull(MlirRegion region) { return !region.ptr; }
886
887/// Checks whether two region handles point to the same region. This does not
888/// perform deep comparison.
889MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other);
890
891/// Gets the first block in the region.
892MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region);
893
894/// Takes a block owned by the caller and appends it to the given region.
896 MlirBlock block);
897
898/// Takes a block owned by the caller and inserts it at `pos` to the given
899/// region. This is an expensive operation that linearly scans the region,
900/// prefer insertAfter/Before instead.
902mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block);
903
904/// Takes a block owned by the caller and inserts it after the (non-owned)
905/// reference block in the given region. The reference block must belong to the
906/// region. If the reference block is null, prepends the block to the region.
908 MlirBlock reference,
909 MlirBlock block);
910
911/// Takes a block owned by the caller and inserts it before the (non-owned)
912/// reference block in the given region. The reference block must belong to the
913/// region. If the reference block is null, appends the block to the region.
915 MlirBlock reference,
916 MlirBlock block);
917
918/// Returns first region attached to the operation.
919MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op);
920
921/// Returns the region immediately following the given region in its parent
922/// operation.
923MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region);
924
925/// Moves the entire content of the source region to the target region.
927 MlirRegion source);
928
929//===----------------------------------------------------------------------===//
930// Block API.
931//===----------------------------------------------------------------------===//
932
933/// Creates a new empty block with the given argument types and transfers
934/// ownership to the caller.
936 MlirType const *args,
937 MlirLocation const *locs);
938
939/// Takes a block owned by the caller and destroys it.
940MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block);
941
942/// Detach a block from the owning region and assume ownership.
943MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block);
944
945/// Checks whether a block is null.
946static inline bool mlirBlockIsNull(MlirBlock block) { return !block.ptr; }
947
948/// Checks whether two blocks handles point to the same block. This does not
949/// perform deep comparison.
950MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other);
951
952/// Returns the closest surrounding operation that contains this block.
953MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock);
954
955/// Returns the region that contains this block.
956MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block);
957
958/// Returns the block immediately following the given block in its parent
959/// region.
960MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block);
961
962/// Returns the first operation in the block.
963MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block);
964
965/// Returns the terminator operation in the block or null if no terminator.
966MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block);
967
968/// Takes an operation owned by the caller and appends it to the block.
970 MlirOperation operation);
971
972/// Takes an operation owned by the caller and inserts it as `pos` to the block.
973/// This is an expensive operation that scans the block linearly, prefer
974/// insertBefore/After instead.
976 intptr_t pos,
977 MlirOperation operation);
978
979/// Takes an operation owned by the caller and inserts it after the (non-owned)
980/// reference operation in the given block. If the reference is null, prepends
981/// the operation. Otherwise, the reference must belong to the block.
983mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference,
984 MlirOperation operation);
985
986/// Takes an operation owned by the caller and inserts it before the (non-owned)
987/// reference operation in the given block. If the reference is null, appends
988/// the operation. Otherwise, the reference must belong to the block.
990mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference,
991 MlirOperation operation);
992
993/// Returns the number of arguments of the block.
995
996/// Appends an argument of the specified type to the block. Returns the newly
997/// added argument.
998MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block,
999 MlirType type,
1000 MlirLocation loc);
1001
1002/// Erase the argument at 'index' and remove it from the argument list.
1003MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index);
1004
1005/// Inserts an argument of the specified type at a specified index to the block.
1006/// Returns the newly added argument.
1007MLIR_CAPI_EXPORTED MlirValue mlirBlockInsertArgument(MlirBlock block,
1008 intptr_t pos,
1009 MlirType type,
1010 MlirLocation loc);
1011
1012/// Returns `pos`-th argument of the block.
1013MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block,
1014 intptr_t pos);
1015
1016/// Prints a block by sending chunks of the string representation and
1017/// forwarding `userData to `callback`. Note that the callback may be called
1018/// several times with consecutive chunks of the string.
1020mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData);
1021
1022/// Returns the number of successor blocks of the block.
1024
1025/// Returns `pos`-th successor of the block.
1026MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetSuccessor(MlirBlock block,
1027 intptr_t pos);
1028
1029/// Returns the number of predecessor blocks of the block.
1031
1032/// Returns `pos`-th predecessor of the block.
1033///
1034/// WARNING: This getter is more expensive than the others here because
1035/// the impl actually iterates the use-def chain (of block operands) anew for
1036/// each indexed access.
1037MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetPredecessor(MlirBlock block,
1038 intptr_t pos);
1039
1040//===----------------------------------------------------------------------===//
1041// Value API.
1042//===----------------------------------------------------------------------===//
1043
1044/// Returns whether the value is null.
1045static inline bool mlirValueIsNull(MlirValue value) { return !value.ptr; }
1046
1047/// Returns 1 if two values are equal, 0 otherwise.
1048MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2);
1049
1050/// Returns 1 if the value is a block argument, 0 otherwise.
1051MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value);
1052
1053/// Returns 1 if the value is an operation result, 0 otherwise.
1054MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value);
1055
1056/// Returns the block in which this value is defined as an argument. Asserts if
1057/// the value is not a block argument.
1058MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value);
1059
1060/// Returns the position of the value in the argument list of its block.
1062
1063/// Sets the type of the block argument to the given type.
1064MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value,
1065 MlirType type);
1066
1067/// Sets the location of the block argument to the given location.
1069 MlirLocation loc);
1070
1071/// Returns an operation that produced this value as its result. Asserts if the
1072/// value is not an op result.
1073MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value);
1074
1075/// Returns the position of the value in the list of results of the operation
1076/// that produced it.
1078
1079/// Returns the type of the value.
1080MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value);
1081
1082/// Set the type of the value.
1083MLIR_CAPI_EXPORTED void mlirValueSetType(MlirValue value, MlirType type);
1084
1085/// Prints the value to the standard error stream.
1086MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value);
1087
1088/// Prints a value by sending chunks of the string representation and
1089/// forwarding `userData to `callback`. Note that the callback may be called
1090/// several times with consecutive chunks of the string.
1092mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData);
1093
1094/// Prints a value as an operand (i.e., the ValueID).
1095MLIR_CAPI_EXPORTED void mlirValuePrintAsOperand(MlirValue value,
1096 MlirAsmState state,
1097 MlirStringCallback callback,
1098 void *userData);
1099
1100/// Returns an op operand representing the first use of the value, or a null op
1101/// operand if there are no uses.
1102MLIR_CAPI_EXPORTED MlirOpOperand mlirValueGetFirstUse(MlirValue value);
1103
1104/// Replace all uses of 'of' value with the 'with' value, updating anything in
1105/// the IR that uses 'of' to use the other value instead. When this returns
1106/// there are zero uses of 'of'.
1108 MlirValue with);
1109
1110/// Replace all uses of 'of' value with 'with' value, updating anything in the
1111/// IR that uses 'of' to use 'with' instead, except if the user is listed in
1112/// 'exceptions'. The 'exceptions' parameter is an array of MlirOperation
1113/// pointers with a length of 'numExceptions'.
1115mlirValueReplaceAllUsesExcept(MlirValue of, MlirValue with,
1116 intptr_t numExceptions,
1117 MlirOperation *exceptions);
1118
1119/// Gets the location of the value.
1120MLIR_CAPI_EXPORTED MlirLocation mlirValueGetLocation(MlirValue v);
1121
1122/// Gets the context that a value was created with.
1123MLIR_CAPI_EXPORTED MlirContext mlirValueGetContext(MlirValue v);
1124
1125//===----------------------------------------------------------------------===//
1126// OpOperand API.
1127//===----------------------------------------------------------------------===//
1128
1129/// Returns whether the op operand is null.
1130MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand);
1131
1132/// Returns the value of an op operand.
1133MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand);
1134
1135/// Returns the owner operation of an op operand.
1136MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand);
1137
1138/// Returns the operand number of an op operand.
1139MLIR_CAPI_EXPORTED unsigned
1140mlirOpOperandGetOperandNumber(MlirOpOperand opOperand);
1141
1142/// Returns an op operand representing the next use of the value, or a null op
1143/// operand if there is no next use.
1144MLIR_CAPI_EXPORTED MlirOpOperand
1145mlirOpOperandGetNextUse(MlirOpOperand opOperand);
1146
1147//===----------------------------------------------------------------------===//
1148// Type API.
1149//===----------------------------------------------------------------------===//
1150
1151/// Parses a type. The type is owned by the context.
1152MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context,
1153 MlirStringRef type);
1154
1155/// Gets the context that a type was created with.
1156MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type);
1157
1158/// Gets the type ID of the type.
1159MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type);
1160
1161/// Gets the dialect a type belongs to.
1162MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type);
1163
1164/// Checks whether a type is null.
1165static inline bool mlirTypeIsNull(MlirType type) { return !type.ptr; }
1166
1167/// Checks if two types are equal.
1168MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2);
1169
1170/// Prints a location by sending chunks of the string representation and
1171/// forwarding `userData to `callback`. Note that the callback may be called
1172/// several times with consecutive chunks of the string.
1174mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData);
1175
1176/// Prints the type to the standard error stream.
1177MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type);
1178
1179//===----------------------------------------------------------------------===//
1180// Attribute API.
1181//===----------------------------------------------------------------------===//
1182
1183/// Parses an attribute. The attribute is owned by the context.
1184MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context,
1185 MlirStringRef attr);
1186
1187/// Gets the context that an attribute was created with.
1188MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute);
1189
1190/// Gets the type of this attribute.
1191MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute);
1192
1193/// Gets the type id of the attribute.
1194MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute);
1195
1196/// Gets the dialect of the attribute.
1197MLIR_CAPI_EXPORTED MlirDialect mlirAttributeGetDialect(MlirAttribute attribute);
1198
1199/// Checks whether an attribute is null.
1200static inline bool mlirAttributeIsNull(MlirAttribute attr) { return !attr.ptr; }
1201
1202/// Checks if two attributes are equal.
1203MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2);
1204
1205/// Prints an attribute by sending chunks of the string representation and
1206/// forwarding `userData to `callback`. Note that the callback may be called
1207/// several times with consecutive chunks of the string.
1208MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr,
1209 MlirStringCallback callback,
1210 void *userData);
1211
1212/// Prints the attribute to the standard error stream.
1213MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr);
1214
1215/// Associates an attribute with the name. Takes ownership of neither.
1217 MlirAttribute attr);
1218
1219//===----------------------------------------------------------------------===//
1220// Identifier API.
1221//===----------------------------------------------------------------------===//
1222
1223/// Gets an identifier with the given string value.
1224MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context,
1225 MlirStringRef str);
1226
1227/// Returns the context associated with this identifier
1228MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier);
1229
1230/// Checks whether two identifiers are the same.
1231MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident,
1232 MlirIdentifier other);
1233
1234/// Gets the string value of the identifier.
1236
1237//===----------------------------------------------------------------------===//
1238// Symbol and SymbolTable API.
1239//===----------------------------------------------------------------------===//
1240
1241/// Returns the name of the attribute used to store symbol names compatible with
1242/// symbol tables.
1244
1245/// Returns the name of the attribute used to store symbol visibility.
1248
1249/// Creates a symbol table for the given operation. If the operation does not
1250/// have the SymbolTable trait, returns a null symbol table.
1251MLIR_CAPI_EXPORTED MlirSymbolTable
1252mlirSymbolTableCreate(MlirOperation operation);
1253
1254/// Returns true if the symbol table is null.
1255static inline bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable) {
1256 return !symbolTable.ptr;
1257}
1258
1259/// Destroys the symbol table created with mlirSymbolTableCreate. This does not
1260/// affect the operations in the table.
1261MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable);
1262
1263/// Looks up a symbol with the given name in the given symbol table and returns
1264/// the operation that corresponds to the symbol. If the symbol cannot be found,
1265/// returns a null operation.
1266MLIR_CAPI_EXPORTED MlirOperation
1267mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name);
1268
1269/// Inserts the given operation into the given symbol table. The operation must
1270/// have the symbol trait. If the symbol table already has a symbol with the
1271/// same name, renames the symbol being inserted to ensure name uniqueness. Note
1272/// that this does not move the operation itself into the block of the symbol
1273/// table operation, this should be done separately. Returns the name of the
1274/// symbol after insertion.
1275MLIR_CAPI_EXPORTED MlirAttribute
1276mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation);
1277
1278/// Removes the given operation from the symbol table and erases it.
1279MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable,
1280 MlirOperation operation);
1281
1282/// Attempt to replace all uses that are nested within the given operation
1283/// of the given symbol 'oldSymbol' with the provided 'newSymbol'. This does
1284/// not traverse into nested symbol tables. Will fail atomically if there are
1285/// any unknown operations that may be potential symbol tables.
1287 MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from);
1288
1289/// Walks all symbol table operations nested within, and including, `op`. For
1290/// each symbol table operation, the provided callback is invoked with the op
1291/// and a boolean signifying if the symbols within that symbol table can be
1292/// treated as if all uses within the IR are visible to the caller.
1293/// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
1294/// within `op` are visible.
1296 MlirOperation from, bool allSymUsesVisible,
1297 void (*callback)(MlirOperation, bool, void *userData), void *userData);
1298
1299#ifdef __cplusplus
1300}
1301#endif
1302
1303#endif // MLIR_C_IR_H
lhs
MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:786
MlirContext mlirModuleGetContext(MlirModule module)
Definition IR.cpp:445
size_t mlirModuleHashValue(MlirModule mod)
Definition IR.cpp:471
intptr_t mlirBlockGetNumPredecessors(MlirBlock block)
Definition IR.cpp:1105
MlirIdentifier mlirOperationGetName(MlirOperation op)
Definition IR.cpp:674
bool mlirValueIsABlockArgument(MlirValue value)
Definition IR.cpp:1125
intptr_t mlirOperationGetNumRegions(MlirOperation op)
Definition IR.cpp:686
MlirBlock mlirOperationGetBlock(MlirOperation op)
Definition IR.cpp:678
void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Definition IR.cpp:1142
void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition IR.cpp:520
MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Definition IR.cpp:741
MlirModule mlirModuleCreateParseFromFile(MlirContext context, MlirStringRef fileName)
Definition IR.cpp:436
bool mlirOperationNameHasTrait(MlirStringRef opName, MlirTypeID traitTypeID, MlirContext context)
Definition IR.cpp:654
MlirAsmState mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags)
Definition IR.cpp:177
intptr_t mlirOperationGetNumResults(MlirOperation op)
Definition IR.cpp:737
void mlirOperationDestroy(MlirOperation op)
Definition IR.cpp:638
MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:759
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Definition IR.cpp:1290
MlirType mlirValueGetType(MlirValue value)
Definition IR.cpp:1161
void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
Definition IR.cpp:1091
void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:791
MlirOpPrintingFlags mlirOpPrintingFlagsCreate()
Definition IR.cpp:201
bool mlirModuleEqual(MlirModule lhs, MlirModule rhs)
Definition IR.cpp:467
void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags, intptr_t largeElementLimit)
Definition IR.cpp:209
void mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block)
Definition IR.cpp:802
MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
Definition IR.cpp:710
void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
Definition IR.cpp:219
MlirOperation mlirModuleGetOperation(MlirModule module)
Definition IR.cpp:459
void mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags, intptr_t largeResourceLimit)
Definition IR.cpp:214
void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
Definition IR.cpp:232
MlirTypeID mlirOperationGetTypeID(MlirOperation op)
Definition IR.cpp:668
intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
Definition IR.cpp:1137
MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Definition IR.cpp:749
bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Definition IR.cpp:1309
MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags)
Definition IR.cpp:156
bool mlirOperationEqual(MlirOperation op, MlirOperation other)
Definition IR.cpp:642
void mlirOperationSetInherentAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:767
void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
Definition IR.cpp:236
bool mlirValueEqual(MlirValue value1, MlirValue value2)
Definition IR.cpp:1121
void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
Definition IR.cpp:251
MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1101
void mlirModuleDestroy(MlirModule module)
Definition IR.cpp:453
MlirModule mlirModuleCreateEmpty(MlirLocation location)
Definition IR.cpp:424
void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
Definition IR.cpp:224
MlirOperation mlirOperationGetParentOperation(MlirOperation op)
Definition IR.cpp:682
void mlirValueSetType(MlirValue value, MlirType type)
Definition IR.cpp:1165
intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Definition IR.cpp:745
MlirDialect mlirAttributeGetDialect(MlirAttribute attr)
Definition IR.cpp:1305
void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
Definition IR.cpp:414
void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:821
void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Definition IR.cpp:726
MlirOperation mlirOpResultGetOwner(MlirValue value)
Definition IR.cpp:1152
MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
Definition IR.cpp:428
size_t mlirOperationHashValue(MlirOperation op)
Definition IR.cpp:646
void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n, MlirType const *results)
Definition IR.cpp:503
MlirOperation mlirOperationClone(MlirOperation op)
Definition IR.cpp:634
MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
Definition IR.cpp:1133
void mlirBlockArgumentSetLocation(MlirValue value, MlirLocation loc)
Definition IR.cpp:1147
MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:718
MlirModule mlirModuleFromOperation(MlirOperation op)
Definition IR.cpp:463
MlirOpOperand mlirOperationGetOpOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:722
MlirLocation mlirOperationGetLocation(MlirOperation op)
Definition IR.cpp:660
MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:816
MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr)
Definition IR.cpp:1301
intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
Definition IR.cpp:774
void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
Definition IR.cpp:512
void mlirOperationSetLocation(MlirOperation op, MlirLocation loc)
Definition IR.cpp:664
MlirType mlirAttributeGetType(MlirAttribute attribute)
Definition IR.cpp:1294
bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:797
bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:826
bool mlirValueIsAOpResult(MlirValue value)
Definition IR.cpp:1129
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:754
MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1110
MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Definition IR.cpp:690
MlirOperation mlirOperationCreate(MlirOperationState *state)
Definition IR.cpp:588
void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags, int64_t version)
Definition IR.cpp:255
MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
Definition IR.cpp:1286
void mlirOperationRemoveFromParent(MlirOperation op)
Definition IR.cpp:640
intptr_t mlirBlockGetNumSuccessors(MlirBlock block)
Definition IR.cpp:1097
MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:811
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Definition IR.cpp:205
void mlirValueDump(MlirValue value)
Definition IR.cpp:1169
void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
Definition IR.cpp:731
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
Definition IR.cpp:1275
MlirBlock mlirModuleGetBody(MlirModule module)
Definition IR.cpp:449
MlirOperation mlirOperationCreateParse(MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName)
Definition IR.cpp:625
void mlirAsmStateDestroy(MlirAsmState state)
Destroys printing flags created with mlirAsmStateCreate.
Definition IR.cpp:195
MlirContext mlirOperationGetContext(MlirOperation op)
Definition IR.cpp:650
intptr_t mlirOpResultGetResultNumber(MlirValue value)
Definition IR.cpp:1156
MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:779
void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
Definition IR.cpp:525
void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
Definition IR.cpp:516
MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate()
Definition IR.cpp:247
void mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags)
Definition IR.cpp:228
void mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags)
Definition IR.cpp:240
void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
Definition IR.cpp:508
MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
Definition IR.cpp:479
intptr_t mlirOperationGetNumOperands(MlirOperation op)
Definition IR.cpp:714
void mlirTypeDump(MlirType type)
Definition IR.cpp:1280
intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Definition IR.cpp:807
MLIR_CAPI_EXPORTED MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
Definition IR.cpp:264
MlirWalkResult(* MlirOperationWalkCallback)(MlirOperation, void *userData)
Operation walker type.
Definition IR.h:860
MLIR_CAPI_EXPORTED MlirLocation mlirValueGetLocation(MlirValue v)
Gets the location of the value.
Definition IR.cpp:1212
MLIR_CAPI_EXPORTED unsigned mlirContextGetNumThreads(MlirContext context)
Gets the number of threads of the thread pool of the context when multithreading is enabled.
Definition IR.cpp:116
MLIR_CAPI_EXPORTED void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
Definition IR.cpp:851
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFileLineColGet(MlirContext context, MlirStringRef filename, unsigned line, unsigned col)
Creates an File/Line/Column location owned by the given context.
Definition IR.cpp:272
MLIR_CAPI_EXPORTED void mlirSymbolTableWalkSymbolTables(MlirOperation from, bool allSymUsesVisible, void(*callback)(MlirOperation, bool, void *userData), void *userData)
Walks all symbol table operations nested within, and including, op.
Definition IR.cpp:1394
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition IR.cpp:136
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetEndColumn(MlirLocation location)
Getter for end_column of FileLineColRange.
Definition IR.cpp:310
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
Definition IR.cpp:1373
MLIR_CAPI_EXPORTED MlirDialect mlirDialectHandleLoadDialect(MlirDialectHandle, MlirContext)
Loads the dialect associated with the provided dialect handle.
MlirWalkOrder
Traversal order for operation walk.
Definition IR.h:853
@ MlirWalkPreOrder
Definition IR.h:854
@ MlirWalkPostOrder
Definition IR.h:855
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
Definition IR.cpp:1321
MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGetChildLoc(MlirLocation location)
Getter for childLoc of Name.
Definition IR.cpp:391
MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
Definition IR.cpp:1378
MLIR_CAPI_EXPORTED void mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry)
Append the contents of the given dialect registry to the registry associated with the context.
Definition IR.cpp:83
MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
Definition IR.cpp:1342
MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition IR.cpp:1255
MLIR_CAPI_EXPORTED void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
Definition IR.cpp:148
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
Definition IR.cpp:90
MLIR_CAPI_EXPORTED MlirOpOperand mlirOpOperandGetNextUse(MlirOpOperand opOperand)
Returns an op operand representing the next use of the value, or a null op operand if there is no nex...
Definition IR.cpp:1238
MLIR_CAPI_EXPORTED void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
Definition IR.cpp:72
MLIR_CAPI_EXPORTED void mlirRegionInsertOwnedBlockBefore(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it before the (non-owned) reference block in the given ...
Definition IR.cpp:961
MLIR_CAPI_EXPORTED bool mlirLocationIsAFileLineColRange(MlirLocation location)
Checks whether the given location is an FileLineColRange.
Definition IR.cpp:320
MLIR_CAPI_EXPORTED unsigned mlirLocationFusedGetNumLocations(MlirLocation location)
Getter for number of locations fused together.
Definition IR.cpp:354
MLIR_CAPI_EXPORTED void mlirValueReplaceAllUsesOfWith(MlirValue of, MlirValue with)
Replace all uses of 'of' value with the 'with' value, updating anything in the IR that uses 'of' to u...
Definition IR.cpp:1194
MLIR_CAPI_EXPORTED void mlirValuePrintAsOperand(MlirValue value, MlirAsmState state, MlirStringCallback callback, void *userData)
Prints a value as an operand (i.e., the ValueID).
Definition IR.cpp:1177
MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
Definition IR.cpp:402
MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
Definition IR.cpp:1226
MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition IR.cpp:1338
MLIR_CAPI_EXPORTED MlirIdentifier mlirLocationFileLineColRangeGetFilename(MlirLocation location)
Getter for filename of FileLineColRange.
Definition IR.cpp:288
MLIR_CAPI_EXPORTED void mlirLocationFusedGetLocations(MlirLocation location, MlirLocation *locationsCPtr)
Getter for locations of Fused.
Definition IR.cpp:360
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
Definition IR.cpp:79
MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData to callback`...
Definition IR.cpp:1313
MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition IR.cpp:1000
MLIR_CAPI_EXPORTED void mlirOperationMoveBefore(MlirOperation op, MlirOperation other)
Moves the given operation immediately before the other operation in its parent block.
Definition IR.cpp:875
MLIR_CAPI_EXPORTED void mlirValueReplaceAllUsesExcept(MlirValue of, MlirValue with, intptr_t numExceptions, MlirOperation *exceptions)
Replace all uses of 'of' value with 'with' value, updating anything in the IR that uses 'of' to use '...
Definition IR.cpp:1198
MLIR_CAPI_EXPORTED void mlirOperationPrintWithState(MlirOperation op, MlirAsmState state, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts AsmState controlling the printing behavior as well as caching ...
Definition IR.cpp:842
MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition IR.cpp:1062
MlirWalkResult
Operation walk result.
Definition IR.h:846
@ MlirWalkResultInterrupt
Definition IR.h:848
@ MlirWalkResultSkip
Definition IR.h:849
@ MlirWalkResultAdvance
Definition IR.h:847
MLIR_CAPI_EXPORTED void mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block)
Takes a block owned by the caller and inserts it at pos to the given region.
Definition IR.cpp:941
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition IR.h:1165
MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition IR.cpp:926
MLIR_CAPI_EXPORTED bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
Definition IR.cpp:99
MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
Definition IR.cpp:1069
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetStartLine(MlirLocation location)
Getter for start_line of FileLineColRange.
Definition IR.cpp:292
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations, MlirLocation const *locations, MlirAttribute metadata)
Creates a fused location with an array of locations and metadata.
Definition IR.cpp:346
MLIR_CAPI_EXPORTED void mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference, MlirOperation operation)
Takes an operation owned by the caller and inserts it before the (non-owned) reference operation in t...
Definition IR.cpp:1050
static bool mlirContextIsNull(MlirContext context)
Checks whether a context is null.
Definition IR.h:104
MLIR_CAPI_EXPORTED MlirDialect mlirContextGetOrLoadDialect(MlirContext context, MlirStringRef name)
Gets the dialect instance owned by the given context using the dialect namespace to identify it,...
Definition IR.cpp:94
MLIR_CAPI_EXPORTED void mlirDialectHandleRegisterDialect(MlirDialectHandle, MlirContext)
Registers the dialect associated with the provided dialect handle.
MLIR_CAPI_EXPORTED bool mlirLocationIsACallSite(MlirLocation location)
Checks whether the given location is an CallSite.
Definition IR.cpp:342
#define DEFINE_C_API_STRUCT(name, storage)
Opaque type declarations.
Definition IR.h:45
struct MlirNamedAttribute MlirNamedAttribute
Definition IR.h:80
MLIR_CAPI_EXPORTED void mlirRegionInsertOwnedBlockAfter(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it after the (non-owned) reference block in the given r...
Definition IR.cpp:947
MLIR_CAPI_EXPORTED MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args, MlirLocation const *locs)
Creates a new empty block with the given argument types and transfers ownership to the caller.
Definition IR.cpp:984
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition IR.h:946
MLIR_CAPI_EXPORTED void mlirBlockAppendOwnedOperation(MlirBlock block, MlirOperation operation)
Takes an operation owned by the caller and appends it to the block.
Definition IR.cpp:1025
MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition IR.cpp:1087
MLIR_CAPI_EXPORTED MlirOperation mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name)
Looks up a symbol with the given name in the given symbol table and returns the operation that corres...
Definition IR.cpp:1368
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition IR.cpp:1259
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFileLineColRangeGet(MlirContext context, MlirStringRef filename, unsigned start_line, unsigned start_col, unsigned end_line, unsigned end_col)
Creates an File/Line/Column range location owned by the given context.
Definition IR.cpp:280
MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
Definition IR.cpp:1224
MLIR_CAPI_EXPORTED MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition IR.cpp:1358
MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
Definition IR.cpp:406
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetStartColumn(MlirLocation location)
Getter for start_column of FileLineColRange.
Definition IR.cpp:298
MLIR_CAPI_EXPORTED bool mlirLocationIsAFused(MlirLocation location)
Checks whether the given location is an Fused.
Definition IR.cpp:374
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
Definition IR.h:370
MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
Definition IR.cpp:1073
MLIR_CAPI_EXPORTED void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts flags controlling the printing behavior.
Definition IR.cpp:836
MLIR_CAPI_EXPORTED MlirOpOperand mlirValueGetFirstUse(MlirValue value)
Returns an op operand representing the first use of the value, or a null op operand if there are no u...
Definition IR.cpp:1184
MLIR_CAPI_EXPORTED void mlirContextSetThreadPool(MlirContext context, MlirLlvmThreadPool threadPool)
Sets the thread pool of the context explicitly, enabling multithreading in the process.
Definition IR.cpp:111
MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
Definition IR.cpp:867
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition IR.cpp:1271
MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition IR.cpp:1364
MLIR_CAPI_EXPORTED unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition IR.cpp:1234
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGetCaller(MlirLocation location)
Getter for caller of CallSite.
Definition IR.cpp:333
MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
Definition IR.cpp:128
MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
Definition IR.cpp:992
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition IR.cpp:1015
MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition IR.cpp:972
MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier)
Returns the context associated with this identifier.
Definition IR.cpp:1334
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectHandleGetNamespace(MlirDialectHandle)
Returns the namespace associated with the provided dialect handle.
MLIR_CAPI_EXPORTED MlirIdentifier mlirLocationNameGetName(MlirLocation location)
Getter for name of Name.
Definition IR.cpp:387
MLIR_CAPI_EXPORTED bool mlirOperationIsBeforeInBlock(MlirOperation op, MlirOperation other)
Given an operation 'other' that is within the same parent block, return whether the current operation...
Definition IR.cpp:879
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
Definition IR.cpp:268
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
Definition IR.cpp:1263
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetVisibilityAttributeName(void)
Returns the name of the attribute used to store symbol visibility.
Definition IR.cpp:1354
static bool mlirDialectIsNull(MlirDialect dialect)
Checks if the dialect is null.
Definition IR.h:182
MLIR_CAPI_EXPORTED MlirAttribute mlirLocationFusedGetMetadata(MlirLocation location)
Getter for metadata of Fused.
Definition IR.cpp:368
MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
Definition IR.cpp:1004
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
Definition IR.cpp:324
MLIR_CAPI_EXPORTED bool mlirLocationIsAName(MlirLocation location)
Checks whether the given location is an Name.
Definition IR.cpp:398
static bool mlirDialectRegistryIsNull(MlirDialectRegistry registry)
Checks if the dialect registry is null.
Definition IR.h:244
MLIR_CAPI_EXPORTED void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder)
Walks operation op in walkOrder and calls callback on that operation.
Definition IR.cpp:897
MLIR_CAPI_EXPORTED MlirContext mlirContextCreateWithThreading(bool threadingEnabled)
Creates an MLIR context with an explicit setting of the multithreading setting and transfers its owne...
Definition IR.cpp:54
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock)
Returns the closest surrounding operation that contains this block.
Definition IR.cpp:996
MLIR_CAPI_EXPORTED void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
Definition IR.cpp:976
MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
Definition IR.cpp:410
MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index)
Erase the argument at 'index' and remove it from the argument list.
Definition IR.cpp:1078
MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition IR.cpp:1319
MLIR_CAPI_EXPORTED MlirLogicalResult mlirSymbolTableReplaceAllSymbolUses(MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from)
Attempt to replace all uses that are nested within the given operation of the given symbol 'oldSymbol...
Definition IR.cpp:1383
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationFileLineColRangeGetTypeID(void)
TypeID Getter for FileLineColRange.
Definition IR.cpp:316
MLIR_CAPI_EXPORTED void mlirRegionAppendOwnedBlock(MlirRegion region, MlirBlock block)
Takes a block owned by the caller and appends it to the given region.
Definition IR.cpp:937
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition IR.cpp:1008
MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData to callback`...
Definition IR.cpp:830
static bool mlirRegionIsNull(MlirRegion region)
Checks whether a region is null.
Definition IR.h:885
MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand)
Returns the value of an op operand.
Definition IR.cpp:1230
MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition IR.cpp:701
MLIR_CAPI_EXPORTED MlirValue mlirBlockInsertArgument(MlirBlock block, intptr_t pos, MlirType type, MlirLocation loc)
Inserts an argument of the specified type at a specified index to the block.
Definition IR.cpp:1082
MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
Definition IR.cpp:1267
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition IR.cpp:1330
MLIR_CAPI_EXPORTED void mlirContextLoadAllAvailableDialects(MlirContext context)
Eagerly loads all available dialects registered with a context, making them available for use for IR ...
Definition IR.cpp:107
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationCallSiteGetTypeID(void)
TypeID Getter for CallSite.
Definition IR.cpp:338
MLIR_CAPI_EXPORTED MlirLlvmThreadPool mlirContextGetThreadPool(MlirContext context)
Gets the thread pool of the context when enabled multithreading, otherwise an assertion is raised.
Definition IR.cpp:120
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetEndLine(MlirLocation location)
Getter for end_line of FileLineColRange.
Definition IR.cpp:304
MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void)
Creates a dialect registry and transfers its ownership to the caller.
Definition IR.cpp:144
MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
Definition IR.cpp:378
MLIR_CAPI_EXPORTED MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry, bool threadingEnabled)
Creates an MLIR context, setting the multithreading setting explicitly and pre-loading the dialects f...
Definition IR.cpp:59
MLIR_CAPI_EXPORTED void mlirContextEnableMultithreading(MlirContext context, bool enable)
Set threading mode (must be set to false to mlir-print-ir-after-all).
Definition IR.cpp:103
MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
Definition IR.cpp:694
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGetCallee(MlirLocation location)
Getter for callee of CallSite.
Definition IR.cpp:328
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationNameGetTypeID(void)
TypeID Getter for Name.
Definition IR.cpp:396
MLIR_CAPI_EXPORTED MlirContext mlirValueGetContext(MlirValue v)
Gets the context that a value was created with.
Definition IR.cpp:1216
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetSymbolAttributeName(void)
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition IR.cpp:1350
MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void)
Creates a new empty region and transfers ownership to the caller.
Definition IR.cpp:924
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationFusedGetTypeID(void)
TypeID Getter for Fused.
Definition IR.cpp:372
MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
Definition IR.cpp:1064
MLIR_CAPI_EXPORTED void mlirDialectHandleInsertDialect(MlirDialectHandle, MlirDialectRegistry)
Inserts the dialect associated with the provided dialect handle into the provided dialect registry.
MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op)
Prints an operation to stderr.
Definition IR.cpp:865
MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
Definition IR.cpp:66
MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
Definition IR.cpp:132
MLIR_CAPI_EXPORTED void mlirBlockInsertOwnedOperation(MlirBlock block, intptr_t pos, MlirOperation operation)
Takes an operation owned by the caller and inserts it as pos to the block.
Definition IR.cpp:1029
MLIR_CAPI_EXPORTED MlirContext mlirContextCreate(void)
Creates an MLIR context and transfers its ownership to the caller.
Definition IR.cpp:44
static bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable)
Returns true if the symbol table is null.
Definition IR.h:1255
MLIR_CAPI_EXPORTED bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
Definition IR.cpp:76
MLIR_CAPI_EXPORTED void mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with)
Replace uses of 'of' value with the 'with' value inside the 'op' operation.
Definition IR.cpp:915
MLIR_CAPI_EXPORTED void mlirOperationMoveAfter(MlirOperation op, MlirOperation other)
Moves the given operation immediately after the other operation in its parent block.
Definition IR.cpp:871
MLIR_CAPI_EXPORTED void mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData)
Prints a block by sending chunks of the string representation and forwarding userData to callback`.
Definition IR.cpp:1171
MLIR_CAPI_EXPORTED void mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference, MlirOperation operation)
Takes an operation owned by the caller and inserts it after the (non-owned) reference operation in th...
Definition IR.cpp:1035
MLIR_CAPI_EXPORTED MlirLogicalResult mlirOperationWriteBytecodeWithConfig(MlirOperation op, MlirBytecodeWriterConfig config, MlirStringCallback callback, void *userData)
Same as mlirOperationWriteBytecode but with writer config and returns failure only if desired bytecod...
Definition IR.cpp:858
MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
Definition IR.cpp:70
MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
Definition IR.cpp:930
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
struct MlirStringRef MlirStringRef
Definition Support.h:82
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition Support.h:110
const void * ptr
Definition IR.h:211
A logical result value, essentially a boolean with named states.
Definition Support.h:121
Named MLIR attribute.
Definition IR.h:76
MlirAttribute attribute
Definition IR.h:78
MlirIdentifier name
Definition IR.h:77
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78