MLIR 24.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);
62DEFINE_C_API_STRUCT(MlirIRMapping, void);
63
64DEFINE_C_API_STRUCT(MlirAttribute, const void);
65DEFINE_C_API_STRUCT(MlirIdentifier, const void);
66DEFINE_C_API_STRUCT(MlirLocation, const void);
67DEFINE_C_API_STRUCT(MlirModule, const void);
68DEFINE_C_API_STRUCT(MlirType, const void);
69DEFINE_C_API_STRUCT(MlirValue, const void);
70
71#undef DEFINE_C_API_STRUCT
72
73/// Named MLIR attribute.
74///
75/// A named attribute is essentially a (name, attribute) pair where the name is
76/// a string.
78 MlirIdentifier name;
79 MlirAttribute attribute;
80};
82
83//===----------------------------------------------------------------------===//
84// Context API.
85//===----------------------------------------------------------------------===//
86
87/// Creates an MLIR context and transfers its ownership to the caller.
88/// This sets the default multithreading option (enabled).
90
91/// Creates an MLIR context with an explicit setting of the multithreading
92/// setting and transfers its ownership to the caller.
93MLIR_CAPI_EXPORTED MlirContext
94mlirContextCreateWithThreading(bool threadingEnabled);
95
96/// Creates an MLIR context, setting the multithreading setting explicitly and
97/// pre-loading the dialects from the provided DialectRegistry.
99 MlirDialectRegistry registry, bool threadingEnabled);
100
101/// Checks if two contexts are equal.
102MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2);
103
104/// Checks whether a context is null.
105static inline bool mlirContextIsNull(MlirContext context) {
106 return !context.ptr;
107}
108
109/// Takes an MLIR context owned by the caller and destroys it.
110MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context);
111
112/// Sets whether unregistered dialects are allowed in this context.
114mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow);
115
116/// Returns whether the context allows unregistered dialects.
118mlirContextGetAllowUnregisteredDialects(MlirContext context);
119
120/// Returns the number of dialects registered with the given context. A
121/// registered dialect will be loaded if needed by the parser.
123mlirContextGetNumRegisteredDialects(MlirContext context);
124
125/// Append the contents of the given dialect registry to the registry associated
126/// with the context.
128mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry);
129
130/// Returns the number of dialects loaded by the context.
131
133mlirContextGetNumLoadedDialects(MlirContext context);
134
135/// Gets the dialect instance owned by the given context using the dialect
136/// namespace to identify it, loads (i.e., constructs the instance of) the
137/// dialect if necessary. If the dialect is not registered with the context,
138/// returns null. Use mlirContextLoad<Name>Dialect to load an unregistered
139/// dialect.
140MLIR_CAPI_EXPORTED MlirDialect mlirContextGetOrLoadDialect(MlirContext context,
142
143/// Gets the dialect instance owned by the given context using the dialect
144/// namespace to identify it. If the dialect is not loaded by the context,
145/// returns null. Use mlirContextGetOrLoadDialect to load a dialect if it is
146/// registered with the context.
147MLIR_CAPI_EXPORTED MlirDialect mlirContextGetLoadedDialect(MlirContext context,
149
150/// Set threading mode (must be set to false to mlir-print-ir-after-all).
152 bool enable);
153
154/// Eagerly loads all available dialects registered with a context, making
155/// them available for use for IR construction.
157mlirContextLoadAllAvailableDialects(MlirContext context);
158
159/// Returns whether the given fully-qualified operation (i.e.
160/// 'dialect.operation') is registered with the context. This will return true
161/// if the dialect is loaded and the operation is registered within the
162/// dialect.
165
166/// Sets the thread pool of the context explicitly, enabling multithreading in
167/// the process. This API should be used to avoid re-creating thread pools in
168/// long-running applications that perform multiple compilations, see
169/// the C++ documentation for MLIRContext for details.
170MLIR_CAPI_EXPORTED void mlirContextSetThreadPool(MlirContext context,
171 MlirLlvmThreadPool threadPool);
172
173/// Gets the number of threads of the thread pool of the context when
174/// multithreading is enabled. Returns 1 if no multithreading.
175MLIR_CAPI_EXPORTED unsigned mlirContextGetNumThreads(MlirContext context);
176
177/// Gets the thread pool of the context when enabled multithreading, otherwise
178/// an assertion is raised.
179MLIR_CAPI_EXPORTED MlirLlvmThreadPool
180mlirContextGetThreadPool(MlirContext context);
181
182/// Begins a transient scope on the context, freezing the base layer (loaded
183/// dialects, registered operations, interface models, and existing
184/// types/attributes).
185/// Precondition: The context must not already be in a transient scope.
186MLIR_CAPI_EXPORTED void mlirContextBeginTransientScope(MlirContext context);
187
188/// Ends the transient scope and resets the context to the base state, pruning
189/// transient types, attributes, affine expressions, distinct attributes, and
190/// unregistered operations added during the transient scope.
191MLIR_CAPI_EXPORTED void mlirContextEndTransientScope(MlirContext context);
192
193/// Returns whether the context is currently in a transient scope.
194MLIR_CAPI_EXPORTED bool mlirContextIsInTransientScope(MlirContext context);
195
196//===----------------------------------------------------------------------===//
197// Dialect API.
198//===----------------------------------------------------------------------===//
199
200/// Returns the context that owns the dialect.
201MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect);
202
203/// Checks if the dialect is null.
204static inline bool mlirDialectIsNull(MlirDialect dialect) {
205 return !dialect.ptr;
206}
207
208/// Checks if two dialects that belong to the same context are equal. Dialects
209/// from different contexts will not compare equal.
210MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1,
211 MlirDialect dialect2);
212
213/// Returns the namespace of the given dialect.
215
216//===----------------------------------------------------------------------===//
217// DialectHandle API.
218// Registration entry-points for each dialect are declared using the common
219// MLIR_DECLARE_DIALECT_REGISTRATION_CAPI macro, which takes the dialect
220// API name (i.e. "Func", "Tensor", "Linalg") and namespace (i.e. "func",
221// "tensor", "linalg"). The following declarations are produced:
222//
223// /// Gets the above hook methods in struct form for a dialect by namespace.
224// /// This is intended to facilitate dynamic lookup and registration of
225// /// dialects via a plugin facility based on shared library symbol lookup.
226// const MlirDialectHandle *mlirGetDialectHandle__{NAMESPACE}__();
227//
228// This is done via a common macro to facilitate future expansion to
229// registration schemes.
230//===----------------------------------------------------------------------===//
231
233 const void *ptr;
234};
236
237#define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace) \
238 MLIR_CAPI_EXPORTED MlirDialectHandle mlirGetDialectHandle__##Namespace##__( \
239 void)
240
241/// Returns the namespace associated with the provided dialect handle.
244
245/// Inserts the dialect associated with the provided dialect handle into the
246/// provided dialect registry
248 MlirDialectRegistry);
249
250/// Registers the dialect associated with the provided dialect handle.
252 MlirContext);
253
254/// Loads the dialect associated with the provided dialect handle.
256 MlirContext);
257
258//===----------------------------------------------------------------------===//
259// DialectRegistry API.
260//===----------------------------------------------------------------------===//
261
262/// Creates a dialect registry and transfers its ownership to the caller.
263MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void);
264
265/// Checks if the dialect registry is null.
266static inline bool mlirDialectRegistryIsNull(MlirDialectRegistry registry) {
267 return !registry.ptr;
268}
269
270/// Takes a dialect registry owned by the caller and destroys it.
272mlirDialectRegistryDestroy(MlirDialectRegistry registry);
273
274//===----------------------------------------------------------------------===//
275// Location API.
276//===----------------------------------------------------------------------===//
277
278/// Returns the underlying location attribute of this location.
279MLIR_CAPI_EXPORTED MlirAttribute
280mlirLocationGetAttribute(MlirLocation location);
281
282/// Creates a location from a location attribute.
283MLIR_CAPI_EXPORTED MlirLocation
284mlirLocationFromAttribute(MlirAttribute attribute);
285
286/// Creates an File/Line/Column location owned by the given context.
288 MlirContext context, MlirStringRef filename, unsigned line, unsigned col);
289
290/// Creates an File/Line/Column range location owned by the given context.
292 MlirContext context, MlirStringRef filename, unsigned start_line,
293 unsigned start_col, unsigned end_line, unsigned end_col);
294
295/// Getter for filename of FileLineColRange.
296MLIR_CAPI_EXPORTED MlirIdentifier
297mlirLocationFileLineColRangeGetFilename(MlirLocation location);
298
299/// Getter for start_line of FileLineColRange.
301mlirLocationFileLineColRangeGetStartLine(MlirLocation location);
302
303/// Getter for start_column of FileLineColRange.
305mlirLocationFileLineColRangeGetStartColumn(MlirLocation location);
306
307/// Getter for end_line of FileLineColRange.
309mlirLocationFileLineColRangeGetEndLine(MlirLocation location);
310
311/// Getter for end_column of FileLineColRange.
313mlirLocationFileLineColRangeGetEndColumn(MlirLocation location);
314
315/// TypeID Getter for FileLineColRange.
317
318/// Checks whether the given location is an FileLineColRange.
319MLIR_CAPI_EXPORTED bool mlirLocationIsAFileLineColRange(MlirLocation location);
320
321/// Creates a call site location with a callee and a caller.
322MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
323 MlirLocation caller);
324
325/// Getter for callee of CallSite.
326MLIR_CAPI_EXPORTED MlirLocation
327mlirLocationCallSiteGetCallee(MlirLocation location);
328
329/// Getter for caller of CallSite.
330MLIR_CAPI_EXPORTED MlirLocation
331mlirLocationCallSiteGetCaller(MlirLocation location);
332
333/// TypeID Getter for CallSite.
335
336/// Checks whether the given location is an CallSite.
337MLIR_CAPI_EXPORTED bool mlirLocationIsACallSite(MlirLocation location);
338
339/// Creates a fused location with an array of locations and metadata.
340MLIR_CAPI_EXPORTED MlirLocation
341mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
342 MlirLocation const *locations, MlirAttribute metadata);
343
344/// Getter for number of locations fused together.
345MLIR_CAPI_EXPORTED unsigned
346mlirLocationFusedGetNumLocations(MlirLocation location);
347
348/// Getter for locations of Fused. Requires pre-allocated memory of
349/// #fusedLocations X sizeof(MlirLocation).
351mlirLocationFusedGetLocations(MlirLocation location,
352 MlirLocation *locationsCPtr);
353
354/// Getter for metadata of Fused.
355MLIR_CAPI_EXPORTED MlirAttribute
356mlirLocationFusedGetMetadata(MlirLocation location);
357
358/// TypeID Getter for Fused.
360
361/// Checks whether the given location is an Fused.
362MLIR_CAPI_EXPORTED bool mlirLocationIsAFused(MlirLocation location);
363
364/// Creates a name location owned by the given context. Providing null location
365/// for childLoc is allowed and if childLoc is null location, then the behavior
366/// is the same as having unknown child location.
367MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context,
368 MlirStringRef name,
369 MlirLocation childLoc);
370
371/// Getter for name of Name.
372MLIR_CAPI_EXPORTED MlirIdentifier
373mlirLocationNameGetName(MlirLocation location);
374
375/// Getter for childLoc of Name.
376MLIR_CAPI_EXPORTED MlirLocation
377mlirLocationNameGetChildLoc(MlirLocation location);
378
379/// TypeID Getter for Name.
381
382/// Checks whether the given location is an Name.
383MLIR_CAPI_EXPORTED bool mlirLocationIsAName(MlirLocation location);
384
385/// Creates a location with unknown position owned by the given context.
386MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context);
387
388/// TypeID Getter for Unknown.
390
391/// Checks whether the given location is an Unknown.
392MLIR_CAPI_EXPORTED bool mlirLocationIsAUnknown(MlirLocation location);
393
394/// Gets the context that a location was created with.
395MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location);
396
397/// Checks if the location is null.
398static inline bool mlirLocationIsNull(MlirLocation location) {
399 return !location.ptr;
400}
401
402/// Checks if two locations are equal.
403MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2);
404
405/// Prints a location by sending chunks of the string representation and
406/// forwarding `userData to `callback`. Note that the callback may be called
407/// several times with consecutive chunks of the string.
408MLIR_CAPI_EXPORTED void mlirLocationPrint(MlirLocation location,
409 MlirStringCallback callback,
410 void *userData);
411
412//===----------------------------------------------------------------------===//
413// Module API.
414//===----------------------------------------------------------------------===//
415
416/// Creates a new, empty module and transfers ownership to the caller.
417MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateEmpty(MlirLocation location);
418
419/// Parses a module from the string and transfers ownership to the caller.
420MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateParse(MlirContext context,
421 MlirStringRef module);
422
423/// Parses a module from file and transfers ownership to the caller.
424MLIR_CAPI_EXPORTED MlirModule
425mlirModuleCreateParseFromFile(MlirContext context, MlirStringRef fileName);
426
427/// Gets the context that a module was created with.
428MLIR_CAPI_EXPORTED MlirContext mlirModuleGetContext(MlirModule module);
429
430/// Gets the body of the module, i.e. the only block it contains.
431MLIR_CAPI_EXPORTED MlirBlock mlirModuleGetBody(MlirModule module);
432
433/// Checks whether a module is null.
434static inline bool mlirModuleIsNull(MlirModule module) { return !module.ptr; }
435
436/// Takes a module owned by the caller and deletes it.
437MLIR_CAPI_EXPORTED void mlirModuleDestroy(MlirModule module);
438
439/// Views the module as a generic operation.
440MLIR_CAPI_EXPORTED MlirOperation mlirModuleGetOperation(MlirModule module);
441
442/// Views the generic operation as a module.
443/// The returned module is null when the input operation was not a ModuleOp.
444MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op);
445
446/// Checks if two modules are equal.
447MLIR_CAPI_EXPORTED bool mlirModuleEqual(MlirModule lhs, MlirModule rhs);
448
449/// Compute a hash for the given module.
450MLIR_CAPI_EXPORTED size_t mlirModuleHashValue(MlirModule mod);
451
452//===----------------------------------------------------------------------===//
453// Operation state.
454//===----------------------------------------------------------------------===//
455
456/// An auxiliary class for constructing operations.
457///
458/// This class contains all the information necessary to construct the
459/// operation. It owns the MlirRegions it has pointers to and does not own
460/// anything else. By default, the state can be constructed from a name and
461/// location, the latter being also used to access the context, and has no other
462/// components. These components can be added progressively until the operation
463/// is constructed. Users are not expected to rely on the internals of this
464/// class and should use mlirOperationState* functions instead.
465
466struct MlirOperationState {
467 MlirStringRef name;
468 MlirLocation location;
469 intptr_t nResults;
470 MlirType *results;
471 intptr_t nOperands;
472 MlirValue *operands;
473 intptr_t nRegions;
474 MlirRegion *regions;
475 intptr_t nSuccessors;
476 MlirBlock *successors;
477 intptr_t nAttributes;
478 MlirNamedAttribute *attributes;
479 bool enableResultTypeInference;
480};
481typedef struct MlirOperationState MlirOperationState;
482
483/// Constructs an operation state from a name and a location.
485 MlirLocation loc);
486
487/// Adds a list of components to the operation state.
488MLIR_CAPI_EXPORTED void mlirOperationStateAddResults(MlirOperationState *state,
489 intptr_t n,
490 MlirType const *results);
492mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n,
493 MlirValue const *operands);
495mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n,
496 MlirRegion const *regions);
498mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n,
499 MlirBlock const *successors);
501mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n,
502 MlirNamedAttribute const *attributes);
503
504/// Enables result type inference for the operation under construction. If
505/// enabled, then the caller must not have called
506/// mlirOperationStateAddResults(). Note that if enabled, the
507/// mlirOperationCreate() call is failable: it will return a null operation
508/// on inference failure and will emit diagnostics.
510mlirOperationStateEnableResultTypeInference(MlirOperationState *state);
511
512//===----------------------------------------------------------------------===//
513// AsmState API.
514// While many of these are simple settings that could be represented in a
515// struct, they are wrapped in a heap allocated object and accessed via
516// functions to maximize the possibility of compatibility over time.
517//===----------------------------------------------------------------------===//
518
519/// Creates new AsmState, as with AsmState the IR should not be mutated
520/// in-between using this state.
521/// Must be freed with a call to mlirAsmStateDestroy().
522// TODO: This should be expanded to handle location & resouce map.
523MLIR_CAPI_EXPORTED MlirAsmState
524mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags);
525
526/// Creates new AsmState from value.
527/// Must be freed with a call to mlirAsmStateDestroy().
528// TODO: This should be expanded to handle location & resouce map.
529MLIR_CAPI_EXPORTED MlirAsmState
530mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags);
531
532/// Destroys printing flags created with mlirAsmStateCreate.
533MLIR_CAPI_EXPORTED void mlirAsmStateDestroy(MlirAsmState state);
534
535//===----------------------------------------------------------------------===//
536// Op Printing flags API.
537// While many of these are simple settings that could be represented in a
538// struct, they are wrapped in a heap allocated object and accessed via
539// functions to maximize the possibility of compatibility over time.
540//===----------------------------------------------------------------------===//
541
542/// Creates new printing flags with defaults, intended for customization.
543/// Must be freed with a call to mlirOpPrintingFlagsDestroy().
544MLIR_CAPI_EXPORTED MlirOpPrintingFlags mlirOpPrintingFlagsCreate(void);
545
546/// Destroys printing flags created with mlirOpPrintingFlagsCreate.
547MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags);
548
549/// Enables the elision of large elements attributes by printing a lexically
550/// valid but otherwise meaningless form instead of the element data. The
551/// `largeElementLimit` is used to configure what is considered to be a "large"
552/// ElementsAttr by providing an upper limit to the number of elements.
554mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
555 intptr_t largeElementLimit);
556
557/// Enables the elision of large resources strings by omitting them from the
558/// `dialect_resources` section. The `largeResourceLimit` is used to configure
559/// what is considered to be a "large" resource by providing an upper limit to
560/// the string size.
562mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags,
563 intptr_t largeResourceLimit);
564
565/// Enable or disable printing of debug information (based on `enable`). If
566/// 'prettyForm' is set to true, debug information is printed in a more readable
567/// 'pretty' form. Note: The IR generated with 'prettyForm' is not parsable.
569mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
570 bool prettyForm);
571
572/// Always print operations in the generic form.
574mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags);
575
576/// Print the name and location, if NamedLoc, as a prefix to the SSA ID.
578mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags);
579
580/// Use local scope when printing the operation. This allows for using the
581/// printer in a more localized and thread-safe setting, but may not
582/// necessarily be identical to what the IR will look like when dumping
583/// the full module.
585mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags);
586
587/// Do not verify the operation when using custom operation printers.
589mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags);
590
591/// Skip printing regions.
593mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags);
594
595//===----------------------------------------------------------------------===//
596// Bytecode printing flags API.
597//===----------------------------------------------------------------------===//
598
599/// Creates new printing flags with defaults, intended for customization.
600/// Must be freed with a call to mlirBytecodeWriterConfigDestroy().
601MLIR_CAPI_EXPORTED MlirBytecodeWriterConfig
603
604/// Destroys printing flags created with mlirBytecodeWriterConfigCreate.
606mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config);
607
608/// Sets the version to emit in the writer config.
610mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags,
611 int64_t version);
612
613//===----------------------------------------------------------------------===//
614// Operation API.
615//===----------------------------------------------------------------------===//
616
617/// Creates an operation and transfers ownership to the caller.
618/// Note that caller owned child objects are transferred in this call and must
619/// not be further used. Particularly, this applies to any regions added to
620/// the state (the implementation may invalidate any such pointers).
621///
622/// This call can fail under the following conditions, in which case, it will
623/// return a null operation and emit diagnostics:
624/// - Result type inference is enabled and cannot be performed.
625MLIR_CAPI_EXPORTED MlirOperation mlirOperationCreate(MlirOperationState *state);
626
627/// Parses an operation, giving ownership to the caller. If parsing fails a null
628/// operation will be returned, and an error diagnostic emitted.
629///
630/// `sourceStr` may be either the text assembly format, or binary bytecode
631/// format. `sourceName` is used as the file name of the source; any IR without
632/// locations will get a `FileLineColLoc` location with `sourceName` as the file
633/// name.
635 MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName);
636
637/// Creates a deep copy of an operation. The operation is not inserted and
638/// ownership is transferred to the caller.
639MLIR_CAPI_EXPORTED MlirOperation mlirOperationClone(MlirOperation op);
640
641/// Takes an operation owned by the caller and destroys it.
642MLIR_CAPI_EXPORTED void mlirOperationDestroy(MlirOperation op);
643
644/// Removes the given operation from its parent block. The operation is not
645/// destroyed. The ownership of the operation is transferred to the caller.
647
648/// Checks whether the underlying operation is null.
649static inline bool mlirOperationIsNull(MlirOperation op) { return !op.ptr; }
650
651/// Checks whether two operation handles point to the same operation. This does
652/// not perform deep comparison.
653MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op,
654 MlirOperation other);
655
656/// Compute a hash for the given operation. Operand and result SSA values are
657/// hashed by identity and locations are significant, so equivalent-but-distinct
658/// operations hash differently; use mlirOperationStructuralHashValue for a hash
659/// that pairs with mlirOperationIsStructurallyEquivalent.
660MLIR_CAPI_EXPORTED size_t mlirOperationHashValue(MlirOperation op);
661
662/// Flags controlling structural operation equivalence and hashing. These mirror
663/// `mlir::OperationEquivalence::Flags` and may be combined with bitwise OR.
664typedef enum MlirOperationEquivalenceFlags {
665 /// No flags: locations, discardable attributes, properties and
666 /// commutativity are all significant.
667 MLIR_OPERATION_EQUIVALENCE_NONE = 0,
668 /// Ignore the locations attached to operations.
669 MLIR_OPERATION_EQUIVALENCE_IGNORE_LOCATIONS = 1,
670 /// Ignore the discardable attributes attached to operations.
671 MLIR_OPERATION_EQUIVALENCE_IGNORE_DISCARDABLE_ATTRS = 2,
672 /// Ignore the properties attached to operations.
673 MLIR_OPERATION_EQUIVALENCE_IGNORE_PROPERTIES = 4,
674 /// Ignore commutativity, comparing operands in an order-sensitive way.
675 MLIR_OPERATION_EQUIVALENCE_IGNORE_COMMUTATIVITY = 8,
676} MlirOperationEquivalenceFlags;
677
678/// Checks whether two operations are structurally equivalent, i.e. they have
679/// the same name, attributes, operand and result types, and recursively
680/// equivalent regions. Operand equivalence is tracked structurally while
681/// recursing into regions, so operands defined inside the compared regions need
682/// not be the exact same SSA values; operands defined outside must be. `flags`
683/// is a bitwise OR of MlirOperationEquivalenceFlags values.
685 MlirOperation rhs,
686 uint32_t flags);
687
688/// Computes a hash for the given operation that pairs with
689/// mlirOperationIsStructurallyEquivalent: two operations that are structurally
690/// equivalent under the same `flags` hash equally. Operands are hashed by
691/// identity, results are not hashed at all, and regions do not participate in
692/// the hash. `flags` is a bitwise OR of MlirOperationEquivalenceFlags values.
694 uint32_t flags);
695
696/// Gets the context this operation is associated with
697MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op);
698
699/// Checks if the operation name has a trait identified by the given type id.
701 MlirTypeID traitTypeID,
702 MlirContext context);
703
704/// Gets the location of the operation.
705MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation(MlirOperation op);
706
707/// Sets the location of the operation.
708MLIR_CAPI_EXPORTED void mlirOperationSetLocation(MlirOperation op,
709 MlirLocation loc);
710
711/// Gets the type id of the operation.
712/// Returns null if the operation does not have a registered operation
713/// description.
714MLIR_CAPI_EXPORTED MlirTypeID mlirOperationGetTypeID(MlirOperation op);
715
716/// Gets the name of the operation as an identifier.
717MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op);
718
719/// Gets the block that owns this operation, returning null if the operation is
720/// not owned.
721MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetBlock(MlirOperation op);
722
723/// Gets the operation that owns this operation, returning null if the operation
724/// is not owned.
725MLIR_CAPI_EXPORTED MlirOperation
726mlirOperationGetParentOperation(MlirOperation op);
727
728/// Returns true if `a` is an ancestor of `b`, i.e. `a` contains `b` or
729/// `a == b`.
731 MlirOperation b);
732
733/// Returns true if `a` is a proper ancestor of `b`, i.e. `a` contains `b` but
734/// `a != b`.
736 MlirOperation b);
737
738/// Returns the number of regions attached to the given operation.
740
741/// Returns `pos`-th region attached to the operation.
742MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op,
743 intptr_t pos);
744
745/// Returns an operation immediately following the given operation it its
746/// enclosing block.
747MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetNextInBlock(MlirOperation op);
748
749/// Returns the number of operands of the operation.
751
752/// Returns `pos`-th operand of the operation.
753MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op,
754 intptr_t pos);
755
756/// Returns `pos`-th OpOperand of the operation.
757MLIR_CAPI_EXPORTED MlirOpOperand mlirOperationGetOpOperand(MlirOperation op,
758 intptr_t pos);
759
760/// Sets the `pos`-th operand of the operation.
761MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
762 MlirValue newValue);
763
764/// Replaces the operands of the operation.
765MLIR_CAPI_EXPORTED void mlirOperationSetOperands(MlirOperation op,
766 intptr_t nOperands,
767 MlirValue const *operands);
768
769/// Returns the number of results of the operation.
771
772/// Returns `pos`-th result of the operation.
773MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op,
774 intptr_t pos);
775
776/// Returns the number of successor blocks of the operation.
778
779/// Returns `pos`-th successor of the operation.
780MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op,
781 intptr_t pos);
782
783/// Set `pos`-th successor of the operation.
785mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block);
786
787/// Returns true if this operation defines an inherent attribute with this name.
788/// Note: the attribute can be optional, so
789/// `mlirOperationGetInherentAttributeByName` can still return a null attribute.
792
793/// Returns an inherent attribute attached to the operation given its name.
794MLIR_CAPI_EXPORTED MlirAttribute
796
797/// Sets an inherent attribute by name, replacing the existing if it exists.
798/// This has no effect if "name" does not match an inherent attribute.
801 MlirAttribute attr);
802
803/// Returns the number of discardable attributes attached to the operation.
806
807/// Return `pos`-th discardable attribute of the operation.
810
811/// Returns a discardable attribute attached to the operation given its name.
813 MlirOperation op, MlirStringRef name);
814
815/// Sets a discardable attribute by name, replacing the existing if it exists or
816/// adding a new one otherwise. The new `attr` Attribute is not allowed to be
817/// null, use `mlirOperationRemoveDiscardableAttributeByName` to remove an
818/// Attribute instead.
821 MlirAttribute attr);
822
823/// Removes a discardable attribute by name. Returns false if the attribute was
824/// not found and true if removed.
827 MlirStringRef name);
828
829/// Returns the number of attributes attached to the operation.
830/// Deprecated, please use `mlirOperationGetNumInherentAttributes` or
831/// `mlirOperationGetNumDiscardableAttributes`.
833
834/// Return `pos`-th attribute of the operation.
835/// Deprecated, please use `mlirOperationGetInherentAttribute` or
836/// `mlirOperationGetDiscardableAttribute`.
838mlirOperationGetAttribute(MlirOperation op, intptr_t pos);
839
840/// Returns an attribute attached to the operation given its name.
841/// Deprecated, please use `mlirOperationGetInherentAttributeByName` or
842/// `mlirOperationGetDiscardableAttributeByName`.
843MLIR_CAPI_EXPORTED MlirAttribute
844mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name);
845
846/// Sets an attribute by name, replacing the existing if it exists or
847/// adding a new one otherwise.
848/// Deprecated, please use `mlirOperationSetInherentAttributeByName` or
849/// `mlirOperationSetDiscardableAttributeByName`.
851 MlirStringRef name,
852 MlirAttribute attr);
853
854/// Removes an attribute by name. Returns false if the attribute was not found
855/// and true if removed.
856/// Deprecated, please use `mlirOperationRemoveInherentAttributeByName` or
857/// `mlirOperationRemoveDiscardableAttributeByName`.
859 MlirStringRef name);
860
861/// Prints an operation by sending chunks of the string representation and
862/// forwarding `userData to `callback`. Note that the callback may be called
863/// several times with consecutive chunks of the string.
864MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op,
865 MlirStringCallback callback,
866 void *userData);
867
868/// Same as mlirOperationPrint but accepts flags controlling the printing
869/// behavior.
871 MlirOpPrintingFlags flags,
872 MlirStringCallback callback,
873 void *userData);
874
875/// Same as mlirOperationPrint but accepts AsmState controlling the printing
876/// behavior as well as caching computed names.
878 MlirAsmState state,
879 MlirStringCallback callback,
880 void *userData);
881
882/// Same as mlirOperationPrint but writing the bytecode format.
884 MlirStringCallback callback,
885 void *userData);
886
887/// Same as mlirOperationWriteBytecode but with writer config and returns
888/// failure only if desired bytecode could not be honored.
890 MlirOperation op, MlirBytecodeWriterConfig config,
891 MlirStringCallback callback, void *userData);
892
893/// Prints an operation to stderr.
894MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op);
895
896/// Verify the operation and return true if it passes, false if it fails.
897MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op);
898
899/// Moves the given operation immediately after the other operation in its
900/// parent block. The given operation may be owned by the caller or by its
901/// current block. The other operation must belong to a block. In any case, the
902/// ownership is transferred to the block of the other operation.
903MLIR_CAPI_EXPORTED void mlirOperationMoveAfter(MlirOperation op,
904 MlirOperation other);
905
906/// Moves the given operation immediately before the other operation in its
907/// parent block. The given operation may be owner by the caller or by its
908/// current block. The other operation must belong to a block. In any case, the
909/// ownership is transferred to the block of the other operation.
910MLIR_CAPI_EXPORTED void mlirOperationMoveBefore(MlirOperation op,
911 MlirOperation other);
912
913/// Given an operation 'other' that is within the same parent block, return
914/// whether the current operation is before 'other' in the operation list
915/// of the parent block.
916/// Note: This function has an average complexity of O(1), but worst case may
917/// take O(N) where N is the number of operations within the parent block.
919 MlirOperation other);
920/// Operation walk result.
926
927/// Traversal order for operation walk.
932
933/// Operation walker type. The handler is passed an (opaque) reference to an
934/// operation and a pointer to a `userData`.
936 void *userData);
937
938/// Walks operation `op` in `walkOrder` and calls `callback` on that operation.
939/// `*userData` is passed to the callback as well and can be used to tunnel some
940/// context or other data into the callback.
942void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback,
943 void *userData, MlirWalkOrder walkOrder);
944
945/// Replace uses of 'of' value with the 'with' value inside the 'op' operation.
947mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with);
948
949//===----------------------------------------------------------------------===//
950// Region API.
951//===----------------------------------------------------------------------===//
952
953/// Creates a new empty region and transfers ownership to the caller.
954MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void);
955
956/// Takes a region owned by the caller and destroys it.
957MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region);
958
959/// Checks whether a region is null.
960static inline bool mlirRegionIsNull(MlirRegion region) { return !region.ptr; }
961
962/// Checks whether two region handles point to the same region. This does not
963/// perform deep comparison.
964MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other);
965
966/// Gets the first block in the region.
967MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region);
968
969/// Takes a block owned by the caller and appends it to the given region.
971 MlirBlock block);
972
973/// Takes a block owned by the caller and inserts it at `pos` to the given
974/// region. This is an expensive operation that linearly scans the region,
975/// prefer insertAfter/Before instead.
977mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block);
978
979/// Takes a block owned by the caller and inserts it after the (non-owned)
980/// reference block in the given region. The reference block must belong to the
981/// region. If the reference block is null, prepends the block to the region.
983 MlirBlock reference,
984 MlirBlock block);
985
986/// Takes a block owned by the caller and inserts it before the (non-owned)
987/// reference block in the given region. The reference block must belong to the
988/// region. If the reference block is null, appends the block to the region.
990 MlirBlock reference,
991 MlirBlock block);
992
993/// Returns first region attached to the operation.
994MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op);
995
996/// Returns the region immediately following the given region in its parent
997/// operation.
998MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region);
999
1000/// Moves the entire content of the source region to the target region.
1002 MlirRegion source);
1003
1004//===----------------------------------------------------------------------===//
1005// Block API.
1006//===----------------------------------------------------------------------===//
1007
1008/// Creates a new empty block with the given argument types and transfers
1009/// ownership to the caller.
1011 MlirType const *args,
1012 MlirLocation const *locs);
1013
1014/// Takes a block owned by the caller and destroys it.
1015MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block);
1016
1017/// Detach a block from the owning region and assume ownership.
1018MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block);
1019
1020/// Checks whether a block is null.
1021static inline bool mlirBlockIsNull(MlirBlock block) { return !block.ptr; }
1022
1023/// Checks whether two blocks handles point to the same block. This does not
1024/// perform deep comparison.
1025MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other);
1026
1027/// Returns the closest surrounding operation that contains this block.
1028MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock);
1029
1030/// Returns the region that contains this block.
1031MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block);
1032
1033/// Returns the block immediately following the given block in its parent
1034/// region.
1035MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block);
1036
1037/// Returns the first operation in the block.
1038MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block);
1039
1040/// Returns the terminator operation in the block or null if no terminator.
1041MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block);
1042
1043/// Takes an operation owned by the caller and appends it to the block.
1045 MlirOperation operation);
1046
1047/// Takes an operation owned by the caller and inserts it as `pos` to the block.
1048/// This is an expensive operation that scans the block linearly, prefer
1049/// insertBefore/After instead.
1051 intptr_t pos,
1052 MlirOperation operation);
1053
1054/// Takes an operation owned by the caller and inserts it after the (non-owned)
1055/// reference operation in the given block. If the reference is null, prepends
1056/// the operation. Otherwise, the reference must belong to the block.
1058mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference,
1059 MlirOperation operation);
1060
1061/// Takes an operation owned by the caller and inserts it before the (non-owned)
1062/// reference operation in the given block. If the reference is null, appends
1063/// the operation. Otherwise, the reference must belong to the block.
1065mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference,
1066 MlirOperation operation);
1067
1068/// Returns the number of arguments of the block.
1070
1071/// Appends an argument of the specified type to the block. Returns the newly
1072/// added argument.
1073MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block,
1074 MlirType type,
1075 MlirLocation loc);
1076
1077/// Erase the argument at 'index' and remove it from the argument list.
1078MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index);
1079
1080/// Inserts an argument of the specified type at a specified index to the block.
1081/// Returns the newly added argument.
1082MLIR_CAPI_EXPORTED MlirValue mlirBlockInsertArgument(MlirBlock block,
1083 intptr_t pos,
1084 MlirType type,
1085 MlirLocation loc);
1086
1087/// Returns `pos`-th argument of the block.
1088MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block,
1089 intptr_t pos);
1090
1091/// Prints a block by sending chunks of the string representation and
1092/// forwarding `userData to `callback`. Note that the callback may be called
1093/// several times with consecutive chunks of the string.
1095mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData);
1096
1097/// Returns the number of successor blocks of the block.
1099
1100/// Returns `pos`-th successor of the block.
1101MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetSuccessor(MlirBlock block,
1102 intptr_t pos);
1103
1104/// Returns the number of predecessor blocks of the block.
1106
1107/// Returns `pos`-th predecessor of the block.
1108///
1109/// WARNING: This getter is more expensive than the others here because
1110/// the impl actually iterates the use-def chain (of block operands) anew for
1111/// each indexed access.
1112MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetPredecessor(MlirBlock block,
1113 intptr_t pos);
1114
1115//===----------------------------------------------------------------------===//
1116// Value API.
1117//===----------------------------------------------------------------------===//
1118
1119/// Returns whether the value is null.
1120static inline bool mlirValueIsNull(MlirValue value) { return !value.ptr; }
1121
1122/// Returns 1 if two values are equal, 0 otherwise.
1123MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2);
1124
1125/// Returns 1 if the value is a block argument, 0 otherwise.
1126MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value);
1127
1128/// Returns 1 if the value is an operation result, 0 otherwise.
1129MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value);
1130
1131/// Returns the block in which this value is defined as an argument. Asserts if
1132/// the value is not a block argument.
1133MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value);
1134
1135/// Returns the position of the value in the argument list of its block.
1137
1138/// Sets the type of the block argument to the given type.
1139MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value,
1140 MlirType type);
1141
1142/// Sets the location of the block argument to the given location.
1144 MlirLocation loc);
1145
1146/// Returns an operation that produced this value as its result. Asserts if the
1147/// value is not an op result.
1148MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value);
1149
1150/// Returns the position of the value in the list of results of the operation
1151/// that produced it.
1153
1154/// Returns the type of the value.
1155MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value);
1156
1157/// Set the type of the value.
1158MLIR_CAPI_EXPORTED void mlirValueSetType(MlirValue value, MlirType type);
1159
1160/// Prints the value to the standard error stream.
1161MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value);
1162
1163/// Prints a value by sending chunks of the string representation and
1164/// forwarding `userData to `callback`. Note that the callback may be called
1165/// several times with consecutive chunks of the string.
1167mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData);
1168
1169/// Prints a value as an operand (i.e., the ValueID).
1170MLIR_CAPI_EXPORTED void mlirValuePrintAsOperand(MlirValue value,
1171 MlirAsmState state,
1172 MlirStringCallback callback,
1173 void *userData);
1174
1175/// Returns an op operand representing the first use of the value, or a null op
1176/// operand if there are no uses.
1177MLIR_CAPI_EXPORTED MlirOpOperand mlirValueGetFirstUse(MlirValue value);
1178
1179/// Replace all uses of 'of' value with the 'with' value, updating anything in
1180/// the IR that uses 'of' to use the other value instead. When this returns
1181/// there are zero uses of 'of'.
1183 MlirValue with);
1184
1185/// Replace all uses of 'of' value with 'with' value, updating anything in the
1186/// IR that uses 'of' to use 'with' instead, except if the user is listed in
1187/// 'exceptions'. The 'exceptions' parameter is an array of MlirOperation
1188/// pointers with a length of 'numExceptions'.
1190mlirValueReplaceAllUsesExcept(MlirValue of, MlirValue with,
1191 intptr_t numExceptions,
1192 MlirOperation *exceptions);
1193
1194/// Callback deciding whether a particular use should be replaced. It is passed
1195/// the use as an MlirOpOperand (from which the owner operation, operand number
1196/// and value can be queried) and the user-provided `userData`. Returns true to
1197/// replace this use.
1198typedef bool (*MlirOpOperandReplaceFilterCallback)(MlirOpOperand opOperand,
1199 void *userData);
1200
1201/// Replace uses of 'of' value with 'with' value, but only for the uses for
1202/// which the `filter` callback returns true. `filter` must not be NULL; this is
1203/// only checked by an assertion, i.e. in builds with assertions enabled.
1205mlirValueReplaceUsesWithIf(MlirValue of, MlirValue with,
1207 void *userData);
1208
1209/// Gets the location of the value.
1210MLIR_CAPI_EXPORTED MlirLocation mlirValueGetLocation(MlirValue v);
1211
1212/// Gets the context that a value was created with.
1213MLIR_CAPI_EXPORTED MlirContext mlirValueGetContext(MlirValue v);
1214
1215//===----------------------------------------------------------------------===//
1216// OpOperand API.
1217//===----------------------------------------------------------------------===//
1218
1219/// Returns whether the op operand is null.
1220MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand);
1221
1222/// Returns the value of an op operand.
1223MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand);
1224
1225/// Returns the owner operation of an op operand.
1226MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand);
1227
1228/// Returns the operand number of an op operand.
1229MLIR_CAPI_EXPORTED unsigned
1230mlirOpOperandGetOperandNumber(MlirOpOperand opOperand);
1231
1232/// Returns an op operand representing the next use of the value, or a null op
1233/// operand if there is no next use.
1234MLIR_CAPI_EXPORTED MlirOpOperand
1235mlirOpOperandGetNextUse(MlirOpOperand opOperand);
1236
1237//===----------------------------------------------------------------------===//
1238// Type API.
1239//===----------------------------------------------------------------------===//
1240
1241/// Parses a type. The type is owned by the context.
1242MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context,
1243 MlirStringRef type);
1244
1245/// Gets the context that a type was created with.
1246MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type);
1247
1248/// Gets the type ID of the type.
1249MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type);
1250
1251/// Gets the dialect a type belongs to.
1252MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type);
1253
1254/// Checks whether a type is null.
1255static inline bool mlirTypeIsNull(MlirType type) { return !type.ptr; }
1256
1257/// Checks if two types are equal.
1258MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2);
1259
1260/// Prints a location by sending chunks of the string representation and
1261/// forwarding `userData to `callback`. Note that the callback may be called
1262/// several times with consecutive chunks of the string.
1264mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData);
1265
1266/// Prints the type to the standard error stream.
1267MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type);
1268
1269//===----------------------------------------------------------------------===//
1270// Attribute API.
1271//===----------------------------------------------------------------------===//
1272
1273/// Parses an attribute. The attribute is owned by the context.
1274MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context,
1275 MlirStringRef attr);
1276
1277/// Gets the context that an attribute was created with.
1278MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute);
1279
1280/// Gets the type of this attribute.
1281MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute);
1282
1283/// Gets the type id of the attribute.
1284MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute);
1285
1286/// Gets the dialect of the attribute.
1287MLIR_CAPI_EXPORTED MlirDialect mlirAttributeGetDialect(MlirAttribute attribute);
1288
1289/// Checks whether an attribute is null.
1290static inline bool mlirAttributeIsNull(MlirAttribute attr) { return !attr.ptr; }
1291
1292/// Checks if two attributes are equal.
1293MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2);
1294
1295/// Prints an attribute by sending chunks of the string representation and
1296/// forwarding `userData to `callback`. Note that the callback may be called
1297/// several times with consecutive chunks of the string.
1298MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr,
1299 MlirStringCallback callback,
1300 void *userData);
1301
1302/// Prints the attribute to the standard error stream.
1303MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr);
1304
1305/// Associates an attribute with the name. Takes ownership of neither.
1307 MlirAttribute attr);
1308
1309//===----------------------------------------------------------------------===//
1310// Identifier API.
1311//===----------------------------------------------------------------------===//
1312
1313/// Gets an identifier with the given string value.
1314MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context,
1315 MlirStringRef str);
1316
1317/// Returns the context associated with this identifier
1318MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier);
1319
1320/// Checks whether two identifiers are the same.
1321MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident,
1322 MlirIdentifier other);
1323
1324/// Gets the string value of the identifier.
1326
1327//===----------------------------------------------------------------------===//
1328// Symbol and SymbolTable API.
1329//===----------------------------------------------------------------------===//
1330
1331/// Returns the name of the attribute used to store symbol names compatible with
1332/// symbol tables.
1334
1335/// Returns the name of the attribute used by default to store symbol
1336/// visibility.
1339
1340/// Creates a symbol table for the given operation. If the operation does not
1341/// have the SymbolTable trait, returns a null symbol table.
1342MLIR_CAPI_EXPORTED MlirSymbolTable
1343mlirSymbolTableCreate(MlirOperation operation);
1344
1345/// Returns true if the symbol table is null.
1346static inline bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable) {
1347 return !symbolTable.ptr;
1348}
1349
1350/// Destroys the symbol table created with mlirSymbolTableCreate. This does not
1351/// affect the operations in the table.
1352MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable);
1353
1354/// Looks up a symbol with the given name in the given symbol table and returns
1355/// the operation that corresponds to the symbol. If the symbol cannot be found,
1356/// returns a null operation.
1357MLIR_CAPI_EXPORTED MlirOperation
1358mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name);
1359
1360/// Inserts the given operation into the given symbol table. The operation must
1361/// have the symbol trait. If the symbol table already has a symbol with the
1362/// same name, renames the symbol being inserted to ensure name uniqueness. Note
1363/// that this does not move the operation itself into the block of the symbol
1364/// table operation, this should be done separately. Returns the name of the
1365/// symbol after insertion.
1366MLIR_CAPI_EXPORTED MlirAttribute
1367mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation);
1368
1369/// Removes the given operation from the symbol table and erases it.
1370MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable,
1371 MlirOperation operation);
1372
1373/// Attempt to replace all uses that are nested within the given operation
1374/// of the given symbol 'oldSymbol' with the provided 'newSymbol'. This does
1375/// not traverse into nested symbol tables. Will fail atomically if there are
1376/// any unknown operations that may be potential symbol tables.
1378 MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from);
1379
1380/// Walks all symbol table operations nested within, and including, `op`. For
1381/// each symbol table operation, the provided callback is invoked with the op
1382/// and a boolean signifying if the symbols within that symbol table can be
1383/// treated as if all uses within the IR are visible to the caller.
1384/// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
1385/// within `op` are visible.
1387 MlirOperation from, bool allSymUsesVisible,
1388 void (*callback)(MlirOperation, bool, void *userData), void *userData);
1389
1390//===----------------------------------------------------------------------===//
1391// IRMapping API
1392//===----------------------------------------------------------------------===//
1393
1394/// Creates a new empty IRMapping.
1395MLIR_CAPI_EXPORTED MlirIRMapping mlirIRMappingCreate(void);
1396
1397/// Destroys the given IRMapping.
1398MLIR_CAPI_EXPORTED void mlirIRMappingDestroy(MlirIRMapping mapping);
1399
1400/// Checks whether an IRMapping is null.
1401static inline bool mlirIRMappingIsNull(MlirIRMapping mapping) {
1402 return !mapping.ptr;
1403}
1404
1405/// Maps a Value in the mapping.
1406MLIR_CAPI_EXPORTED void mlirIRMappingMapValue(MlirIRMapping mapping,
1407 MlirValue from, MlirValue to);
1408
1409/// Maps a Block in the mapping.
1410MLIR_CAPI_EXPORTED void mlirIRMappingMapBlock(MlirIRMapping mapping,
1411 MlirBlock from, MlirBlock to);
1412
1413/// Maps an Operation in the mapping.
1414MLIR_CAPI_EXPORTED void mlirIRMappingMapOperation(MlirIRMapping mapping,
1415 MlirOperation from,
1416 MlirOperation to);
1417
1418/// Clears all mappings.
1419MLIR_CAPI_EXPORTED void mlirIRMappingClear(MlirIRMapping mapping);
1420
1421/// Looks up a mapped Value. Returns the mapped value, or the input value if
1422/// no mapping exists.
1423MLIR_CAPI_EXPORTED MlirValue
1424mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping, MlirValue from);
1425
1426/// Looks up a mapped Value. Returns a null MlirValue if no mapping exists.
1427MLIR_CAPI_EXPORTED MlirValue
1428mlirIRMappingLookupOrNullValue(MlirIRMapping mapping, MlirValue from);
1429
1430/// Looks up a mapped Block. Returns the mapped block, or the input block if
1431/// no mapping exists.
1432MLIR_CAPI_EXPORTED MlirBlock
1433mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping, MlirBlock from);
1434
1435/// Looks up a mapped Block. Returns a null MlirBlock if no mapping exists.
1436MLIR_CAPI_EXPORTED MlirBlock
1437mlirIRMappingLookupOrNullBlock(MlirIRMapping mapping, MlirBlock from);
1438
1439/// Looks up a mapped Operation. Returns the mapped operation, or the input
1440/// operation if no mapping exists.
1442 MlirIRMapping mapping, MlirOperation from);
1443
1444/// Looks up a mapped Operation. Returns a null MlirOperation if no mapping
1445/// exists.
1446MLIR_CAPI_EXPORTED MlirOperation
1447mlirIRMappingLookupOrNullOperation(MlirIRMapping mapping, MlirOperation from);
1448
1449/// Returns true if the mapping contains a mapping for the given value.
1450MLIR_CAPI_EXPORTED bool mlirIRMappingContainsValue(MlirIRMapping mapping,
1451 MlirValue value);
1452
1453/// Returns true if the mapping contains a mapping for the given block.
1454MLIR_CAPI_EXPORTED bool mlirIRMappingContainsBlock(MlirIRMapping mapping,
1455 MlirBlock block);
1456
1457/// Returns true if the mapping contains a mapping for the given operation.
1458MLIR_CAPI_EXPORTED bool mlirIRMappingContainsOperation(MlirIRMapping mapping,
1459 MlirOperation op);
1460
1461/// Erases a value mapping.
1462MLIR_CAPI_EXPORTED void mlirIRMappingEraseValue(MlirIRMapping mapping,
1463 MlirValue value);
1464
1465/// Erases a block mapping.
1466MLIR_CAPI_EXPORTED void mlirIRMappingEraseBlock(MlirIRMapping mapping,
1467 MlirBlock block);
1468
1469/// Erases an operation mapping.
1470MLIR_CAPI_EXPORTED void mlirIRMappingEraseOperation(MlirIRMapping mapping,
1471 MlirOperation op);
1472
1473/// Clones the operation with the given mapping. The mapping is updated with
1474/// the cloned operation's results and regions.
1475MLIR_CAPI_EXPORTED MlirOperation
1476mlirOperationCloneWithMapping(MlirOperation op, MlirIRMapping mapping);
1477
1478#ifdef __cplusplus
1479}
1480#endif
1481
1482#endif // MLIR_C_IR_H
MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:839
MlirContext mlirModuleGetContext(MlirModule module)
Definition IR.cpp:471
size_t mlirModuleHashValue(MlirModule mod)
Definition IR.cpp:497
intptr_t mlirBlockGetNumPredecessors(MlirBlock block)
Definition IR.cpp:1158
MlirIdentifier mlirOperationGetName(MlirOperation op)
Definition IR.cpp:719
bool mlirValueIsABlockArgument(MlirValue value)
Definition IR.cpp:1178
intptr_t mlirOperationGetNumRegions(MlirOperation op)
Definition IR.cpp:739
MlirBlock mlirOperationGetBlock(MlirOperation op)
Definition IR.cpp:723
void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Definition IR.cpp:1195
void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition IR.cpp:546
MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Definition IR.cpp:794
MlirModule mlirModuleCreateParseFromFile(MlirContext context, MlirStringRef fileName)
Definition IR.cpp:462
bool mlirOperationNameHasTrait(MlirStringRef opName, MlirTypeID traitTypeID, MlirContext context)
Definition IR.cpp:699
MlirAsmState mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags)
Definition IR.cpp:195
intptr_t mlirOperationGetNumResults(MlirOperation op)
Definition IR.cpp:790
bool mlirOperationIsAncestor(MlirOperation a, MlirOperation b)
Definition IR.cpp:731
void mlirOperationDestroy(MlirOperation op)
Definition IR.cpp:664
MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:812
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Definition IR.cpp:1353
MlirType mlirValueGetType(MlirValue value)
Definition IR.cpp:1214
void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
Definition IR.cpp:1144
void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:844
MlirOpPrintingFlags mlirOpPrintingFlagsCreate()
Definition IR.cpp:219
bool mlirModuleEqual(MlirModule lhs, MlirModule rhs)
Definition IR.cpp:493
void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags, intptr_t largeElementLimit)
Definition IR.cpp:227
void mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block)
Definition IR.cpp:855
MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
Definition IR.cpp:763
void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
Definition IR.cpp:237
MlirOperation mlirModuleGetOperation(MlirModule module)
Definition IR.cpp:485
void mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags, intptr_t largeResourceLimit)
Definition IR.cpp:232
void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
Definition IR.cpp:250
MlirTypeID mlirOperationGetTypeID(MlirOperation op)
Definition IR.cpp:713
intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
Definition IR.cpp:1190
MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Definition IR.cpp:802
bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Definition IR.cpp:1372
MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags)
Definition IR.cpp:174
bool mlirOperationEqual(MlirOperation op, MlirOperation other)
Definition IR.cpp:668
void mlirOperationSetInherentAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:820
void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
Definition IR.cpp:254
bool mlirValueEqual(MlirValue value1, MlirValue value2)
Definition IR.cpp:1174
void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
Definition IR.cpp:269
MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1154
void mlirModuleDestroy(MlirModule module)
Definition IR.cpp:479
MlirModule mlirModuleCreateEmpty(MlirLocation location)
Definition IR.cpp:450
void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
Definition IR.cpp:242
MlirOperation mlirOperationGetParentOperation(MlirOperation op)
Definition IR.cpp:727
void mlirValueSetType(MlirValue value, MlirType type)
Definition IR.cpp:1218
intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Definition IR.cpp:798
MlirDialect mlirAttributeGetDialect(MlirAttribute attr)
Definition IR.cpp:1368
void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
Definition IR.cpp:440
void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:874
void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Definition IR.cpp:779
MlirOperation mlirOpResultGetOwner(MlirValue value)
Definition IR.cpp:1205
MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
Definition IR.cpp:454
size_t mlirOperationHashValue(MlirOperation op)
Definition IR.cpp:672
void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n, MlirType const *results)
Definition IR.cpp:529
MlirOperation mlirOperationClone(MlirOperation op)
Definition IR.cpp:660
MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
Definition IR.cpp:1186
void mlirBlockArgumentSetLocation(MlirValue value, MlirLocation loc)
Definition IR.cpp:1200
MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:771
MlirModule mlirModuleFromOperation(MlirOperation op)
Definition IR.cpp:489
MlirOpOperand mlirOperationGetOpOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:775
MlirLocation mlirOperationGetLocation(MlirOperation op)
Definition IR.cpp:705
MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:869
MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr)
Definition IR.cpp:1364
intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
Definition IR.cpp:827
void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
Definition IR.cpp:538
void mlirOperationSetLocation(MlirOperation op, MlirLocation loc)
Definition IR.cpp:709
MlirType mlirAttributeGetType(MlirAttribute attribute)
Definition IR.cpp:1357
bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:850
bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:879
bool mlirValueIsAOpResult(MlirValue value)
Definition IR.cpp:1182
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:807
MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1163
size_t mlirOperationStructuralHashValue(MlirOperation op, uint32_t flags)
Definition IR.cpp:688
MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Definition IR.cpp:743
MlirOperation mlirOperationCreate(MlirOperationState *state)
Definition IR.cpp:614
bool mlirOperationIsStructurallyEquivalent(MlirOperation lhs, MlirOperation rhs, uint32_t flags)
Definition IR.cpp:682
void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags, int64_t version)
Definition IR.cpp:273
MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
Definition IR.cpp:1349
void mlirOperationRemoveFromParent(MlirOperation op)
Definition IR.cpp:666
intptr_t mlirBlockGetNumSuccessors(MlirBlock block)
Definition IR.cpp:1150
MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:864
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Definition IR.cpp:223
void mlirValueDump(MlirValue value)
Definition IR.cpp:1222
void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
Definition IR.cpp:784
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
Definition IR.cpp:1338
MlirBlock mlirModuleGetBody(MlirModule module)
Definition IR.cpp:475
MlirOperation mlirOperationCreateParse(MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName)
Definition IR.cpp:651
void mlirAsmStateDestroy(MlirAsmState state)
Destroys printing flags created with mlirAsmStateCreate.
Definition IR.cpp:213
MlirContext mlirOperationGetContext(MlirOperation op)
Definition IR.cpp:695
intptr_t mlirOpResultGetResultNumber(MlirValue value)
Definition IR.cpp:1209
MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:832
void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
Definition IR.cpp:551
void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
Definition IR.cpp:542
MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate()
Definition IR.cpp:265
void mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags)
Definition IR.cpp:246
void mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags)
Definition IR.cpp:258
void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
Definition IR.cpp:534
MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
Definition IR.cpp:505
intptr_t mlirOperationGetNumOperands(MlirOperation op)
Definition IR.cpp:767
bool mlirOperationIsProperAncestor(MlirOperation a, MlirOperation b)
Definition IR.cpp:735
void mlirTypeDump(MlirType type)
Definition IR.cpp:1343
intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Definition IR.cpp:860
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
MLIR_CAPI_EXPORTED MlirValue mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value.
Definition IR.cpp:1493
MLIR_CAPI_EXPORTED MlirOperation mlirIRMappingLookupOrDefaultOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
Definition IR.cpp:1513
MLIR_CAPI_EXPORTED MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
Definition IR.cpp:282
MlirWalkResult(* MlirOperationWalkCallback)(MlirOperation, void *userData)
Operation walker type.
Definition IR.h:935
MLIR_CAPI_EXPORTED MlirLocation mlirValueGetLocation(MlirValue v)
Gets the location of the value.
Definition IR.cpp:1275
MLIR_CAPI_EXPORTED MlirBlock mlirIRMappingLookupOrNullBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block. Returns a null MlirBlock if no mapping exists.
Definition IR.cpp:1508
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:122
MLIR_CAPI_EXPORTED void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
Definition IR.cpp:904
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:290
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:1457
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition IR.cpp:154
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetEndColumn(MlirLocation location)
Getter for end_column of FileLineColRange.
Definition IR.cpp:328
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
Definition IR.cpp:1436
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetDefaultVisibilityAttributeName(void)
Returns the name of the attribute used by default to store symbol visibility.
Definition IR.cpp:1417
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:928
@ MlirWalkPreOrder
Definition IR.h:929
@ MlirWalkPostOrder
Definition IR.h:930
MLIR_CAPI_EXPORTED bool mlirLocationIsAUnknown(MlirLocation location)
Checks whether the given location is an Unknown.
Definition IR.cpp:428
MLIR_CAPI_EXPORTED MlirOperation mlirIRMappingLookupOrNullOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
Definition IR.cpp:1518
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationUnknownGetTypeID(void)
TypeID Getter for Unknown.
Definition IR.cpp:424
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
Definition IR.cpp:1384
MLIR_CAPI_EXPORTED MlirOperation mlirOperationCloneWithMapping(MlirOperation op, MlirIRMapping mapping)
Clones the operation with the given mapping.
Definition IR.cpp:1547
MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGetChildLoc(MlirLocation location)
Getter for childLoc of Name.
Definition IR.cpp:409
MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
Definition IR.cpp:1441
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:84
MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
Definition IR.cpp:1405
MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition IR.cpp:1318
MLIR_CAPI_EXPORTED void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
Definition IR.cpp:166
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
Definition IR.cpp:91
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:1301
MLIR_CAPI_EXPORTED void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
Definition IR.cpp:73
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:1014
MLIR_CAPI_EXPORTED void mlirContextBeginTransientScope(MlirContext context)
Begins a transient scope on the context, freezing the base layer (loaded dialects,...
Definition IR.cpp:130
MLIR_CAPI_EXPORTED bool mlirLocationIsAFileLineColRange(MlirLocation location)
Checks whether the given location is an FileLineColRange.
Definition IR.cpp:338
bool(* MlirOpOperandReplaceFilterCallback)(MlirOpOperand opOperand, void *userData)
Callback deciding whether a particular use should be replaced.
Definition IR.h:1198
MLIR_CAPI_EXPORTED unsigned mlirLocationFusedGetNumLocations(MlirLocation location)
Getter for number of locations fused together.
Definition IR.cpp:372
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:1247
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:1230
MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
Definition IR.cpp:420
MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
Definition IR.cpp:1289
MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition IR.cpp:1401
MLIR_CAPI_EXPORTED void mlirIRMappingDestroy(MlirIRMapping mapping)
Destroys the given IRMapping.
Definition IR.cpp:1474
MLIR_CAPI_EXPORTED MlirIdentifier mlirLocationFileLineColRangeGetFilename(MlirLocation location)
Getter for filename of FileLineColRange.
Definition IR.cpp:306
MLIR_CAPI_EXPORTED void mlirLocationFusedGetLocations(MlirLocation location, MlirLocation *locationsCPtr)
Getter for locations of Fused.
Definition IR.cpp:378
MLIR_CAPI_EXPORTED void mlirIRMappingMapBlock(MlirIRMapping mapping, MlirBlock from, MlirBlock to)
Maps a Block in the mapping.
Definition IR.cpp:1481
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
Definition IR.cpp:80
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:1376
MLIR_CAPI_EXPORTED void mlirIRMappingClear(MlirIRMapping mapping)
Clears all mappings.
Definition IR.cpp:1491
MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition IR.cpp:1053
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:928
MLIR_CAPI_EXPORTED bool mlirIRMappingContainsValue(MlirIRMapping mapping, MlirValue value)
Returns true if the mapping contains a mapping for the given value.
Definition IR.cpp:1523
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:1251
MLIR_CAPI_EXPORTED void mlirIRMappingEraseValue(MlirIRMapping mapping, MlirValue value)
Erases a value mapping.
Definition IR.cpp:1535
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:895
MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition IR.cpp:1115
MlirWalkResult
Operation walk result.
Definition IR.h:921
@ MlirWalkResultInterrupt
Definition IR.h:923
@ MlirWalkResultSkip
Definition IR.h:924
@ MlirWalkResultAdvance
Definition IR.h:922
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:994
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition IR.h:1255
MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition IR.cpp:979
MLIR_CAPI_EXPORTED bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
Definition IR.cpp:105
MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
Definition IR.cpp:1122
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetStartLine(MlirLocation location)
Getter for start_line of FileLineColRange.
Definition IR.cpp:310
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:364
MLIR_CAPI_EXPORTED void mlirIRMappingEraseBlock(MlirIRMapping mapping, MlirBlock block)
Erases a block mapping.
Definition IR.cpp:1539
MLIR_CAPI_EXPORTED MlirDialect mlirContextGetLoadedDialect(MlirContext context, MlirStringRef name)
Gets the dialect instance owned by the given context using the dialect namespace to identify it.
Definition IR.cpp:100
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:1103
static bool mlirContextIsNull(MlirContext context)
Checks whether a context is null.
Definition IR.h:105
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:95
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:360
#define DEFINE_C_API_STRUCT(name, storage)
Opaque type declarations.
Definition IR.h:45
struct MlirNamedAttribute MlirNamedAttribute
Definition IR.h:81
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:1000
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:1037
MLIR_CAPI_EXPORTED MlirIRMapping mlirIRMappingCreate(void)
Creates a new empty IRMapping.
Definition IR.cpp:1472
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition IR.h:1021
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:1078
MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition IR.cpp:1140
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:1431
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition IR.cpp:1322
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:298
MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
Definition IR.cpp:1287
MLIR_CAPI_EXPORTED MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition IR.cpp:1421
MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
Definition IR.cpp:432
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetStartColumn(MlirLocation location)
Getter for start_column of FileLineColRange.
Definition IR.cpp:316
MLIR_CAPI_EXPORTED bool mlirContextIsInTransientScope(MlirContext context)
Returns whether the context is currently in a transient scope.
Definition IR.cpp:138
MLIR_CAPI_EXPORTED bool mlirLocationIsAFused(MlirLocation location)
Checks whether the given location is an Fused.
Definition IR.cpp:392
MLIR_CAPI_EXPORTED bool mlirIRMappingContainsOperation(MlirIRMapping mapping, MlirOperation op)
Returns true if the mapping contains a mapping for the given operation.
Definition IR.cpp:1531
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
Definition IR.h:398
MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
Definition IR.cpp:1126
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:889
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:1237
MLIR_CAPI_EXPORTED void mlirContextEndTransientScope(MlirContext context)
Ends the transient scope and resets the context to the base state, pruning transient types,...
Definition IR.cpp:134
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:117
MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
Definition IR.cpp:920
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition IR.cpp:1334
MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition IR.cpp:1427
MLIR_CAPI_EXPORTED unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition IR.cpp:1297
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGetCaller(MlirLocation location)
Getter for caller of CallSite.
Definition IR.cpp:351
MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
Definition IR.cpp:146
MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
Definition IR.cpp:1045
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition IR.cpp:1068
MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition IR.cpp:1025
MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier)
Returns the context associated with this identifier.
Definition IR.cpp:1397
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:405
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:932
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
Definition IR.cpp:286
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
Definition IR.cpp:1326
MLIR_CAPI_EXPORTED bool mlirIRMappingContainsBlock(MlirIRMapping mapping, MlirBlock block)
Returns true if the mapping contains a mapping for the given block.
Definition IR.cpp:1527
static bool mlirDialectIsNull(MlirDialect dialect)
Checks if the dialect is null.
Definition IR.h:204
MLIR_CAPI_EXPORTED MlirAttribute mlirLocationFusedGetMetadata(MlirLocation location)
Getter for metadata of Fused.
Definition IR.cpp:386
MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
Definition IR.cpp:1057
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
Definition IR.cpp:342
MLIR_CAPI_EXPORTED bool mlirLocationIsAName(MlirLocation location)
Checks whether the given location is an Name.
Definition IR.cpp:416
static bool mlirDialectRegistryIsNull(MlirDialectRegistry registry)
Checks if the dialect registry is null.
Definition IR.h:266
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:950
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:55
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock)
Returns the closest surrounding operation that contains this block.
Definition IR.cpp:1049
MLIR_CAPI_EXPORTED void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
Definition IR.cpp:1029
MLIR_CAPI_EXPORTED void mlirValueReplaceUsesWithIf(MlirValue of, MlirValue with, MlirOpOperandReplaceFilterCallback filter, void *userData)
Replace uses of 'of' value with 'with' value, but only for the uses for which the filter callback ret...
Definition IR.cpp:1265
MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
Definition IR.cpp:436
MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index)
Erase the argument at 'index' and remove it from the argument list.
Definition IR.cpp:1131
MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition IR.cpp:1382
MLIR_CAPI_EXPORTED MlirBlock mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block.
Definition IR.cpp:1503
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:1446
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationFileLineColRangeGetTypeID(void)
TypeID Getter for FileLineColRange.
Definition IR.cpp:334
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:990
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition IR.cpp:1061
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:883
static bool mlirRegionIsNull(MlirRegion region)
Checks whether a region is null.
Definition IR.h:960
MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand)
Returns the value of an op operand.
Definition IR.cpp:1293
MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition IR.cpp:754
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:1135
MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
Definition IR.cpp:1330
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition IR.cpp:1393
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:113
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationCallSiteGetTypeID(void)
TypeID Getter for CallSite.
Definition IR.cpp:356
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:126
MLIR_CAPI_EXPORTED int mlirLocationFileLineColRangeGetEndLine(MlirLocation location)
Getter for end_line of FileLineColRange.
Definition IR.cpp:322
MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void)
Creates a dialect registry and transfers its ownership to the caller.
Definition IR.cpp:162
MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
Definition IR.cpp:396
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:60
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:109
MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
Definition IR.cpp:747
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGetCallee(MlirLocation location)
Getter for callee of CallSite.
Definition IR.cpp:346
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationNameGetTypeID(void)
TypeID Getter for Name.
Definition IR.cpp:414
MLIR_CAPI_EXPORTED MlirContext mlirValueGetContext(MlirValue v)
Gets the context that a value was created with.
Definition IR.cpp:1279
MLIR_CAPI_EXPORTED MlirValue mlirIRMappingLookupOrNullValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value. Returns a null MlirValue if no mapping exists.
Definition IR.cpp:1498
MLIR_CAPI_EXPORTED void mlirIRMappingMapValue(MlirIRMapping mapping, MlirValue from, MlirValue to)
Maps a Value in the mapping.
Definition IR.cpp:1476
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetSymbolAttributeName(void)
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition IR.cpp:1413
MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void)
Creates a new empty region and transfers ownership to the caller.
Definition IR.cpp:977
MLIR_CAPI_EXPORTED void mlirIRMappingEraseOperation(MlirIRMapping mapping, MlirOperation op)
Erases an operation mapping.
Definition IR.cpp:1543
MLIR_CAPI_EXPORTED MlirTypeID mlirLocationFusedGetTypeID(void)
TypeID Getter for Fused.
Definition IR.cpp:390
MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
Definition IR.cpp:1117
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:918
MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
Definition IR.cpp:67
MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
Definition IR.cpp:150
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:1082
MLIR_CAPI_EXPORTED MlirContext mlirContextCreate(void)
Creates an MLIR context and transfers its ownership to the caller.
Definition IR.cpp:45
MLIR_CAPI_EXPORTED void mlirIRMappingMapOperation(MlirIRMapping mapping, MlirOperation from, MlirOperation to)
Maps an Operation in the mapping.
Definition IR.cpp:1486
static bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable)
Returns true if the symbol table is null.
Definition IR.h:1346
MLIR_CAPI_EXPORTED bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
Definition IR.cpp:77
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:968
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:924
static bool mlirIRMappingIsNull(MlirIRMapping mapping)
Checks whether an IRMapping is null.
Definition IR.h:1401
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:1224
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:1088
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:911
MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
Definition IR.cpp:71
MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
Definition IR.cpp:983
#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:233
A logical result value, essentially a boolean with named states.
Definition Support.h:121
Named MLIR attribute.
Definition IR.h:77
MlirAttribute attribute
Definition IR.h:79
MlirIdentifier name
Definition IR.h:78
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78