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