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