MLIR  17.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(MlirContext, void);
52 DEFINE_C_API_STRUCT(MlirDialect, void);
53 DEFINE_C_API_STRUCT(MlirDialectRegistry, void);
54 DEFINE_C_API_STRUCT(MlirOperation, void);
55 DEFINE_C_API_STRUCT(MlirOpOperand, void);
56 DEFINE_C_API_STRUCT(MlirOpPrintingFlags, void);
57 DEFINE_C_API_STRUCT(MlirBlock, void);
58 DEFINE_C_API_STRUCT(MlirRegion, void);
59 DEFINE_C_API_STRUCT(MlirSymbolTable, void);
60 
61 DEFINE_C_API_STRUCT(MlirAttribute, const void);
62 DEFINE_C_API_STRUCT(MlirIdentifier, const void);
63 DEFINE_C_API_STRUCT(MlirLocation, const void);
64 DEFINE_C_API_STRUCT(MlirModule, const void);
65 DEFINE_C_API_STRUCT(MlirType, const void);
66 DEFINE_C_API_STRUCT(MlirValue, const void);
67 
68 #undef DEFINE_C_API_STRUCT
69 
70 /// Named MLIR attribute.
71 ///
72 /// A named attribute is essentially a (name, attribute) pair where the name is
73 /// a string.
74 
76  MlirIdentifier name;
77  MlirAttribute attribute;
78 };
80 
81 //===----------------------------------------------------------------------===//
82 // Context API.
83 //===----------------------------------------------------------------------===//
84 
85 /// Creates an MLIR context and transfers its ownership to the caller.
86 MLIR_CAPI_EXPORTED MlirContext mlirContextCreate(void);
87 
88 /// Checks if two contexts are equal.
89 MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2);
90 
91 /// Checks whether a context is null.
92 static inline bool mlirContextIsNull(MlirContext context) {
93  return !context.ptr;
94 }
95 
96 /// Takes an MLIR context owned by the caller and destroys it.
97 MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context);
98 
99 /// Sets whether unregistered dialects are allowed in this context.
101 mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow);
102 
103 /// Returns whether the context allows unregistered dialects.
105 mlirContextGetAllowUnregisteredDialects(MlirContext context);
106 
107 /// Returns the number of dialects registered with the given context. A
108 /// registered dialect will be loaded if needed by the parser.
109 MLIR_CAPI_EXPORTED intptr_t
110 mlirContextGetNumRegisteredDialects(MlirContext context);
111 
112 /// Append the contents of the given dialect registry to the registry associated
113 /// with the context.
115 mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry);
116 
117 /// Returns the number of dialects loaded by the context.
118 
119 MLIR_CAPI_EXPORTED intptr_t
120 mlirContextGetNumLoadedDialects(MlirContext context);
121 
122 /// Gets the dialect instance owned by the given context using the dialect
123 /// namespace to identify it, loads (i.e., constructs the instance of) the
124 /// dialect if necessary. If the dialect is not registered with the context,
125 /// returns null. Use mlirContextLoad<Name>Dialect to load an unregistered
126 /// dialect.
127 MLIR_CAPI_EXPORTED MlirDialect mlirContextGetOrLoadDialect(MlirContext context,
129 
130 /// Set threading mode (must be set to false to mlir-print-ir-after-all).
131 MLIR_CAPI_EXPORTED void mlirContextEnableMultithreading(MlirContext context,
132  bool enable);
133 
134 /// Eagerly loads all available dialects registered with a context, making
135 /// them available for use for IR construction.
137 mlirContextLoadAllAvailableDialects(MlirContext context);
138 
139 /// Returns whether the given fully-qualified operation (i.e.
140 /// 'dialect.operation') is registered with the context. This will return true
141 /// if the dialect is loaded and the operation is registered within the
142 /// dialect.
145 
146 //===----------------------------------------------------------------------===//
147 // Dialect API.
148 //===----------------------------------------------------------------------===//
149 
150 /// Returns the context that owns the dialect.
151 MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect);
152 
153 /// Checks if the dialect is null.
154 static inline bool mlirDialectIsNull(MlirDialect dialect) {
155  return !dialect.ptr;
156 }
157 
158 /// Checks if two dialects that belong to the same context are equal. Dialects
159 /// from different contexts will not compare equal.
160 MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1,
161  MlirDialect dialect2);
162 
163 /// Returns the namespace of the given dialect.
165 
166 //===----------------------------------------------------------------------===//
167 // DialectHandle API.
168 // Registration entry-points for each dialect are declared using the common
169 // MLIR_DECLARE_DIALECT_REGISTRATION_CAPI macro, which takes the dialect
170 // API name (i.e. "Func", "Tensor", "Linalg") and namespace (i.e. "func",
171 // "tensor", "linalg"). The following declarations are produced:
172 //
173 // /// Gets the above hook methods in struct form for a dialect by namespace.
174 // /// This is intended to facilitate dynamic lookup and registration of
175 // /// dialects via a plugin facility based on shared library symbol lookup.
176 // const MlirDialectHandle *mlirGetDialectHandle__{NAMESPACE}__();
177 //
178 // This is done via a common macro to facilitate future expansion to
179 // registration schemes.
180 //===----------------------------------------------------------------------===//
181 
183  const void *ptr;
184 };
185 typedef struct MlirDialectHandle MlirDialectHandle;
186 
187 #define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace) \
188  MLIR_CAPI_EXPORTED MlirDialectHandle mlirGetDialectHandle__##Namespace##__( \
189  void)
190 
191 /// Returns the namespace associated with the provided dialect handle.
194 
195 /// Inserts the dialect associated with the provided dialect handle into the
196 /// provided dialect registry
198  MlirDialectRegistry);
199 
200 /// Registers the dialect associated with the provided dialect handle.
202  MlirContext);
203 
204 /// Loads the dialect associated with the provided dialect handle.
206  MlirContext);
207 
208 //===----------------------------------------------------------------------===//
209 // DialectRegistry API.
210 //===----------------------------------------------------------------------===//
211 
212 /// Creates a dialect registry and transfers its ownership to the caller.
213 MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void);
214 
215 /// Checks if the dialect registry is null.
216 static inline bool mlirDialectRegistryIsNull(MlirDialectRegistry registry) {
217  return !registry.ptr;
218 }
219 
220 /// Takes a dialect registry owned by the caller and destroys it.
222 mlirDialectRegistryDestroy(MlirDialectRegistry registry);
223 
224 //===----------------------------------------------------------------------===//
225 // Location API.
226 //===----------------------------------------------------------------------===//
227 
228 /// Returns the underlying location attribute of this location.
229 MLIR_CAPI_EXPORTED MlirAttribute
230 mlirLocationGetAttribute(MlirLocation location);
231 
232 /// Creates a location from a location attribute.
233 MLIR_CAPI_EXPORTED MlirLocation
234 mlirLocationFromAttribute(MlirAttribute attribute);
235 
236 /// Creates an File/Line/Column location owned by the given context.
238  MlirContext context, MlirStringRef filename, unsigned line, unsigned col);
239 
240 /// Creates a call site location with a callee and a caller.
241 MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
242  MlirLocation caller);
243 
244 /// Creates a fused location with an array of locations and metadata.
245 MLIR_CAPI_EXPORTED MlirLocation
246 mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
247  MlirLocation const *locations, MlirAttribute metadata);
248 
249 /// Creates a name location owned by the given context. Providing null location
250 /// for childLoc is allowed and if childLoc is null location, then the behavior
251 /// is the same as having unknown child location.
252 MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context,
253  MlirStringRef name,
254  MlirLocation childLoc);
255 
256 /// Creates a location with unknown position owned by the given context.
257 MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context);
258 
259 /// Gets the context that a location was created with.
260 MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location);
261 
262 /// Checks if the location is null.
263 static inline bool mlirLocationIsNull(MlirLocation location) {
264  return !location.ptr;
265 }
266 
267 /// Checks if two locations are equal.
268 MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2);
269 
270 /// Prints a location by sending chunks of the string representation and
271 /// forwarding `userData to `callback`. Note that the callback may be called
272 /// several times with consecutive chunks of the string.
273 MLIR_CAPI_EXPORTED void mlirLocationPrint(MlirLocation location,
274  MlirStringCallback callback,
275  void *userData);
276 
277 //===----------------------------------------------------------------------===//
278 // Module API.
279 //===----------------------------------------------------------------------===//
280 
281 /// Creates a new, empty module and transfers ownership to the caller.
282 MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateEmpty(MlirLocation location);
283 
284 /// Parses a module from the string and transfers ownership to the caller.
285 MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateParse(MlirContext context,
286  MlirStringRef module);
287 
288 /// Gets the context that a module was created with.
289 MLIR_CAPI_EXPORTED MlirContext mlirModuleGetContext(MlirModule module);
290 
291 /// Gets the body of the module, i.e. the only block it contains.
292 MLIR_CAPI_EXPORTED MlirBlock mlirModuleGetBody(MlirModule module);
293 
294 /// Checks whether a module is null.
295 static inline bool mlirModuleIsNull(MlirModule module) { return !module.ptr; }
296 
297 /// Takes a module owned by the caller and deletes it.
298 MLIR_CAPI_EXPORTED void mlirModuleDestroy(MlirModule module);
299 
300 /// Views the module as a generic operation.
301 MLIR_CAPI_EXPORTED MlirOperation mlirModuleGetOperation(MlirModule module);
302 
303 /// Views the generic operation as a module.
304 /// The returned module is null when the input operation was not a ModuleOp.
305 MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op);
306 
307 //===----------------------------------------------------------------------===//
308 // Operation state.
309 //===----------------------------------------------------------------------===//
310 
311 /// An auxiliary class for constructing operations.
312 ///
313 /// This class contains all the information necessary to construct the
314 /// operation. It owns the MlirRegions it has pointers to and does not own
315 /// anything else. By default, the state can be constructed from a name and
316 /// location, the latter being also used to access the context, and has no other
317 /// components. These components can be added progressively until the operation
318 /// is constructed. Users are not expected to rely on the internals of this
319 /// class and should use mlirOperationState* functions instead.
320 
323  MlirLocation location;
324  intptr_t nResults;
325  MlirType *results;
326  intptr_t nOperands;
327  MlirValue *operands;
328  intptr_t nRegions;
329  MlirRegion *regions;
330  intptr_t nSuccessors;
331  MlirBlock *successors;
332  intptr_t nAttributes;
335 };
337 
338 /// Constructs an operation state from a name and a location.
340  MlirLocation loc);
341 
342 /// Adds a list of components to the operation state.
344  intptr_t n,
345  MlirType const *results);
348  MlirValue const *operands);
351  MlirRegion const *regions);
354  MlirBlock const *successors);
358 
359 /// Enables result type inference for the operation under construction. If
360 /// enabled, then the caller must not have called
361 /// mlirOperationStateAddResults(). Note that if enabled, the
362 /// mlirOperationCreate() call is failable: it will return a null operation
363 /// on inference failure and will emit diagnostics.
366 
367 //===----------------------------------------------------------------------===//
368 // Op Printing flags API.
369 // While many of these are simple settings that could be represented in a
370 // struct, they are wrapped in a heap allocated object and accessed via
371 // functions to maximize the possibility of compatibility over time.
372 //===----------------------------------------------------------------------===//
373 
374 /// Creates new printing flags with defaults, intended for customization.
375 /// Must be freed with a call to mlirOpPrintingFlagsDestroy().
376 MLIR_CAPI_EXPORTED MlirOpPrintingFlags mlirOpPrintingFlagsCreate(void);
377 
378 /// Destroys printing flags created with mlirOpPrintingFlagsCreate.
379 MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags);
380 
381 /// Enables the elision of large elements attributes by printing a lexically
382 /// valid but otherwise meaningless form instead of the element data. The
383 /// `largeElementLimit` is used to configure what is considered to be a "large"
384 /// ElementsAttr by providing an upper limit to the number of elements.
386 mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
387  intptr_t largeElementLimit);
388 
389 /// Enable or disable printing of debug information (based on `enable`). If
390 /// 'prettyForm' is set to true, debug information is printed in a more readable
391 /// 'pretty' form. Note: The IR generated with 'prettyForm' is not parsable.
393 mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
394  bool prettyForm);
395 
396 /// Always print operations in the generic form.
398 mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags);
399 
400 /// Use local scope when printing the operation. This allows for using the
401 /// printer in a more localized and thread-safe setting, but may not
402 /// necessarily be identical to what the IR will look like when dumping
403 /// the full module.
405 mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags);
406 
407 //===----------------------------------------------------------------------===//
408 // Operation API.
409 //===----------------------------------------------------------------------===//
410 
411 /// Creates an operation and transfers ownership to the caller.
412 /// Note that caller owned child objects are transferred in this call and must
413 /// not be further used. Particularly, this applies to any regions added to
414 /// the state (the implementation may invalidate any such pointers).
415 ///
416 /// This call can fail under the following conditions, in which case, it will
417 /// return a null operation and emit diagnostics:
418 /// - Result type inference is enabled and cannot be performed.
420 
421 /// Creates a deep copy of an operation. The operation is not inserted and
422 /// ownership is transferred to the caller.
423 MLIR_CAPI_EXPORTED MlirOperation mlirOperationClone(MlirOperation op);
424 
425 /// Takes an operation owned by the caller and destroys it.
426 MLIR_CAPI_EXPORTED void mlirOperationDestroy(MlirOperation op);
427 
428 /// Removes the given operation from its parent block. The operation is not
429 /// destroyed. The ownership of the operation is transferred to the caller.
431 
432 /// Checks whether the underlying operation is null.
433 static inline bool mlirOperationIsNull(MlirOperation op) { return !op.ptr; }
434 
435 /// Checks whether two operation handles point to the same operation. This does
436 /// not perform deep comparison.
437 MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op,
438  MlirOperation other);
439 
440 /// Gets the context this operation is associated with
441 MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op);
442 
443 /// Gets the location of the operation.
444 MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation(MlirOperation op);
445 
446 /// Gets the type id of the operation.
447 /// Returns null if the operation does not have a registered operation
448 /// description.
449 MLIR_CAPI_EXPORTED MlirTypeID mlirOperationGetTypeID(MlirOperation op);
450 
451 /// Gets the name of the operation as an identifier.
452 MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op);
453 
454 /// Gets the block that owns this operation, returning null if the operation is
455 /// not owned.
456 MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetBlock(MlirOperation op);
457 
458 /// Gets the operation that owns this operation, returning null if the operation
459 /// is not owned.
460 MLIR_CAPI_EXPORTED MlirOperation
461 mlirOperationGetParentOperation(MlirOperation op);
462 
463 /// Returns the number of regions attached to the given operation.
464 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumRegions(MlirOperation op);
465 
466 /// Returns `pos`-th region attached to the operation.
467 MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op,
468  intptr_t pos);
469 
470 /// Returns an operation immediately following the given operation it its
471 /// enclosing block.
472 MLIR_CAPI_EXPORTED MlirOperation mlirOperationGetNextInBlock(MlirOperation op);
473 
474 /// Returns the number of operands of the operation.
475 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumOperands(MlirOperation op);
476 
477 /// Returns `pos`-th operand of the operation.
478 MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op,
479  intptr_t pos);
480 
481 /// Sets the `pos`-th operand of the operation.
482 MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
483  MlirValue newValue);
484 
485 /// Returns the number of results of the operation.
486 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumResults(MlirOperation op);
487 
488 /// Returns `pos`-th result of the operation.
489 MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op,
490  intptr_t pos);
491 
492 /// Returns the number of successor blocks of the operation.
493 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumSuccessors(MlirOperation op);
494 
495 /// Returns `pos`-th successor of the operation.
496 MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op,
497  intptr_t pos);
498 
499 /// Returns the number of attributes attached to the operation.
500 MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumAttributes(MlirOperation op);
501 
502 /// Return `pos`-th attribute of the operation.
504 mlirOperationGetAttribute(MlirOperation op, intptr_t pos);
505 
506 /// Returns an attribute attached to the operation given its name.
507 MLIR_CAPI_EXPORTED MlirAttribute
509 
510 /// Sets an attribute by name, replacing the existing if it exists or
511 /// adding a new one otherwise.
514  MlirAttribute attr);
515 
516 /// Removes an attribute by name. Returns false if the attribute was not found
517 /// and true if removed.
520 
521 /// Prints an operation by sending chunks of the string representation and
522 /// forwarding `userData to `callback`. Note that the callback may be called
523 /// several times with consecutive chunks of the string.
524 MLIR_CAPI_EXPORTED void mlirOperationPrint(MlirOperation op,
525  MlirStringCallback callback,
526  void *userData);
527 
528 /// Same as mlirOperationPrint but accepts flags controlling the printing
529 /// behavior.
530 MLIR_CAPI_EXPORTED void mlirOperationPrintWithFlags(MlirOperation op,
531  MlirOpPrintingFlags flags,
532  MlirStringCallback callback,
533  void *userData);
534 
535 /// Same as mlirOperationPrint but writing the bytecode format out.
536 MLIR_CAPI_EXPORTED void mlirOperationWriteBytecode(MlirOperation op,
537  MlirStringCallback callback,
538  void *userData);
539 
540 /// Prints an operation to stderr.
541 MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op);
542 
543 /// Verify the operation and return true if it passes, false if it fails.
544 MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op);
545 
546 /// Moves the given operation immediately after the other operation in its
547 /// parent block. The given operation may be owned by the caller or by its
548 /// current block. The other operation must belong to a block. In any case, the
549 /// ownership is transferred to the block of the other operation.
550 MLIR_CAPI_EXPORTED void mlirOperationMoveAfter(MlirOperation op,
551  MlirOperation other);
552 
553 /// Moves the given operation immediately before the other operation in its
554 /// parent block. The given operation may be owner by the caller or by its
555 /// current block. The other operation must belong to a block. In any case, the
556 /// ownership is transferred to the block of the other operation.
557 MLIR_CAPI_EXPORTED void mlirOperationMoveBefore(MlirOperation op,
558  MlirOperation other);
559 //===----------------------------------------------------------------------===//
560 // Region API.
561 //===----------------------------------------------------------------------===//
562 
563 /// Creates a new empty region and transfers ownership to the caller.
564 MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void);
565 
566 /// Takes a region owned by the caller and destroys it.
567 MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region);
568 
569 /// Checks whether a region is null.
570 static inline bool mlirRegionIsNull(MlirRegion region) { return !region.ptr; }
571 
572 /// Checks whether two region handles point to the same region. This does not
573 /// perform deep comparison.
574 MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other);
575 
576 /// Gets the first block in the region.
577 MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region);
578 
579 /// Takes a block owned by the caller and appends it to the given region.
580 MLIR_CAPI_EXPORTED void mlirRegionAppendOwnedBlock(MlirRegion region,
581  MlirBlock block);
582 
583 /// Takes a block owned by the caller and inserts it at `pos` to the given
584 /// region. This is an expensive operation that linearly scans the region,
585 /// prefer insertAfter/Before instead.
587 mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block);
588 
589 /// Takes a block owned by the caller and inserts it after the (non-owned)
590 /// reference block in the given region. The reference block must belong to the
591 /// region. If the reference block is null, prepends the block to the region.
593  MlirBlock reference,
594  MlirBlock block);
595 
596 /// Takes a block owned by the caller and inserts it before the (non-owned)
597 /// reference block in the given region. The reference block must belong to the
598 /// region. If the reference block is null, appends the block to the region.
600  MlirBlock reference,
601  MlirBlock block);
602 
603 /// Returns first region attached to the operation.
604 MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op);
605 
606 /// Returns the region immediately following the given region in its parent
607 /// operation.
608 MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region);
609 
610 //===----------------------------------------------------------------------===//
611 // Block API.
612 //===----------------------------------------------------------------------===//
613 
614 /// Creates a new empty block with the given argument types and transfers
615 /// ownership to the caller.
616 MLIR_CAPI_EXPORTED MlirBlock mlirBlockCreate(intptr_t nArgs,
617  MlirType const *args,
618  MlirLocation const *locs);
619 
620 /// Takes a block owned by the caller and destroys it.
621 MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block);
622 
623 /// Detach a block from the owning region and assume ownership.
624 MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block);
625 
626 /// Checks whether a block is null.
627 static inline bool mlirBlockIsNull(MlirBlock block) { return !block.ptr; }
628 
629 /// Checks whether two blocks handles point to the same block. This does not
630 /// perform deep comparison.
631 MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other);
632 
633 /// Returns the closest surrounding operation that contains this block.
634 MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock);
635 
636 /// Returns the region that contains this block.
637 MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block);
638 
639 /// Returns the block immediately following the given block in its parent
640 /// region.
641 MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block);
642 
643 /// Returns the first operation in the block.
644 MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block);
645 
646 /// Returns the terminator operation in the block or null if no terminator.
647 MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block);
648 
649 /// Takes an operation owned by the caller and appends it to the block.
651  MlirOperation operation);
652 
653 /// Takes an operation owned by the caller and inserts it as `pos` to the block.
654 /// This is an expensive operation that scans the block linearly, prefer
655 /// insertBefore/After instead.
657  intptr_t pos,
658  MlirOperation operation);
659 
660 /// Takes an operation owned by the caller and inserts it after the (non-owned)
661 /// reference operation in the given block. If the reference is null, prepends
662 /// the operation. Otherwise, the reference must belong to the block.
664 mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference,
665  MlirOperation operation);
666 
667 /// Takes an operation owned by the caller and inserts it before the (non-owned)
668 /// reference operation in the given block. If the reference is null, appends
669 /// the operation. Otherwise, the reference must belong to the block.
671 mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference,
672  MlirOperation operation);
673 
674 /// Returns the number of arguments of the block.
675 MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block);
676 
677 /// Appends an argument of the specified type to the block. Returns the newly
678 /// added argument.
679 MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block,
680  MlirType type,
681  MlirLocation loc);
682 
683 /// Returns `pos`-th argument of the block.
684 MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block,
685  intptr_t pos);
686 
687 /// Prints a block by sending chunks of the string representation and
688 /// forwarding `userData to `callback`. Note that the callback may be called
689 /// several times with consecutive chunks of the string.
691 mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData);
692 
693 //===----------------------------------------------------------------------===//
694 // Value API.
695 //===----------------------------------------------------------------------===//
696 
697 /// Returns whether the value is null.
698 static inline bool mlirValueIsNull(MlirValue value) { return !value.ptr; }
699 
700 /// Returns 1 if two values are equal, 0 otherwise.
701 MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2);
702 
703 /// Returns 1 if the value is a block argument, 0 otherwise.
704 MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value);
705 
706 /// Returns 1 if the value is an operation result, 0 otherwise.
707 MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value);
708 
709 /// Returns the block in which this value is defined as an argument. Asserts if
710 /// the value is not a block argument.
711 MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value);
712 
713 /// Returns the position of the value in the argument list of its block.
714 MLIR_CAPI_EXPORTED intptr_t mlirBlockArgumentGetArgNumber(MlirValue value);
715 
716 /// Sets the type of the block argument to the given type.
717 MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value,
718  MlirType type);
719 
720 /// Returns an operation that produced this value as its result. Asserts if the
721 /// value is not an op result.
722 MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value);
723 
724 /// Returns the position of the value in the list of results of the operation
725 /// that produced it.
726 MLIR_CAPI_EXPORTED intptr_t mlirOpResultGetResultNumber(MlirValue value);
727 
728 /// Returns the type of the value.
729 MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value);
730 
731 /// Prints the value to the standard error stream.
732 MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value);
733 
734 /// Prints a value by sending chunks of the string representation and
735 /// forwarding `userData to `callback`. Note that the callback may be called
736 /// several times with consecutive chunks of the string.
738 mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData);
739 
740 /// Returns an op operand representing the first use of the value, or a null op
741 /// operand if there are no uses.
742 MLIR_CAPI_EXPORTED MlirOpOperand mlirValueGetFirstUse(MlirValue value);
743 
744 //===----------------------------------------------------------------------===//
745 // OpOperand API.
746 //===----------------------------------------------------------------------===//
747 
748 /// Returns whether the op operand is null.
749 MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand);
750 
751 /// Returns the owner operation of an op operand.
752 MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand);
753 
754 /// Returns the operand number of an op operand.
755 MLIR_CAPI_EXPORTED unsigned
756 mlirOpOperandGetOperandNumber(MlirOpOperand opOperand);
757 
758 /// Returns an op operand representing the next use of the value, or a null op
759 /// operand if there is no next use.
760 MLIR_CAPI_EXPORTED MlirOpOperand
761 mlirOpOperandGetNextUse(MlirOpOperand opOperand);
762 
763 //===----------------------------------------------------------------------===//
764 // Type API.
765 //===----------------------------------------------------------------------===//
766 
767 /// Parses a type. The type is owned by the context.
768 MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context,
769  MlirStringRef type);
770 
771 /// Gets the context that a type was created with.
772 MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type);
773 
774 /// Gets the type ID of the type.
775 MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type);
776 
777 /// Checks whether a type is null.
778 static inline bool mlirTypeIsNull(MlirType type) { return !type.ptr; }
779 
780 /// Checks if two types are equal.
781 MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2);
782 
783 /// Prints a location by sending chunks of the string representation and
784 /// forwarding `userData to `callback`. Note that the callback may be called
785 /// several times with consecutive chunks of the string.
787 mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData);
788 
789 /// Prints the type to the standard error stream.
790 MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type);
791 
792 //===----------------------------------------------------------------------===//
793 // Attribute API.
794 //===----------------------------------------------------------------------===//
795 
796 /// Parses an attribute. The attribute is owned by the context.
797 MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context,
798  MlirStringRef attr);
799 
800 /// Gets the context that an attribute was created with.
801 MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute);
802 
803 /// Gets the type of this attribute.
804 MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute);
805 
806 /// Gets the type id of the attribute.
807 MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute);
808 
809 /// Checks whether an attribute is null.
810 static inline bool mlirAttributeIsNull(MlirAttribute attr) { return !attr.ptr; }
811 
812 /// Checks if two attributes are equal.
813 MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2);
814 
815 /// Prints an attribute by sending chunks of the string representation and
816 /// forwarding `userData to `callback`. Note that the callback may be called
817 /// several times with consecutive chunks of the string.
818 MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr,
819  MlirStringCallback callback,
820  void *userData);
821 
822 /// Prints the attribute to the standard error stream.
823 MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr);
824 
825 /// Associates an attribute with the name. Takes ownership of neither.
827  MlirAttribute attr);
828 
829 //===----------------------------------------------------------------------===//
830 // Identifier API.
831 //===----------------------------------------------------------------------===//
832 
833 /// Gets an identifier with the given string value.
834 MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context,
835  MlirStringRef str);
836 
837 /// Returns the context associated with this identifier
838 MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier);
839 
840 /// Checks whether two identifiers are the same.
841 MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident,
842  MlirIdentifier other);
843 
844 /// Gets the string value of the identifier.
846 
847 //===----------------------------------------------------------------------===//
848 // Symbol and SymbolTable API.
849 //===----------------------------------------------------------------------===//
850 
851 /// Returns the name of the attribute used to store symbol names compatible with
852 /// symbol tables.
854 
855 /// Returns the name of the attribute used to store symbol visibility.
858 
859 /// Creates a symbol table for the given operation. If the operation does not
860 /// have the SymbolTable trait, returns a null symbol table.
861 MLIR_CAPI_EXPORTED MlirSymbolTable
862 mlirSymbolTableCreate(MlirOperation operation);
863 
864 /// Returns true if the symbol table is null.
865 static inline bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable) {
866  return !symbolTable.ptr;
867 }
868 
869 /// Destroys the symbol table created with mlirSymbolTableCreate. This does not
870 /// affect the operations in the table.
871 MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable);
872 
873 /// Looks up a symbol with the given name in the given symbol table and returns
874 /// the operation that corresponds to the symbol. If the symbol cannot be found,
875 /// returns a null operation.
876 MLIR_CAPI_EXPORTED MlirOperation
877 mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name);
878 
879 /// Inserts the given operation into the given symbol table. The operation must
880 /// have the symbol trait. If the symbol table already has a symbol with the
881 /// same name, renames the symbol being inserted to ensure name uniqueness. Note
882 /// that this does not move the operation itself into the block of the symbol
883 /// table operation, this should be done separately. Returns the name of the
884 /// symbol after insertion.
885 MLIR_CAPI_EXPORTED MlirAttribute
886 mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation);
887 
888 /// Removes the given operation from the symbol table and erases it.
889 MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable,
890  MlirOperation operation);
891 
892 /// Attempt to replace all uses that are nested within the given operation
893 /// of the given symbol 'oldSymbol' with the provided 'newSymbol'. This does
894 /// not traverse into nested symbol tables. Will fail atomically if there are
895 /// any unknown operations that may be potential symbol tables.
897  MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from);
898 
899 /// Walks all symbol table operations nested within, and including, `op`. For
900 /// each symbol table operation, the provided callback is invoked with the op
901 /// and a boolean signifying if the symbols within that symbol table can be
902 /// treated as if all uses within the IR are visible to the caller.
903 /// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
904 /// within `op` are visible.
906  MlirOperation from, bool allSymUsesVisible,
907  void (*callback)(MlirOperation, bool, void *userData), void *userData);
908 
909 #ifdef __cplusplus
910 }
911 #endif
912 
913 #endif // MLIR_C_IR_H
MLIR_CAPI_EXPORTED MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
Definition: IR.cpp:148
MLIR_CAPI_EXPORTED intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
Returns the position of the value in the argument list of its block.
Definition: IR.cpp:701
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
Definition: IR.h:810
MLIR_CAPI_EXPORTED void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format out.
Definition: IR.cpp:497
MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op)
Gets the name of the operation as an identifier.
Definition: IR.cpp:393
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:156
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:903
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition: IR.cpp:98
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumResults(MlirOperation op)
Returns the number of results of the operation.
Definition: IR.cpp:446
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
Definition: IR.cpp:882
MLIR_CAPI_EXPORTED MlirDialect mlirDialectHandleLoadDialect(MlirDialectHandle, MlirContext)
Loads the dialect associated with the provided dialect handle.
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Return pos-th attribute of the operation.
Definition: IR.cpp:466
MLIR_CAPI_EXPORTED void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
Definition: IR.cpp:273
MLIR_CAPI_EXPORTED void mlirModuleDestroy(MlirModule module)
Takes a module owned by the caller and deletes it.
Definition: IR.cpp:226
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
Definition: IR.cpp:830
MLIR_CAPI_EXPORTED void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
Definition: IR.cpp:887
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
Use local scope when printing the operation.
Definition: IR.cpp:140
MLIR_CAPI_EXPORTED bool mlirValueIsABlockArgument(MlirValue value)
Returns 1 if the value is a block argument, 0 otherwise.
Definition: IR.cpp:689
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:58
MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
Definition: IR.cpp:851
static bool mlirModuleIsNull(MlirModule module)
Checks whether a module is null.
Definition: IR.h:295
MLIR_CAPI_EXPORTED MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition: IR.cpp:772
MLIR_CAPI_EXPORTED void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
Definition: IR.cpp:110
MLIR_CAPI_EXPORTED MlirTypeID mlirOperationGetTypeID(MlirOperation op)
Gets the type id of the operation.
Definition: IR.cpp:387
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
Definition: IR.cpp:65
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:755
MLIR_CAPI_EXPORTED MlirType mlirAttributeGetType(MlirAttribute attribute)
Gets the type of this attribute.
Definition: IR.cpp:807
MLIR_CAPI_EXPORTED void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
Definition: IR.cpp:47
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:558
MLIR_CAPI_EXPORTED MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Returns pos-th successor of the operation.
Definition: IR.cpp:458
MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
Definition: IR.cpp:184
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:788
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:476
MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
Definition: IR.cpp:747
MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition: IR.cpp:847
MLIR_CAPI_EXPORTED intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
Definition: IR.cpp:54
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:822
MLIR_CAPI_EXPORTED MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition: IR.cpp:593
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:513
static bool mlirValueIsNull(MlirValue value)
Returns whether the value is null.
Definition: IR.h:698
MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition: IR.cpp:655
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:538
MLIR_CAPI_EXPORTED MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Returns an attribute attached to the operation given its name.
Definition: IR.cpp:471
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition: IR.h:778
MLIR_CAPI_EXPORTED bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition: IR.cpp:523
MLIR_CAPI_EXPORTED bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
Definition: IR.cpp:74
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Returns the number of successor blocks of the operation.
Definition: IR.cpp:454
MLIR_CAPI_EXPORTED MlirOperation mlirOperationClone(MlirOperation op)
Creates a deep copy of an operation.
Definition: IR.cpp:367
MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
Definition: IR.cpp:662
MLIR_CAPI_EXPORTED void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
Enables result type inference for the operation under construction.
Definition: IR.cpp:290
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
Always print operations in the generic form.
Definition: IR.cpp:136
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:167
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:643
static bool mlirContextIsNull(MlirContext context)
Checks whether a context is null.
Definition: IR.h:92
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:69
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:126
#define DEFINE_C_API_STRUCT(name, storage)
Opaque type declarations.
Definition: IR.h:45
MLIR_CAPI_EXPORTED bool mlirValueEqual(MlirValue value1, MlirValue value2)
Returns 1 if two values are equal, 0 otherwise.
Definition: IR.cpp:685
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:544
MLIR_CAPI_EXPORTED void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Sets the type of the block argument to the given type.
Definition: IR.cpp:706
MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op)
Gets the context this operation is associated with.
Definition: IR.cpp:379
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:577
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition: IR.h:627
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:618
MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition: IR.cpp:671
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:877
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition: IR.cpp:776
MLIR_CAPI_EXPORTED void mlirValueDump(MlirValue value)
Prints the value to the standard error stream.
Definition: IR.cpp:723
MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateEmpty(MlirLocation location)
Creates a new, empty module and transfers ownership to the caller.
Definition: IR.cpp:206
MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
Definition: IR.cpp:745
MLIR_CAPI_EXPORTED MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition: IR.cpp:867
MLIR_CAPI_EXPORTED bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
Definition: IR.cpp:188
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:397
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
Definition: IR.h:263
MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op, MlirOperation other)
Checks whether two operation handles point to the same operation.
Definition: IR.cpp:375
MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
Definition: IR.cpp:666
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:491
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:731
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:196
MLIR_CAPI_EXPORTED bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
Definition: IR.cpp:505
MLIR_CAPI_EXPORTED MlirOperation mlirModuleGetOperation(MlirModule module)
Views the module as a generic operation.
Definition: IR.cpp:232
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition: IR.cpp:784
MLIR_CAPI_EXPORTED void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition: IR.cpp:873
MLIR_CAPI_EXPORTED MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
Constructs an operation state from a name and a location.
Definition: IR.cpp:244
MLIR_CAPI_EXPORTED unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition: IR.cpp:751
MLIR_CAPI_EXPORTED MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
Definition: IR.cpp:90
MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
Definition: IR.cpp:585
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition: IR.cpp:608
MLIR_CAPI_EXPORTED void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition: IR.cpp:569
MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier)
Returns the context associated with this identifier.
Definition: IR.cpp:843
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:429
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:401
MLIR_CAPI_EXPORTED MlirContext mlirModuleGetContext(MlirModule module)
Gets the context that a module was created with.
Definition: IR.cpp:218
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
Definition: IR.cpp:152
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
Definition: IR.cpp:780
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetVisibilityAttributeName(void)
Returns the name of the attribute used to store symbol visibility.
Definition: IR.cpp:863
static bool mlirDialectIsNull(MlirDialect dialect)
Checks if the dialect is null.
Definition: IR.h:154
MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Returns pos-th operand of the operation.
Definition: IR.cpp:437
MLIR_CAPI_EXPORTED void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition: IR.cpp:285
MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
Definition: IR.cpp:597
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
Definition: IR.cpp:163
MLIR_CAPI_EXPORTED MlirOperation mlirOpResultGetOwner(MlirValue value)
Returns an operation that produced this value as its result.
Definition: IR.cpp:710
MLIR_CAPI_EXPORTED bool mlirValueIsAOpResult(MlirValue value)
Returns 1 if the value is an operation result, 0 otherwise.
Definition: IR.cpp:693
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumOperands(MlirOperation op)
Returns the number of operands of the operation.
Definition: IR.cpp:433
static bool mlirDialectRegistryIsNull(MlirDialectRegistry registry)
Checks if the dialect registry is null.
Definition: IR.h:216
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock)
Returns the closest surrounding operation that contains this block.
Definition: IR.cpp:589
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumRegions(MlirOperation op)
Returns the number of regions attached to the given operation.
Definition: IR.cpp:405
MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
Definition: IR.cpp:192
MLIR_CAPI_EXPORTED bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Removes an attribute by name.
Definition: IR.cpp:481
MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition: IR.cpp:828
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:892
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
Parses an attribute. The attribute is owned by the context.
Definition: IR.cpp:799
MLIR_CAPI_EXPORTED MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
Parses a module from the string and transfers ownership to the caller.
Definition: IR.cpp:210
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:534
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition: IR.cpp:601
MLIR_CAPI_EXPORTED void mlirTypeDump(MlirType type)
Prints the type to the standard error stream.
Definition: IR.cpp:793
MLIR_CAPI_EXPORTED MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Returns pos-th result of the operation.
Definition: IR.cpp:450
MLIR_CAPI_EXPORTED MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Gets the context that an attribute was created with.
Definition: IR.cpp:803
MLIR_CAPI_EXPORTED MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
Returns the block in which this value is defined as an argument.
Definition: IR.cpp:697
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:485
static bool mlirRegionIsNull(MlirRegion region)
Checks whether a region is null.
Definition: IR.h:570
MLIR_CAPI_EXPORTED void mlirOperationDestroy(MlirOperation op)
Takes an operation owned by the caller and destroys it.
Definition: IR.cpp:371
MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Returns pos-th region attached to the operation.
Definition: IR.cpp:409
MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition: IR.cpp:420
MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op)
Views the generic operation as a module.
Definition: IR.cpp:236
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition: IR.cpp:839
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:82
MLIR_CAPI_EXPORTED void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
Definition: IR.cpp:277
MLIR_CAPI_EXPORTED void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
Definition: IR.cpp:281
MLIR_CAPI_EXPORTED MlirBlock mlirModuleGetBody(MlirModule module)
Gets the body of the module, i.e. the only block it contains.
Definition: IR.cpp:222
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Destroys printing flags created with mlirOpPrintingFlagsCreate.
Definition: IR.cpp:122
MLIR_CAPI_EXPORTED MlirDialectRegistry mlirDialectRegistryCreate(void)
Creates a dialect registry and transfers its ownership to the caller.
Definition: IR.cpp:106
MLIR_CAPI_EXPORTED MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
Definition: IR.cpp:175
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:78
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:675
MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
Definition: IR.cpp:413
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolTableGetSymbolAttributeName(void)
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition: IR.cpp:859
MLIR_CAPI_EXPORTED MlirRegion mlirRegionCreate(void)
Creates a new empty region and transfers ownership to the caller.
Definition: IR.cpp:521
MLIR_CAPI_EXPORTED void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
Definition: IR.cpp:657
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:268
MLIR_CAPI_EXPORTED void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
Enable or disable printing of debug information (based on enable).
Definition: IR.cpp:131
MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation(MlirOperation op)
Gets the location of the operation.
Definition: IR.cpp:383
MLIR_CAPI_EXPORTED void mlirDialectHandleInsertDialect(MlirDialectHandle, MlirDialectRegistry)
Inserts the dialect associated with the provided dialect handle into the provided dialect registry.
MLIR_CAPI_EXPORTED MlirTypeID mlirAttributeGetTypeID(MlirAttribute attribute)
Gets the type id of the attribute.
Definition: IR.cpp:814
MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Sets the pos-th operand of the operation.
Definition: IR.cpp:441
MLIR_CAPI_EXPORTED void mlirOperationDump(MlirOperation op)
Prints an operation to stderr.
Definition: IR.cpp:503
MLIR_CAPI_EXPORTED bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
Definition: IR.cpp:41
MLIR_CAPI_EXPORTED bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
Definition: IR.cpp:94
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:714
MLIR_CAPI_EXPORTED void mlirOperationRemoveFromParent(MlirOperation op)
Removes the given operation from its parent block.
Definition: IR.cpp:373
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:622
MLIR_CAPI_EXPORTED MlirOpPrintingFlags mlirOpPrintingFlagsCreate(void)
Creates new printing flags with defaults, intended for customization.
Definition: IR.cpp:118
MLIR_CAPI_EXPORTED MlirContext mlirContextCreate(void)
Creates an MLIR context and transfers its ownership to the caller.
Definition: IR.cpp:36
MLIR_CAPI_EXPORTED MlirOperation mlirOperationCreate(MlirOperationState *state)
Creates an operation and transfers ownership to the caller.
Definition: IR.cpp:329
static bool mlirSymbolTableIsNull(MlirSymbolTable symbolTable)
Returns true if the symbol table is null.
Definition: IR.h:865
MLIR_CAPI_EXPORTED bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
Definition: IR.cpp:51
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:509
MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Returns the number of attributes attached to the operation.
Definition: IR.cpp:462
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:725
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:628
MLIR_CAPI_EXPORTED MlirType mlirValueGetType(MlirValue value)
Returns the type of the value.
Definition: IR.cpp:719
MLIR_CAPI_EXPORTED void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
Definition: IR.cpp:45
MLIR_CAPI_EXPORTED bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Checks if two attributes are equal.
Definition: IR.cpp:818
static bool mlirOperationIsNull(MlirOperation op)
Checks whether the underlying operation is null.
Definition: IR.h:433
MLIR_CAPI_EXPORTED MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
Definition: IR.cpp:527
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:103
const void * ptr
Definition: IR.h:183
A logical result value, essentially a boolean with named states.
Definition: Support.h:114
Named MLIR attribute.
Definition: IR.h:75
MlirAttribute attribute
Definition: IR.h:77
MlirIdentifier name
Definition: IR.h:76
An auxiliary class for constructing operations.
Definition: IR.h:321
MlirBlock * successors
Definition: IR.h:331
intptr_t nAttributes
Definition: IR.h:332
bool enableResultTypeInference
Definition: IR.h:334
MlirLocation location
Definition: IR.h:323
intptr_t nSuccessors
Definition: IR.h:330
MlirStringRef name
Definition: IR.h:322
MlirType * results
Definition: IR.h:325
MlirValue * operands
Definition: IR.h:327
intptr_t nResults
Definition: IR.h:324
intptr_t nOperands
Definition: IR.h:326
MlirNamedAttribute * attributes
Definition: IR.h:333
intptr_t nRegions
Definition: IR.h:328
MlirRegion * regions
Definition: IR.h:329
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:71