MLIR 24.0.0git
IR.cpp
Go to the documentation of this file.
1//===- IR.cpp - C Interface for Core MLIR APIs ----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir-c/IR.h"
10#include "mlir-c/Support.h"
11
14#include "mlir/CAPI/IR.h"
15#include "mlir/CAPI/IRMapping.h"
16#include "mlir/CAPI/Support.h"
17#include "mlir/CAPI/Utils.h"
18#include "mlir/IR/Attributes.h"
20#include "mlir/IR/BuiltinOps.h"
21#include "mlir/IR/Diagnostics.h"
22#include "mlir/IR/Dialect.h"
23#include "mlir/IR/Location.h"
24#include "mlir/IR/Operation.h"
26#include "mlir/IR/OwningOpRef.h"
27#include "mlir/IR/Types.h"
28#include "mlir/IR/Value.h"
29#include "mlir/IR/Verifier.h"
30#include "mlir/IR/Visitors.h"
32#include "mlir/Parser/Parser.h"
33#include "llvm/ADT/SmallPtrSet.h"
34
35#include <cstddef>
36#include <memory>
37#include <optional>
38
39using namespace mlir;
40
41//===----------------------------------------------------------------------===//
42// Context API.
43//===----------------------------------------------------------------------===//
44
45MlirContext mlirContextCreate() {
46 auto *context = new MLIRContext;
47 return wrap(context);
48}
49
50static inline MLIRContext::Threading toThreadingEnum(bool threadingEnabled) {
51 return threadingEnabled ? MLIRContext::Threading::ENABLED
53}
54
55MlirContext mlirContextCreateWithThreading(bool threadingEnabled) {
56 auto *context = new MLIRContext(toThreadingEnum(threadingEnabled));
57 return wrap(context);
58}
59
60MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry,
61 bool threadingEnabled) {
62 auto *context =
63 new MLIRContext(*unwrap(registry), toThreadingEnum(threadingEnabled));
64 return wrap(context);
65}
66
67bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2) {
68 return unwrap(ctx1) == unwrap(ctx2);
69}
70
71void mlirContextDestroy(MlirContext context) { delete unwrap(context); }
72
73void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow) {
74 unwrap(context)->allowUnregisteredDialects(allow);
75}
76
77bool mlirContextGetAllowUnregisteredDialects(MlirContext context) {
78 return unwrap(context)->allowsUnregisteredDialects();
79}
81 return static_cast<intptr_t>(unwrap(context)->getAvailableDialects().size());
82}
83
85 MlirDialectRegistry registry) {
86 unwrap(ctx)->appendDialectRegistry(*unwrap(registry));
87}
88
89// TODO: expose a cheaper way than constructing + sorting a vector only to take
90// its size.
92 return static_cast<intptr_t>(unwrap(context)->getLoadedDialects().size());
93}
94
95MlirDialect mlirContextGetOrLoadDialect(MlirContext context,
96 MlirStringRef name) {
97 return wrap(unwrap(context)->getOrLoadDialect(unwrap(name)));
98}
99
100MlirDialect mlirContextGetLoadedDialect(MlirContext context,
101 MlirStringRef name) {
102 return wrap(unwrap(context)->getLoadedDialect(unwrap(name)));
103}
104
105bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name) {
106 return unwrap(context)->isOperationRegistered(unwrap(name));
107}
108
109void mlirContextEnableMultithreading(MlirContext context, bool enable) {
110 return unwrap(context)->enableMultithreading(enable);
111}
112
113void mlirContextLoadAllAvailableDialects(MlirContext context) {
114 unwrap(context)->loadAllAvailableDialects();
115}
116
117void mlirContextSetThreadPool(MlirContext context,
118 MlirLlvmThreadPool threadPool) {
119 unwrap(context)->setThreadPool(*unwrap(threadPool));
120}
121
122unsigned mlirContextGetNumThreads(MlirContext context) {
123 return unwrap(context)->getNumThreads();
124}
125
126MlirLlvmThreadPool mlirContextGetThreadPool(MlirContext context) {
127 return wrap(&unwrap(context)->getThreadPool());
128}
129
130//===----------------------------------------------------------------------===//
131// Dialect API.
132//===----------------------------------------------------------------------===//
133
134MlirContext mlirDialectGetContext(MlirDialect dialect) {
135 return wrap(unwrap(dialect)->getContext());
136}
137
138bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2) {
139 return unwrap(dialect1) == unwrap(dialect2);
140}
141
143 return wrap(unwrap(dialect)->getNamespace());
144}
145
146//===----------------------------------------------------------------------===//
147// DialectRegistry API.
148//===----------------------------------------------------------------------===//
149
150MlirDialectRegistry mlirDialectRegistryCreate() {
151 return wrap(new DialectRegistry());
152}
153
154void mlirDialectRegistryDestroy(MlirDialectRegistry registry) {
155 delete unwrap(registry);
156}
157
158//===----------------------------------------------------------------------===//
159// AsmState API.
160//===----------------------------------------------------------------------===//
161
162MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op,
163 MlirOpPrintingFlags flags) {
164 return wrap(new AsmState(unwrap(op), *unwrap(flags)));
165}
166
167static Operation *findParent(Operation *op, bool shouldUseLocalScope) {
168 do {
169 // If we are printing local scope, stop at the first operation that is
170 // isolated from above.
171 if (shouldUseLocalScope && op->hasTrait<OpTrait::IsIsolatedFromAbove>())
172 break;
173
174 // Otherwise, traverse up to the next parent.
175 Operation *parentOp = op->getParentOp();
176 if (!parentOp)
177 break;
178 op = parentOp;
179 } while (true);
180 return op;
181}
182
183MlirAsmState mlirAsmStateCreateForValue(MlirValue value,
184 MlirOpPrintingFlags flags) {
185 Operation *op;
186 mlir::Value val = unwrap(value);
187 if (auto result = llvm::dyn_cast<OpResult>(val)) {
188 op = result.getOwner();
189 } else {
190 op = llvm::cast<BlockArgument>(val).getOwner()->getParentOp();
191 if (!op) {
192 emitError(val.getLoc()) << "<<UNKNOWN SSA VALUE>>";
193 return {nullptr};
194 }
195 }
196 op = findParent(op, unwrap(flags)->shouldUseLocalScope());
197 return wrap(new AsmState(op, *unwrap(flags)));
198}
199
200/// Destroys printing flags created with mlirAsmStateCreate.
201void mlirAsmStateDestroy(MlirAsmState state) { delete unwrap(state); }
202
203//===----------------------------------------------------------------------===//
204// Printing flags API.
205//===----------------------------------------------------------------------===//
206
207MlirOpPrintingFlags mlirOpPrintingFlagsCreate() {
208 return wrap(new OpPrintingFlags());
209}
210
211void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags) {
212 delete unwrap(flags);
213}
214
215void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
216 intptr_t largeElementLimit) {
217 unwrap(flags)->elideLargeElementsAttrs(largeElementLimit);
218}
219
220void mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags,
221 intptr_t largeResourceLimit) {
222 unwrap(flags)->elideLargeResourceString(largeResourceLimit);
223}
224
225void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
226 bool prettyForm) {
227 unwrap(flags)->enableDebugInfo(enable, /*prettyForm=*/prettyForm);
228}
229
230void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags) {
231 unwrap(flags)->printGenericOpForm();
232}
233
234void mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags) {
235 unwrap(flags)->printNameLocAsPrefix();
236}
237
238void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags) {
239 unwrap(flags)->useLocalScope();
240}
241
242void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags) {
243 unwrap(flags)->assumeVerified();
244}
245
246void mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags) {
247 unwrap(flags)->skipRegions();
248}
249//===----------------------------------------------------------------------===//
250// Bytecode printing flags API.
251//===----------------------------------------------------------------------===//
252
253MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate() {
254 return wrap(new BytecodeWriterConfig());
255}
256
257void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config) {
258 delete unwrap(config);
259}
260
261void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags,
262 int64_t version) {
263 unwrap(flags)->setDesiredBytecodeVersion(version);
264}
265
266//===----------------------------------------------------------------------===//
267// Location API.
268//===----------------------------------------------------------------------===//
269
270MlirAttribute mlirLocationGetAttribute(MlirLocation location) {
271 return wrap(LocationAttr(unwrap(location)));
272}
273
274MlirLocation mlirLocationFromAttribute(MlirAttribute attribute) {
275 return wrap(Location(llvm::dyn_cast<LocationAttr>(unwrap(attribute))));
276}
277
278MlirLocation mlirLocationFileLineColGet(MlirContext context,
279 MlirStringRef filename, unsigned line,
280 unsigned col) {
281 return wrap(Location(
282 FileLineColLoc::get(unwrap(context), unwrap(filename), line, col)));
283}
284
285MlirLocation
286mlirLocationFileLineColRangeGet(MlirContext context, MlirStringRef filename,
287 unsigned startLine, unsigned startCol,
288 unsigned endLine, unsigned endCol) {
289 return wrap(
290 Location(FileLineColRange::get(unwrap(context), unwrap(filename),
291 startLine, startCol, endLine, endCol)));
292}
293
294MlirIdentifier mlirLocationFileLineColRangeGetFilename(MlirLocation location) {
295 return wrap(llvm::dyn_cast<FileLineColRange>(unwrap(location)).getFilename());
296}
297
299 if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap(location)))
300 return loc.getStartLine();
301 return -1;
302}
303
305 if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap(location)))
306 return loc.getStartColumn();
307 return -1;
308}
309
310int mlirLocationFileLineColRangeGetEndLine(MlirLocation location) {
311 if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap(location)))
312 return loc.getEndLine();
313 return -1;
314}
315
317 if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap(location)))
318 return loc.getEndColumn();
319 return -1;
320}
321
323 return wrap(FileLineColRange::getTypeID());
324}
325
326bool mlirLocationIsAFileLineColRange(MlirLocation location) {
327 return isa<FileLineColRange>(unwrap(location));
328}
329
330MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller) {
331 return wrap(Location(CallSiteLoc::get(unwrap(callee), unwrap(caller))));
332}
333
334MlirLocation mlirLocationCallSiteGetCallee(MlirLocation location) {
335 return wrap(
336 Location(llvm::dyn_cast<CallSiteLoc>(unwrap(location)).getCallee()));
337}
338
339MlirLocation mlirLocationCallSiteGetCaller(MlirLocation location) {
340 return wrap(
341 Location(llvm::dyn_cast<CallSiteLoc>(unwrap(location)).getCaller()));
342}
343
345 return wrap(CallSiteLoc::getTypeID());
346}
347
348bool mlirLocationIsACallSite(MlirLocation location) {
349 return isa<CallSiteLoc>(unwrap(location));
350}
351
352MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
353 MlirLocation const *locations,
354 MlirAttribute metadata) {
356 ArrayRef<Location> unwrappedLocs = unwrapList(nLocations, locations, locs);
357 return wrap(FusedLoc::get(unwrappedLocs, unwrap(metadata), unwrap(ctx)));
358}
359
360unsigned mlirLocationFusedGetNumLocations(MlirLocation location) {
361 if (auto locationsArrRef = llvm::dyn_cast<FusedLoc>(unwrap(location)))
362 return locationsArrRef.getLocations().size();
363 return 0;
364}
365
366void mlirLocationFusedGetLocations(MlirLocation location,
367 MlirLocation *locationsCPtr) {
368 if (auto locationsArrRef = llvm::dyn_cast<FusedLoc>(unwrap(location))) {
369 for (auto [i, location] : llvm::enumerate(locationsArrRef.getLocations()))
370 locationsCPtr[i] = wrap(location);
371 }
372}
373
374MlirAttribute mlirLocationFusedGetMetadata(MlirLocation location) {
375 return wrap(llvm::dyn_cast<FusedLoc>(unwrap(location)).getMetadata());
376}
377
378MlirTypeID mlirLocationFusedGetTypeID() { return wrap(FusedLoc::getTypeID()); }
379
380bool mlirLocationIsAFused(MlirLocation location) {
381 return isa<FusedLoc>(unwrap(location));
382}
383
384MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name,
385 MlirLocation childLoc) {
386 if (mlirLocationIsNull(childLoc))
387 return wrap(
388 Location(NameLoc::get(StringAttr::get(unwrap(context), unwrap(name)))));
389 return wrap(Location(NameLoc::get(
390 StringAttr::get(unwrap(context), unwrap(name)), unwrap(childLoc))));
391}
392
393MlirIdentifier mlirLocationNameGetName(MlirLocation location) {
394 return wrap((llvm::dyn_cast<NameLoc>(unwrap(location)).getName()));
395}
396
397MlirLocation mlirLocationNameGetChildLoc(MlirLocation location) {
398 return wrap(
399 Location(llvm::dyn_cast<NameLoc>(unwrap(location)).getChildLoc()));
400}
401
402MlirTypeID mlirLocationNameGetTypeID() { return wrap(NameLoc::getTypeID()); }
403
404bool mlirLocationIsAName(MlirLocation location) {
405 return isa<NameLoc>(unwrap(location));
406}
407
408MlirLocation mlirLocationUnknownGet(MlirContext context) {
409 return wrap(Location(UnknownLoc::get(unwrap(context))));
410}
411
413 return wrap(UnknownLoc::getTypeID());
414}
415
416bool mlirLocationIsAUnknown(MlirLocation location) {
417 return isa<UnknownLoc>(unwrap(location));
418}
419
420bool mlirLocationEqual(MlirLocation l1, MlirLocation l2) {
421 return unwrap(l1) == unwrap(l2);
422}
423
424MlirContext mlirLocationGetContext(MlirLocation location) {
425 return wrap(unwrap(location).getContext());
426}
427
428void mlirLocationPrint(MlirLocation location, MlirStringCallback callback,
429 void *userData) {
430 detail::CallbackOstream stream(callback, userData);
431 unwrap(location).print(stream);
432}
433
434//===----------------------------------------------------------------------===//
435// Module API.
436//===----------------------------------------------------------------------===//
437
438MlirModule mlirModuleCreateEmpty(MlirLocation location) {
439 return wrap(ModuleOp::create(unwrap(location)));
440}
441
442MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module) {
443 OwningOpRef<ModuleOp> owning =
444 parseSourceString<ModuleOp>(unwrap(module), unwrap(context));
445 if (!owning)
446 return MlirModule{nullptr};
447 return MlirModule{owning.release().getOperation()};
448}
449
450MlirModule mlirModuleCreateParseFromFile(MlirContext context,
451 MlirStringRef fileName) {
452 OwningOpRef<ModuleOp> owning =
453 parseSourceFile<ModuleOp>(unwrap(fileName), unwrap(context));
454 if (!owning)
455 return MlirModule{nullptr};
456 return MlirModule{owning.release().getOperation()};
457}
458
459MlirContext mlirModuleGetContext(MlirModule module) {
460 return wrap(unwrap(module).getContext());
461}
462
463MlirBlock mlirModuleGetBody(MlirModule module) {
464 return wrap(unwrap(module).getBody());
465}
466
467void mlirModuleDestroy(MlirModule module) {
468 // Transfer ownership to an OwningOpRef<ModuleOp> so that its destructor is
469 // called.
471}
472
473MlirOperation mlirModuleGetOperation(MlirModule module) {
474 return wrap(unwrap(module).getOperation());
475}
476
477MlirModule mlirModuleFromOperation(MlirOperation op) {
478 return wrap(dyn_cast<ModuleOp>(unwrap(op)));
479}
480
481bool mlirModuleEqual(MlirModule lhs, MlirModule rhs) {
482 return unwrap(lhs) == unwrap(rhs);
483}
484
485size_t mlirModuleHashValue(MlirModule mod) {
486 return OperationEquivalence::computeHash(unwrap(mod).getOperation());
487}
488
489//===----------------------------------------------------------------------===//
490// Operation state API.
491//===----------------------------------------------------------------------===//
492
493MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc) {
494 MlirOperationState state;
495 state.name = name;
496 state.location = loc;
497 state.nResults = 0;
498 state.results = nullptr;
499 state.nOperands = 0;
500 state.operands = nullptr;
501 state.nRegions = 0;
502 state.regions = nullptr;
503 state.nSuccessors = 0;
504 state.successors = nullptr;
505 state.nAttributes = 0;
506 state.attributes = nullptr;
507 state.enableResultTypeInference = false;
508 return state;
509}
510
511#define APPEND_ELEMS(type, sizeName, elemName) \
512 state->elemName = \
513 (type *)realloc(state->elemName, (state->sizeName + n) * sizeof(type)); \
514 memcpy(state->elemName + state->sizeName, elemName, n * sizeof(type)); \
515 state->sizeName += n;
516
517void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n,
518 MlirType const *results) {
519 APPEND_ELEMS(MlirType, nResults, results);
520}
521
522void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n,
523 MlirValue const *operands) {
524 APPEND_ELEMS(MlirValue, nOperands, operands);
525}
526void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n,
527 MlirRegion const *regions) {
528 APPEND_ELEMS(MlirRegion, nRegions, regions);
529}
530void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n,
531 MlirBlock const *successors) {
532 APPEND_ELEMS(MlirBlock, nSuccessors, successors);
533}
534void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n,
535 MlirNamedAttribute const *attributes) {
536 APPEND_ELEMS(MlirNamedAttribute, nAttributes, attributes);
537}
538
539void mlirOperationStateEnableResultTypeInference(MlirOperationState *state) {
540 state->enableResultTypeInference = true;
541}
542
543//===----------------------------------------------------------------------===//
544// Operation API.
545//===----------------------------------------------------------------------===//
546
547static LogicalResult inferOperationTypes(OperationState &state) {
548 MLIRContext *context = state.getContext();
549 std::optional<RegisteredOperationName> info = state.name.getRegisteredInfo();
550 if (!info) {
551 emitError(state.location)
552 << "type inference was requested for the operation " << state.name
553 << ", but the operation was not registered; ensure that the dialect "
554 "containing the operation is linked into MLIR and registered with "
555 "the context";
556 return failure();
557 }
558
559 auto *inferInterface = info->getInterface<InferTypeOpInterface>();
560 if (!inferInterface) {
561 emitError(state.location)
562 << "type inference was requested for the operation " << state.name
563 << ", but the operation does not support type inference; result "
564 "types must be specified explicitly";
565 return failure();
566 }
567
568 DictionaryAttr attributes = state.attributes.getDictionary(context);
569 PropertyRef properties = state.getRawProperties();
570
571 if (!properties && info->getOpPropertyByteSize() > 0 && !attributes.empty()) {
572 auto propAlloc = std::make_unique<char[]>(info->getOpPropertyByteSize());
573 properties = PropertyRef(info->getOpPropertiesTypeID(), propAlloc.get());
574 if (properties) {
575 auto emitError = [&]() {
576 return mlir::emitError(state.location)
577 << " failed properties conversion while building "
578 << state.name.getStringRef() << " with `" << attributes << "`: ";
579 };
580 if (failed(info->setOpPropertiesFromAttribute(state.name, properties,
581 attributes, emitError)))
582 return failure();
583 }
584 if (succeeded(inferInterface->inferReturnTypes(
585 context, state.location, state.operands, attributes, properties,
586 state.regions, state.types))) {
587 return success();
588 }
589 // Diagnostic emitted by interface.
590 return failure();
591 }
592
593 if (succeeded(inferInterface->inferReturnTypes(
594 context, state.location, state.operands, attributes, properties,
595 state.regions, state.types)))
596 return success();
597
598 // Diagnostic emitted by interface.
599 return failure();
600}
601
602MlirOperation mlirOperationCreate(MlirOperationState *state) {
603 assert(state);
604 OperationState cppState(unwrap(state->location), unwrap(state->name));
605 SmallVector<Type, 4> resultStorage;
606 SmallVector<Value, 8> operandStorage;
607 SmallVector<Block *, 2> successorStorage;
608 cppState.addTypes(unwrapList(state->nResults, state->results, resultStorage));
609 cppState.addOperands(
610 unwrapList(state->nOperands, state->operands, operandStorage));
611 cppState.addSuccessors(
612 unwrapList(state->nSuccessors, state->successors, successorStorage));
613
614 cppState.attributes.reserve(state->nAttributes);
615 for (intptr_t i = 0; i < state->nAttributes; ++i)
616 cppState.addAttribute(unwrap(state->attributes[i].name),
617 unwrap(state->attributes[i].attribute));
618
619 for (intptr_t i = 0; i < state->nRegions; ++i)
620 cppState.addRegion(std::unique_ptr<Region>(unwrap(state->regions[i])));
621
622 free(state->results);
623 free(state->operands);
624 free(state->successors);
625 free(state->regions);
626 free(state->attributes);
627
628 // Infer result types.
629 if (state->enableResultTypeInference) {
630 assert(cppState.types.empty() &&
631 "result type inference enabled and result types provided");
632 if (failed(inferOperationTypes(cppState)))
633 return {nullptr};
634 }
635
636 return wrap(Operation::create(cppState));
637}
638
639MlirOperation mlirOperationCreateParse(MlirContext context,
640 MlirStringRef sourceStr,
641 MlirStringRef sourceName) {
642
643 return wrap(
644 parseSourceString(unwrap(sourceStr), unwrap(context), unwrap(sourceName))
645 .release());
646}
647
648MlirOperation mlirOperationClone(MlirOperation op) {
649 return wrap(unwrap(op)->clone());
650}
651
652void mlirOperationDestroy(MlirOperation op) { unwrap(op)->erase(); }
653
654void mlirOperationRemoveFromParent(MlirOperation op) { unwrap(op)->remove(); }
655
656bool mlirOperationEqual(MlirOperation op, MlirOperation other) {
657 return unwrap(op) == unwrap(other);
658}
659
660size_t mlirOperationHashValue(MlirOperation op) {
662}
663
664/// Translates the C equivalence flags to mlir::OperationEquivalence::Flags. The
665/// enumerator values mirror each other.
667 return static_cast<OperationEquivalence::Flags>(flags);
668}
669
670bool mlirOperationIsStructurallyEquivalent(MlirOperation lhs, MlirOperation rhs,
671 uint32_t flags) {
674}
675
676size_t mlirOperationStructuralHashValue(MlirOperation op, uint32_t flags) {
678 unwrap(op), /*hashOperands=*/OperationEquivalence::directHashValue,
681}
682
683MlirContext mlirOperationGetContext(MlirOperation op) {
684 return wrap(unwrap(op)->getContext());
685}
686
687bool mlirOperationNameHasTrait(MlirStringRef opName, MlirTypeID traitTypeID,
688 MlirContext context) {
689 return OperationName(unwrap(opName), unwrap(context))
690 .hasTrait(unwrap(traitTypeID));
691}
692
693MlirLocation mlirOperationGetLocation(MlirOperation op) {
694 return wrap(unwrap(op)->getLoc());
695}
696
697void mlirOperationSetLocation(MlirOperation op, MlirLocation loc) {
698 unwrap(op)->setLoc(unwrap(loc));
699}
700
701MlirTypeID mlirOperationGetTypeID(MlirOperation op) {
702 if (auto info = unwrap(op)->getRegisteredInfo())
703 return wrap(info->getTypeID());
704 return {nullptr};
705}
706
707MlirIdentifier mlirOperationGetName(MlirOperation op) {
708 return wrap(unwrap(op)->getName().getIdentifier());
709}
710
711MlirBlock mlirOperationGetBlock(MlirOperation op) {
712 return wrap(unwrap(op)->getBlock());
713}
714
715MlirOperation mlirOperationGetParentOperation(MlirOperation op) {
716 return wrap(unwrap(op)->getParentOp());
717}
718
720 return static_cast<intptr_t>(unwrap(op)->getNumRegions());
721}
722
723MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos) {
724 return wrap(&unwrap(op)->getRegion(static_cast<unsigned>(pos)));
725}
726
727MlirRegion mlirOperationGetFirstRegion(MlirOperation op) {
728 Operation *cppOp = unwrap(op);
729 if (cppOp->getNumRegions() == 0)
730 return wrap(static_cast<Region *>(nullptr));
731 return wrap(&cppOp->getRegion(0));
732}
733
734MlirRegion mlirRegionGetNextInOperation(MlirRegion region) {
735 Region *cppRegion = unwrap(region);
736 Operation *parent = cppRegion->getParentOp();
737 intptr_t next = cppRegion->getRegionNumber() + 1;
738 if (parent->getNumRegions() > next)
739 return wrap(&parent->getRegion(next));
740 return wrap(static_cast<Region *>(nullptr));
741}
742
743MlirOperation mlirOperationGetNextInBlock(MlirOperation op) {
744 return wrap(unwrap(op)->getNextNode());
745}
746
748 return static_cast<intptr_t>(unwrap(op)->getNumOperands());
749}
750
751MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos) {
752 return wrap(unwrap(op)->getOperand(static_cast<unsigned>(pos)));
753}
754
755MlirOpOperand mlirOperationGetOpOperand(MlirOperation op, intptr_t pos) {
756 return wrap(&unwrap(op)->getOpOperand(static_cast<unsigned>(pos)));
757}
758
759void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
760 MlirValue newValue) {
761 unwrap(op)->setOperand(static_cast<unsigned>(pos), unwrap(newValue));
762}
763
764void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands,
765 MlirValue const *operands) {
767 unwrap(op)->setOperands(unwrapList(nOperands, operands, ops));
768}
769
771 return static_cast<intptr_t>(unwrap(op)->getNumResults());
772}
773
774MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos) {
775 return wrap(unwrap(op)->getResult(static_cast<unsigned>(pos)));
776}
777
779 return static_cast<intptr_t>(unwrap(op)->getNumSuccessors());
780}
781
782MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos) {
783 return wrap(unwrap(op)->getSuccessor(static_cast<unsigned>(pos)));
784}
785
788 std::optional<Attribute> attr = unwrap(op)->getInherentAttr(unwrap(name));
789 return attr.has_value();
790}
791
792MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op,
793 MlirStringRef name) {
794 std::optional<Attribute> attr = unwrap(op)->getInherentAttr(unwrap(name));
795 if (attr.has_value())
796 return wrap(*attr);
797 return {};
798}
799
801 MlirStringRef name,
802 MlirAttribute attr) {
803 unwrap(op)->setInherentAttr(
804 StringAttr::get(unwrap(op)->getContext(), unwrap(name)), unwrap(attr));
805}
806
808 return static_cast<intptr_t>(
809 llvm::range_size(unwrap(op)->getDiscardableAttrs()));
810}
811
813 intptr_t pos) {
814 NamedAttribute attr =
815 *std::next(unwrap(op)->getDiscardableAttrs().begin(), pos);
816 return MlirNamedAttribute{wrap(attr.getName()), wrap(attr.getValue())};
817}
818
819MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op,
820 MlirStringRef name) {
821 return wrap(unwrap(op)->getDiscardableAttr(unwrap(name)));
822}
823
825 MlirStringRef name,
826 MlirAttribute attr) {
827 unwrap(op)->setDiscardableAttr(unwrap(name), unwrap(attr));
828}
829
831 MlirStringRef name) {
832 return !!unwrap(op)->removeDiscardableAttr(unwrap(name));
833}
834
835void mlirOperationSetSuccessor(MlirOperation op, intptr_t pos,
836 MlirBlock block) {
837 unwrap(op)->setSuccessor(unwrap(block), static_cast<unsigned>(pos));
838}
839
841 return static_cast<intptr_t>(unwrap(op)->getAttrs().size());
842}
843
845 NamedAttribute attr = unwrap(op)->getAttrs()[pos];
846 return MlirNamedAttribute{wrap(attr.getName()), wrap(attr.getValue())};
847}
848
849MlirAttribute mlirOperationGetAttributeByName(MlirOperation op,
850 MlirStringRef name) {
851 return wrap(unwrap(op)->getAttr(unwrap(name)));
852}
853
855 MlirAttribute attr) {
856 unwrap(op)->setAttr(unwrap(name), unwrap(attr));
857}
858
860 return !!unwrap(op)->removeAttr(unwrap(name));
861}
862
863void mlirOperationPrint(MlirOperation op, MlirStringCallback callback,
864 void *userData) {
865 detail::CallbackOstream stream(callback, userData);
866 unwrap(op)->print(stream);
867}
868
869void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags,
870 MlirStringCallback callback, void *userData) {
871 detail::CallbackOstream stream(callback, userData);
872 unwrap(op)->print(stream, *unwrap(flags));
873}
874
875void mlirOperationPrintWithState(MlirOperation op, MlirAsmState state,
876 MlirStringCallback callback, void *userData) {
877 detail::CallbackOstream stream(callback, userData);
878 if (state.ptr)
879 unwrap(op)->print(stream, *unwrap(state));
880 else
881 unwrap(op)->print(stream);
882}
883
884void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback,
885 void *userData) {
886 detail::CallbackOstream stream(callback, userData);
887 // As no desired version is set, no failure can occur.
888 (void)writeBytecodeToFile(unwrap(op), stream);
889}
890
892 MlirOperation op, MlirBytecodeWriterConfig config,
893 MlirStringCallback callback, void *userData) {
894 detail::CallbackOstream stream(callback, userData);
895 return wrap(writeBytecodeToFile(unwrap(op), stream, *unwrap(config)));
896}
897
898void mlirOperationDump(MlirOperation op) { return unwrap(op)->dump(); }
899
900bool mlirOperationVerify(MlirOperation op) {
901 return succeeded(verify(unwrap(op)));
902}
903
904void mlirOperationMoveAfter(MlirOperation op, MlirOperation other) {
905 return unwrap(op)->moveAfter(unwrap(other));
906}
907
908void mlirOperationMoveBefore(MlirOperation op, MlirOperation other) {
909 return unwrap(op)->moveBefore(unwrap(other));
910}
911
912bool mlirOperationIsBeforeInBlock(MlirOperation op, MlirOperation other) {
913 return unwrap(op)->isBeforeInBlock(unwrap(other));
914}
915
917 switch (result) {
920
923
925 return mlir::WalkResult::skip();
926 }
927 llvm_unreachable("unknown result in WalkResult::unwrap");
928}
929
930void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback,
931 void *userData, MlirWalkOrder walkOrder) {
932 switch (walkOrder) {
933
934 case MlirWalkPreOrder:
936 [callback, userData](Operation *op) {
937 return unwrap(callback(wrap(op), userData));
938 });
939 break;
942 [callback, userData](Operation *op) {
943 return unwrap(callback(wrap(op), userData));
944 });
945 }
946}
947
948void mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue oldValue,
949 MlirValue newValue) {
950 unwrap(op)->replaceUsesOfWith(unwrap(oldValue), unwrap(newValue));
951}
952
953//===----------------------------------------------------------------------===//
954// Region API.
955//===----------------------------------------------------------------------===//
956
957MlirRegion mlirRegionCreate() { return wrap(new Region); }
958
959bool mlirRegionEqual(MlirRegion region, MlirRegion other) {
960 return unwrap(region) == unwrap(other);
961}
962
963MlirBlock mlirRegionGetFirstBlock(MlirRegion region) {
964 Region *cppRegion = unwrap(region);
965 if (cppRegion->empty())
966 return wrap(static_cast<Block *>(nullptr));
967 return wrap(&cppRegion->front());
968}
969
970void mlirRegionAppendOwnedBlock(MlirRegion region, MlirBlock block) {
971 unwrap(region)->push_back(unwrap(block));
972}
973
974void mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos,
975 MlirBlock block) {
976 auto &blockList = unwrap(region)->getBlocks();
977 blockList.insert(std::next(blockList.begin(), pos), unwrap(block));
978}
979
980void mlirRegionInsertOwnedBlockAfter(MlirRegion region, MlirBlock reference,
981 MlirBlock block) {
982 Region *cppRegion = unwrap(region);
983 if (mlirBlockIsNull(reference)) {
984 cppRegion->getBlocks().insert(cppRegion->begin(), unwrap(block));
985 return;
986 }
987
988 assert(unwrap(reference)->getParent() == unwrap(region) &&
989 "expected reference block to belong to the region");
990 cppRegion->getBlocks().insertAfter(Region::iterator(unwrap(reference)),
991 unwrap(block));
992}
993
994void mlirRegionInsertOwnedBlockBefore(MlirRegion region, MlirBlock reference,
995 MlirBlock block) {
996 if (mlirBlockIsNull(reference))
997 return mlirRegionAppendOwnedBlock(region, block);
998
999 assert(unwrap(reference)->getParent() == unwrap(region) &&
1000 "expected reference block to belong to the region");
1001 unwrap(region)->getBlocks().insert(Region::iterator(unwrap(reference)),
1002 unwrap(block));
1003}
1004
1005void mlirRegionDestroy(MlirRegion region) {
1006 delete static_cast<Region *>(region.ptr);
1007}
1008
1009void mlirRegionTakeBody(MlirRegion target, MlirRegion source) {
1010 unwrap(target)->takeBody(*unwrap(source));
1011}
1012
1013//===----------------------------------------------------------------------===//
1014// Block API.
1015//===----------------------------------------------------------------------===//
1016
1017MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args,
1018 MlirLocation const *locs) {
1019 Block *b = new Block;
1020 for (intptr_t i = 0; i < nArgs; ++i)
1021 b->addArgument(unwrap(args[i]), unwrap(locs[i]));
1022 return wrap(b);
1023}
1024
1025bool mlirBlockEqual(MlirBlock block, MlirBlock other) {
1026 return unwrap(block) == unwrap(other);
1027}
1028
1029MlirOperation mlirBlockGetParentOperation(MlirBlock block) {
1030 return wrap(unwrap(block)->getParentOp());
1031}
1032
1033MlirRegion mlirBlockGetParentRegion(MlirBlock block) {
1034 return wrap(unwrap(block)->getParent());
1035}
1036
1037MlirBlock mlirBlockGetNextInRegion(MlirBlock block) {
1038 return wrap(unwrap(block)->getNextNode());
1039}
1040
1041MlirOperation mlirBlockGetFirstOperation(MlirBlock block) {
1042 Block *cppBlock = unwrap(block);
1043 if (cppBlock->empty())
1044 return wrap(static_cast<Operation *>(nullptr));
1045 return wrap(&cppBlock->front());
1046}
1047
1048MlirOperation mlirBlockGetTerminator(MlirBlock block) {
1049 Block *cppBlock = unwrap(block);
1050 if (cppBlock->empty())
1051 return wrap(static_cast<Operation *>(nullptr));
1052 Operation &back = cppBlock->back();
1053 if (!back.hasTrait<OpTrait::IsTerminator>())
1054 return wrap(static_cast<Operation *>(nullptr));
1055 return wrap(&back);
1056}
1057
1058void mlirBlockAppendOwnedOperation(MlirBlock block, MlirOperation operation) {
1059 unwrap(block)->push_back(unwrap(operation));
1060}
1061
1062void mlirBlockInsertOwnedOperation(MlirBlock block, intptr_t pos,
1063 MlirOperation operation) {
1064 auto &opList = unwrap(block)->getOperations();
1065 opList.insert(std::next(opList.begin(), pos), unwrap(operation));
1066}
1067
1069 MlirOperation reference,
1070 MlirOperation operation) {
1071 Block *cppBlock = unwrap(block);
1072 if (mlirOperationIsNull(reference)) {
1073 cppBlock->getOperations().insert(cppBlock->begin(), unwrap(operation));
1074 return;
1075 }
1076
1077 assert(unwrap(reference)->getBlock() == unwrap(block) &&
1078 "expected reference operation to belong to the block");
1079 cppBlock->getOperations().insertAfter(Block::iterator(unwrap(reference)),
1080 unwrap(operation));
1081}
1082
1084 MlirOperation reference,
1085 MlirOperation operation) {
1086 if (mlirOperationIsNull(reference))
1087 return mlirBlockAppendOwnedOperation(block, operation);
1088
1089 assert(unwrap(reference)->getBlock() == unwrap(block) &&
1090 "expected reference operation to belong to the block");
1091 unwrap(block)->getOperations().insert(Block::iterator(unwrap(reference)),
1092 unwrap(operation));
1093}
1094
1095void mlirBlockDestroy(MlirBlock block) { delete unwrap(block); }
1096
1097void mlirBlockDetach(MlirBlock block) {
1098 Block *b = unwrap(block);
1099 b->getParent()->getBlocks().remove(b);
1100}
1101
1103 return static_cast<intptr_t>(unwrap(block)->getNumArguments());
1104}
1105
1106MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type,
1107 MlirLocation loc) {
1108 return wrap(unwrap(block)->addArgument(unwrap(type), unwrap(loc)));
1109}
1110
1111void mlirBlockEraseArgument(MlirBlock block, unsigned index) {
1112 return unwrap(block)->eraseArgument(index);
1113}
1114
1115MlirValue mlirBlockInsertArgument(MlirBlock block, intptr_t pos, MlirType type,
1116 MlirLocation loc) {
1117 return wrap(unwrap(block)->insertArgument(pos, unwrap(type), unwrap(loc)));
1118}
1119
1120MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos) {
1121 return wrap(unwrap(block)->getArgument(static_cast<unsigned>(pos)));
1122}
1123
1124void mlirBlockPrint(MlirBlock block, MlirStringCallback callback,
1125 void *userData) {
1126 detail::CallbackOstream stream(callback, userData);
1127 unwrap(block)->print(stream);
1128}
1129
1131 return static_cast<intptr_t>(unwrap(block)->getNumSuccessors());
1132}
1133
1134MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos) {
1135 return wrap(unwrap(block)->getSuccessor(static_cast<unsigned>(pos)));
1136}
1137
1139 Block *b = unwrap(block);
1140 return static_cast<intptr_t>(std::distance(b->pred_begin(), b->pred_end()));
1141}
1142
1143MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos) {
1144 Block *b = unwrap(block);
1145 Block::pred_iterator it = b->pred_begin();
1146 std::advance(it, pos);
1147 return wrap(*it);
1148}
1149
1150//===----------------------------------------------------------------------===//
1151// Value API.
1152//===----------------------------------------------------------------------===//
1153
1154bool mlirValueEqual(MlirValue value1, MlirValue value2) {
1155 return unwrap(value1) == unwrap(value2);
1156}
1157
1158bool mlirValueIsABlockArgument(MlirValue value) {
1159 return llvm::isa<BlockArgument>(unwrap(value));
1160}
1161
1162bool mlirValueIsAOpResult(MlirValue value) {
1163 return llvm::isa<OpResult>(unwrap(value));
1164}
1165
1166MlirBlock mlirBlockArgumentGetOwner(MlirValue value) {
1167 return wrap(llvm::dyn_cast<BlockArgument>(unwrap(value)).getOwner());
1168}
1169
1171 return static_cast<intptr_t>(
1172 llvm::dyn_cast<BlockArgument>(unwrap(value)).getArgNumber());
1173}
1174
1175void mlirBlockArgumentSetType(MlirValue value, MlirType type) {
1176 if (auto blockArg = llvm::dyn_cast<BlockArgument>(unwrap(value)))
1177 blockArg.setType(unwrap(type));
1178}
1179
1180void mlirBlockArgumentSetLocation(MlirValue value, MlirLocation loc) {
1181 if (auto blockArg = llvm::dyn_cast<BlockArgument>(unwrap(value)))
1182 blockArg.setLoc(unwrap(loc));
1183}
1184
1185MlirOperation mlirOpResultGetOwner(MlirValue value) {
1186 return wrap(llvm::dyn_cast<OpResult>(unwrap(value)).getOwner());
1187}
1188
1190 return static_cast<intptr_t>(
1191 llvm::dyn_cast<OpResult>(unwrap(value)).getResultNumber());
1192}
1193
1194MlirType mlirValueGetType(MlirValue value) {
1195 return wrap(unwrap(value).getType());
1196}
1197
1198void mlirValueSetType(MlirValue value, MlirType type) {
1199 unwrap(value).setType(unwrap(type));
1200}
1201
1202void mlirValueDump(MlirValue value) { unwrap(value).dump(); }
1203
1204void mlirValuePrint(MlirValue value, MlirStringCallback callback,
1205 void *userData) {
1206 detail::CallbackOstream stream(callback, userData);
1207 unwrap(value).print(stream);
1208}
1209
1210void mlirValuePrintAsOperand(MlirValue value, MlirAsmState state,
1211 MlirStringCallback callback, void *userData) {
1212 detail::CallbackOstream stream(callback, userData);
1213 Value cppValue = unwrap(value);
1214 cppValue.printAsOperand(stream, *unwrap(state));
1215}
1216
1217MlirOpOperand mlirValueGetFirstUse(MlirValue value) {
1218 Value cppValue = unwrap(value);
1219 if (cppValue.use_empty())
1220 return {};
1221
1222 OpOperand *opOperand = cppValue.use_begin().getOperand();
1223
1224 return wrap(opOperand);
1225}
1226
1227void mlirValueReplaceAllUsesOfWith(MlirValue oldValue, MlirValue newValue) {
1228 unwrap(oldValue).replaceAllUsesWith(unwrap(newValue));
1229}
1230
1231void mlirValueReplaceAllUsesExcept(MlirValue oldValue, MlirValue newValue,
1232 intptr_t numExceptions,
1233 MlirOperation *exceptions) {
1234 Value oldValueCpp = unwrap(oldValue);
1235 Value newValueCpp = unwrap(newValue);
1236
1238 for (intptr_t i = 0; i < numExceptions; ++i) {
1239 exceptionSet.insert(unwrap(exceptions[i]));
1240 }
1241
1242 oldValueCpp.replaceAllUsesExcept(newValueCpp, exceptionSet);
1243}
1244
1245void mlirValueReplaceUsesWithIf(MlirValue of, MlirValue with,
1247 void *userData) {
1248 assert(filter && "expected non-null filter callback");
1249 unwrap(of).replaceUsesWithIf(unwrap(with),
1250 [filter, userData](OpOperand &operand) -> bool {
1251 return filter(wrap(&operand), userData);
1252 });
1253}
1254
1255MlirLocation mlirValueGetLocation(MlirValue v) {
1256 return wrap(unwrap(v).getLoc());
1257}
1258
1259MlirContext mlirValueGetContext(MlirValue v) {
1260 return wrap(unwrap(v).getContext());
1261}
1262
1263//===----------------------------------------------------------------------===//
1264// OpOperand API.
1265//===----------------------------------------------------------------------===//
1266
1267bool mlirOpOperandIsNull(MlirOpOperand opOperand) { return !opOperand.ptr; }
1268
1269MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand) {
1270 return wrap(unwrap(opOperand)->getOwner());
1271}
1272
1273MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand) {
1274 return wrap(unwrap(opOperand)->get());
1275}
1276
1277unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand) {
1278 return unwrap(opOperand)->getOperandNumber();
1279}
1280
1281MlirOpOperand mlirOpOperandGetNextUse(MlirOpOperand opOperand) {
1282 if (mlirOpOperandIsNull(opOperand))
1283 return {};
1284
1285 OpOperand *nextOpOperand = static_cast<OpOperand *>(
1286 unwrap(opOperand)->getNextOperandUsingThisValue());
1287
1288 if (!nextOpOperand)
1289 return {};
1290
1291 return wrap(nextOpOperand);
1292}
1293
1294//===----------------------------------------------------------------------===//
1295// Type API.
1296//===----------------------------------------------------------------------===//
1297
1298MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type) {
1299 return wrap(mlir::parseType(unwrap(type), unwrap(context)));
1300}
1301
1302MlirContext mlirTypeGetContext(MlirType type) {
1303 return wrap(unwrap(type).getContext());
1304}
1305
1306MlirTypeID mlirTypeGetTypeID(MlirType type) {
1307 return wrap(unwrap(type).getTypeID());
1308}
1309
1310MlirDialect mlirTypeGetDialect(MlirType type) {
1311 return wrap(&unwrap(type).getDialect());
1312}
1313
1314bool mlirTypeEqual(MlirType t1, MlirType t2) {
1315 return unwrap(t1) == unwrap(t2);
1316}
1317
1318void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData) {
1319 detail::CallbackOstream stream(callback, userData);
1320 unwrap(type).print(stream);
1321}
1322
1323void mlirTypeDump(MlirType type) { unwrap(type).dump(); }
1324
1325//===----------------------------------------------------------------------===//
1326// Attribute API.
1327//===----------------------------------------------------------------------===//
1328
1329MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr) {
1330 return wrap(mlir::parseAttribute(unwrap(attr), unwrap(context)));
1331}
1332
1333MlirContext mlirAttributeGetContext(MlirAttribute attribute) {
1334 return wrap(unwrap(attribute).getContext());
1335}
1336
1337MlirType mlirAttributeGetType(MlirAttribute attribute) {
1338 Attribute attr = unwrap(attribute);
1339 if (auto typedAttr = llvm::dyn_cast<TypedAttr>(attr))
1340 return wrap(typedAttr.getType());
1341 return wrap(NoneType::get(attr.getContext()));
1342}
1343
1344MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr) {
1345 return wrap(unwrap(attr).getTypeID());
1346}
1347
1348MlirDialect mlirAttributeGetDialect(MlirAttribute attr) {
1349 return wrap(&unwrap(attr).getDialect());
1350}
1351
1352bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2) {
1353 return unwrap(a1) == unwrap(a2);
1354}
1355
1356void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback,
1357 void *userData) {
1358 detail::CallbackOstream stream(callback, userData);
1359 unwrap(attr).print(stream);
1360}
1361
1362void mlirAttributeDump(MlirAttribute attr) { unwrap(attr).dump(); }
1363
1365 MlirAttribute attr) {
1366 return MlirNamedAttribute{name, attr};
1367}
1368
1369//===----------------------------------------------------------------------===//
1370// Identifier API.
1371//===----------------------------------------------------------------------===//
1372
1373MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str) {
1374 return wrap(StringAttr::get(unwrap(context), unwrap(str)));
1375}
1376
1377MlirContext mlirIdentifierGetContext(MlirIdentifier ident) {
1378 return wrap(unwrap(ident).getContext());
1379}
1380
1381bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other) {
1382 return unwrap(ident) == unwrap(other);
1383}
1384
1385MlirStringRef mlirIdentifierStr(MlirIdentifier ident) {
1386 return wrap(unwrap(ident).strref());
1387}
1388
1389//===----------------------------------------------------------------------===//
1390// Symbol and SymbolTable API.
1391//===----------------------------------------------------------------------===//
1392
1396
1400
1401MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation) {
1402 if (!unwrap(operation)->hasTrait<OpTrait::SymbolTable>())
1403 return wrap(static_cast<SymbolTable *>(nullptr));
1404 return wrap(new SymbolTable(unwrap(operation)));
1405}
1406
1407void mlirSymbolTableDestroy(MlirSymbolTable symbolTable) {
1408 delete unwrap(symbolTable);
1409}
1410
1411MlirOperation mlirSymbolTableLookup(MlirSymbolTable symbolTable,
1412 MlirStringRef name) {
1413 return wrap(unwrap(symbolTable)->lookup(StringRef(name.data, name.length)));
1414}
1415
1416MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable,
1417 MlirOperation operation) {
1418 return wrap((Attribute)unwrap(symbolTable)->insert(unwrap(operation)));
1419}
1420
1421void mlirSymbolTableErase(MlirSymbolTable symbolTable,
1422 MlirOperation operation) {
1423 unwrap(symbolTable)->erase(unwrap(operation));
1424}
1425
1427 MlirStringRef newSymbol,
1428 MlirOperation from) {
1429 auto *cppFrom = unwrap(from);
1430 auto *context = cppFrom->getContext();
1431 auto oldSymbolAttr = StringAttr::get(context, unwrap(oldSymbol));
1432 auto newSymbolAttr = StringAttr::get(context, unwrap(newSymbol));
1433 return wrap(SymbolTable::replaceAllSymbolUses(oldSymbolAttr, newSymbolAttr,
1434 unwrap(from)));
1435}
1436
1437void mlirSymbolTableWalkSymbolTables(MlirOperation from, bool allSymUsesVisible,
1438 void (*callback)(MlirOperation, bool,
1439 void *userData),
1440 void *userData) {
1441 SymbolTable::walkSymbolTables(unwrap(from), allSymUsesVisible,
1442 [&](Operation *foundOpCpp, bool isVisible) {
1443 callback(wrap(foundOpCpp), isVisible,
1444 userData);
1445 });
1446}
1447
1448//===----------------------------------------------------------------------===//
1449// IRMapping API
1450//===----------------------------------------------------------------------===//
1451
1452MlirIRMapping mlirIRMappingCreate(void) { return wrap(new IRMapping()); }
1453
1454void mlirIRMappingDestroy(MlirIRMapping mapping) { delete unwrap(mapping); }
1455
1456void mlirIRMappingMapValue(MlirIRMapping mapping, MlirValue from,
1457 MlirValue to) {
1458 unwrap(mapping)->map(unwrap(from), unwrap(to));
1459}
1460
1461void mlirIRMappingMapBlock(MlirIRMapping mapping, MlirBlock from,
1462 MlirBlock to) {
1463 unwrap(mapping)->map(unwrap(from), unwrap(to));
1464}
1465
1466void mlirIRMappingMapOperation(MlirIRMapping mapping, MlirOperation from,
1467 MlirOperation to) {
1468 unwrap(mapping)->map(unwrap(from), unwrap(to));
1469}
1470
1471void mlirIRMappingClear(MlirIRMapping mapping) { unwrap(mapping)->clear(); }
1472
1473MlirValue mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping,
1474 MlirValue from) {
1475 return wrap(unwrap(mapping)->lookupOrDefault(unwrap(from)));
1476}
1477
1478MlirValue mlirIRMappingLookupOrNullValue(MlirIRMapping mapping,
1479 MlirValue from) {
1480 return wrap(unwrap(mapping)->lookupOrNull(unwrap(from)));
1481}
1482
1483MlirBlock mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping,
1484 MlirBlock from) {
1485 return wrap(unwrap(mapping)->lookupOrDefault(unwrap(from)));
1486}
1487
1488MlirBlock mlirIRMappingLookupOrNullBlock(MlirIRMapping mapping,
1489 MlirBlock from) {
1490 return wrap(unwrap(mapping)->lookupOrNull(unwrap(from)));
1491}
1492
1493MlirOperation mlirIRMappingLookupOrDefaultOperation(MlirIRMapping mapping,
1494 MlirOperation from) {
1495 return wrap(unwrap(mapping)->lookupOrDefault(unwrap(from)));
1496}
1497
1498MlirOperation mlirIRMappingLookupOrNullOperation(MlirIRMapping mapping,
1499 MlirOperation from) {
1500 return wrap(unwrap(mapping)->lookupOrNull(unwrap(from)));
1501}
1502
1503bool mlirIRMappingContainsValue(MlirIRMapping mapping, MlirValue value) {
1504 return unwrap(mapping)->contains(unwrap(value));
1505}
1506
1507bool mlirIRMappingContainsBlock(MlirIRMapping mapping, MlirBlock block) {
1508 return unwrap(mapping)->contains(unwrap(block));
1509}
1510
1511bool mlirIRMappingContainsOperation(MlirIRMapping mapping, MlirOperation op) {
1512 return unwrap(mapping)->contains(unwrap(op));
1513}
1514
1515void mlirIRMappingEraseValue(MlirIRMapping mapping, MlirValue value) {
1516 unwrap(mapping)->erase(unwrap(value));
1517}
1518
1519void mlirIRMappingEraseBlock(MlirIRMapping mapping, MlirBlock block) {
1520 unwrap(mapping)->erase(unwrap(block));
1521}
1522
1523void mlirIRMappingEraseOperation(MlirIRMapping mapping, MlirOperation op) {
1524 unwrap(mapping)->erase(unwrap(op));
1525}
1526
1527MlirOperation mlirOperationCloneWithMapping(MlirOperation op,
1528 MlirIRMapping mapping) {
1529 return wrap(unwrap(op)->clone(*unwrap(mapping)));
1530}
return success()
lhs
unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition IR.cpp:1277
MlirLocation mlirValueGetLocation(MlirValue v)
Gets the location of the value.
Definition IR.cpp:1255
void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
Definition IR.cpp:71
void mlirOperationDump(MlirOperation op)
Prints an operation to stderr.
Definition IR.cpp:898
MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:819
MlirOperation mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name)
Looks up a symbol with the given name in the given symbol table and returns the operation that corres...
Definition IR.cpp:1411
MlirRegion mlirRegionCreate()
Creates a new empty region and transfers ownership to the caller.
Definition IR.cpp:957
void mlirOperationPrint(MlirOperation op, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData to callback`...
Definition IR.cpp:863
MlirBlock mlirIRMappingLookupOrNullBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block. Returns a null MlirBlock if no mapping exists.
Definition IR.cpp:1488
MlirValue mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value.
Definition IR.cpp:1473
MlirContext mlirModuleGetContext(MlirModule module)
Definition IR.cpp:459
void mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData)
Prints a block by sending chunks of the string representation and forwarding userData to callback`.
Definition IR.cpp:1204
MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
Definition IR.cpp:424
MlirDialect mlirContextGetLoadedDialect(MlirContext context, MlirStringRef name)
Gets the dialect instance owned by the given context using the dialect namespace to identify it.
Definition IR.cpp:100
size_t mlirModuleHashValue(MlirModule mod)
Definition IR.cpp:485
intptr_t mlirBlockGetNumPredecessors(MlirBlock block)
Definition IR.cpp:1138
bool mlirLocationIsAName(MlirLocation location)
Checks whether the given location is an Name.
Definition IR.cpp:404
MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
Definition IR.cpp:1269
bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
Definition IR.cpp:138
MlirOperation mlirIRMappingLookupOrDefaultOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
Definition IR.cpp:1493
MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition IR.cpp:734
MlirLogicalResult mlirOperationWriteBytecodeWithConfig(MlirOperation op, MlirBytecodeWriterConfig config, MlirStringCallback callback, void *userData)
Same as mlirOperationWriteBytecode but with writer config and returns failure only if desired bytecod...
Definition IR.cpp:891
MlirIdentifier mlirOperationGetName(MlirOperation op)
Definition IR.cpp:707
void mlirIRMappingMapBlock(MlirIRMapping mapping, MlirBlock from, MlirBlock to)
Maps a Block in the mapping.
Definition IR.cpp:1461
void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
Definition IR.cpp:154
bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition IR.cpp:1381
void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts flags controlling the printing behavior.
Definition IR.cpp:869
bool mlirValueIsABlockArgument(MlirValue value)
Definition IR.cpp:1158
MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
Definition IR.cpp:1306
void mlirValueReplaceAllUsesOfWith(MlirValue oldValue, MlirValue newValue)
Replace all uses of 'of' value with the 'with' value, updating anything in the IR that uses 'of' to u...
Definition IR.cpp:1227
MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
Definition IR.cpp:1106
intptr_t mlirOperationGetNumRegions(MlirOperation op)
Definition IR.cpp:719
MlirBlock mlirOperationGetBlock(MlirOperation op)
Definition IR.cpp:711
void mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry)
Append the contents of the given dialect registry to the registry associated with the context.
Definition IR.cpp:84
MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition IR.cpp:1373
void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Definition IR.cpp:1175
MlirLocation mlirLocationFileLineColGet(MlirContext context, MlirStringRef filename, unsigned line, unsigned col)
Creates an File/Line/Column location owned by the given context.
Definition IR.cpp:278
intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
Definition IR.cpp:91
MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
Definition IR.cpp:1364
MlirStringRef mlirSymbolTableGetVisibilityAttributeName()
Returns the name of the attribute used to store symbol visibility.
Definition IR.cpp:1397
void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition IR.cpp:534
MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Definition IR.cpp:774
bool mlirLocationIsACallSite(MlirLocation location)
Checks whether the given location is an CallSite.
Definition IR.cpp:348
void mlirSymbolTableWalkSymbolTables(MlirOperation from, bool allSymUsesVisible, void(*callback)(MlirOperation, bool, void *userData), void *userData)
Walks all symbol table operations nested within, and including, op.
Definition IR.cpp:1437
void mlirContextLoadAllAvailableDialects(MlirContext context)
Eagerly loads all available dialects registered with a context, making them available for use for IR ...
Definition IR.cpp:113
MlirModule mlirModuleCreateParseFromFile(MlirContext context, MlirStringRef fileName)
Definition IR.cpp:450
bool mlirOperationNameHasTrait(MlirStringRef opName, MlirTypeID traitTypeID, MlirContext context)
Definition IR.cpp:687
void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData to callback`...
Definition IR.cpp:1356
MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
Definition IR.cpp:963
MlirIRMapping mlirIRMappingCreate(void)
Creates a new empty IRMapping.
Definition IR.cpp:1452
MlirLogicalResult mlirSymbolTableReplaceAllSymbolUses(MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from)
Attempt to replace all uses that are nested within the given operation of the given symbol 'oldSymbol...
Definition IR.cpp:1426
MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations, MlirLocation const *locations, MlirAttribute metadata)
Creates a fused location with an array of locations and metadata.
Definition IR.cpp:352
MlirAsmState mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags)
Definition IR.cpp:183
intptr_t mlirOperationGetNumResults(MlirOperation op)
Definition IR.cpp:770
MlirOpOperand mlirValueGetFirstUse(MlirValue value)
Returns an op operand representing the first use of the value, or a null op operand if there are no u...
Definition IR.cpp:1217
void mlirRegionInsertOwnedBlockAfter(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it after the (non-owned) reference block in the given r...
Definition IR.cpp:980
void mlirOperationDestroy(MlirOperation op)
Definition IR.cpp:652
void mlirValueReplaceAllUsesExcept(MlirValue oldValue, MlirValue newValue, intptr_t numExceptions, MlirOperation *exceptions)
Replace all uses of 'of' value with 'with' value, updating anything in the IR that uses 'of' to use '...
Definition IR.cpp:1231
void mlirBlockAppendOwnedOperation(MlirBlock block, MlirOperation operation)
Takes an operation owned by the caller and appends it to the block.
Definition IR.cpp:1058
MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
Definition IR.cpp:727
MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:792
MlirDialect mlirContextGetOrLoadDialect(MlirContext context, MlirStringRef name)
Gets the dialect instance owned by the given context using the dialect namespace to identify it,...
Definition IR.cpp:95
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Definition IR.cpp:1333
MlirStringRef mlirSymbolTableGetSymbolAttributeName()
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition IR.cpp:1393
void mlirBlockInsertOwnedOperation(MlirBlock block, intptr_t pos, MlirOperation operation)
Takes an operation owned by the caller and inserts it as pos to the block.
Definition IR.cpp:1062
MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition IR.cpp:1033
MlirType mlirValueGetType(MlirValue value)
Definition IR.cpp:1194
void mlirOperationMoveAfter(MlirOperation op, MlirOperation other)
Moves the given operation immediately after the other operation in its parent block.
Definition IR.cpp:904
void mlirRegionAppendOwnedBlock(MlirRegion region, MlirBlock block)
Takes a block owned by the caller and appends it to the given region.
Definition IR.cpp:970
void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
Definition IR.cpp:1124
void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:824
MlirOpPrintingFlags mlirOpPrintingFlagsCreate()
Definition IR.cpp:207
bool mlirModuleEqual(MlirModule lhs, MlirModule rhs)
Definition IR.cpp:481
void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags, intptr_t largeElementLimit)
Definition IR.cpp:215
MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
Definition IR.cpp:1037
void mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block)
Definition IR.cpp:835
MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand)
Returns the value of an op operand.
Definition IR.cpp:1273
#define APPEND_ELEMS(type, sizeName, elemName)
Definition IR.cpp:511
bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
Definition IR.cpp:105
MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
Definition IR.cpp:743
void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
Definition IR.cpp:225
MlirOperation mlirModuleGetOperation(MlirModule module)
Definition IR.cpp:473
static mlir::WalkResult unwrap(MlirWalkResult result)
Definition IR.cpp:916
void mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags, intptr_t largeResourceLimit)
Definition IR.cpp:220
void mlirRegionInsertOwnedBlockBefore(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it before the (non-owned) reference block in the given ...
Definition IR.cpp:994
MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition IR.cpp:1120
unsigned mlirLocationFusedGetNumLocations(MlirLocation location)
Getter for number of locations fused together.
Definition IR.cpp:360
bool mlirIRMappingContainsBlock(MlirIRMapping mapping, MlirBlock block)
Returns true if the mapping contains a mapping for the given block.
Definition IR.cpp:1507
MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition IR.cpp:142
void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
Definition IR.cpp:238
MlirTypeID mlirOperationGetTypeID(MlirOperation op)
Definition IR.cpp:701
intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
Definition IR.cpp:1170
void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder)
Walks operation op in walkOrder and calls callback on that operation.
Definition IR.cpp:930
MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Definition IR.cpp:782
void mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference, MlirOperation operation)
Takes an operation owned by the caller and inserts it before the (non-owned) reference operation in t...
Definition IR.cpp:1083
bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Definition IR.cpp:1352
MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags)
Definition IR.cpp:162
bool mlirOperationEqual(MlirOperation op, MlirOperation other)
Definition IR.cpp:656
void mlirOperationSetInherentAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:800
void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
Definition IR.cpp:242
MlirOperation mlirOperationCloneWithMapping(MlirOperation op, MlirIRMapping mapping)
Clones the operation with the given mapping.
Definition IR.cpp:1527
bool mlirValueEqual(MlirValue value1, MlirValue value2)
Definition IR.cpp:1154
MlirContext mlirIdentifierGetContext(MlirIdentifier ident)
Returns the context associated with this identifier.
Definition IR.cpp:1377
void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
Definition IR.cpp:257
MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1134
void mlirModuleDestroy(MlirModule module)
Definition IR.cpp:467
MlirBlock mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block.
Definition IR.cpp:1483
MlirModule mlirModuleCreateEmpty(MlirLocation location)
Definition IR.cpp:438
void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
Definition IR.cpp:230
MlirOperation mlirOperationGetParentOperation(MlirOperation op)
Definition IR.cpp:715
void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
Definition IR.cpp:1009
MlirLlvmThreadPool mlirContextGetThreadPool(MlirContext context)
Gets the thread pool of the context when enabled multithreading, otherwise an assertion is raised.
Definition IR.cpp:126
MlirValue mlirBlockInsertArgument(MlirBlock block, intptr_t pos, MlirType type, MlirLocation loc)
Inserts an argument of the specified type at a specified index to the block.
Definition IR.cpp:1115
void mlirValueSetType(MlirValue value, MlirType type)
Definition IR.cpp:1198
intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Definition IR.cpp:778
MlirDialect mlirAttributeGetDialect(MlirAttribute attr)
Definition IR.cpp:1348
void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
Definition IR.cpp:428
void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Definition IR.cpp:854
void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition IR.cpp:1095
void mlirIRMappingDestroy(MlirIRMapping mapping)
Destroys the given IRMapping.
Definition IR.cpp:1454
void mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block)
Takes a block owned by the caller and inserts it at pos to the given region.
Definition IR.cpp:974
void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Definition IR.cpp:759
intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
Definition IR.cpp:1102
MlirTypeID mlirLocationFileLineColRangeGetTypeID()
TypeID Getter for FileLineColRange.
Definition IR.cpp:322
MlirOperation mlirOpResultGetOwner(MlirValue value)
Definition IR.cpp:1185
void mlirBlockEraseArgument(MlirBlock block, unsigned index)
Erase the argument at 'index' and remove it from the argument list.
Definition IR.cpp:1111
bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
Definition IR.cpp:1267
MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
Definition IR.cpp:1310
MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
Definition IR.cpp:442
MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry, bool threadingEnabled)
Creates an MLIR context, setting the multithreading setting explicitly and pre-loading the dialects f...
Definition IR.cpp:60
size_t mlirOperationHashValue(MlirOperation op)
Definition IR.cpp:660
void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
Definition IR.cpp:73
void mlirIRMappingClear(MlirIRMapping mapping)
Clears all mappings.
Definition IR.cpp:1471
void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n, MlirType const *results)
Definition IR.cpp:517
void mlirOperationMoveBefore(MlirOperation op, MlirOperation other)
Moves the given operation immediately before the other operation in its parent block.
Definition IR.cpp:908
static LogicalResult inferOperationTypes(OperationState &state)
Definition IR.cpp:547
MlirOperation mlirOperationClone(MlirOperation op)
Definition IR.cpp:648
bool mlirLocationIsAUnknown(MlirLocation location)
Checks whether the given location is an Unknown.
Definition IR.cpp:416
void mlirValuePrintAsOperand(MlirValue value, MlirAsmState state, MlirStringCallback callback, void *userData)
Prints a value as an operand (i.e., the ValueID).
Definition IR.cpp:1210
MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
Definition IR.cpp:1166
void mlirBlockArgumentSetLocation(MlirValue value, MlirLocation loc)
Definition IR.cpp:1180
MlirDialectRegistry mlirDialectRegistryCreate()
Creates a dialect registry and transfers its ownership to the caller.
Definition IR.cpp:150
MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:751
bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
Definition IR.cpp:77
MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
Definition IR.cpp:270
MlirModule mlirModuleFromOperation(MlirOperation op)
Definition IR.cpp:477
MlirTypeID mlirLocationNameGetTypeID()
TypeID Getter for Name.
Definition IR.cpp:402
MlirOpOperand mlirOperationGetOpOperand(MlirOperation op, intptr_t pos)
Definition IR.cpp:755
MlirLocation mlirOperationGetLocation(MlirOperation op)
Definition IR.cpp:693
bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition IR.cpp:1314
bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
Definition IR.cpp:67
void mlirIRMappingEraseOperation(MlirIRMapping mapping, MlirOperation op)
Erases an operation mapping.
Definition IR.cpp:1523
MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:849
bool mlirOperationIsBeforeInBlock(MlirOperation op, MlirOperation other)
Given an operation 'other' that is within the same parent block, return whether the current operation...
Definition IR.cpp:912
MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr)
Definition IR.cpp:1344
MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
Definition IR.cpp:1416
bool mlirLocationIsAFileLineColRange(MlirLocation location)
Checks whether the given location is an FileLineColRange.
Definition IR.cpp:326
intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
Definition IR.cpp:807
MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition IR.cpp:1401
void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
Definition IR.cpp:526
void mlirOperationSetLocation(MlirOperation op, MlirLocation loc)
Definition IR.cpp:697
MlirValue mlirIRMappingLookupOrNullValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value. Returns a null MlirValue if no mapping exists.
Definition IR.cpp:1478
MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
Definition IR.cpp:408
MlirLocation mlirLocationCallSiteGetCallee(MlirLocation location)
Getter for callee of CallSite.
Definition IR.cpp:334
static Operation * findParent(Operation *op, bool shouldUseLocalScope)
Definition IR.cpp:167
MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition IR.cpp:1041
static OperationEquivalence::Flags unwrapEquivalenceFlags(uint32_t flags)
Translates the C equivalence flags to mlir::OperationEquivalence::Flags.
Definition IR.cpp:666
MlirType mlirAttributeGetType(MlirAttribute attribute)
Definition IR.cpp:1337
bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:830
void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition IR.cpp:1005
bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:859
bool mlirValueIsAOpResult(MlirValue value)
Definition IR.cpp:1162
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
Definition IR.cpp:787
MlirContext mlirContextCreateWithThreading(bool threadingEnabled)
Creates an MLIR context with an explicit setting of the multithreading setting and transfers its owne...
Definition IR.cpp:55
MlirTypeID mlirLocationCallSiteGetTypeID()
TypeID Getter for CallSite.
Definition IR.cpp:344
MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos)
Definition IR.cpp:1143
MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition IR.cpp:1048
bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
Definition IR.cpp:420
size_t mlirOperationStructuralHashValue(MlirOperation op, uint32_t flags)
Definition IR.cpp:676
MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Definition IR.cpp:723
void mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue oldValue, MlirValue newValue)
Replace uses of 'of' value with the 'with' value inside the 'op' operation.
Definition IR.cpp:948
int mlirLocationFileLineColRangeGetEndColumn(MlirLocation location)
Getter for end_column of FileLineColRange.
Definition IR.cpp:316
MlirOperation mlirOperationCreate(MlirOperationState *state)
Definition IR.cpp:602
bool mlirIRMappingContainsOperation(MlirIRMapping mapping, MlirOperation op)
Returns true if the mapping contains a mapping for the given operation.
Definition IR.cpp:1511
unsigned mlirContextGetNumThreads(MlirContext context)
Gets the number of threads of the thread pool of the context when multithreading is enabled.
Definition IR.cpp:122
bool mlirOperationIsStructurallyEquivalent(MlirOperation lhs, MlirOperation rhs, uint32_t flags)
Definition IR.cpp:670
void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags, int64_t version)
Definition IR.cpp:261
int mlirLocationFileLineColRangeGetStartColumn(MlirLocation location)
Getter for start_column of FileLineColRange.
Definition IR.cpp:304
MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
Definition IR.cpp:1329
void mlirLocationFusedGetLocations(MlirLocation location, MlirLocation *locationsCPtr)
Getter for locations of Fused.
Definition IR.cpp:366
void mlirOperationRemoveFromParent(MlirOperation op)
Definition IR.cpp:654
void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition IR.cpp:1407
intptr_t mlirBlockGetNumSuccessors(MlirBlock block)
Definition IR.cpp:1130
MlirContext mlirContextCreate()
Creates an MLIR context and transfers its ownership to the caller.
Definition IR.cpp:45
void mlirOperationPrintWithState(MlirOperation op, MlirAsmState state, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts AsmState controlling the printing behavior as well as caching ...
Definition IR.cpp:875
bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
Definition IR.cpp:900
void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
Definition IR.cpp:1097
void mlirIRMappingMapOperation(MlirIRMapping mapping, MlirOperation from, MlirOperation to)
Maps an Operation in the mapping.
Definition IR.cpp:1466
bool mlirIRMappingContainsValue(MlirIRMapping mapping, MlirValue value)
Returns true if the mapping contains a mapping for the given value.
Definition IR.cpp:1503
int mlirLocationFileLineColRangeGetEndLine(MlirLocation location)
Getter for end_line of FileLineColRange.
Definition IR.cpp:310
MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:844
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Definition IR.cpp:211
MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
Definition IR.cpp:330
void mlirIRMappingEraseValue(MlirIRMapping mapping, MlirValue value)
Erases a value mapping.
Definition IR.cpp:1515
void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
Definition IR.cpp:884
void mlirValueDump(MlirValue value)
Definition IR.cpp:1202
MlirTypeID mlirLocationUnknownGetTypeID()
TypeID Getter for Unknown.
Definition IR.cpp:412
void mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference, MlirOperation operation)
Takes an operation owned by the caller and inserts it after the (non-owned) reference operation in th...
Definition IR.cpp:1068
void mlirIRMappingEraseBlock(MlirIRMapping mapping, MlirBlock block)
Erases a block mapping.
Definition IR.cpp:1519
intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
Definition IR.cpp:80
MlirTypeID mlirLocationFusedGetTypeID()
TypeID Getter for Fused.
Definition IR.cpp:378
void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
Definition IR.cpp:764
static MLIRContext::Threading toThreadingEnum(bool threadingEnabled)
Definition IR.cpp:50
MlirIdentifier mlirLocationFileLineColRangeGetFilename(MlirLocation location)
Getter for filename of FileLineColRange.
Definition IR.cpp:294
MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition IR.cpp:1302
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
Definition IR.cpp:1318
MlirBlock mlirModuleGetBody(MlirModule module)
Definition IR.cpp:463
MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
Definition IR.cpp:134
bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition IR.cpp:959
int mlirLocationFileLineColRangeGetStartLine(MlirLocation location)
Getter for start_line of FileLineColRange.
Definition IR.cpp:298
MlirOperation mlirOperationCreateParse(MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName)
Definition IR.cpp:639
MlirOperation mlirIRMappingLookupOrNullOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
Definition IR.cpp:1498
MlirLocation mlirLocationCallSiteGetCaller(MlirLocation location)
Getter for caller of CallSite.
Definition IR.cpp:339
void mlirAsmStateDestroy(MlirAsmState state)
Destroys printing flags created with mlirAsmStateCreate.
Definition IR.cpp:201
MlirContext mlirOperationGetContext(MlirOperation op)
Definition IR.cpp:683
intptr_t mlirOpResultGetResultNumber(MlirValue value)
Definition IR.cpp:1189
MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
Definition IR.cpp:384
MlirLocation mlirLocationFileLineColRangeGet(MlirContext context, MlirStringRef filename, unsigned startLine, unsigned startCol, unsigned endLine, unsigned endCol)
Creates an File/Line/Column range location owned by the given context.
Definition IR.cpp:286
bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
Definition IR.cpp:1025
bool mlirLocationIsAFused(MlirLocation location)
Checks whether the given location is an Fused.
Definition IR.cpp:380
MlirAttribute mlirLocationFusedGetMetadata(MlirLocation location)
Getter for metadata of Fused.
Definition IR.cpp:374
void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
Definition IR.cpp:1421
MlirLocation mlirLocationNameGetChildLoc(MlirLocation location)
Getter for childLoc of Name.
Definition IR.cpp:397
MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
Definition IR.cpp:812
void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
Definition IR.cpp:539
void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
Definition IR.cpp:530
MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate()
Definition IR.cpp:253
void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition IR.cpp:1362
void mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags)
Definition IR.cpp:234
MlirIdentifier mlirLocationNameGetName(MlirLocation location)
Getter for name of Name.
Definition IR.cpp:393
MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
Definition IR.cpp:1385
void mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags)
Definition IR.cpp:246
void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
Definition IR.cpp:522
MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
Definition IR.cpp:493
MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
Definition IR.cpp:274
MlirOperation mlirBlockGetParentOperation(MlirBlock block)
Returns the closest surrounding operation that contains this block.
Definition IR.cpp:1029
MlirOpOperand mlirOpOperandGetNextUse(MlirOpOperand opOperand)
Returns an op operand representing the next use of the value, or a null op operand if there is no nex...
Definition IR.cpp:1281
void mlirValueReplaceUsesWithIf(MlirValue of, MlirValue with, MlirOpOperandReplaceFilterCallback filter, void *userData)
Replace uses of 'of' value with 'with' value, but only for the uses for which the filter callback ret...
Definition IR.cpp:1245
intptr_t mlirOperationGetNumOperands(MlirOperation op)
Definition IR.cpp:747
void mlirIRMappingMapValue(MlirIRMapping mapping, MlirValue from, MlirValue to)
Maps a Value in the mapping.
Definition IR.cpp:1456
void mlirContextSetThreadPool(MlirContext context, MlirLlvmThreadPool threadPool)
Sets the thread pool of the context explicitly, enabling multithreading in the process.
Definition IR.cpp:117
MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition IR.cpp:1298
MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args, MlirLocation const *locs)
Creates a new empty block with the given argument types and transfers ownership to the caller.
Definition IR.cpp:1017
void mlirContextEnableMultithreading(MlirContext context, bool enable)
Set threading mode (must be set to false to mlir-print-ir-after-all).
Definition IR.cpp:109
void mlirTypeDump(MlirType type)
Definition IR.cpp:1323
intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Definition IR.cpp:840
MlirContext mlirValueGetContext(MlirValue v)
Gets the context that a value was created with.
Definition IR.cpp:1259
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
b getContext())
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition Wrap.h:40
This class provides management for the lifetime of the state used when printing the IR.
Definition AsmState.h:542
Attributes are known-constant values of operations.
Definition Attributes.h:25
MLIRContext * getContext() const
Return the context this attribute belongs to.
Block represents an ordered list of Operations.
Definition Block.h:33
OpListType::iterator iterator
Definition Block.h:164
bool empty()
Definition Block.h:172
OpListType & getOperations()
Definition Block.h:161
Operation & front()
Definition Block.h:177
Operation & back()
Definition Block.h:176
PredecessorIterator pred_iterator
Definition Block.h:259
iterator begin()
Definition Block.h:167
This class contains the configuration used for the bytecode writer.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)
Definition Location.cpp:157
This is a utility class for mapping one set of IR entities to another.
Definition IRMapping.h:26
Location objects represent source locations information in MLIR.
Definition Location.h:32
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
void reserve(size_type N)
NamedAttribute represents a combination of a name and an Attribute value.
Definition Attributes.h:164
StringAttr getName() const
Return the name of the attribute.
Attribute getValue() const
Return the value of the attribute.
Definition Attributes.h:179
This class represents an operand of an operation.
Definition Value.h:254
Set of flags used to control the behavior of the various IR print methods (e.g.
This class provides the API for ops that are known to be isolated from above.
This class provides the API for ops that are known to be terminators.
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
bool hasTrait() const
Returns true if the operation was registered with a particular trait, e.g.
std::optional< RegisteredOperationName > getRegisteredInfo() const
If this operation is registered, returns the registered information, std::nullopt otherwise.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
Definition Operation.h:711
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Definition Operation.h:774
unsigned getNumRegions()
Returns the number of regions held by this operation.
Definition Operation.h:699
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Definition Operation.h:251
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, PropertyRef properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
Definition Operation.cpp:65
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
Definition OwningOpRef.h:29
OpTy release()
Release the referenced op.
Definition OwningOpRef.h:67
Type-safe wrapper around a void* for passing properties, including the properties structs of operatio...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
Block & front()
Definition Region.h:65
unsigned getRegionNumber()
Return the number of this region in the parent operation.
Definition Region.cpp:62
bool empty()
Definition Region.h:60
iterator begin()
Definition Region.h:55
Operation * getParentOp()
Return the parent operation this region is attached to.
Definition Region.h:213
BlockListType & getBlocks()
Definition Region.h:45
BlockListType::iterator iterator
Definition Region.h:52
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Definition SymbolTable.h:24
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
Definition SymbolTable.h:76
static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol, StringAttr newSymbol, Operation *from)
Attempt to replace all uses of the given symbol 'oldSymbol' with the provided symbol 'newSymbol' that...
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
Definition SymbolTable.h:82
static void walkSymbolTables(Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback)
Walks all symbol table operations nested within, and including, op.
OperandType * getOperand() const
Returns the current operands.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
bool use_empty() const
Returns true if this value has no uses.
Definition Value.h:208
void replaceAllUsesExcept(Value newValue, const SmallPtrSetImpl< Operation * > &exceptions)
Replace all uses of 'this' value with 'newValue', updating anything in the IR that uses 'this' to use...
Definition Value.cpp:71
void printAsOperand(raw_ostream &os, AsmState &state) const
Print this value as if it were an operand.
Location getLoc() const
Return the location of this value.
Definition Value.cpp:24
use_iterator use_begin() const
Definition Value.h:184
A utility result that is used to signal how to proceed with an ongoing walk:
Definition WalkResult.h:29
static WalkResult skip()
Definition WalkResult.h:48
static WalkResult advance()
Definition WalkResult.h:47
static WalkResult interrupt()
Definition WalkResult.h:46
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
Definition Utils.h:30
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
MlirWalkResult(* MlirOperationWalkCallback)(MlirOperation, void *userData)
Operation walker type.
Definition IR.h:911
MlirWalkOrder
Traversal order for operation walk.
Definition IR.h:904
@ MlirWalkPreOrder
Definition IR.h:905
@ MlirWalkPostOrder
Definition IR.h:906
bool(* MlirOpOperandReplaceFilterCallback)(MlirOpOperand opOperand, void *userData)
Callback deciding whether a particular use should be replaced.
Definition IR.h:1174
MlirWalkResult
Operation walk result.
Definition IR.h:897
@ MlirWalkResultInterrupt
Definition IR.h:899
@ MlirWalkResultSkip
Definition IR.h:900
@ MlirWalkResultAdvance
Definition IR.h:898
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition IR.h:997
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
Definition IR.h:384
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition Support.h:110
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition Utils.cpp:307
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context, Type type={}, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR attribute to an MLIR context if it was valid.
LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, const ParserConfig &config, StringRef sourceName="", LocationAttr *sourceFileLoc=nullptr)
This parses the IR string and appends parsed operations to the given block.
Definition Parser.cpp:108
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
LogicalResult parseSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, const ParserConfig &config, LocationAttr *sourceFileLoc=nullptr)
This parses the file specified by the indicated SourceMgr and appends parsed operations to the given ...
Definition Parser.cpp:38
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Type parseType(llvm::StringRef typeStr, MLIRContext *context, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR type to an MLIR context if it was valid.
LogicalResult writeBytecodeToFile(Operation *op, raw_ostream &os, const BytecodeWriterConfig &config={})
Write the bytecode for the given operation to the provided output stream.
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
Definition Verifier.cpp:566
A logical result value, essentially a boolean with named states.
Definition Support.h:121
Named MLIR attribute.
Definition IR.h:77
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78
const char * data
Pointer to the first symbol.
Definition Support.h:79
size_t length
Length of the fragment.
Definition Support.h:80
static llvm::hash_code ignoreHashValue(Value)
Helper that can be used with computeHash above to ignore operation operands/result mapping.
static bool isEquivalentTo(Operation *lhs, Operation *rhs, function_ref< LogicalResult(Value, Value)> checkEquivalent, function_ref< void(Value, Value)> markEquivalent=nullptr, Flags flags=Flags::None, function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent=nullptr)
Compare two operations (including their regions) and return if they are equivalent.
static llvm::hash_code directHashValue(Value v)
Helper that can be used with computeHash to compute the hash value of operands/results directly.
static llvm::hash_code computeHash(Operation *op, function_ref< llvm::hash_code(Value)> hashOperands=[](Value v) { return hash_value(v);}, function_ref< llvm::hash_code(Value)> hashResults=[](Value v) { return hash_value(v);}, Flags flags=Flags::None)
Compute a hash for the given operation.
This represents an operation in an abstracted form, suitable for use with the builder APIs.
SmallVector< Value, 4 > operands
void addOperands(ValueRange newOperands)
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
void addSuccessors(Block *successor)
Adds a successor to the operation sate. successor must not be null.
void addTypes(ArrayRef< Type > newTypes)
MLIRContext * getContext() const
Get the context held by this operation state.
SmallVector< std::unique_ptr< Region >, 1 > regions
Regions that the op will hold.
PropertyRef getRawProperties()
SmallVector< Type, 4 > types
Types of the results of this operation.
Region * addRegion()
Create a region that should be attached to the operation.