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