MLIR  20.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
27 extern "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 
51 DEFINE_C_API_STRUCT(MlirAsmState, void);
52 DEFINE_C_API_STRUCT(MlirBytecodeWriterConfig, void);
53 DEFINE_C_API_STRUCT(MlirContext, void);
54 DEFINE_C_API_STRUCT(MlirDialect, void);
55 DEFINE_C_API_STRUCT(MlirDialectRegistry, void);
56 DEFINE_C_API_STRUCT(MlirOperation, void);
57 DEFINE_C_API_STRUCT(MlirOpOperand, void);
58 DEFINE_C_API_STRUCT(MlirOpPrintingFlags, void);
59 DEFINE_C_API_STRUCT(MlirBlock, void);
60 DEFINE_C_API_STRUCT(MlirRegion, void);
61 DEFINE_C_API_STRUCT(MlirSymbolTable, void);
62 
63 DEFINE_C_API_STRUCT(MlirAttribute, const void);
64 DEFINE_C_API_STRUCT(MlirIdentifier, const void);
65 DEFINE_C_API_STRUCT(MlirLocation, const void);
66 DEFINE_C_API_STRUCT(MlirModule, const void);
67 DEFINE_C_API_STRUCT(MlirType, const void);
68 DEFINE_C_API_STRUCT(MlirValue, const void);
69 
70 #undef DEFINE_C_API_STRUCT
71 
72 /// Named MLIR attribute.
73 ///
74 /// A named attribute is essentially a (name, attribute) pair where the name is
75 /// a string.
77  MlirIdentifier name;
78  MlirAttribute attribute;
79 };
81 
82 //===----------------------------------------------------------------------===//
83 // Context API.
84 //===----------------------------------------------------------------------===//
85 
86 /// Creates an MLIR context and transfers its ownership to the caller.
87 /// This sets the default multithreading option (enabled).
88 MLIR_CAPI_EXPORTED MlirContext mlirContextCreate(void);
89 
90 /// Creates an MLIR context with an explicit setting of the multithreading
91 /// setting and transfers its ownership to the caller.
92 MLIR_CAPI_EXPORTED MlirContext
93 mlirContextCreateWithThreading(bool threadingEnabled);
94 
95 /// Creates an MLIR context, setting the multithreading setting explicitly and
96 /// pre-loading the dialects from the provided DialectRegistry.
98  MlirDialectRegistry registry, bool threadingEnabled);
99 
100 /// Checks if two contexts are equal.
101 MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2);
102 
103 /// Checks whether a context is null.
104 static inline bool mlirContextIsNull(MlirContext context) {
105  return !context.ptr;
106 }
107 
108 /// Takes an MLIR context owned by the caller and destroys it.
109 MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context);
110 
111 /// Sets whether unregistered dialects are allowed in this context.
113 mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow);
114 
115 /// Returns whether the context allows unregistered dialects.
117 mlirContextGetAllowUnregisteredDialects(MlirContext context);
118 
119 /// Returns the number of dialects registered with the given context. A
120 /// registered dialect will be loaded if needed by the parser.
121 MLIR_CAPI_EXPORTED intptr_t
122 mlirContextGetNumRegisteredDialects(MlirContext context);
123 
124 /// Append the contents of the given dialect registry to the registry associated
125 /// with the context.
127 mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry);
128 
129 /// Returns the number of dialects loaded by the context.
130 
131 MLIR_CAPI_EXPORTED intptr_t
132 mlirContextGetNumLoadedDialects(MlirContext context);
133 
134 /// Gets the dialect instance owned by the given context using the dialect
135 /// namespace to identify it, loads (i.e., constructs the instance of) the
136 /// dialect if necessary. If the dialect is not registered with the context,
137 /// returns null. Use mlirContextLoad<Name>Dialect to load an unregistered
138 /// dialect.
139 MLIR_CAPI_EXPORTED MlirDialect mlirContextGetOrLoadDialect(MlirContext context,
141 
142 /// Set threading mode (must be set to false to mlir-print-ir-after-all).
143 MLIR_CAPI_EXPORTED void mlirContextEnableMultithreading(MlirContext context,
144  bool enable);
145 
146 /// Eagerly loads all available dialects registered with a context, making
147 /// them available for use for IR construction.
149 mlirContextLoadAllAvailableDialects(MlirContext context);
150 
151 /// Returns whether the given fully-qualified operation (i.e.
152 /// 'dialect.operation') is registered with the context. This will return true
153 /// if the dialect is loaded and the operation is registered within the
154 /// dialect.
157 
158 /// Sets the thread pool of the context explicitly, enabling multithreading in
159 /// the process. This API should be used to avoid re-creating thread pools in
160 /// long-running applications that perform multiple compilations, see
161 /// the C++ documentation for MLIRContext for details.
162 MLIR_CAPI_EXPORTED void mlirContextSetThreadPool(MlirContext context,
163  MlirLlvmThreadPool threadPool);
164 
165 //===----------------------------------------------------------------------===//
166 // Dialect API.
167 //===----------------------------------------------------------------------===//
168 
169 /// Returns the context that owns the dialect.
170 MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect);
171 
172 /// Checks if the dialect is null.
173 static inline bool mlirDialectIsNull(MlirDialect dialect) {
174  return !dialect.ptr;
175 }
176 
177 /// Checks if two dialects that belong to the same context are equal. Dialects
178 /// from different contexts will not compare equal.
179 MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1,
180  MlirDialect dialect2);
181 
182 /// Returns the namespace of the given dialect.
184 
185 //===----------------------------------------------------------------------===//
186 // DialectHandle API.
187 // Registration entry-points for each dialect are declared using the common
188 // MLIR_DECLARE_DIALECT_REGISTRATION_CAPI macro, which takes the dialect
189 // API name (i.e. "Func", "Tensor", "Linalg") and namespace (i.e. "func",
190 // "tensor", "linalg"). The following declarations are produced:
191 //
192 // /// Gets the above hook methods in struct form for a dialect by namespace.
193 // /// This is intended to facilitate dynamic lookup and registration of
194 // /// dialects via a plugin facility based on shared library symbol lookup.
195 // const MlirDialectHandle *mlirGetDialectHandle__{NAMESPACE}__();
196 //
197 // This is done via a common macro to facilitate future expansion to
198 // registration schemes.
199 //===----------------------------------------------------------------------===//
200 
202  const void *ptr;
203 };
204 typedef struct MlirDialectHandle MlirDialectHandle;
205 
206 #define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace) \
207  MLIR_CAPI_EXPORTED MlirDialectHandle mlirGetDialectHandle__##Namespace##__( \
208  void)
209 
210 /// Returns the namespace associated with the provided dialect handle.
213 
214 /// Inserts the dialect associated with the provided dialect handle into the
215 /// provided dialect registry
217  MlirDialectRegistry);
218 
219 /// Registers the dialect associated with the provided dialect handle.
221  MlirContext);
222 
223 /// Loads the dialect associated with the provided dialect handle.
225  MlirContext);
226 
227 //===----------------------------------------------------------------------===//
228 // DialectRegistry API.
229 //===----------------------------------------------------------------------===//
230 
231 /// Creates a dialect registry and transfers its ownership to the caller.
232 MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void);
233 
234 /// Checks if the dialect registry is null.
235 static inline bool mlirDialectRegistryIsNull(MlirDialectRegistry registry) {
236  return !registry.ptr;
237 }
238 
239 /// Takes a dialect registry owned by the caller and destroys it.
241 mlirDialectRegistryDestroy(MlirDialectRegistry registry);
242 
243 //===----------------------------------------------------------------------===//
244 // Location API.
245 //===----------------------------------------------------------------------===//
246 
247 /// Returns the underlying location attribute of this location.
248 MLIR_CAPI_EXPORTED MlirAttribute
249 mlirLocationGetAttribute(MlirLocation location);
250 
251 /// Creates a location from a location attribute.
252 MLIR_CAPI_EXPORTED MlirLocation
253 mlirLocationFromAttribute(MlirAttribute attribute);
254 
255 /// Creates an File/Line/Column location owned by the given context.
257  MlirContext context, MlirStringRef filename, unsigned line, unsigned col);
258 
259 /// Creates a call site location with a callee and a caller.
260 MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
261  MlirLocation caller);
262 
263 /// Creates a fused location with an array of locations and metadata.
264 MLIR_CAPI_EXPORTED MlirLocation
265 mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
266  MlirLocation const *locations, MlirAttribute metadata);
267 
268 /// Creates a name location owned by the given context. Providing null location
269 /// for childLoc is allowed and if childLoc is null location, then the behavior
270 /// is the same as having unknown child location.
271 MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context,
272  MlirStringRef name,
273  MlirLocation childLoc);
274 
275 /// Creates a location with unknown position owned by the given context.
276 MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context);
277 
278 /// Gets the context that a location was created with.
279 MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location);
280 
281 /// Checks if the location is null.
282 static inline bool mlirLocationIsNull(MlirLocation location) {
283  return !location.ptr;
284 }
285 
286 /// Checks if two locations are equal.
287 MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2);
288 
289 /// Prints a location by sending chunks of the string representation and
290 /// forwarding `userData to `callback`. Note that the callback may be called
291 /// several times with consecutive chunks of the string.
292 MLIR_CAPI_EXPORTED void mlirLocationPrint(MlirLocation location,
293  MlirStringCallback callback,
294  void *userData);
295 
296 //===----------------------------------------------------------------------===//
297 // Module API.
298 //===----------------------------------------------------------------------===//
299 
300 /// Creates a new, empty module and transfers ownership to the caller.
301 MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateEmpty(MlirLocation location);
302 
303 /// Parses a module from the string and transfers ownership to the caller.
304 MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateParse(MlirContext context,
305  MlirStringRef module);
306 
307 /// Gets the context that a module was created with.
308 MLIR_CAPI_EXPORTED MlirContext mlirModuleGetContext(MlirModule module);
309 
310 /// Gets the body of the module, i.e. the only block it contains.
311 MLIR_CAPI_EXPORTED MlirBlock mlirModuleGetBody(MlirModule module);
312 
313 /// Checks whether a module is null.
314 static inline bool mlirModuleIsNull(MlirModule module) { return !module.ptr; }
315 
316 /// Takes a module owned by the caller and deletes it.
317 MLIR_CAPI_EXPORTED void mlirModuleDestroy(MlirModule module);
318 
319 /// Views the module as a generic operation.
320 MLIR_CAPI_EXPORTED MlirOperation mlirModuleGetOperation(MlirModule module);
321 
322 /// Views the generic operation as a module.
323 /// The returned module is null when the input operation was not a ModuleOp.
324 MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op);
325 
326 //===----------------------------------------------------------------------===//
327 // Operation state.
328 //===----------------------------------------------------------------------===//
329 
330 /// An auxiliary class for constructing operations.
331 ///
332 /// This class contains all the information necessary to construct the
333 /// operation. It owns the MlirRegions it has pointers to and does not own
334 /// anything else. By default, the state can be constructed from a name and
335 /// location, the latter being also used to access the context, and has no other
336 /// components. These components can be added progressively until the operation
337 /// is constructed. Users are not expected to rely on the internals of this
338 /// class and should use mlirOperationState* functions instead.
339 
342  MlirLocation location;
343  intptr_t nResults;
344  MlirType *results;
345  intptr_t nOperands;
346  MlirValue *operands;
347  intptr_t nRegions;
348  MlirRegion *regions;
349  intptr_t nSuccessors;
350  MlirBlock *successors;
351  intptr_t nAttributes;
354 };
356 
357 /// Constructs an operation state from a name and a location.
359  MlirLocation loc);
360 
361 /// Adds a list of components to the operation state.
363  intptr_t n,
364  MlirType const *results);
367  MlirValue const *operands);
370  MlirRegion const *regions);
373  MlirBlock const *successors);
377 
378 /// Enables result type inference for the operation under construction. If
379 /// enabled, then the caller must not have called
380 /// mlirOperationStateAddResults(). Note that if enabled, the
381 /// mlirOperationCreate() call is failable: it will return a null operation
382 /// on inference failure and will emit diagnostics.
385 
386 //===----------------------------------------------------------------------===//
387 // AsmState API.
388 // While many of these are simple settings that could be represented in a
389 // struct, they are wrapped in a heap allocated object and accessed via
390 // functions to maximize the possibility of compatibility over time.
391 //===----------------------------------------------------------------------===//
392 
393 /// Creates new AsmState, as with AsmState the IR should not be mutated
394 /// in-between using this state.
395 /// Must be freed with a call to mlirAsmStateDestroy().
396 // TODO: This should be expanded to handle location & resouce map.
397 MLIR_CAPI_EXPORTED MlirAsmState
398 mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags);
399 
400 /// Creates new AsmState from value.
401 /// Must be freed with a call to mlirAsmStateDestroy().
402 // TODO: This should be expanded to handle location & resouce map.
403 MLIR_CAPI_EXPORTED MlirAsmState
404 mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags);
405 
406 /// Destroys printing flags created with mlirAsmStateCreate.
407 MLIR_CAPI_EXPORTED void mlirAsmStateDestroy(MlirAsmState state);
408 
409 //===----------------------------------------------------------------------===//
410 // Op Printing flags API.
411 // While many of these are simple settings that could be represented in a
412 // struct, they are wrapped in a heap allocated object and accessed via
413 // functions to maximize the possibility of compatibility over time.
414 //===----------------------------------------------------------------------===//
415 
416 /// Creates new printing flags with defaults, intended for customization.
417 /// Must be freed with a call to mlirOpPrintingFlagsDestroy().
418 MLIR_CAPI_EXPORTED MlirOpPrintingFlags mlirOpPrintingFlagsCreate(void);
419 
420 /// Destroys printing flags created with mlirOpPrintingFlagsCreate.
421 MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags);
422 
423 /// Enables the elision of large elements attributes by printing a lexically
424 /// valid but otherwise meaningless form instead of the element data. The
425 /// `largeElementLimit` is used to configure what is considered to be a "large"
426 /// ElementsAttr by providing an upper limit to the number of elements.
428 mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
429  intptr_t largeElementLimit);
430 
431 /// Enables the elision of large resources strings by omitting them from the
432 /// `dialect_resources` section. The `largeResourceLimit` is used to configure
433 /// what is considered to be a "large" resource by providing an upper limit to
434 /// the string size.
436 mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags,
437  intptr_t largeResourceLimit);
438 
439 /// Enable or disable printing of debug information (based on `enable`). If
440 /// 'prettyForm' is set to true, debug information is printed in a more readable
441 /// 'pretty' form. Note: The IR generated with 'prettyForm' is not parsable.
443 mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
444  bool prettyForm);
445 
446 /// Always print operations in the generic form.
448 mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags);
449 
450 /// Use local scope when printing the operation. This allows for using the
451 /// printer in a more localized and thread-safe setting, but may not
452 /// necessarily be identical to what the IR will look like when dumping
453 /// the full module.
455 mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags);
456 
457 /// Do not verify the operation when using custom operation printers.
459 mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags);
460 
461 /// Skip printing regions.
463 mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags);
464 
465 //===----------------------------------------------------------------------===//
466 // Bytecode printing flags API.
467 //===----------------------------------------------------------------------===//
468 
469 /// Creates new printing flags with defaults, intended for customization.
470 /// Must be freed with a call to mlirBytecodeWriterConfigDestroy().
471 MLIR_CAPI_EXPORTED MlirBytecodeWriterConfig
473 
474 /// Destroys printing flags created with mlirBytecodeWriterConfigCreate.
476 mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config);
477 
478 /// Sets the version to emit in the writer config.
480 mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags,
481  int64_t version);
482 
483 //===----------------------------------------------------------------------===//
484 // Operation API.
485 //===----------------------------------------------------------------------===//
486 
487 /// Creates an operation and transfers ownership to the caller.
488 /// Note that caller owned child objects are transferred in this call and must
489 /// not be further used. Particularly, this applies to any regions added to
490 /// the state (the implementation may invalidate any such pointers).
491 ///
492 /// This call can fail under the following conditions, in which case, it will
493 /// return a null operation and emit diagnostics:
494 /// - Result type inference is enabled and cannot be performed.
496 
497 /// Parses an operation, giving ownership to the caller. If parsing fails a null
498 /// operation will be returned, and an error diagnostic emitted.
499 ///
500 /// `sourceStr` may be either the text assembly format, or binary bytecode
501 /// format. `sourceName` is used as the file name of the source; any IR without
502 /// locations will get a `FileLineColLoc` location with `sourceName` as the file
503 /// name.
505  MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName);
506 
507 /// Creates a deep copy of an operation. The operation is not inserted and
508 /// ownership is transferred to the caller.
509 MLIR_CAPI_EXPORTED MlirOperation mlirOperationClone(MlirOperation op);
510 
511 /// Takes an operation owned by the caller and destroys it.
512 MLIR_CAPI_EXPORTED void mlirOperationDestroy(MlirOperation op);
513 
514 /// Removes the given operation from its parent block. The operation is not
515 /// destroyed. The ownership of the operation is transferred to the caller.
517 
518 /// Checks whether the underlying operation is null.
519 static inline bool mlirOperationIsNull(MlirOperation op) { return !op.ptr; }
520 
521 /// Checks whether two operation handles point to the same operation. This does
522 /// not perform deep comparison.
523 MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op,
524  MlirOperation other);
525 
526 /// Gets the context this operation is associated with
527 MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op);
528 
529 /// Gets the location of the operation.
530 MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation(MlirOperation op);
531 
532 /// Gets the type id of the operation.
533 /// Returns null if the operation does not have a registered operation
534 /// description.
535 MLIR_CAPI_EXPORTED MlirTypeID mlirOperationGetTypeID(MlirOperation op);
536 
537 /// Gets the name of the operation as an identifier.
538 MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op);
539 
540 /// Gets the block that owns this operation, returning null if the operation is
541 /// not owned.
542 MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetBlock(MlirOperation op);
543 
544 /// Gets the operation that owns this operation, returning null if the operation
545 /// is not owned.
546 MLIR_CAPI_EXPORTED MlirOperation
547 mlirOperationGetParentOperation(MlirOperation op);
548 
549 /// Returns the number of regions attached to the given operation.
550 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumRegions(MlirOperation op);
551 
552 /// Returns `pos`-th region attached to the operation.
553 MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op,
554  intptr_t pos);
555 
556 /// Returns an operation immediately following the given operation it its
557 /// enclosing block.
558 MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetNextInBlock(MlirOperation op);
559 
560 /// Returns the number of operands of the operation.
561 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumOperands(MlirOperation op);
562 
563 /// Returns `pos`-th operand of the operation.
564 MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op,
565  intptr_t pos);
566 
567 /// Sets the `pos`-th operand of the operation.
568 MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
569  MlirValue newValue);
570 
571 /// Replaces the operands of the operation.
572 MLIR_CAPI_EXPORTED void mlirOperationSetOperands(MlirOperation op,
573  intptr_t nOperands,
574  MlirValue const *operands);
575 
576 /// Returns the number of results of the operation.
577 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumResults(MlirOperation op);
578 
579 /// Returns `pos`-th result of the operation.
580 MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op,
581  intptr_t pos);
582 
583 /// Returns the number of successor blocks of the operation.
584 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumSuccessors(MlirOperation op);
585 
586 /// Returns `pos`-th successor of the operation.
587 MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op,
588  intptr_t pos);
589 
590 /// Set `pos`-th successor of the operation.
592 mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block);
593 
594 /// Returns true if this operation defines an inherent attribute with this name.
595 /// Note: the attribute can be optional, so
596 /// `mlirOperationGetInherentAttributeByName` can still return a null attribute.
599 
600 /// Returns an inherent attribute attached to the operation given its name.
601 MLIR_CAPI_EXPORTED MlirAttribute
603 
604 /// Sets an inherent attribute by name, replacing the existing if it exists.
605 /// This has no effect if "name" does not match an inherent attribute.
608  MlirAttribute attr);
609 
610 /// Returns the number of discardable attributes attached to the operation.
611 MLIR_CAPI_EXPORTED intptr_t
613 
614 /// Return `pos`-th discardable attribute of the operation.
616 mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos);
617 
618 /// Returns a discardable attribute attached to the operation given its name.
620  MlirOperation op, MlirStringRef name);
621 
622 /// Sets a discardable attribute by name, replacing the existing if it exists or
623 /// adding a new one otherwise. The new `attr` Attribute is not allowed to be
624 /// null, use `mlirOperationRemoveDiscardableAttributeByName` to remove an
625 /// Attribute instead.
628  MlirAttribute attr);
629 
630 /// Removes a discardable attribute by name. Returns false if the attribute was
631 /// not found and true if removed.
635 
636 /// Returns the number of attributes attached to the operation.
637 /// Deprecated, please use `mlirOperationGetNumInherentAttributes` or
638 /// `mlirOperationGetNumDiscardableAttributes`.
639 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumAttributes(MlirOperation op);
640 
641 /// Return `pos`-th attribute of the operation.
642 /// Deprecated, please use `mlirOperationGetInherentAttribute` or
643 /// `mlirOperationGetDiscardableAttribute`.
645 mlirOperationGetAttribute(MlirOperation op, intptr_t pos);
646 
647 /// Returns an attribute attached to the operation given its name.
648 /// Deprecated, please use `mlirOperationGetInherentAttributeByName` or
649 /// `mlirOperationGetDiscardableAttributeByName`.
650 MLIR_CAPI_EXPORTED MlirAttribute
652 
653 /// Sets an attribute by name, replacing the existing if it exists or
654 /// adding a new one otherwise.
655 /// Deprecated, please use `mlirOperationSetInherentAttributeByName` or
656 /// `mlirOperationSetDiscardableAttributeByName`.
659  MlirAttribute attr);
660 
661 /// Removes an attribute by name. Returns false if the attribute was not found
662 /// and true if removed.
663 /// Deprecated, please use `mlirOperationRemoveInherentAttributeByName` or
664 /// `mlirOperationRemoveDiscardableAttributeByName`.
667 
668 /// Prints an operation by sending chunks of the string representation and
669 /// forwarding `userData to `callback`. Note that the callback may be called
670 /// several times with consecutive chunks of the string.
671 MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op,
672  MlirStringCallback callback,
673  void *userData);
674 
675 /// Same as mlirOperationPrint but accepts flags controlling the printing
676 /// behavior.
677 MLIR_CAPI_EXPORTED void mlirOperationPrintWithFlags(MlirOperation op,
678  MlirOpPrintingFlags flags,
679  MlirStringCallback callback,
680  void *userData);
681 
682 /// Same as mlirOperationPrint but accepts AsmState controlling the printing
683 /// behavior as well as caching computed names.
684 MLIR_CAPI_EXPORTED void mlirOperationPrintWithState(MlirOperation op,
685  MlirAsmState state,
686  MlirStringCallback callback,
687  void *userData);
688 
689 /// Same as mlirOperationPrint but writing the bytecode format.
690 MLIR_CAPI_EXPORTED void mlirOperationWriteBytecode(MlirOperation op,
691  MlirStringCallback callback,
692  void *userData);
693 
694 /// Same as mlirOperationWriteBytecode but with writer config and returns
695 /// failure only if desired bytecode could not be honored.
697  MlirOperation op, MlirBytecodeWriterConfig config,
698  MlirStringCallback callback, void *userData);
699 
700 /// Prints an operation to stderr.
701 MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op);
702 
703 /// Verify the operation and return true if it passes, false if it fails.
704 MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op);
705 
706 /// Moves the given operation immediately after the other operation in its
707 /// parent block. The given operation may be owned by the caller or by its
708 /// current block. The other operation must belong to a block. In any case, the
709 /// ownership is transferred to the block of the other operation.
710 MLIR_CAPI_EXPORTED void mlirOperationMoveAfter(MlirOperation op,
711  MlirOperation other);
712 
713 /// Moves the given operation immediately before the other operation in its
714 /// parent block. The given operation may be owner by the caller or by its
715 /// current block. The other operation must belong to a block. In any case, the
716 /// ownership is transferred to the block of the other operation.
717 MLIR_CAPI_EXPORTED void mlirOperationMoveBefore(MlirOperation op,
718  MlirOperation other);
719 
720 /// Operation walk result.
721 typedef enum MlirWalkResult {
726 
727 /// Traversal order for operation walk.
728 typedef enum MlirWalkOrder {
732 
733 /// Operation walker type. The handler is passed an (opaque) reference to an
734 /// operation and a pointer to a `userData`.
735 typedef MlirWalkResult (*MlirOperationWalkCallback)(MlirOperation,
736  void *userData);
737 
738 /// Walks operation `op` in `walkOrder` and calls `callback` on that operation.
739 /// `*userData` is passed to the callback as well and can be used to tunnel some
740 /// context or other data into the callback.
742 void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback,
743  void *userData, MlirWalkOrder walkOrder);
744 
745 //===----------------------------------------------------------------------===//
746 // Region API.
747 //===----------------------------------------------------------------------===//
748 
749 /// Creates a new empty region and transfers ownership to the caller.
750 MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void);
751 
752 /// Takes a region owned by the caller and destroys it.
753 MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region);
754 
755 /// Checks whether a region is null.
756 static inline bool mlirRegionIsNull(MlirRegion region) { return !region.ptr; }
757 
758 /// Checks whether two region handles point to the same region. This does not
759 /// perform deep comparison.
760 MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other);
761 
762 /// Gets the first block in the region.
763 MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region);
764 
765 /// Takes a block owned by the caller and appends it to the given region.
766 MLIR_CAPI_EXPORTED void mlirRegionAppendOwnedBlock(MlirRegion region,
767  MlirBlock block);
768 
769 /// Takes a block owned by the caller and inserts it at `pos` to the given
770 /// region. This is an expensive operation that linearly scans the region,
771 /// prefer insertAfter/Before instead.
773 mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block);
774 
775 /// Takes a block owned by the caller and inserts it after the (non-owned)
776 /// reference block in the given region. The reference block must belong to the
777 /// region. If the reference block is null, prepends the block to the region.
779  MlirBlock reference,
780  MlirBlock block);
781 
782 /// Takes a block owned by the caller and inserts it before the (non-owned)
783 /// reference block in the given region. The reference block must belong to the
784 /// region. If the reference block is null, appends the block to the region.
786  MlirBlock reference,
787  MlirBlock block);
788 
789 /// Returns first region attached to the operation.
790 MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op);
791 
792 /// Returns the region immediately following the given region in its parent
793 /// operation.
794 MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region);
795 
796 /// Moves the entire content of the source region to the target region.
797 MLIR_CAPI_EXPORTED void mlirRegionTakeBody(MlirRegion target,
798  MlirRegion source);
799 
800 //===----------------------------------------------------------------------===//
801 // Block API.
802 //===----------------------------------------------------------------------===//
803 
804 /// Creates a new empty block with the given argument types and transfers
805 /// ownership to the caller.
806 MLIR_CAPI_EXPORTED MlirBlock mlirBlockCreate(intptr_t nArgs,
807  MlirType const *args,
808  MlirLocation const *locs);
809 
810 /// Takes a block owned by the caller and destroys it.
811 MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block);
812 
813 /// Detach a block from the owning region and assume ownership.
814 MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block);
815 
816 /// Checks whether a block is null.
817 static inline bool mlirBlockIsNull(MlirBlock block) { return !block.ptr; }
818 
819 /// Checks whether two blocks handles point to the same block. This does not
820 /// perform deep comparison.
821 MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other);
822 
823 /// Returns the closest surrounding operation that contains this block.
824 MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock);
825 
826 /// Returns the region that contains this block.
827 MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block);
828 
829 /// Returns the block immediately following the given block in its parent
830 /// region.
831 MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block);
832 
833 /// Returns the first operation in the block.
834 MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block);
835 
836 /// Returns the terminator operation in the block or null if no terminator.
837 MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block);
838 
839 /// Takes an operation owned by the caller and appends it to the block.
841  MlirOperation operation);
842 
843 /// Takes an operation owned by the caller and inserts it as `pos` to the block.
844 /// This is an expensive operation that scans the block linearly, prefer
845 /// insertBefore/After instead.
847  intptr_t pos,
848  MlirOperation operation);
849 
850 /// Takes an operation owned by the caller and inserts it after the (non-owned)
851 /// reference operation in the given block. If the reference is null, prepends
852 /// the operation. Otherwise, the reference must belong to the block.
854 mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference,
855  MlirOperation operation);
856 
857 /// Takes an operation owned by the caller and inserts it before the (non-owned)
858 /// reference operation in the given block. If the reference is null, appends
859 /// the operation. Otherwise, the reference must belong to the block.
861 mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference,
862  MlirOperation operation);
863 
864 /// Returns the number of arguments of the block.
865 MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block);
866 
867 /// Appends an argument of the specified type to the block. Returns the newly
868 /// added argument.
869 MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block,
870  MlirType type,
871  MlirLocation loc);
872 
873 /// Erase the argument at 'index' and remove it from the argument list.
874 MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index);
875 
876 /// Inserts an argument of the specified type at a specified index to the block.
877 /// Returns the newly added argument.
878 MLIR_CAPI_EXPORTED MlirValue mlirBlockInsertArgument(MlirBlock block,
879  intptr_t pos,
880  MlirType type,
881  MlirLocation loc);
882 
883 /// Returns `pos`-th argument of the block.
884 MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block,
885  intptr_t pos);
886 
887 /// Prints a block by sending chunks of the string representation and
888 /// forwarding `userData to `callback`. Note that the callback may be called
889 /// several times with consecutive chunks of the string.
891 mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData);
892 
893 //===----------------------------------------------------------------------===//
894 // Value API.
895 //===----------------------------------------------------------------------===//
896 
897 /// Returns whether the value is null.
898 static inline bool mlirValueIsNull(MlirValue value) { return !value.ptr; }
899 
900 /// Returns 1 if two values are equal, 0 otherwise.
901 MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2);
902 
903 /// Returns 1 if the value is a block argument, 0 otherwise.
904 MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value);
905 
906 /// Returns 1 if the value is an operation result, 0 otherwise.
907 MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value);
908 
909 /// Returns the block in which this value is defined as an argument. Asserts if
910 /// the value is not a block argument.
911 MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value);
912 
913 /// Returns the position of the value in the argument list of its block.
914 MLIR_CAPI_EXPORTED intptr_t mlirBlockArgumentGetArgNumber(MlirValue value);
915 
916 /// Sets the type of the block argument to the given type.
917 MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value,
918  MlirType type);
919 
920 /// Returns an operation that produced this value as its result. Asserts if the
921 /// value is not an op result.
922 MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value);
923 
924 /// Returns the position of the value in the list of results of the operation
925 /// that produced it.
926 MLIR_CAPI_EXPORTED intptr_t mlirOpResultGetResultNumber(MlirValue value);
927 
928 /// Returns the type of the value.
929 MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value);
930 
931 /// Set the type of the value.
932 MLIR_CAPI_EXPORTED void mlirValueSetType(MlirValue value, MlirType type);
933 
934 /// Prints the value to the standard error stream.
935 MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value);
936 
937 /// Prints a value by sending chunks of the string representation and
938 /// forwarding `userData to `callback`. Note that the callback may be called
939 /// several times with consecutive chunks of the string.
941 mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData);
942 
943 /// Prints a value as an operand (i.e., the ValueID).
944 MLIR_CAPI_EXPORTED void mlirValuePrintAsOperand(MlirValue value,
945  MlirAsmState state,
946  MlirStringCallback callback,
947  void *userData);
948 
949 /// Returns an op operand representing the first use of the value, or a null op
950 /// operand if there are no uses.
951 MLIR_CAPI_EXPORTED MlirOpOperand mlirValueGetFirstUse(MlirValue value);
952 
953 /// Replace all uses of 'of' value with the 'with' value, updating anything in
954 /// the IR that uses 'of' to use the other value instead. When this returns
955 /// there are zero uses of 'of'.
957  MlirValue with);
958 
959 /// Replace all uses of 'of' value with 'with' value, updating anything in the
960 /// IR that uses 'of' to use 'with' instead, except if the user is listed in
961 /// 'exceptions'. The 'exceptions' parameter is an array of MlirOperation
962 /// pointers with a length of 'numExceptions'.
964 mlirValueReplaceAllUsesExcept(MlirValue of, MlirValue with,
965  intptr_t numExceptions,
966  MlirOperation *exceptions);
967 
968 //===----------------------------------------------------------------------===//
969 // OpOperand API.
970 //===----------------------------------------------------------------------===//
971 
972 /// Returns whether the op operand is null.
973 MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand);
974 
975 /// Returns the value of an op operand.
976 MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand);
977 
978 /// Returns the owner operation of an op operand.
979 MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand);
980 
981 /// Returns the operand number of an op operand.
982 MLIR_CAPI_EXPORTED unsigned
983 mlirOpOperandGetOperandNumber(MlirOpOperand opOperand);
984 
985 /// Returns an op operand representing the next use of the value, or a null op
986 /// operand if there is no next use.
987 MLIR_CAPI_EXPORTED MlirOpOperand
988 mlirOpOperandGetNextUse(MlirOpOperand opOperand);
989 
990 //===----------------------------------------------------------------------===//
991 // Type API.
992 //===----------------------------------------------------------------------===//
993 
994 /// Parses a type. The type is owned by the context.
995 MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context,
996  MlirStringRef type);
997 
998 /// Gets the context that a type was created with.
999 MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type);
1000 
1001 /// Gets the type ID of the type.
1002 MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type);
1003 
1004 /// Gets the dialect a type belongs to.
1005 MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type);
1006 
1007 /// Checks whether a type is null.
1008 static inline bool mlirTypeIsNull(MlirType type) { return !type.ptr; }
1009 
1010 /// Checks if two types are equal.
1011 MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2);
1012 
1013 /// Prints a location by sending chunks of the string representation and
1014 /// forwarding `userData to `callback`. Note that the callback may be called
1015 /// several times with consecutive chunks of the string.
1016 MLIR_CAPI_EXPORTED void
1017 mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData);
1018 
1019 /// Prints the type to the standard error stream.
1020 MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type);
1021 
1022 //===----------------------------------------------------------------------===//
1023 // Attribute API.
1024 //===----------------------------------------------------------------------===//
1025 
1026 /// Parses an attribute. The attribute is owned by the context.
1027 MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context,
1028  MlirStringRef attr);
1029 
1030 /// Gets the context that an attribute was created with.
1031 MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute);
1032 
1033 /// Gets the type of this attribute.
1034 MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute);
1035 
1036 /// Gets the type id of the attribute.
1037 MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute);
1038 
1039 /// Gets the dialect of the attribute.
1040 MLIR_CAPI_EXPORTED MlirDialect mlirAttributeGetDialect(MlirAttribute attribute);
1041 
1042 /// Checks whether an attribute is null.
1043 static inline bool mlirAttributeIsNull(MlirAttribute attr) { return !attr.ptr; }
1044 
1045 /// Checks if two attributes are equal.
1046 MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2);
1047 
1048 /// Prints an attribute by sending chunks of the string representation and
1049 /// forwarding `userData to `callback`. Note that the callback may be called
1050 /// several times with consecutive chunks of the string.
1051 MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr,
1052  MlirStringCallback callback,
1053  void *userData);
1054 
1055 /// Prints the attribute to the standard error stream.
1056 MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr);
1057 
1058 /// Associates an attribute with the name. Takes ownership of neither.
1060  MlirAttribute attr);
1061 
1062 //===----------------------------------------------------------------------===//
1063 // Identifier API.
1064 //===----------------------------------------------------------------------===//
1065 
1066 /// Gets an identifier with the given string value.
1067 MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context,
1068  MlirStringRef str);
1069 
1070 /// Returns the context associated with this identifier
1071 MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier);
1072 
1073 /// Checks whether two identifiers are the same.
1074 MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident,
1075  MlirIdentifier other);
1076 
1077 /// Gets the string value of the identifier.
1078 MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident);
1079 
1080 //===----------------------------------------------------------------------===//
1081 // Symbol and SymbolTable API.
1082 //===----------------------------------------------------------------------===//
1083 
1084 /// Returns the name of the attribute used to store symbol names compatible with
1085 /// symbol tables.
1087 
1088 /// Returns the name of the attribute used to store symbol visibility.
1091 
1092 /// Creates a symbol table for the given operation. If the operation does not
1093 /// have the SymbolTable trait, returns a null symbol table.
1094 MLIR_CAPI_EXPORTED MlirSymbolTable
1095 mlirSymbolTableCreate(MlirOperation operation);
1096 
1097 /// Returns true if the symbol table is null.
1098 static inline bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable) {
1099  return !symbolTable.ptr;
1100 }
1101 
1102 /// Destroys the symbol table created with mlirSymbolTableCreate. This does not
1103 /// affect the operations in the table.
1104 MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable);
1105 
1106 /// Looks up a symbol with the given name in the given symbol table and returns
1107 /// the operation that corresponds to the symbol. If the symbol cannot be found,
1108 /// returns a null operation.
1109 MLIR_CAPI_EXPORTED MlirOperation
1110 mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name);
1111 
1112 /// Inserts the given operation into the given symbol table. The operation must
1113 /// have the symbol trait. If the symbol table already has a symbol with the
1114 /// same name, renames the symbol being inserted to ensure name uniqueness. Note
1115 /// that this does not move the operation itself into the block of the symbol
1116 /// table operation, this should be done separately. Returns the name of the
1117 /// symbol after insertion.
1118 MLIR_CAPI_EXPORTED MlirAttribute
1119 mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation);
1120 
1121 /// Removes the given operation from the symbol table and erases it.
1122 MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable,
1123  MlirOperation operation);
1124 
1125 /// Attempt to replace all uses that are nested within the given operation
1126 /// of the given symbol 'oldSymbol' with the provided 'newSymbol'. This does
1127 /// not traverse into nested symbol tables. Will fail atomically if there are
1128 /// any unknown operations that may be potential symbol tables.
1130  MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from);
1131 
1132 /// Walks all symbol table operations nested within, and including, `op`. For
1133 /// each symbol table operation, the provided callback is invoked with the op
1134 /// and a boolean signifying if the symbols within that symbol table can be
1135 /// treated as if all uses within the IR are visible to the caller.
1136 /// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
1137 /// within `op` are visible.
1139  MlirOperation from, bool allSymUsesVisible,
1140  void (*callback)(MlirOperation, bool, void *userData), void *userData);
1141 
1142 #ifdef __cplusplus
1143 }
1144 #endif
1145 
1146 #endif // MLIR_C_IR_H
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
Returns the number of discardable attributes attached to the operation.
Definition: IR.cpp:625
MLIR_CAPI_EXPORTED MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
Definition: IR.cpp:252
MLIR_CAPI_EXPORTED intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
Returns the position of the value in the argument list of its block.
Definition: IR.cpp:958
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
Definition: IR.h:1043
MlirWalkResult(* MlirOperationWalkCallback)(MlirOperation, void *userData)
Operation walker type.
Definition: IR.h:735
MLIR_CAPI_EXPORTED void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
Definition: IR.cpp:701
MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op)
Gets the name of the operation as an identifier.
Definition: IR.cpp:529
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:260
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:1201
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition: IR.cpp:128
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumResults(MlirOperation op)
Returns the number of results of the operation.
Definition: IR.cpp:588
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
Definition: IR.cpp:1180
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:728
@ MlirWalkPreOrder
Definition: IR.h:729
@ MlirWalkPostOrder
Definition: IR.h:730
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Return pos-th attribute of the operation.
Definition: IR.cpp:662
MLIR_CAPI_EXPORTED void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
Definition: IR.cpp:377
MLIR_CAPI_EXPORTED void mlirModuleDestroy(MlirModule module)
Takes a module owned by the caller and deletes it.
Definition: IR.cpp:330
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
Definition: IR.cpp:1128
MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
Definition: IR.cpp:1185
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
Use local scope when printing the operation.
Definition: IR.cpp:220
MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value)
Returns 1 if the value is a block argument, 0 otherwise.
Definition: IR.cpp:946
MLIR_CAPI_EXPORTED void mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry)
Append the contents of the given dialect registry to the registry associated with the context.
Definition: IR.cpp:83
MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
Definition: IR.cpp:1149
static bool mlirModuleIsNull(MlirModule module)
Checks whether a module is null.
Definition: IR.h:314
MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition: IR.cpp:1062
MLIR_CAPI_EXPORTED void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
Definition: IR.cpp:140
MLIR_CAPI_EXPORTED MlirTypeID mlirOperationGetTypeID(MlirOperation op)
Gets the type id of the operation.
Definition: IR.cpp:523
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
Definition: IR.cpp:90
MLIR_CAPI_EXPORTED MlirOpOperand mlirOpOperandGetNextUse(MlirOpOperand opOperand)
Returns an op operand representing the next use of the value, or a null op operand if there is no nex...
Definition: IR.cpp:1045
MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute)
Gets the type of this attribute.
Definition: IR.cpp:1101
MLIR_CAPI_EXPORTED void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
Definition: IR.cpp:72
MLIR_CAPI_EXPORTED void mlirRegionInsertOwnedBlockBefore(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it before the (non-owned) reference block in the given ...
Definition: IR.cpp:802
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
Return pos-th discardable attribute of the operation.
Definition: IR.cpp:630
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:1009
MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Returns pos-th successor of the operation.
Definition: IR.cpp:600
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:992
MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
Definition: IR.cpp:288
MLIR_CAPI_EXPORTED void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:1082
MLIR_CAPI_EXPORTED void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Sets an attribute by name, replacing the existing if it exists or adding a new one otherwise.
Definition: IR.cpp:672
MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
Definition: IR.cpp:1033
MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition: IR.cpp:1145
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags, intptr_t largeResourceLimit)
Enables the elision of large resources strings by omitting them from the dialect_resources section.
Definition: IR.cpp:206
MLIR_CAPI_EXPORTED MlirDialect mlirAttributeGetDialect(MlirAttribute attribute)
Gets the dialect of the attribute.
Definition: IR.cpp:1112
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
Definition: IR.cpp:79
MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback, void *userData)
Prints an attribute by sending chunks of the string representation and forwarding userData tocallback...
Definition: IR.cpp:1120
MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition: IR.cpp:841
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:725
static bool mlirValueIsNull(MlirValue value)
Returns whether the value is null.
Definition: IR.h:898
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:1013
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:693
MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition: IR.cpp:903
MlirWalkResult
Operation walk result.
Definition: IR.h:721
@ MlirWalkResultInterrupt
Definition: IR.h:723
@ MlirWalkResultSkip
Definition: IR.h:724
@ MlirWalkResultAdvance
Definition: IR.h:722
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:782
MLIR_CAPI_EXPORTED MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Returns an attribute attached to the operation given its name.
Definition: IR.cpp:667
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition: IR.h:1008
MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition: IR.cpp:767
MLIR_CAPI_EXPORTED bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
Definition: IR.cpp:99
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Returns the number of successor blocks of the operation.
Definition: IR.cpp:596
MLIR_CAPI_EXPORTED MlirOperation mlirOperationClone(MlirOperation op)
Creates a deep copy of an operation.
Definition: IR.cpp:503
MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
Definition: IR.cpp:910
MLIR_CAPI_EXPORTED void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
Enables result type inference for the operation under construction.
Definition: IR.cpp:394
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
Always print operations in the generic form.
Definition: IR.cpp:216
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:271
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:891
MLIR_CAPI_EXPORTED void mlirAsmStateDestroy(MlirAsmState state)
Destroys printing flags created with mlirAsmStateCreate.
Definition: IR.cpp:187
static bool mlirContextIsNull(MlirContext context)
Checks whether a context is null.
Definition: IR.h:104
MLIR_CAPI_EXPORTED MlirDialect mlirContextGetOrLoadDialect(MlirContext context, MlirStringRef name)
Gets the dialect instance owned by the given context using the dialect namespace to identify it,...
Definition: IR.cpp:94
MLIR_CAPI_EXPORTED void mlirDialectHandleRegisterDialect(MlirDialectHandle, MlirContext)
Registers the dialect associated with the provided dialect handle.
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags, intptr_t largeElementLimit)
Enables the elision of large elements attributes by printing a lexically valid but otherwise meaningl...
Definition: IR.cpp:201
#define DEFINE_C_API_STRUCT(name, storage)
Opaque type declarations.
Definition: IR.h:45
MLIR_CAPI_EXPORTED bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Removes a discardable attribute by name.
Definition: IR.cpp:648
MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2)
Returns 1 if two values are equal, 0 otherwise.
Definition: IR.cpp:942
MLIR_CAPI_EXPORTED MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Returns a discardable attribute attached to the operation given its name.
Definition: IR.cpp:637
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:788
MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Sets the type of the block argument to the given type.
Definition: IR.cpp:963
MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op)
Gets the context this operation is associated with.
Definition: IR.cpp:515
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:825
MLIR_CAPI_EXPORTED MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags)
Creates new AsmState, as with AsmState the IR should not be mutated in-between using this state.
Definition: IR.cpp:148
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition: IR.h:817
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:866
MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition: IR.cpp:928
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:1175
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition: IR.cpp:1066
MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value)
Prints the value to the standard error stream.
Definition: IR.cpp:984
MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateEmpty(MlirLocation location)
Creates a new, empty module and transfers ownership to the caller.
Definition: IR.cpp:310
MLIR_CAPI_EXPORTED void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Sets a discardable attribute by name, replacing the existing if it exists or adding a new one otherwi...
Definition: IR.cpp:642
MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
Definition: IR.cpp:1031
MLIR_CAPI_EXPORTED MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition: IR.cpp:1165
MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
Definition: IR.cpp:292
MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetBlock(MlirOperation op)
Gets the block that owns this operation, returning null if the operation is not owned.
Definition: IR.cpp:533
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
Definition: IR.h:282
MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op, MlirOperation other)
Checks whether two operation handles point to the same operation.
Definition: IR.cpp:511
MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
Definition: IR.cpp:914
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:687
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:999
MLIR_CAPI_EXPORTED void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:300
MLIR_CAPI_EXPORTED void mlirContextSetThreadPool(MlirContext context, MlirLlvmThreadPool threadPool)
Sets the thread pool of the context explicitly, enabling multithreading in the process.
Definition: IR.cpp:111
MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
Definition: IR.cpp:717
MLIR_CAPI_EXPORTED MlirOperation mlirModuleGetOperation(MlirModule module)
Views the module as a generic operation.
Definition: IR.cpp:336
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition: IR.cpp:1078
MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition: IR.cpp:1171
MLIR_CAPI_EXPORTED MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
Constructs an operation state from a name and a location.
Definition: IR.cpp:348
MLIR_CAPI_EXPORTED unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition: IR.cpp:1041
MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
Definition: IR.cpp:120
MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
Definition: IR.cpp:833
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition: IR.cpp:856
MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition: IR.cpp:813
MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier)
Returns the context associated with this identifier.
Definition: IR.cpp:1141
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags)
Skip printing regions.
Definition: IR.cpp:228
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectHandleGetNamespace(MlirDialectHandle)
Returns the namespace associated with the provided dialect handle.
MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
Returns an operation immediately following the given operation it its enclosing block.
Definition: IR.cpp:565
MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetParentOperation(MlirOperation op)
Gets the operation that owns this operation, returning null if the operation is not owned.
Definition: IR.cpp:537
MLIR_CAPI_EXPORTED MlirContext mlirModuleGetContext(MlirModule module)
Gets the context that a module was created with.
Definition: IR.cpp:322
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
Definition: IR.cpp:256
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
Do not verify the operation when using custom operation printers.
Definition: IR.cpp:224
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
Definition: IR.cpp:1070
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetVisibilityAttributeName(void)
Returns the name of the attribute used to store symbol visibility.
Definition: IR.cpp:1161
static bool mlirDialectIsNull(MlirDialect dialect)
Checks if the dialect is null.
Definition: IR.h:173
MLIR_CAPI_EXPORTED void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
Destroys printing flags created with mlirBytecodeWriterConfigCreate.
Definition: IR.cpp:239
MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Returns pos-th operand of the operation.
Definition: IR.cpp:573
MLIR_CAPI_EXPORTED void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition: IR.cpp:389
MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
Definition: IR.cpp:845
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
Definition: IR.cpp:267
MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value)
Returns an operation that produced this value as its result.
Definition: IR.cpp:967
MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value)
Returns 1 if the value is an operation result, 0 otherwise.
Definition: IR.cpp:950
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumOperands(MlirOperation op)
Returns the number of operands of the operation.
Definition: IR.cpp:569
static bool mlirDialectRegistryIsNull(MlirDialectRegistry registry)
Checks if the dialect registry is null.
Definition: IR.h:235
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:743
MLIR_CAPI_EXPORTED void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
Replaces the operands of the operation.
Definition: IR.cpp:582
MLIR_CAPI_EXPORTED MlirContext mlirContextCreateWithThreading(bool threadingEnabled)
Creates an MLIR context with an explicit setting of the multithreading setting and transfers its owne...
Definition: IR.cpp:54
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock)
Returns the closest surrounding operation that contains this block.
Definition: IR.cpp:837
MLIR_CAPI_EXPORTED void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
Definition: IR.cpp:817
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumRegions(MlirOperation op)
Returns the number of regions attached to the given operation.
Definition: IR.cpp:541
MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
Definition: IR.cpp:296
MLIR_CAPI_EXPORTED void mlirBlockEraseArgument(MlirBlock block, unsigned index)
Erase the argument at 'index' and remove it from the argument list.
Definition: IR.cpp:919
MLIR_CAPI_EXPORTED bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Removes an attribute by name.
Definition: IR.cpp:677
MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition: IR.cpp:1126
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
Returns true if this operation defines an inherent attribute with this name.
Definition: IR.cpp:605
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:1190
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
Parses an attribute. The attribute is owned by the context.
Definition: IR.cpp:1093
MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
Parses a module from the string and transfers ownership to the caller.
Definition: IR.cpp:314
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:778
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition: IR.cpp:849
MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type)
Prints the type to the standard error stream.
Definition: IR.cpp:1087
MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Returns pos-th result of the operation.
Definition: IR.cpp:592
MLIR_CAPI_EXPORTED MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate(void)
Creates new printing flags with defaults, intended for customization.
Definition: IR.cpp:235
MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Gets the context that an attribute was created with.
Definition: IR.cpp:1097
MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
Returns the block in which this value is defined as an argument.
Definition: IR.cpp:954
MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op, MlirStringCallback callback, void *userData)
Prints an operation by sending chunks of the string representation and forwarding userData tocallback...
Definition: IR.cpp:681
static bool mlirRegionIsNull(MlirRegion region)
Checks whether a region is null.
Definition: IR.h:756
MLIR_CAPI_EXPORTED void mlirOperationDestroy(MlirOperation op)
Takes an operation owned by the caller and destroys it.
Definition: IR.cpp:507
MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Returns pos-th region attached to the operation.
Definition: IR.cpp:545
MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand)
Returns the value of an op operand.
Definition: IR.cpp:1037
MLIR_CAPI_EXPORTED void mlirOperationSetInherentAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Sets an inherent attribute by name, replacing the existing if it exists.
Definition: IR.cpp:618
MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition: IR.cpp:556
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:923
MLIR_CAPI_EXPORTED MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
Definition: IR.cpp:1074
MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op)
Views the generic operation as a module.
Definition: IR.cpp:340
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition: IR.cpp:1137
MLIR_CAPI_EXPORTED void mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block)
Set pos-th successor of the operation.
Definition: IR.cpp:653
MLIR_CAPI_EXPORTED void mlirContextLoadAllAvailableDialects(MlirContext context)
Eagerly loads all available dialects registered with a context, making them available for use for IR ...
Definition: IR.cpp:107
MLIR_CAPI_EXPORTED void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
Definition: IR.cpp:381
MLIR_CAPI_EXPORTED void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
Definition: IR.cpp:385
MLIR_CAPI_EXPORTED MlirBlock mlirModuleGetBody(MlirModule module)
Gets the body of the module, i.e. the only block it contains.
Definition: IR.cpp:326
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Destroys printing flags created with mlirOpPrintingFlagsCreate.
Definition: IR.cpp:197
MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void)
Creates a dialect registry and transfers its ownership to the caller.
Definition: IR.cpp:136
MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
Definition: IR.cpp:279
MLIR_CAPI_EXPORTED MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry, bool threadingEnabled)
Creates an MLIR context, setting the multithreading setting explicitly and pre-loading the dialects f...
Definition: IR.cpp:59
MLIR_CAPI_EXPORTED void mlirContextEnableMultithreading(MlirContext context, bool enable)
Set threading mode (must be set to false to mlir-print-ir-after-all).
Definition: IR.cpp:103
MLIR_CAPI_EXPORTED void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
Prints a block by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:932
MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
Definition: IR.cpp:549
MLIR_CAPI_EXPORTED void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags, int64_t version)
Sets the version to emit in the writer config.
Definition: IR.cpp:243
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetSymbolAttributeName(void)
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition: IR.cpp:1157
MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void)
Creates a new empty region and transfers ownership to the caller.
Definition: IR.cpp:765
MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
Definition: IR.cpp:905
MLIR_CAPI_EXPORTED void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n, MlirType const *results)
Adds a list of components to the operation state.
Definition: IR.cpp:372
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
Enable or disable printing of debug information (based on enable).
Definition: IR.cpp:211
MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation(MlirOperation op)
Gets the location of the operation.
Definition: IR.cpp:519
MLIR_CAPI_EXPORTED void mlirDialectHandleInsertDialect(MlirDialectHandle, MlirDialectRegistry)
Inserts the dialect associated with the provided dialect handle into the provided dialect registry.
MLIR_CAPI_EXPORTED MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
Returns an inherent attribute attached to the operation given its name.
Definition: IR.cpp:610
MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute)
Gets the type id of the attribute.
Definition: IR.cpp:1108
MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Sets the pos-th operand of the operation.
Definition: IR.cpp:577
MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op)
Prints an operation to stderr.
Definition: IR.cpp:715
MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
Definition: IR.cpp:66
MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
Definition: IR.cpp:124
MLIR_CAPI_EXPORTED intptr_t mlirOpResultGetResultNumber(MlirValue value)
Returns the position of the value in the list of results of the operation that produced it.
Definition: IR.cpp:971
MLIR_CAPI_EXPORTED void mlirOperationRemoveFromParent(MlirOperation op)
Removes the given operation from its parent block.
Definition: IR.cpp:509
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:870
MLIR_CAPI_EXPORTED MlirOpPrintingFlags mlirOpPrintingFlagsCreate(void)
Creates new printing flags with defaults, intended for customization.
Definition: IR.cpp:193
MLIR_CAPI_EXPORTED MlirContext mlirContextCreate(void)
Creates an MLIR context and transfers its ownership to the caller.
Definition: IR.cpp:44
MLIR_CAPI_EXPORTED MlirAsmState mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags)
Creates new AsmState from value.
Definition: IR.cpp:169
MLIR_CAPI_EXPORTED MlirOperation mlirOperationCreate(MlirOperationState *state)
Creates an operation and transfers ownership to the caller.
Definition: IR.cpp:457
static bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable)
Returns true if the symbol table is null.
Definition: IR.h:1098
MLIR_CAPI_EXPORTED bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
Definition: IR.cpp:76
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:721
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Returns the number of attributes attached to the operation.
Definition: IR.cpp:658
MLIR_CAPI_EXPORTED void mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData)
Prints a value by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:986
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:876
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:708
MLIR_CAPI_EXPORTED void mlirValueSetType(MlirValue value, MlirType type)
Set the type of the value.
Definition: IR.cpp:980
MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value)
Returns the type of the value.
Definition: IR.cpp:976
MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
Definition: IR.cpp:70
MLIR_CAPI_EXPORTED MlirOperation mlirOperationCreateParse(MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName)
Parses an operation, giving ownership to the caller.
Definition: IR.cpp:494
MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Checks if two attributes are equal.
Definition: IR.cpp:1116
static bool mlirOperationIsNull(MlirOperation op)
Checks whether the underlying operation is null.
Definition: IR.h:519
MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
Definition: IR.cpp:771
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:105
const FrozenRewritePatternSet GreedyRewriteConfig config
const void * ptr
Definition: IR.h:202
A logical result value, essentially a boolean with named states.
Definition: Support.h:116
Named MLIR attribute.
Definition: IR.h:76
MlirAttribute attribute
Definition: IR.h:78
MlirIdentifier name
Definition: IR.h:77
An auxiliary class for constructing operations.
Definition: IR.h:340
MlirBlock * successors
Definition: IR.h:350
intptr_t nAttributes
Definition: IR.h:351
bool enableResultTypeInference
Definition: IR.h:353
MlirLocation location
Definition: IR.h:342
intptr_t nSuccessors
Definition: IR.h:349
MlirStringRef name
Definition: IR.h:341
MlirType * results
Definition: IR.h:344
MlirValue * operands
Definition: IR.h:346
intptr_t nResults
Definition: IR.h:343
intptr_t nOperands
Definition: IR.h:345
MlirNamedAttribute * attributes
Definition: IR.h:352
intptr_t nRegions
Definition: IR.h:347
MlirRegion * regions
Definition: IR.h:348
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73