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 the number of regions attached to the given operation.
730
731/// Returns `pos`-th region attached to the operation.
732MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op,
733 intptr_t pos);
734
735/// Returns an operation immediately following the given operation it its
736/// enclosing block.
737MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetNextInBlock(MlirOperation op);
738
739/// Returns the number of operands of the operation.
741
742/// Returns `pos`-th operand of the operation.
743MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op,
744 intptr_t pos);
745
746/// Returns `pos`-th OpOperand of the operation.
747MLIR_CAPI_EXPORTED MlirOpOperand mlirOperationGetOpOperand(MlirOperation op,
748 intptr_t pos);
749
750/// Sets the `pos`-th operand of the operation.
751MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
752 MlirValue newValue);
753
754/// Replaces the operands of the operation.
755MLIR_CAPI_EXPORTED void mlirOperationSetOperands(MlirOperation op,
756 intptr_t nOperands,
757 MlirValue const *operands);
758
759/// Returns the number of results of the operation.
761
762/// Returns `pos`-th result of the operation.
763MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op,
764 intptr_t pos);
765
766/// Returns the number of successor blocks of the operation.
768
769/// Returns `pos`-th successor of the operation.
770MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op,
771 intptr_t pos);
772
773/// Set `pos`-th successor of the operation.
775mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block);
776
777/// Returns true if this operation defines an inherent attribute with this name.
778/// Note: the attribute can be optional, so
779/// `mlirOperationGetInherentAttributeByName` can still return a null attribute.
782
783/// Returns an inherent attribute attached to the operation given its name.
784MLIR_CAPI_EXPORTED MlirAttribute
786
787/// Sets an inherent attribute by name, replacing the existing if it exists.
788/// This has no effect if "name" does not match an inherent attribute.
791 MlirAttribute attr);
792
793/// Returns the number of discardable attributes attached to the operation.
796
797/// Return `pos`-th discardable attribute of the operation.
800
801/// Returns a discardable attribute attached to the operation given its name.
803 MlirOperation op, MlirStringRef name);
804
805/// Sets a discardable attribute by name, replacing the existing if it exists or
806/// adding a new one otherwise. The new `attr` Attribute is not allowed to be
807/// null, use `mlirOperationRemoveDiscardableAttributeByName` to remove an
808/// Attribute instead.
811 MlirAttribute attr);
812
813/// Removes a discardable attribute by name. Returns false if the attribute was
814/// not found and true if removed.
817 MlirStringRef name);
818
819/// Returns the number of attributes attached to the operation.
820/// Deprecated, please use `mlirOperationGetNumInherentAttributes` or
821/// `mlirOperationGetNumDiscardableAttributes`.
823
824/// Return `pos`-th attribute of the operation.
825/// Deprecated, please use `mlirOperationGetInherentAttribute` or
826/// `mlirOperationGetDiscardableAttribute`.
828mlirOperationGetAttribute(MlirOperation op, intptr_t pos);
829
830/// Returns an attribute attached to the operation given its name.
831/// Deprecated, please use `mlirOperationGetInherentAttributeByName` or
832/// `mlirOperationGetDiscardableAttributeByName`.
833MLIR_CAPI_EXPORTED MlirAttribute
834mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name);
835
836/// Sets an attribute by name, replacing the existing if it exists or
837/// adding a new one otherwise.
838/// Deprecated, please use `mlirOperationSetInherentAttributeByName` or
839/// `mlirOperationSetDiscardableAttributeByName`.
841 MlirStringRef name,
842 MlirAttribute attr);
843
844/// Removes an attribute by name. Returns false if the attribute was not found
845/// and true if removed.
846/// Deprecated, please use `mlirOperationRemoveInherentAttributeByName` or
847/// `mlirOperationRemoveDiscardableAttributeByName`.
849 MlirStringRef name);
850
851/// Prints an operation by sending chunks of the string representation and
852/// forwarding `userData to `callback`. Note that the callback may be called
853/// several times with consecutive chunks of the string.
854MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op,
855 MlirStringCallback callback,
856 void *userData);
857
858/// Same as mlirOperationPrint but accepts flags controlling the printing
859/// behavior.
861 MlirOpPrintingFlags flags,
862 MlirStringCallback callback,
863 void *userData);
864
865/// Same as mlirOperationPrint but accepts AsmState controlling the printing
866/// behavior as well as caching computed names.
868 MlirAsmState state,
869 MlirStringCallback callback,
870 void *userData);
871
872/// Same as mlirOperationPrint but writing the bytecode format.
874 MlirStringCallback callback,
875 void *userData);
876
877/// Same as mlirOperationWriteBytecode but with writer config and returns
878/// failure only if desired bytecode could not be honored.
880 MlirOperation op, MlirBytecodeWriterConfig config,
881 MlirStringCallback callback, void *userData);
882
883/// Prints an operation to stderr.
884MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op);
885
886/// Verify the operation and return true if it passes, false if it fails.
887MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op);
888
889/// Moves the given operation immediately after the other operation in its
890/// parent block. The given operation may be owned by the caller or by its
891/// current block. The other operation must belong to a block. In any case, the
892/// ownership is transferred to the block of the other operation.
893MLIR_CAPI_EXPORTED void mlirOperationMoveAfter(MlirOperation op,
894 MlirOperation other);
895
896/// Moves the given operation immediately before the other operation in its
897/// parent block. The given operation may be owner by the caller or by its
898/// current block. The other operation must belong to a block. In any case, the
899/// ownership is transferred to the block of the other operation.
900MLIR_CAPI_EXPORTED void mlirOperationMoveBefore(MlirOperation op,
901 MlirOperation other);
902
903/// Given an operation 'other' that is within the same parent block, return
904/// whether the current operation is before 'other' in the operation list
905/// of the parent block.
906/// Note: This function has an average complexity of O(1), but worst case may
907/// take O(N) where N is the number of operations within the parent block.
909 MlirOperation other);
910/// Operation walk result.
916
917/// Traversal order for operation walk.
922
923/// Operation walker type. The handler is passed an (opaque) reference to an
924/// operation and a pointer to a `userData`.
926 void *userData);
927
928/// Walks operation `op` in `walkOrder` and calls `callback` on that operation.
929/// `*userData` is passed to the callback as well and can be used to tunnel some
930/// context or other data into the callback.
932void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback,
933 void *userData, MlirWalkOrder walkOrder);
934
935/// Replace uses of 'of' value with the 'with' value inside the 'op' operation.
937mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue of, MlirValue with);
938
939//===----------------------------------------------------------------------===//
940// Region API.
941//===----------------------------------------------------------------------===//
942
943/// Creates a new empty region and transfers ownership to the caller.
944MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void);
945
946/// Takes a region owned by the caller and destroys it.
947MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region);
948
949/// Checks whether a region is null.
950static inline bool mlirRegionIsNull(MlirRegion region) { return !region.ptr; }
951
952/// Checks whether two region handles point to the same region. This does not
953/// perform deep comparison.
954MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other);
955
956/// Gets the first block in the region.
957MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region);
958
959/// Takes a block owned by the caller and appends it to the given region.
961 MlirBlock block);
962
963/// Takes a block owned by the caller and inserts it at `pos` to the given
964/// region. This is an expensive operation that linearly scans the region,
965/// prefer insertAfter/Before instead.
967mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block);
968
969/// Takes a block owned by the caller and inserts it after the (non-owned)
970/// reference block in the given region. The reference block must belong to the
971/// region. If the reference block is null, prepends the block to the region.
973 MlirBlock reference,
974 MlirBlock block);
975
976/// Takes a block owned by the caller and inserts it before the (non-owned)
977/// reference block in the given region. The reference block must belong to the
978/// region. If the reference block is null, appends the block to the region.
980 MlirBlock reference,
981 MlirBlock block);
982
983/// Returns first region attached to the operation.
984MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op);
985
986/// Returns the region immediately following the given region in its parent
987/// operation.
988MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region);
989
990/// Moves the entire content of the source region to the target region.
992 MlirRegion source);
993
994//===----------------------------------------------------------------------===//
995// Block API.
996//===----------------------------------------------------------------------===//
997
998/// Creates a new empty block with the given argument types and transfers
999/// ownership to the caller.
1001 MlirType const *args,
1002 MlirLocation const *locs);
1003
1004/// Takes a block owned by the caller and destroys it.
1005MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block);
1006
1007/// Detach a block from the owning region and assume ownership.
1008MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block);
1009
1010/// Checks whether a block is null.
1011static inline bool mlirBlockIsNull(MlirBlock block) { return !block.ptr; }
1012
1013/// Checks whether two blocks handles point to the same block. This does not
1014/// perform deep comparison.
1015MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other);
1016
1017/// Returns the closest surrounding operation that contains this block.
1018MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock);
1019
1020/// Returns the region that contains this block.
1021MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block);
1022
1023/// Returns the block immediately following the given block in its parent
1024/// region.
1025MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block);
1026
1027/// Returns the first operation in the block.
1028MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block);
1029
1030/// Returns the terminator operation in the block or null if no terminator.
1031MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block);
1032
1033/// Takes an operation owned by the caller and appends it to the block.
1035 MlirOperation operation);
1036
1037/// Takes an operation owned by the caller and inserts it as `pos` to the block.
1038/// This is an expensive operation that scans the block linearly, prefer
1039/// insertBefore/After instead.
1041 intptr_t pos,
1042 MlirOperation operation);
1043
1044/// Takes an operation owned by the caller and inserts it after the (non-owned)
1045/// reference operation in the given block. If the reference is null, prepends
1046/// the operation. Otherwise, the reference must belong to the block.
1048mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference,
1049 MlirOperation operation);
1050
1051/// Takes an operation owned by the caller and inserts it before the (non-owned)
1052/// reference operation in the given block. If the reference is null, appends
1053/// the operation. Otherwise, the reference must belong to the block.
1055mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference,
1056 MlirOperation operation);
1057
1058/// Returns the number of arguments of the block.
1060
1061/// Appends an argument of the specified type to the block. Returns the newly
1062/// added argument.
1063MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block,
1064 MlirType type,
1065 MlirLocation loc);
1066
1067/// Erase the argument at 'index' and remove it from the argument list.
1068MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index);
1069
1070/// Inserts an argument of the specified type at a specified index to the block.
1071/// Returns the newly added argument.
1072MLIR_CAPI_EXPORTED MlirValue mlirBlockInsertArgument(MlirBlock block,
1073 intptr_t pos,
1074 MlirType type,
1075 MlirLocation loc);
1076
1077/// Returns `pos`-th argument of the block.
1078MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block,
1079 intptr_t pos);
1080
1081/// Prints a block by sending chunks of the string representation and
1082/// forwarding `userData to `callback`. Note that the callback may be called
1083/// several times with consecutive chunks of the string.
1085mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData);
1086
1087/// Returns the number of successor blocks of the block.
1089
1090/// Returns `pos`-th successor of the block.
1091MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetSuccessor(MlirBlock block,
1092 intptr_t pos);
1093
1094/// Returns the number of predecessor blocks of the block.
1096
1097/// Returns `pos`-th predecessor of the block.
1098///
1099/// WARNING: This getter is more expensive than the others here because
1100/// the impl actually iterates the use-def chain (of block operands) anew for
1101/// each indexed access.
1102MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetPredecessor(MlirBlock block,
1103 intptr_t pos);
1104
1105//===----------------------------------------------------------------------===//
1106// Value API.
1107//===----------------------------------------------------------------------===//
1108
1109/// Returns whether the value is null.
1110static inline bool mlirValueIsNull(MlirValue value) { return !value.ptr; }
1111
1112/// Returns 1 if two values are equal, 0 otherwise.
1113MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2);
1114
1115/// Returns 1 if the value is a block argument, 0 otherwise.
1116MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value);
1117
1118/// Returns 1 if the value is an operation result, 0 otherwise.
1119MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value);
1120
1121/// Returns the block in which this value is defined as an argument. Asserts if
1122/// the value is not a block argument.
1123MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value);
1124
1125/// Returns the position of the value in the argument list of its block.
1127
1128/// Sets the type of the block argument to the given type.
1129MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value,
1130 MlirType type);
1131
1132/// Sets the location of the block argument to the given location.
1134 MlirLocation loc);
1135
1136/// Returns an operation that produced this value as its result. Asserts if the
1137/// value is not an op result.
1138MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value);
1139
1140/// Returns the position of the value in the list of results of the operation
1141/// that produced it.
1143
1144/// Returns the type of the value.
1145MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value);
1146
1147/// Set the type of the value.
1148MLIR_CAPI_EXPORTED void mlirValueSetType(MlirValue value, MlirType type);
1149
1150/// Prints the value to the standard error stream.
1151MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value);
1152
1153/// Prints a value by sending chunks of the string representation and
1154/// forwarding `userData to `callback`. Note that the callback may be called
1155/// several times with consecutive chunks of the string.
1157mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData);
1158
1159/// Prints a value as an operand (i.e., the ValueID).
1160MLIR_CAPI_EXPORTED void mlirValuePrintAsOperand(MlirValue value,
1161 MlirAsmState state,
1162 MlirStringCallback callback,
1163 void *userData);
1164
1165/// Returns an op operand representing the first use of the value, or a null op
1166/// operand if there are no uses.
1167MLIR_CAPI_EXPORTED MlirOpOperand mlirValueGetFirstUse(MlirValue value);
1168
1169/// Replace all uses of 'of' value with the 'with' value, updating anything in
1170/// the IR that uses 'of' to use the other value instead. When this returns
1171/// there are zero uses of 'of'.
1173 MlirValue with);
1174
1175/// Replace all uses of 'of' value with 'with' value, updating anything in the
1176/// IR that uses 'of' to use 'with' instead, except if the user is listed in
1177/// 'exceptions'. The 'exceptions' parameter is an array of MlirOperation
1178/// pointers with a length of 'numExceptions'.
1180mlirValueReplaceAllUsesExcept(MlirValue of, MlirValue with,
1181 intptr_t numExceptions,
1182 MlirOperation *exceptions);
1183
1184/// Callback deciding whether a particular use should be replaced. It is passed
1185/// the use as an MlirOpOperand (from which the owner operation, operand number
1186/// and value can be queried) and the user-provided `userData`. Returns true to
1187/// replace this use.
1188typedef bool (*MlirOpOperandReplaceFilterCallback)(MlirOpOperand opOperand,
1189 void *userData);
1190
1191/// Replace uses of 'of' value with 'with' value, but only for the uses for
1192/// which the `filter` callback returns true. `filter` must not be NULL; this is
1193/// only checked by an assertion, i.e. in builds with assertions enabled.
1195mlirValueReplaceUsesWithIf(MlirValue of, MlirValue with,
1197 void *userData);
1198
1199/// Gets the location of the value.
1200MLIR_CAPI_EXPORTED MlirLocation mlirValueGetLocation(MlirValue v);
1201
1202/// Gets the context that a value was created with.
1203MLIR_CAPI_EXPORTED MlirContext mlirValueGetContext(MlirValue v);
1204
1205//===----------------------------------------------------------------------===//
1206// OpOperand API.
1207//===----------------------------------------------------------------------===//
1208
1209/// Returns whether the op operand is null.
1210MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand);
1211
1212/// Returns the value of an op operand.
1213MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand);
1214
1215/// Returns the owner operation of an op operand.
1216MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand);
1217
1218/// Returns the operand number of an op operand.
1219MLIR_CAPI_EXPORTED unsigned
1220mlirOpOperandGetOperandNumber(MlirOpOperand opOperand);
1221
1222/// Returns an op operand representing the next use of the value, or a null op
1223/// operand if there is no next use.
1224MLIR_CAPI_EXPORTED MlirOpOperand
1225mlirOpOperandGetNextUse(MlirOpOperand opOperand);
1226
1227//===----------------------------------------------------------------------===//
1228// Type API.
1229//===----------------------------------------------------------------------===//
1230
1231/// Parses a type. The type is owned by the context.
1232MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context,
1233 MlirStringRef type);
1234
1235/// Gets the context that a type was created with.
1236MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type);
1237
1238/// Gets the type ID of the type.
1239MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type);
1240
1241/// Gets the dialect a type belongs to.
1242MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type);
1243
1244/// Checks whether a type is null.
1245static inline bool mlirTypeIsNull(MlirType type) { return !type.ptr; }
1246
1247/// Checks if two types are equal.
1248MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2);
1249
1250/// Prints a location by sending chunks of the string representation and
1251/// forwarding `userData to `callback`. Note that the callback may be called
1252/// several times with consecutive chunks of the string.
1254mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData);
1255
1256/// Prints the type to the standard error stream.
1257MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type);
1258
1259//===----------------------------------------------------------------------===//
1260// Attribute API.
1261//===----------------------------------------------------------------------===//
1262
1263/// Parses an attribute. The attribute is owned by the context.
1264MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context,
1265 MlirStringRef attr);
1266
1267/// Gets the context that an attribute was created with.
1268MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute);
1269
1270/// Gets the type of this attribute.
1271MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute);
1272
1273/// Gets the type id of the attribute.
1274MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute);
1275
1276/// Gets the dialect of the attribute.
1277MLIR_CAPI_EXPORTED MlirDialect mlirAttributeGetDialect(MlirAttribute attribute);
1278
1279/// Checks whether an attribute is null.
1280static inline bool mlirAttributeIsNull(MlirAttribute attr) { return !attr.ptr; }
1281
1282/// Checks if two attributes are equal.
1283MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2);
1284
1285/// Prints an attribute by sending chunks of the string representation and
1286/// forwarding `userData to `callback`. Note that the callback may be called
1287/// several times with consecutive chunks of the string.
1288MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr,
1289 MlirStringCallback callback,
1290 void *userData);
1291
1292/// Prints the attribute to the standard error stream.
1293MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr);
1294
1295/// Associates an attribute with the name. Takes ownership of neither.
1297 MlirAttribute attr);
1298
1299//===----------------------------------------------------------------------===//
1300// Identifier API.
1301//===----------------------------------------------------------------------===//
1302
1303/// Gets an identifier with the given string value.
1304MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context,
1305 MlirStringRef str);
1306
1307/// Returns the context associated with this identifier
1308MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier);
1309
1310/// Checks whether two identifiers are the same.
1311MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident,
1312 MlirIdentifier other);
1313
1314/// Gets the string value of the identifier.
1316
1317//===----------------------------------------------------------------------===//
1318// Symbol and SymbolTable API.
1319//===----------------------------------------------------------------------===//
1320
1321/// Returns the name of the attribute used to store symbol names compatible with
1322/// symbol tables.
1324
1325/// Returns the name of the attribute used to store symbol visibility.
1328
1329/// Creates a symbol table for the given operation. If the operation does not
1330/// have the SymbolTable trait, returns a null symbol table.
1331MLIR_CAPI_EXPORTED MlirSymbolTable
1332mlirSymbolTableCreate(MlirOperation operation);
1333
1334/// Returns true if the symbol table is null.
1335static inline bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable) {
1336 return !symbolTable.ptr;
1337}
1338
1339/// Destroys the symbol table created with mlirSymbolTableCreate. This does not
1340/// affect the operations in the table.
1341MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable);
1342
1343/// Looks up a symbol with the given name in the given symbol table and returns
1344/// the operation that corresponds to the symbol. If the symbol cannot be found,
1345/// returns a null operation.
1346MLIR_CAPI_EXPORTED MlirOperation
1347mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name);
1348
1349/// Inserts the given operation into the given symbol table. The operation must
1350/// have the symbol trait. If the symbol table already has a symbol with the
1351/// same name, renames the symbol being inserted to ensure name uniqueness. Note
1352/// that this does not move the operation itself into the block of the symbol
1353/// table operation, this should be done separately. Returns the name of the
1354/// symbol after insertion.
1355MLIR_CAPI_EXPORTED MlirAttribute
1356mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation);
1357
1358/// Removes the given operation from the symbol table and erases it.
1359MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable,
1360 MlirOperation operation);
1361
1362/// Attempt to replace all uses that are nested within the given operation
1363/// of the given symbol 'oldSymbol' with the provided 'newSymbol'. This does
1364/// not traverse into nested symbol tables. Will fail atomically if there are
1365/// any unknown operations that may be potential symbol tables.
1367 MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from);
1368
1369/// Walks all symbol table operations nested within, and including, `op`. For
1370/// each symbol table operation, the provided callback is invoked with the op
1371/// and a boolean signifying if the symbols within that symbol table can be
1372/// treated as if all uses within the IR are visible to the caller.
1373/// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
1374/// within `op` are visible.
1376 MlirOperation from, bool allSymUsesVisible,
1377 void (*callback)(MlirOperation, bool, void *userData), void *userData);
1378
1379//===----------------------------------------------------------------------===//
1380// IRMapping API
1381//===----------------------------------------------------------------------===//
1382
1383/// Creates a new empty IRMapping.
1384MLIR_CAPI_EXPORTED MlirIRMapping mlirIRMappingCreate(void);
1385
1386/// Destroys the given IRMapping.
1387MLIR_CAPI_EXPORTED void mlirIRMappingDestroy(MlirIRMapping mapping);
1388
1389/// Checks whether an IRMapping is null.
1390static inline bool mlirIRMappingIsNull(MlirIRMapping mapping) {
1391 return !mapping.ptr;
1392}
1393
1394/// Maps a Value in the mapping.
1395MLIR_CAPI_EXPORTED void mlirIRMappingMapValue(MlirIRMapping mapping,
1396 MlirValue from, MlirValue to);
1397
1398/// Maps a Block in the mapping.
1399MLIR_CAPI_EXPORTED void mlirIRMappingMapBlock(MlirIRMapping mapping,
1400 MlirBlock from, MlirBlock to);
1401
1402/// Maps an Operation in the mapping.
1403MLIR_CAPI_EXPORTED void mlirIRMappingMapOperation(MlirIRMapping mapping,
1404 MlirOperation from,
1405 MlirOperation to);
1406
1407/// Clears all mappings.
1408MLIR_CAPI_EXPORTED void mlirIRMappingClear(MlirIRMapping mapping);
1409
1410/// Looks up a mapped Value. Returns the mapped value, or the input value if
1411/// no mapping exists.
1412MLIR_CAPI_EXPORTED MlirValue
1413mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping, MlirValue from);
1414
1415/// Looks up a mapped Value. Returns a null MlirValue if no mapping exists.
1416MLIR_CAPI_EXPORTED MlirValue
1417mlirIRMappingLookupOrNullValue(MlirIRMapping mapping, MlirValue from);
1418
1419/// Looks up a mapped Block. Returns the mapped block, or the input block if
1420/// no mapping exists.
1421MLIR_CAPI_EXPORTED MlirBlock
1422mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping, MlirBlock from);
1423
1424/// Looks up a mapped Block. Returns a null MlirBlock if no mapping exists.
1425MLIR_CAPI_EXPORTED MlirBlock
1426mlirIRMappingLookupOrNullBlock(MlirIRMapping mapping, MlirBlock from);
1427
1428/// Looks up a mapped Operation. Returns the mapped operation, or the input
1429/// operation if no mapping exists.
1431 MlirIRMapping mapping, MlirOperation from);
1432
1433/// Looks up a mapped Operation. Returns a null MlirOperation if no mapping
1434/// exists.
1435MLIR_CAPI_EXPORTED MlirOperation
1436mlirIRMappingLookupOrNullOperation(MlirIRMapping mapping, MlirOperation from);
1437
1438/// Returns true if the mapping contains a mapping for the given value.
1439MLIR_CAPI_EXPORTED bool mlirIRMappingContainsValue(MlirIRMapping mapping,
1440 MlirValue value);
1441
1442/// Returns true if the mapping contains a mapping for the given block.
1443MLIR_CAPI_EXPORTED bool mlirIRMappingContainsBlock(MlirIRMapping mapping,
1444 MlirBlock block);
1445
1446/// Returns true if the mapping contains a mapping for the given operation.
1447MLIR_CAPI_EXPORTED bool mlirIRMappingContainsOperation(MlirIRMapping mapping,
1448 MlirOperation op);
1449
1450/// Erases a value mapping.
1451MLIR_CAPI_EXPORTED void mlirIRMappingEraseValue(MlirIRMapping mapping,
1452 MlirValue value);
1453
1454/// Erases a block mapping.
1455MLIR_CAPI_EXPORTED void mlirIRMappingEraseBlock(MlirIRMapping mapping,
1456 MlirBlock block);
1457
1458/// Erases an operation mapping.
1459MLIR_CAPI_EXPORTED void mlirIRMappingEraseOperation(MlirIRMapping mapping,
1460 MlirOperation op);
1461
1462/// Clones the operation with the given mapping. The mapping is updated with
1463/// the cloned operation's results and regions.
1464MLIR_CAPI_EXPORTED MlirOperation
1465mlirOperationCloneWithMapping(MlirOperation op, MlirIRMapping mapping);
1466
1467#ifdef __cplusplus
1468}
1469#endif
1470
1471#endif // MLIR_C_IR_H
lhs
MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:831
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:1150
MlirIdentifier mlirOperationGetName(MlirOperation op)
Definition IR.cpp:719
bool mlirValueIsABlockArgument(MlirValue value)
Definition IR.cpp:1170
intptr_t mlirOperationGetNumRegions(MlirOperation op)
Definition IR.cpp:731
MlirBlock mlirOperationGetBlock(MlirOperation op)
Definition IR.cpp:723
void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Definition IR.cpp:1187
void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition IR.cpp:546
MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Definition IR.cpp:786
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:782
void mlirOperationDestroy(MlirOperation op)
Definition IR.cpp:664
MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:804
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Definition IR.cpp:1345
MlirType mlirValueGetType(MlirValue value)
Definition IR.cpp:1206
void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
Definition IR.cpp:1136
void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:836
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:847
MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
Definition IR.cpp:755
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:1182
MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Definition IR.cpp:794
bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Definition IR.cpp:1364
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:812
void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
Definition IR.cpp:254
bool mlirValueEqual(MlirValue value1, MlirValue value2)
Definition IR.cpp:1166
void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
Definition IR.cpp:269
MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1146
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:1210
intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Definition IR.cpp:790
MlirDialect mlirAttributeGetDialect(MlirAttribute attr)
Definition IR.cpp:1360
void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
Definition IR.cpp:440
void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:866
void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Definition IR.cpp:771
MlirOperation mlirOpResultGetOwner(MlirValue value)
Definition IR.cpp:1197
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:1178
void mlirBlockArgumentSetLocation(MlirValue value, MlirLocation loc)
Definition IR.cpp:1192
MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:763
MlirModule mlirModuleFromOperation(MlirOperation op)
Definition IR.cpp:489
MlirOpOperand mlirOperationGetOpOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:767
MlirLocation mlirOperationGetLocation(MlirOperation op)
Definition IR.cpp:705
MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:861
MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr)
Definition IR.cpp:1356
intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
Definition IR.cpp:819
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:1349
bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:842
bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:871
bool mlirValueIsAOpResult(MlirValue value)
Definition IR.cpp:1174
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:799
MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1155
size_t mlirOperationStructuralHashValue(MlirOperation op, uint32_t flags)
Definition IR.cpp:688
MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Definition IR.cpp:735
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:1341
void mlirOperationRemoveFromParent(MlirOperation op)
Definition IR.cpp:666
intptr_t mlirBlockGetNumSuccessors(MlirBlock block)
Definition IR.cpp:1142
MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:856
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Definition IR.cpp:223
void mlirValueDump(MlirValue value)
Definition IR.cpp:1214
void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
Definition IR.cpp:776
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
Definition IR.cpp:1330
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:1201
MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:824
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:759
void mlirTypeDump(MlirType type)
Definition IR.cpp:1335
intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Definition IR.cpp:852
MLIR_CAPI_EXPORTED MlirValue mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value.
Definition IR.cpp:1485
MLIR_CAPI_EXPORTED MlirOperation mlirIRMappingLookupOrDefaultOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
Definition IR.cpp:1505
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:925
MLIR_CAPI_EXPORTED MlirLocation mlirValueGetLocation(MlirValue v)
Gets the location of the value.
Definition IR.cpp:1267
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:1500
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:896
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:1449
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:1428
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:918
@ MlirWalkPreOrder
Definition IR.h:919
@ MlirWalkPostOrder
Definition IR.h:920
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:1510
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:1376
MLIR_CAPI_EXPORTED MlirOperation mlirOperationCloneWithMapping(MlirOperation op, MlirIRMapping mapping)
Clones the operation with the given mapping.
Definition IR.cpp:1539
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:1433
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:1397
MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition IR.cpp:1310
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:1293
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:1006
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:1188
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:1239
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:1222
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:1281
MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition IR.cpp:1393
MLIR_CAPI_EXPORTED void mlirIRMappingDestroy(MlirIRMapping mapping)
Destroys the given IRMapping.
Definition IR.cpp:1466
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:1473
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:1368
MLIR_CAPI_EXPORTED void mlirIRMappingClear(MlirIRMapping mapping)
Clears all mappings.
Definition IR.cpp:1483
MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition IR.cpp:1045
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:920
MLIR_CAPI_EXPORTED bool mlirIRMappingContainsValue(MlirIRMapping mapping, MlirValue value)
Returns true if the mapping contains a mapping for the given value.
Definition IR.cpp:1515
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:1243
MLIR_CAPI_EXPORTED void mlirIRMappingEraseValue(MlirIRMapping mapping, MlirValue value)
Erases a value mapping.
Definition IR.cpp:1527
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:887
MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition IR.cpp:1107
MlirWalkResult
Operation walk result.
Definition IR.h:911
@ MlirWalkResultInterrupt
Definition IR.h:913
@ MlirWalkResultSkip
Definition IR.h:914
@ MlirWalkResultAdvance
Definition IR.h:912
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:986
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition IR.h:1245
MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition IR.cpp:971
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:1114
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:1531
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:1095
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:992
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:1029
MLIR_CAPI_EXPORTED MlirIRMapping mlirIRMappingCreate(void)
Creates a new empty IRMapping.
Definition IR.cpp:1464
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition IR.h:1011
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:1070
MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition IR.cpp:1132
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:1423
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition IR.cpp:1314
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:1279
MLIR_CAPI_EXPORTED MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition IR.cpp:1413
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:1523
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:1118
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:881
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:1229
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:912
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition IR.cpp:1326
MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition IR.cpp:1419
MLIR_CAPI_EXPORTED unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition IR.cpp:1289
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:1037
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition IR.cpp:1060
MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition IR.cpp:1017
MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier)
Returns the context associated with this identifier.
Definition IR.cpp:1389
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:924
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:1318
MLIR_CAPI_EXPORTED bool mlirIRMappingContainsBlock(MlirIRMapping mapping, MlirBlock block)
Returns true if the mapping contains a mapping for the given block.
Definition IR.cpp:1519
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetVisibilityAttributeName(void)
Returns the name of the attribute used to store symbol visibility.
Definition IR.cpp:1409
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:1049
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:942
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:1041
MLIR_CAPI_EXPORTED void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
Definition IR.cpp:1021
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:1257
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:1123
MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition IR.cpp:1374
MLIR_CAPI_EXPORTED MlirBlock mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block.
Definition IR.cpp:1495
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:1438
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:982
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition IR.cpp:1053
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:875
static bool mlirRegionIsNull(MlirRegion region)
Checks whether a region is null.
Definition IR.h:950
MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand)
Returns the value of an op operand.
Definition IR.cpp:1285
MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition IR.cpp:746
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:1127
MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
Definition IR.cpp:1322
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition IR.cpp:1385
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:739
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:1271
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:1490
MLIR_CAPI_EXPORTED void mlirIRMappingMapValue(MlirIRMapping mapping, MlirValue from, MlirValue to)
Maps a Value in the mapping.
Definition IR.cpp:1468
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetSymbolAttributeName(void)
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition IR.cpp:1405
MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void)
Creates a new empty region and transfers ownership to the caller.
Definition IR.cpp:969
MLIR_CAPI_EXPORTED void mlirIRMappingEraseOperation(MlirIRMapping mapping, MlirOperation op)
Erases an operation mapping.
Definition IR.cpp:1535
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:1109
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:910
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:1074
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:1478
static bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable)
Returns true if the symbol table is null.
Definition IR.h:1335
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:960
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:916
static bool mlirIRMappingIsNull(MlirIRMapping mapping)
Checks whether an IRMapping is null.
Definition IR.h:1390
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:1216
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:1080
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:903
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:975
#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