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