MLIR  18.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/Support.h"
16 #include "mlir/CAPI/Utils.h"
17 #include "mlir/IR/Attributes.h"
19 #include "mlir/IR/BuiltinOps.h"
20 #include "mlir/IR/Diagnostics.h"
21 #include "mlir/IR/Dialect.h"
22 #include "mlir/IR/Location.h"
23 #include "mlir/IR/Operation.h"
25 #include "mlir/IR/Types.h"
26 #include "mlir/IR/Value.h"
27 #include "mlir/IR/Verifier.h"
29 #include "mlir/Parser/Parser.h"
30 
31 #include <cstddef>
32 #include <memory>
33 #include <optional>
34 
35 using namespace mlir;
36 
37 //===----------------------------------------------------------------------===//
38 // Context API.
39 //===----------------------------------------------------------------------===//
40 
41 MlirContext mlirContextCreate() {
42  auto *context = new MLIRContext;
43  return wrap(context);
44 }
45 
46 static inline MLIRContext::Threading toThreadingEnum(bool threadingEnabled) {
47  return threadingEnabled ? MLIRContext::Threading::ENABLED
49 }
50 
51 MlirContext mlirContextCreateWithThreading(bool threadingEnabled) {
52  auto *context = new MLIRContext(toThreadingEnum(threadingEnabled));
53  return wrap(context);
54 }
55 
56 MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry,
57  bool threadingEnabled) {
58  auto *context =
59  new MLIRContext(*unwrap(registry), toThreadingEnum(threadingEnabled));
60  return wrap(context);
61 }
62 
63 bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2) {
64  return unwrap(ctx1) == unwrap(ctx2);
65 }
66 
67 void mlirContextDestroy(MlirContext context) { delete unwrap(context); }
68 
69 void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow) {
70  unwrap(context)->allowUnregisteredDialects(allow);
71 }
72 
73 bool mlirContextGetAllowUnregisteredDialects(MlirContext context) {
74  return unwrap(context)->allowsUnregisteredDialects();
75 }
76 intptr_t mlirContextGetNumRegisteredDialects(MlirContext context) {
77  return static_cast<intptr_t>(unwrap(context)->getAvailableDialects().size());
78 }
79 
80 void mlirContextAppendDialectRegistry(MlirContext ctx,
81  MlirDialectRegistry registry) {
82  unwrap(ctx)->appendDialectRegistry(*unwrap(registry));
83 }
84 
85 // TODO: expose a cheaper way than constructing + sorting a vector only to take
86 // its size.
87 intptr_t mlirContextGetNumLoadedDialects(MlirContext context) {
88  return static_cast<intptr_t>(unwrap(context)->getLoadedDialects().size());
89 }
90 
91 MlirDialect mlirContextGetOrLoadDialect(MlirContext context,
92  MlirStringRef name) {
93  return wrap(unwrap(context)->getOrLoadDialect(unwrap(name)));
94 }
95 
96 bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name) {
97  return unwrap(context)->isOperationRegistered(unwrap(name));
98 }
99 
100 void mlirContextEnableMultithreading(MlirContext context, bool enable) {
101  return unwrap(context)->enableMultithreading(enable);
102 }
103 
104 void mlirContextLoadAllAvailableDialects(MlirContext context) {
105  unwrap(context)->loadAllAvailableDialects();
106 }
107 
108 void mlirContextSetThreadPool(MlirContext context,
109  MlirLlvmThreadPool threadPool) {
110  unwrap(context)->setThreadPool(*unwrap(threadPool));
111 }
112 
113 //===----------------------------------------------------------------------===//
114 // Dialect API.
115 //===----------------------------------------------------------------------===//
116 
117 MlirContext mlirDialectGetContext(MlirDialect dialect) {
118  return wrap(unwrap(dialect)->getContext());
119 }
120 
121 bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2) {
122  return unwrap(dialect1) == unwrap(dialect2);
123 }
124 
126  return wrap(unwrap(dialect)->getNamespace());
127 }
128 
129 //===----------------------------------------------------------------------===//
130 // DialectRegistry API.
131 //===----------------------------------------------------------------------===//
132 
133 MlirDialectRegistry mlirDialectRegistryCreate() {
134  return wrap(new DialectRegistry());
135 }
136 
137 void mlirDialectRegistryDestroy(MlirDialectRegistry registry) {
138  delete unwrap(registry);
139 }
140 
141 //===----------------------------------------------------------------------===//
142 // AsmState API.
143 //===----------------------------------------------------------------------===//
144 
145 MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op,
146  MlirOpPrintingFlags flags) {
147  return wrap(new AsmState(unwrap(op), *unwrap(flags)));
148 }
149 
150 static Operation *findParent(Operation *op, bool shouldUseLocalScope) {
151  do {
152  // If we are printing local scope, stop at the first operation that is
153  // isolated from above.
154  if (shouldUseLocalScope && op->hasTrait<OpTrait::IsIsolatedFromAbove>())
155  break;
156 
157  // Otherwise, traverse up to the next parent.
158  Operation *parentOp = op->getParentOp();
159  if (!parentOp)
160  break;
161  op = parentOp;
162  } while (true);
163  return op;
164 }
165 
166 MlirAsmState mlirAsmStateCreateForValue(MlirValue value,
167  MlirOpPrintingFlags flags) {
168  Operation *op;
169  mlir::Value val = unwrap(value);
170  if (auto result = llvm::dyn_cast<OpResult>(val)) {
171  op = result.getOwner();
172  } else {
173  op = llvm::cast<BlockArgument>(val).getOwner()->getParentOp();
174  if (!op) {
175  emitError(val.getLoc()) << "<<UNKNOWN SSA VALUE>>";
176  return {nullptr};
177  }
178  }
179  op = findParent(op, unwrap(flags)->shouldUseLocalScope());
180  return wrap(new AsmState(op, *unwrap(flags)));
181 }
182 
183 /// Destroys printing flags created with mlirAsmStateCreate.
184 void mlirAsmStateDestroy(MlirAsmState state) { delete unwrap(state); }
185 
186 //===----------------------------------------------------------------------===//
187 // Printing flags API.
188 //===----------------------------------------------------------------------===//
189 
190 MlirOpPrintingFlags mlirOpPrintingFlagsCreate() {
191  return wrap(new OpPrintingFlags());
192 }
193 
194 void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags) {
195  delete unwrap(flags);
196 }
197 
198 void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
199  intptr_t largeElementLimit) {
200  unwrap(flags)->elideLargeElementsAttrs(largeElementLimit);
201 }
202 
203 void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
204  bool prettyForm) {
205  unwrap(flags)->enableDebugInfo(enable, /*prettyForm=*/prettyForm);
206 }
207 
208 void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags) {
209  unwrap(flags)->printGenericOpForm();
210 }
211 
212 void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags) {
213  unwrap(flags)->useLocalScope();
214 }
215 
216 void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags) {
217  unwrap(flags)->assumeVerified();
218 }
219 
220 //===----------------------------------------------------------------------===//
221 // Bytecode printing flags API.
222 //===----------------------------------------------------------------------===//
223 
224 MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate() {
225  return wrap(new BytecodeWriterConfig());
226 }
227 
228 void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config) {
229  delete unwrap(config);
230 }
231 
232 void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags,
233  int64_t version) {
234  unwrap(flags)->setDesiredBytecodeVersion(version);
235 }
236 
237 //===----------------------------------------------------------------------===//
238 // Location API.
239 //===----------------------------------------------------------------------===//
240 
241 MlirAttribute mlirLocationGetAttribute(MlirLocation location) {
242  return wrap(LocationAttr(unwrap(location)));
243 }
244 
245 MlirLocation mlirLocationFromAttribute(MlirAttribute attribute) {
246  return wrap(Location(llvm::cast<LocationAttr>(unwrap(attribute))));
247 }
248 
249 MlirLocation mlirLocationFileLineColGet(MlirContext context,
250  MlirStringRef filename, unsigned line,
251  unsigned col) {
252  return wrap(Location(
253  FileLineColLoc::get(unwrap(context), unwrap(filename), line, col)));
254 }
255 
256 MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller) {
257  return wrap(Location(CallSiteLoc::get(unwrap(callee), unwrap(caller))));
258 }
259 
260 MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
261  MlirLocation const *locations,
262  MlirAttribute metadata) {
264  ArrayRef<Location> unwrappedLocs = unwrapList(nLocations, locations, locs);
265  return wrap(FusedLoc::get(unwrappedLocs, unwrap(metadata), unwrap(ctx)));
266 }
267 
268 MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name,
269  MlirLocation childLoc) {
270  if (mlirLocationIsNull(childLoc))
271  return wrap(
272  Location(NameLoc::get(StringAttr::get(unwrap(context), unwrap(name)))));
273  return wrap(Location(NameLoc::get(
274  StringAttr::get(unwrap(context), unwrap(name)), unwrap(childLoc))));
275 }
276 
277 MlirLocation mlirLocationUnknownGet(MlirContext context) {
278  return wrap(Location(UnknownLoc::get(unwrap(context))));
279 }
280 
281 bool mlirLocationEqual(MlirLocation l1, MlirLocation l2) {
282  return unwrap(l1) == unwrap(l2);
283 }
284 
285 MlirContext mlirLocationGetContext(MlirLocation location) {
286  return wrap(unwrap(location).getContext());
287 }
288 
289 void mlirLocationPrint(MlirLocation location, MlirStringCallback callback,
290  void *userData) {
291  detail::CallbackOstream stream(callback, userData);
292  unwrap(location).print(stream);
293 }
294 
295 //===----------------------------------------------------------------------===//
296 // Module API.
297 //===----------------------------------------------------------------------===//
298 
299 MlirModule mlirModuleCreateEmpty(MlirLocation location) {
300  return wrap(ModuleOp::create(unwrap(location)));
301 }
302 
303 MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module) {
304  OwningOpRef<ModuleOp> owning =
305  parseSourceString<ModuleOp>(unwrap(module), unwrap(context));
306  if (!owning)
307  return MlirModule{nullptr};
308  return MlirModule{owning.release().getOperation()};
309 }
310 
311 MlirContext mlirModuleGetContext(MlirModule module) {
312  return wrap(unwrap(module).getContext());
313 }
314 
315 MlirBlock mlirModuleGetBody(MlirModule module) {
316  return wrap(unwrap(module).getBody());
317 }
318 
319 void mlirModuleDestroy(MlirModule module) {
320  // Transfer ownership to an OwningOpRef<ModuleOp> so that its destructor is
321  // called.
322  OwningOpRef<ModuleOp>(unwrap(module));
323 }
324 
325 MlirOperation mlirModuleGetOperation(MlirModule module) {
326  return wrap(unwrap(module).getOperation());
327 }
328 
329 MlirModule mlirModuleFromOperation(MlirOperation op) {
330  return wrap(dyn_cast<ModuleOp>(unwrap(op)));
331 }
332 
333 //===----------------------------------------------------------------------===//
334 // Operation state API.
335 //===----------------------------------------------------------------------===//
336 
338  MlirOperationState state;
339  state.name = name;
340  state.location = loc;
341  state.nResults = 0;
342  state.results = nullptr;
343  state.nOperands = 0;
344  state.operands = nullptr;
345  state.nRegions = 0;
346  state.regions = nullptr;
347  state.nSuccessors = 0;
348  state.successors = nullptr;
349  state.nAttributes = 0;
350  state.attributes = nullptr;
351  state.enableResultTypeInference = false;
352  return state;
353 }
354 
355 #define APPEND_ELEMS(type, sizeName, elemName) \
356  state->elemName = \
357  (type *)realloc(state->elemName, (state->sizeName + n) * sizeof(type)); \
358  memcpy(state->elemName + state->sizeName, elemName, n * sizeof(type)); \
359  state->sizeName += n;
360 
362  MlirType const *results) {
363  APPEND_ELEMS(MlirType, nResults, results);
364 }
365 
367  MlirValue const *operands) {
368  APPEND_ELEMS(MlirValue, nOperands, operands);
369 }
371  MlirRegion const *regions) {
372  APPEND_ELEMS(MlirRegion, nRegions, regions);
373 }
375  MlirBlock const *successors) {
376  APPEND_ELEMS(MlirBlock, nSuccessors, successors);
377 }
379  MlirNamedAttribute const *attributes) {
380  APPEND_ELEMS(MlirNamedAttribute, nAttributes, attributes);
381 }
382 
384  state->enableResultTypeInference = true;
385 }
386 
387 //===----------------------------------------------------------------------===//
388 // Operation API.
389 //===----------------------------------------------------------------------===//
390 
392  MLIRContext *context = state.getContext();
393  std::optional<RegisteredOperationName> info = state.name.getRegisteredInfo();
394  if (!info) {
395  emitError(state.location)
396  << "type inference was requested for the operation " << state.name
397  << ", but the operation was not registered; ensure that the dialect "
398  "containing the operation is linked into MLIR and registered with "
399  "the context";
400  return failure();
401  }
402 
403  auto *inferInterface = info->getInterface<InferTypeOpInterface>();
404  if (!inferInterface) {
405  emitError(state.location)
406  << "type inference was requested for the operation " << state.name
407  << ", but the operation does not support type inference; result "
408  "types must be specified explicitly";
409  return failure();
410  }
411 
412  DictionaryAttr attributes = state.attributes.getDictionary(context);
413  OpaqueProperties properties = state.getRawProperties();
414 
415  if (!properties && info->getOpPropertyByteSize() > 0 && !attributes.empty()) {
416  auto prop = std::make_unique<char[]>(info->getOpPropertyByteSize());
417  properties = OpaqueProperties(prop.get());
418  if (properties) {
419  auto emitError = [&]() {
420  return mlir::emitError(state.location)
421  << " failed properties conversion while building "
422  << state.name.getStringRef() << " with `" << attributes << "`: ";
423  };
424  if (failed(info->setOpPropertiesFromAttribute(state.name, properties,
425  attributes, emitError)))
426  return failure();
427  }
428  if (succeeded(inferInterface->inferReturnTypes(
429  context, state.location, state.operands, attributes, properties,
430  state.regions, state.types))) {
431  return success();
432  }
433  // Diagnostic emitted by interface.
434  return failure();
435  }
436 
437  if (succeeded(inferInterface->inferReturnTypes(
438  context, state.location, state.operands, attributes, properties,
439  state.regions, state.types)))
440  return success();
441 
442  // Diagnostic emitted by interface.
443  return failure();
444 }
445 
447  assert(state);
448  OperationState cppState(unwrap(state->location), unwrap(state->name));
449  SmallVector<Type, 4> resultStorage;
450  SmallVector<Value, 8> operandStorage;
451  SmallVector<Block *, 2> successorStorage;
452  cppState.addTypes(unwrapList(state->nResults, state->results, resultStorage));
453  cppState.addOperands(
454  unwrapList(state->nOperands, state->operands, operandStorage));
455  cppState.addSuccessors(
456  unwrapList(state->nSuccessors, state->successors, successorStorage));
457 
458  cppState.attributes.reserve(state->nAttributes);
459  for (intptr_t i = 0; i < state->nAttributes; ++i)
460  cppState.addAttribute(unwrap(state->attributes[i].name),
461  unwrap(state->attributes[i].attribute));
462 
463  for (intptr_t i = 0; i < state->nRegions; ++i)
464  cppState.addRegion(std::unique_ptr<Region>(unwrap(state->regions[i])));
465 
466  free(state->results);
467  free(state->operands);
468  free(state->successors);
469  free(state->regions);
470  free(state->attributes);
471 
472  // Infer result types.
473  if (state->enableResultTypeInference) {
474  assert(cppState.types.empty() &&
475  "result type inference enabled and result types provided");
476  if (failed(inferOperationTypes(cppState)))
477  return {nullptr};
478  }
479 
480  return wrap(Operation::create(cppState));
481 }
482 
483 MlirOperation mlirOperationCreateParse(MlirContext context,
484  MlirStringRef sourceStr,
485  MlirStringRef sourceName) {
486 
487  return wrap(
488  parseSourceString(unwrap(sourceStr), unwrap(context), unwrap(sourceName))
489  .release());
490 }
491 
492 MlirOperation mlirOperationClone(MlirOperation op) {
493  return wrap(unwrap(op)->clone());
494 }
495 
496 void mlirOperationDestroy(MlirOperation op) { unwrap(op)->erase(); }
497 
498 void mlirOperationRemoveFromParent(MlirOperation op) { unwrap(op)->remove(); }
499 
500 bool mlirOperationEqual(MlirOperation op, MlirOperation other) {
501  return unwrap(op) == unwrap(other);
502 }
503 
504 MlirContext mlirOperationGetContext(MlirOperation op) {
505  return wrap(unwrap(op)->getContext());
506 }
507 
508 MlirLocation mlirOperationGetLocation(MlirOperation op) {
509  return wrap(unwrap(op)->getLoc());
510 }
511 
512 MlirTypeID mlirOperationGetTypeID(MlirOperation op) {
513  if (auto info = unwrap(op)->getRegisteredInfo())
514  return wrap(info->getTypeID());
515  return {nullptr};
516 }
517 
518 MlirIdentifier mlirOperationGetName(MlirOperation op) {
519  return wrap(unwrap(op)->getName().getIdentifier());
520 }
521 
522 MlirBlock mlirOperationGetBlock(MlirOperation op) {
523  return wrap(unwrap(op)->getBlock());
524 }
525 
526 MlirOperation mlirOperationGetParentOperation(MlirOperation op) {
527  return wrap(unwrap(op)->getParentOp());
528 }
529 
530 intptr_t mlirOperationGetNumRegions(MlirOperation op) {
531  return static_cast<intptr_t>(unwrap(op)->getNumRegions());
532 }
533 
534 MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos) {
535  return wrap(&unwrap(op)->getRegion(static_cast<unsigned>(pos)));
536 }
537 
538 MlirRegion mlirOperationGetFirstRegion(MlirOperation op) {
539  Operation *cppOp = unwrap(op);
540  if (cppOp->getNumRegions() == 0)
541  return wrap(static_cast<Region *>(nullptr));
542  return wrap(&cppOp->getRegion(0));
543 }
544 
545 MlirRegion mlirRegionGetNextInOperation(MlirRegion region) {
546  Region *cppRegion = unwrap(region);
547  Operation *parent = cppRegion->getParentOp();
548  intptr_t next = cppRegion->getRegionNumber() + 1;
549  if (parent->getNumRegions() > next)
550  return wrap(&parent->getRegion(next));
551  return wrap(static_cast<Region *>(nullptr));
552 }
553 
554 MlirOperation mlirOperationGetNextInBlock(MlirOperation op) {
555  return wrap(unwrap(op)->getNextNode());
556 }
557 
558 intptr_t mlirOperationGetNumOperands(MlirOperation op) {
559  return static_cast<intptr_t>(unwrap(op)->getNumOperands());
560 }
561 
562 MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos) {
563  return wrap(unwrap(op)->getOperand(static_cast<unsigned>(pos)));
564 }
565 
566 void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
567  MlirValue newValue) {
568  unwrap(op)->setOperand(static_cast<unsigned>(pos), unwrap(newValue));
569 }
570 
571 void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands,
572  MlirValue const *operands) {
573  SmallVector<Value> ops;
574  unwrap(op)->setOperands(unwrapList(nOperands, operands, ops));
575 }
576 
577 intptr_t mlirOperationGetNumResults(MlirOperation op) {
578  return static_cast<intptr_t>(unwrap(op)->getNumResults());
579 }
580 
581 MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos) {
582  return wrap(unwrap(op)->getResult(static_cast<unsigned>(pos)));
583 }
584 
585 intptr_t mlirOperationGetNumSuccessors(MlirOperation op) {
586  return static_cast<intptr_t>(unwrap(op)->getNumSuccessors());
587 }
588 
589 MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos) {
590  return wrap(unwrap(op)->getSuccessor(static_cast<unsigned>(pos)));
591 }
592 
595  std::optional<Attribute> attr = unwrap(op)->getInherentAttr(unwrap(name));
596  return attr.has_value();
597 }
598 
599 MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op,
600  MlirStringRef name) {
601  std::optional<Attribute> attr = unwrap(op)->getInherentAttr(unwrap(name));
602  if (attr.has_value())
603  return wrap(*attr);
604  return {};
605 }
606 
608  MlirStringRef name,
609  MlirAttribute attr) {
610  unwrap(op)->setInherentAttr(
611  StringAttr::get(unwrap(op)->getContext(), unwrap(name)), unwrap(attr));
612 }
613 
614 intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op) {
615  return static_cast<intptr_t>(unwrap(op)->getDiscardableAttrs().size());
616 }
617 
619  intptr_t pos) {
620  NamedAttribute attr = unwrap(op)->getDiscardableAttrs()[pos];
621  return MlirNamedAttribute{wrap(attr.getName()), wrap(attr.getValue())};
622 }
623 
624 MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op,
625  MlirStringRef name) {
626  return wrap(unwrap(op)->getDiscardableAttr(unwrap(name)));
627 }
628 
630  MlirStringRef name,
631  MlirAttribute attr) {
632  unwrap(op)->setDiscardableAttr(unwrap(name), unwrap(attr));
633 }
634 
636  MlirStringRef name) {
637  return !!unwrap(op)->removeDiscardableAttr(unwrap(name));
638 }
639 
640 intptr_t mlirOperationGetNumAttributes(MlirOperation op) {
641  return static_cast<intptr_t>(unwrap(op)->getAttrs().size());
642 }
643 
644 MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos) {
645  NamedAttribute attr = unwrap(op)->getAttrs()[pos];
646  return MlirNamedAttribute{wrap(attr.getName()), wrap(attr.getValue())};
647 }
648 
649 MlirAttribute mlirOperationGetAttributeByName(MlirOperation op,
650  MlirStringRef name) {
651  return wrap(unwrap(op)->getAttr(unwrap(name)));
652 }
653 
654 void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name,
655  MlirAttribute attr) {
656  unwrap(op)->setAttr(unwrap(name), unwrap(attr));
657 }
658 
659 bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name) {
660  return !!unwrap(op)->removeAttr(unwrap(name));
661 }
662 
663 void mlirOperationPrint(MlirOperation op, MlirStringCallback callback,
664  void *userData) {
665  detail::CallbackOstream stream(callback, userData);
666  unwrap(op)->print(stream);
667 }
668 
669 void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags,
670  MlirStringCallback callback, void *userData) {
671  detail::CallbackOstream stream(callback, userData);
672  unwrap(op)->print(stream, *unwrap(flags));
673 }
674 
675 void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback,
676  void *userData) {
677  detail::CallbackOstream stream(callback, userData);
678  // As no desired version is set, no failure can occur.
679  (void)writeBytecodeToFile(unwrap(op), stream);
680 }
681 
683  MlirOperation op, MlirBytecodeWriterConfig config,
684  MlirStringCallback callback, void *userData) {
685  detail::CallbackOstream stream(callback, userData);
686  return wrap(writeBytecodeToFile(unwrap(op), stream, *unwrap(config)));
687 }
688 
689 void mlirOperationDump(MlirOperation op) { return unwrap(op)->dump(); }
690 
691 bool mlirOperationVerify(MlirOperation op) {
692  return succeeded(verify(unwrap(op)));
693 }
694 
695 void mlirOperationMoveAfter(MlirOperation op, MlirOperation other) {
696  return unwrap(op)->moveAfter(unwrap(other));
697 }
698 
699 void mlirOperationMoveBefore(MlirOperation op, MlirOperation other) {
700  return unwrap(op)->moveBefore(unwrap(other));
701 }
702 
703 //===----------------------------------------------------------------------===//
704 // Region API.
705 //===----------------------------------------------------------------------===//
706 
707 MlirRegion mlirRegionCreate() { return wrap(new Region); }
708 
709 bool mlirRegionEqual(MlirRegion region, MlirRegion other) {
710  return unwrap(region) == unwrap(other);
711 }
712 
713 MlirBlock mlirRegionGetFirstBlock(MlirRegion region) {
714  Region *cppRegion = unwrap(region);
715  if (cppRegion->empty())
716  return wrap(static_cast<Block *>(nullptr));
717  return wrap(&cppRegion->front());
718 }
719 
720 void mlirRegionAppendOwnedBlock(MlirRegion region, MlirBlock block) {
721  unwrap(region)->push_back(unwrap(block));
722 }
723 
724 void mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos,
725  MlirBlock block) {
726  auto &blockList = unwrap(region)->getBlocks();
727  blockList.insert(std::next(blockList.begin(), pos), unwrap(block));
728 }
729 
730 void mlirRegionInsertOwnedBlockAfter(MlirRegion region, MlirBlock reference,
731  MlirBlock block) {
732  Region *cppRegion = unwrap(region);
733  if (mlirBlockIsNull(reference)) {
734  cppRegion->getBlocks().insert(cppRegion->begin(), unwrap(block));
735  return;
736  }
737 
738  assert(unwrap(reference)->getParent() == unwrap(region) &&
739  "expected reference block to belong to the region");
740  cppRegion->getBlocks().insertAfter(Region::iterator(unwrap(reference)),
741  unwrap(block));
742 }
743 
744 void mlirRegionInsertOwnedBlockBefore(MlirRegion region, MlirBlock reference,
745  MlirBlock block) {
746  if (mlirBlockIsNull(reference))
747  return mlirRegionAppendOwnedBlock(region, block);
748 
749  assert(unwrap(reference)->getParent() == unwrap(region) &&
750  "expected reference block to belong to the region");
751  unwrap(region)->getBlocks().insert(Region::iterator(unwrap(reference)),
752  unwrap(block));
753 }
754 
755 void mlirRegionDestroy(MlirRegion region) {
756  delete static_cast<Region *>(region.ptr);
757 }
758 
759 void mlirRegionTakeBody(MlirRegion target, MlirRegion source) {
760  unwrap(target)->takeBody(*unwrap(source));
761 }
762 
763 //===----------------------------------------------------------------------===//
764 // Block API.
765 //===----------------------------------------------------------------------===//
766 
767 MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args,
768  MlirLocation const *locs) {
769  Block *b = new Block;
770  for (intptr_t i = 0; i < nArgs; ++i)
771  b->addArgument(unwrap(args[i]), unwrap(locs[i]));
772  return wrap(b);
773 }
774 
775 bool mlirBlockEqual(MlirBlock block, MlirBlock other) {
776  return unwrap(block) == unwrap(other);
777 }
778 
779 MlirOperation mlirBlockGetParentOperation(MlirBlock block) {
780  return wrap(unwrap(block)->getParentOp());
781 }
782 
783 MlirRegion mlirBlockGetParentRegion(MlirBlock block) {
784  return wrap(unwrap(block)->getParent());
785 }
786 
787 MlirBlock mlirBlockGetNextInRegion(MlirBlock block) {
788  return wrap(unwrap(block)->getNextNode());
789 }
790 
791 MlirOperation mlirBlockGetFirstOperation(MlirBlock block) {
792  Block *cppBlock = unwrap(block);
793  if (cppBlock->empty())
794  return wrap(static_cast<Operation *>(nullptr));
795  return wrap(&cppBlock->front());
796 }
797 
798 MlirOperation mlirBlockGetTerminator(MlirBlock block) {
799  Block *cppBlock = unwrap(block);
800  if (cppBlock->empty())
801  return wrap(static_cast<Operation *>(nullptr));
802  Operation &back = cppBlock->back();
803  if (!back.hasTrait<OpTrait::IsTerminator>())
804  return wrap(static_cast<Operation *>(nullptr));
805  return wrap(&back);
806 }
807 
808 void mlirBlockAppendOwnedOperation(MlirBlock block, MlirOperation operation) {
809  unwrap(block)->push_back(unwrap(operation));
810 }
811 
812 void mlirBlockInsertOwnedOperation(MlirBlock block, intptr_t pos,
813  MlirOperation operation) {
814  auto &opList = unwrap(block)->getOperations();
815  opList.insert(std::next(opList.begin(), pos), unwrap(operation));
816 }
817 
819  MlirOperation reference,
820  MlirOperation operation) {
821  Block *cppBlock = unwrap(block);
822  if (mlirOperationIsNull(reference)) {
823  cppBlock->getOperations().insert(cppBlock->begin(), unwrap(operation));
824  return;
825  }
826 
827  assert(unwrap(reference)->getBlock() == unwrap(block) &&
828  "expected reference operation to belong to the block");
829  cppBlock->getOperations().insertAfter(Block::iterator(unwrap(reference)),
830  unwrap(operation));
831 }
832 
834  MlirOperation reference,
835  MlirOperation operation) {
836  if (mlirOperationIsNull(reference))
837  return mlirBlockAppendOwnedOperation(block, operation);
838 
839  assert(unwrap(reference)->getBlock() == unwrap(block) &&
840  "expected reference operation to belong to the block");
841  unwrap(block)->getOperations().insert(Block::iterator(unwrap(reference)),
842  unwrap(operation));
843 }
844 
845 void mlirBlockDestroy(MlirBlock block) { delete unwrap(block); }
846 
847 void mlirBlockDetach(MlirBlock block) {
848  Block *b = unwrap(block);
849  b->getParent()->getBlocks().remove(b);
850 }
851 
852 intptr_t mlirBlockGetNumArguments(MlirBlock block) {
853  return static_cast<intptr_t>(unwrap(block)->getNumArguments());
854 }
855 
856 MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type,
857  MlirLocation loc) {
858  return wrap(unwrap(block)->addArgument(unwrap(type), unwrap(loc)));
859 }
860 
861 MlirValue mlirBlockInsertArgument(MlirBlock block, intptr_t pos, MlirType type,
862  MlirLocation loc) {
863  return wrap(unwrap(block)->insertArgument(pos, unwrap(type), unwrap(loc)));
864 }
865 
866 MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos) {
867  return wrap(unwrap(block)->getArgument(static_cast<unsigned>(pos)));
868 }
869 
870 void mlirBlockPrint(MlirBlock block, MlirStringCallback callback,
871  void *userData) {
872  detail::CallbackOstream stream(callback, userData);
873  unwrap(block)->print(stream);
874 }
875 
876 //===----------------------------------------------------------------------===//
877 // Value API.
878 //===----------------------------------------------------------------------===//
879 
880 bool mlirValueEqual(MlirValue value1, MlirValue value2) {
881  return unwrap(value1) == unwrap(value2);
882 }
883 
884 bool mlirValueIsABlockArgument(MlirValue value) {
885  return llvm::isa<BlockArgument>(unwrap(value));
886 }
887 
888 bool mlirValueIsAOpResult(MlirValue value) {
889  return llvm::isa<OpResult>(unwrap(value));
890 }
891 
892 MlirBlock mlirBlockArgumentGetOwner(MlirValue value) {
893  return wrap(llvm::cast<BlockArgument>(unwrap(value)).getOwner());
894 }
895 
896 intptr_t mlirBlockArgumentGetArgNumber(MlirValue value) {
897  return static_cast<intptr_t>(
898  llvm::cast<BlockArgument>(unwrap(value)).getArgNumber());
899 }
900 
901 void mlirBlockArgumentSetType(MlirValue value, MlirType type) {
902  llvm::cast<BlockArgument>(unwrap(value)).setType(unwrap(type));
903 }
904 
905 MlirOperation mlirOpResultGetOwner(MlirValue value) {
906  return wrap(llvm::cast<OpResult>(unwrap(value)).getOwner());
907 }
908 
909 intptr_t mlirOpResultGetResultNumber(MlirValue value) {
910  return static_cast<intptr_t>(
911  llvm::cast<OpResult>(unwrap(value)).getResultNumber());
912 }
913 
914 MlirType mlirValueGetType(MlirValue value) {
915  return wrap(unwrap(value).getType());
916 }
917 
918 void mlirValueSetType(MlirValue value, MlirType type) {
919  unwrap(value).setType(unwrap(type));
920 }
921 
922 void mlirValueDump(MlirValue value) { unwrap(value).dump(); }
923 
924 void mlirValuePrint(MlirValue value, MlirStringCallback callback,
925  void *userData) {
926  detail::CallbackOstream stream(callback, userData);
927  unwrap(value).print(stream);
928 }
929 
930 void mlirValuePrintAsOperand(MlirValue value, MlirAsmState state,
931  MlirStringCallback callback, void *userData) {
932  detail::CallbackOstream stream(callback, userData);
933  Value cppValue = unwrap(value);
934  cppValue.printAsOperand(stream, *unwrap(state));
935 }
936 
937 MlirOpOperand mlirValueGetFirstUse(MlirValue value) {
938  Value cppValue = unwrap(value);
939  if (cppValue.use_empty())
940  return {};
941 
942  OpOperand *opOperand = cppValue.use_begin().getOperand();
943 
944  return wrap(opOperand);
945 }
946 
947 void mlirValueReplaceAllUsesOfWith(MlirValue oldValue, MlirValue newValue) {
948  unwrap(oldValue).replaceAllUsesWith(unwrap(newValue));
949 }
950 
951 //===----------------------------------------------------------------------===//
952 // OpOperand API.
953 //===----------------------------------------------------------------------===//
954 
955 bool mlirOpOperandIsNull(MlirOpOperand opOperand) { return !opOperand.ptr; }
956 
957 MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand) {
958  return wrap(unwrap(opOperand)->getOwner());
959 }
960 
961 unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand) {
962  return unwrap(opOperand)->getOperandNumber();
963 }
964 
965 MlirOpOperand mlirOpOperandGetNextUse(MlirOpOperand opOperand) {
966  if (mlirOpOperandIsNull(opOperand))
967  return {};
968 
969  OpOperand *nextOpOperand = static_cast<OpOperand *>(
970  unwrap(opOperand)->getNextOperandUsingThisValue());
971 
972  if (!nextOpOperand)
973  return {};
974 
975  return wrap(nextOpOperand);
976 }
977 
978 //===----------------------------------------------------------------------===//
979 // Type API.
980 //===----------------------------------------------------------------------===//
981 
982 MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type) {
983  return wrap(mlir::parseType(unwrap(type), unwrap(context)));
984 }
985 
986 MlirContext mlirTypeGetContext(MlirType type) {
987  return wrap(unwrap(type).getContext());
988 }
989 
990 MlirTypeID mlirTypeGetTypeID(MlirType type) {
991  return wrap(unwrap(type).getTypeID());
992 }
993 
994 MlirDialect mlirTypeGetDialect(MlirType type) {
995  return wrap(&unwrap(type).getDialect());
996 }
997 
998 bool mlirTypeEqual(MlirType t1, MlirType t2) {
999  return unwrap(t1) == unwrap(t2);
1000 }
1001 
1002 void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData) {
1003  detail::CallbackOstream stream(callback, userData);
1004  unwrap(type).print(stream);
1005 }
1006 
1007 void mlirTypeDump(MlirType type) { unwrap(type).dump(); }
1008 
1009 //===----------------------------------------------------------------------===//
1010 // Attribute API.
1011 //===----------------------------------------------------------------------===//
1012 
1013 MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr) {
1014  return wrap(mlir::parseAttribute(unwrap(attr), unwrap(context)));
1015 }
1016 
1017 MlirContext mlirAttributeGetContext(MlirAttribute attribute) {
1018  return wrap(unwrap(attribute).getContext());
1019 }
1020 
1021 MlirType mlirAttributeGetType(MlirAttribute attribute) {
1022  Attribute attr = unwrap(attribute);
1023  if (auto typedAttr = llvm::dyn_cast<TypedAttr>(attr))
1024  return wrap(typedAttr.getType());
1025  return wrap(NoneType::get(attr.getContext()));
1026 }
1027 
1028 MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr) {
1029  return wrap(unwrap(attr).getTypeID());
1030 }
1031 
1032 MlirDialect mlirAttributeGetDialect(MlirAttribute attr) {
1033  return wrap(&unwrap(attr).getDialect());
1034 }
1035 
1036 bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2) {
1037  return unwrap(a1) == unwrap(a2);
1038 }
1039 
1040 void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback,
1041  void *userData) {
1042  detail::CallbackOstream stream(callback, userData);
1043  unwrap(attr).print(stream);
1044 }
1045 
1046 void mlirAttributeDump(MlirAttribute attr) { unwrap(attr).dump(); }
1047 
1049  MlirAttribute attr) {
1050  return MlirNamedAttribute{name, attr};
1051 }
1052 
1053 //===----------------------------------------------------------------------===//
1054 // Identifier API.
1055 //===----------------------------------------------------------------------===//
1056 
1057 MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str) {
1058  return wrap(StringAttr::get(unwrap(context), unwrap(str)));
1059 }
1060 
1061 MlirContext mlirIdentifierGetContext(MlirIdentifier ident) {
1062  return wrap(unwrap(ident).getContext());
1063 }
1064 
1065 bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other) {
1066  return unwrap(ident) == unwrap(other);
1067 }
1068 
1069 MlirStringRef mlirIdentifierStr(MlirIdentifier ident) {
1070  return wrap(unwrap(ident).strref());
1071 }
1072 
1073 //===----------------------------------------------------------------------===//
1074 // Symbol and SymbolTable API.
1075 //===----------------------------------------------------------------------===//
1076 
1079 }
1080 
1083 }
1084 
1085 MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation) {
1086  if (!unwrap(operation)->hasTrait<OpTrait::SymbolTable>())
1087  return wrap(static_cast<SymbolTable *>(nullptr));
1088  return wrap(new SymbolTable(unwrap(operation)));
1089 }
1090 
1091 void mlirSymbolTableDestroy(MlirSymbolTable symbolTable) {
1092  delete unwrap(symbolTable);
1093 }
1094 
1095 MlirOperation mlirSymbolTableLookup(MlirSymbolTable symbolTable,
1096  MlirStringRef name) {
1097  return wrap(unwrap(symbolTable)->lookup(StringRef(name.data, name.length)));
1098 }
1099 
1100 MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable,
1101  MlirOperation operation) {
1102  return wrap((Attribute)unwrap(symbolTable)->insert(unwrap(operation)));
1103 }
1104 
1105 void mlirSymbolTableErase(MlirSymbolTable symbolTable,
1106  MlirOperation operation) {
1107  unwrap(symbolTable)->erase(unwrap(operation));
1108 }
1109 
1111  MlirStringRef newSymbol,
1112  MlirOperation from) {
1113  auto *cppFrom = unwrap(from);
1114  auto *context = cppFrom->getContext();
1115  auto oldSymbolAttr = StringAttr::get(context, unwrap(oldSymbol));
1116  auto newSymbolAttr = StringAttr::get(context, unwrap(newSymbol));
1117  return wrap(SymbolTable::replaceAllSymbolUses(oldSymbolAttr, newSymbolAttr,
1118  unwrap(from)));
1119 }
1120 
1121 void mlirSymbolTableWalkSymbolTables(MlirOperation from, bool allSymUsesVisible,
1122  void (*callback)(MlirOperation, bool,
1123  void *userData),
1124  void *userData) {
1125  SymbolTable::walkSymbolTables(unwrap(from), allSymUsesVisible,
1126  [&](Operation *foundOpCpp, bool isVisible) {
1127  callback(wrap(foundOpCpp), isVisible,
1128  userData);
1129  });
1130 }
unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
Definition: IR.cpp:961
void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
Definition: IR.cpp:67
void mlirOperationDump(MlirOperation op)
Prints an operation to stderr.
Definition: IR.cpp:689
MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Returns a discardable attribute attached to the operation given its name.
Definition: IR.cpp:624
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:1095
MlirRegion mlirRegionCreate()
Creates a new empty region and transfers ownership to the caller.
Definition: IR.cpp:707
void mlirOperationPrint(MlirOperation op, MlirStringCallback callback, void *userData)
Prints an operation by sending chunks of the string representation and forwarding userData tocallback...
Definition: IR.cpp:663
MlirContext mlirModuleGetContext(MlirModule module)
Gets the context that a module was created with.
Definition: IR.cpp:311
void mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData)
Prints a value by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:924
MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
Definition: IR.cpp:285
MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
Definition: IR.cpp:957
bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
Definition: IR.cpp:121
MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
Definition: IR.cpp:545
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:682
MlirIdentifier mlirOperationGetName(MlirOperation op)
Gets the name of the operation as an identifier.
Definition: IR.cpp:518
void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
Definition: IR.cpp:137
bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
Definition: IR.cpp:1065
void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts flags controlling the printing behavior.
Definition: IR.cpp:669
bool mlirValueIsABlockArgument(MlirValue value)
Returns 1 if the value is a block argument, 0 otherwise.
Definition: IR.cpp:884
MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
Definition: IR.cpp:990
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:947
MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
Definition: IR.cpp:856
intptr_t mlirOperationGetNumRegions(MlirOperation op)
Returns the number of regions attached to the given operation.
Definition: IR.cpp:530
MlirBlock mlirOperationGetBlock(MlirOperation op)
Gets the block that owns this operation, returning null if the operation is not owned.
Definition: IR.cpp:522
void mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry)
Append the contents of the given dialect registry to the registry associated with the context.
Definition: IR.cpp:80
MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
Definition: IR.cpp:1057
void mlirBlockArgumentSetType(MlirValue value, MlirType type)
Sets the type of the block argument to the given type.
Definition: IR.cpp:901
MlirLocation mlirLocationFileLineColGet(MlirContext context, MlirStringRef filename, unsigned line, unsigned col)
Creates an File/Line/Column location owned by the given context.
Definition: IR.cpp:249
intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
Definition: IR.cpp:87
MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
Definition: IR.cpp:1048
MlirStringRef mlirSymbolTableGetVisibilityAttributeName()
Returns the name of the attribute used to store symbol visibility.
Definition: IR.cpp:1081
void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
Definition: IR.cpp:378
MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
Returns pos-th result of the operation.
Definition: IR.cpp:581
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:1121
void mlirContextLoadAllAvailableDialects(MlirContext context)
Eagerly loads all available dialects registered with a context, making them available for use for IR ...
Definition: IR.cpp:104
void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback, void *userData)
Prints an attribute by sending chunks of the string representation and forwarding userData tocallback...
Definition: IR.cpp:1040
MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
Definition: IR.cpp:713
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:1110
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:260
MlirAsmState mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags)
Creates new AsmState from value.
Definition: IR.cpp:166
intptr_t mlirOperationGetNumResults(MlirOperation op)
Returns the number of results of the operation.
Definition: IR.cpp:577
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:937
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:730
void mlirOperationDestroy(MlirOperation op)
Takes an operation owned by the caller and destroys it.
Definition: IR.cpp:496
void mlirBlockAppendOwnedOperation(MlirBlock block, MlirOperation operation)
Takes an operation owned by the caller and appends it to the block.
Definition: IR.cpp:808
MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
Definition: IR.cpp:538
MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
Returns an inherent attribute attached to the operation given its name.
Definition: IR.cpp:599
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:91
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Gets the context that an attribute was created with.
Definition: IR.cpp:1017
MlirStringRef mlirSymbolTableGetSymbolAttributeName()
Returns the name of the attribute used to store symbol names compatible with symbol tables.
Definition: IR.cpp:1077
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:812
MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
Definition: IR.cpp:783
MlirType mlirValueGetType(MlirValue value)
Returns the type of the value.
Definition: IR.cpp:914
void mlirOperationMoveAfter(MlirOperation op, MlirOperation other)
Moves the given operation immediately after the other operation in its parent block.
Definition: IR.cpp:695
void mlirRegionAppendOwnedBlock(MlirRegion region, MlirBlock block)
Takes a block owned by the caller and appends it to the given region.
Definition: IR.cpp:720
void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
Prints a block by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:870
void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Sets a discardable attribute by name, replacing the existing if it exists or adding a new one otherwi...
Definition: IR.cpp:629
MlirOpPrintingFlags mlirOpPrintingFlagsCreate()
Creates new printing flags with defaults, intended for customization.
Definition: IR.cpp:190
void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags, intptr_t largeElementLimit)
Enables the elision of large elements attributes by printing a lexically valid but otherwise meaningl...
Definition: IR.cpp:198
MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
Definition: IR.cpp:787
#define APPEND_ELEMS(type, sizeName, elemName)
Definition: IR.cpp:355
bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
Definition: IR.cpp:96
MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
Returns an operation immediately following the given operation it its enclosing block.
Definition: IR.cpp:554
void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
Enable or disable printing of debug information (based on enable).
Definition: IR.cpp:203
MlirOperation mlirModuleGetOperation(MlirModule module)
Views the module as a generic operation.
Definition: IR.cpp:325
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:744
MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
Definition: IR.cpp:866
MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition: IR.cpp:125
void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
Use local scope when printing the operation.
Definition: IR.cpp:212
MlirTypeID mlirOperationGetTypeID(MlirOperation op)
Gets the type id of the operation.
Definition: IR.cpp:512
intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
Returns the position of the value in the argument list of its block.
Definition: IR.cpp:896
MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
Returns pos-th successor of the operation.
Definition: IR.cpp:589
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:833
bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
Checks if two attributes are equal.
Definition: IR.cpp:1036
MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags)
Creates new AsmState, as with AsmState the IR should not be mutated in-between using this state.
Definition: IR.cpp:145
bool mlirOperationEqual(MlirOperation op, MlirOperation other)
Checks whether two operation handles point to the same operation.
Definition: IR.cpp:500
void mlirOperationSetInherentAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Sets an inherent attribute by name, replacing the existing if it exists.
Definition: IR.cpp:607
void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
Do not verify the operation when using custom operation printers.
Definition: IR.cpp:216
bool mlirValueEqual(MlirValue value1, MlirValue value2)
Returns 1 if two values are equal, 0 otherwise.
Definition: IR.cpp:880
MlirContext mlirIdentifierGetContext(MlirIdentifier ident)
Returns the context associated with this identifier.
Definition: IR.cpp:1061
void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
Destroys printing flags created with mlirBytecodeWriterConfigCreate.
Definition: IR.cpp:228
void mlirModuleDestroy(MlirModule module)
Takes a module owned by the caller and deletes it.
Definition: IR.cpp:319
MlirModule mlirModuleCreateEmpty(MlirLocation location)
Creates a new, empty module and transfers ownership to the caller.
Definition: IR.cpp:299
void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
Always print operations in the generic form.
Definition: IR.cpp:208
MlirOperation mlirOperationGetParentOperation(MlirOperation op)
Gets the operation that owns this operation, returning null if the operation is not owned.
Definition: IR.cpp:526
void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
Definition: IR.cpp:759
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:861
void mlirValueSetType(MlirValue value, MlirType type)
Set the type of the value.
Definition: IR.cpp:918
intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
Returns the number of successor blocks of the operation.
Definition: IR.cpp:585
MlirDialect mlirAttributeGetDialect(MlirAttribute attr)
Gets the dialect of the attribute.
Definition: IR.cpp:1032
void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:289
void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
Sets an attribute by name, replacing the existing if it exists or adding a new one otherwise.
Definition: IR.cpp:654
void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
Definition: IR.cpp:845
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:724
void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
Sets the pos-th operand of the operation.
Definition: IR.cpp:566
intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
Definition: IR.cpp:852
MlirOperation mlirOpResultGetOwner(MlirValue value)
Returns an operation that produced this value as its result.
Definition: IR.cpp:905
bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
Definition: IR.cpp:955
MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
Definition: IR.cpp:994
MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
Parses a module from the string and transfers ownership to the caller.
Definition: IR.cpp:303
MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry, bool threadingEnabled)
Creates an MLIR context, setting the multithreading setting explicitly and pre-loading the dialects f...
Definition: IR.cpp:56
void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
Definition: IR.cpp:69
void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n, MlirType const *results)
Adds a list of components to the operation state.
Definition: IR.cpp:361
void mlirOperationMoveBefore(MlirOperation op, MlirOperation other)
Moves the given operation immediately before the other operation in its parent block.
Definition: IR.cpp:699
static LogicalResult inferOperationTypes(OperationState &state)
Definition: IR.cpp:391
MlirOperation mlirOperationClone(MlirOperation op)
Creates a deep copy of an operation.
Definition: IR.cpp:492
void mlirValuePrintAsOperand(MlirValue value, MlirAsmState state, MlirStringCallback callback, void *userData)
Prints a value as an operand (i.e., the ValueID).
Definition: IR.cpp:930
MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
Returns the block in which this value is defined as an argument.
Definition: IR.cpp:892
MlirDialectRegistry mlirDialectRegistryCreate()
Creates a dialect registry and transfers its ownership to the caller.
Definition: IR.cpp:133
MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
Returns pos-th operand of the operation.
Definition: IR.cpp:562
bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
Definition: IR.cpp:73
MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
Definition: IR.cpp:241
MlirModule mlirModuleFromOperation(MlirOperation op)
Views the generic operation as a module.
Definition: IR.cpp:329
MlirLocation mlirOperationGetLocation(MlirOperation op)
Gets the location of the operation.
Definition: IR.cpp:508
bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
Definition: IR.cpp:998
bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
Definition: IR.cpp:63
MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
Returns an attribute attached to the operation given its name.
Definition: IR.cpp:649
MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr)
Gets the type id of the attribute.
Definition: IR.cpp:1028
static Operation * findParent(Operation *op, bool shouldUseLocalScope)
Definition: IR.cpp:150
MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
Definition: IR.cpp:1100
intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
Returns the number of discardable attributes attached to the operation.
Definition: IR.cpp:614
MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
Definition: IR.cpp:1085
void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
Definition: IR.cpp:370
MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
Definition: IR.cpp:277
MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
Definition: IR.cpp:791
MlirType mlirAttributeGetType(MlirAttribute attribute)
Gets the type of this attribute.
Definition: IR.cpp:1021
bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
Removes a discardable attribute by name.
Definition: IR.cpp:635
void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
Definition: IR.cpp:755
bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
Removes an attribute by name.
Definition: IR.cpp:659
bool mlirValueIsAOpResult(MlirValue value)
Returns 1 if the value is an operation result, 0 otherwise.
Definition: IR.cpp:888
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
Returns true if this operation defines an inherent attribute with this name.
Definition: IR.cpp:594
MlirContext mlirContextCreateWithThreading(bool threadingEnabled)
Creates an MLIR context with an explicit setting of the multithreading setting and transfers its owne...
Definition: IR.cpp:51
MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
Definition: IR.cpp:798
bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
Definition: IR.cpp:281
MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
Returns pos-th region attached to the operation.
Definition: IR.cpp:534
MlirOperation mlirOperationCreate(MlirOperationState *state)
Creates an operation and transfers ownership to the caller.
Definition: IR.cpp:446
void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags, int64_t version)
Sets the version to emit in the writer config.
Definition: IR.cpp:232
MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
Parses an attribute. The attribute is owned by the context.
Definition: IR.cpp:1013
void mlirOperationRemoveFromParent(MlirOperation op)
Removes the given operation from its parent block.
Definition: IR.cpp:498
void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
Definition: IR.cpp:1091
MlirContext mlirContextCreate()
Creates an MLIR context and transfers its ownership to the caller.
Definition: IR.cpp:41
bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
Definition: IR.cpp:691
void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
Definition: IR.cpp:847
MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
Return pos-th attribute of the operation.
Definition: IR.cpp:644
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
Destroys printing flags created with mlirOpPrintingFlagsCreate.
Definition: IR.cpp:194
MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
Definition: IR.cpp:256
void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
Definition: IR.cpp:675
void mlirValueDump(MlirValue value)
Prints the value to the standard error stream.
Definition: IR.cpp:922
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:818
intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
Definition: IR.cpp:76
void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
Replaces the operands of the operation.
Definition: IR.cpp:571
static MLIRContext::Threading toThreadingEnum(bool threadingEnabled)
Definition: IR.cpp:46
MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
Definition: IR.cpp:986
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData tocallback`.
Definition: IR.cpp:1002
MlirBlock mlirModuleGetBody(MlirModule module)
Gets the body of the module, i.e. the only block it contains.
Definition: IR.cpp:315
MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
Definition: IR.cpp:117
bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
Definition: IR.cpp:709
MlirOperation mlirOperationCreateParse(MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName)
Parses an operation, giving ownership to the caller.
Definition: IR.cpp:483
void mlirAsmStateDestroy(MlirAsmState state)
Destroys printing flags created with mlirAsmStateCreate.
Definition: IR.cpp:184
MlirContext mlirOperationGetContext(MlirOperation op)
Gets the context this operation is associated with.
Definition: IR.cpp:504
intptr_t mlirOpResultGetResultNumber(MlirValue value)
Returns the position of the value in the list of results of the operation that produced it.
Definition: IR.cpp:909
MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
Definition: IR.cpp:268
bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
Definition: IR.cpp:775
void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
Definition: IR.cpp:1105
MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
Return pos-th discardable attribute of the operation.
Definition: IR.cpp:618
void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
Enables result type inference for the operation under construction.
Definition: IR.cpp:383
void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
Definition: IR.cpp:374
MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate()
Creates new printing flags with defaults, intended for customization.
Definition: IR.cpp:224
void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
Definition: IR.cpp:1046
MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
Definition: IR.cpp:1069
void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
Definition: IR.cpp:366
MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
Constructs an operation state from a name and a location.
Definition: IR.cpp:337
MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
Definition: IR.cpp:245
MlirOperation mlirBlockGetParentOperation(MlirBlock block)
Returns the closest surrounding operation that contains this block.
Definition: IR.cpp:779
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:965
intptr_t mlirOperationGetNumOperands(MlirOperation op)
Returns the number of operands of the operation.
Definition: IR.cpp:558
void mlirContextSetThreadPool(MlirContext context, MlirLlvmThreadPool threadPool)
Sets the thread pool of the context explicitly, enabling multithreading in the process.
Definition: IR.cpp:108
MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
Definition: IR.cpp:982
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:767
void mlirContextEnableMultithreading(MlirContext context, bool enable)
Set threading mode (must be set to false to mlir-print-ir-after-all).
Definition: IR.cpp:100
void mlirTypeDump(MlirType type)
Prints the type to the standard error stream.
Definition: IR.cpp:1007
intptr_t mlirOperationGetNumAttributes(MlirOperation op)
Returns the number of attributes attached to the operation.
Definition: IR.cpp:640
static MLIRContext * getContext(OpFoldResult val)
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition: Wrap.h:40
This class provides management for the lifetime of the state used when printing the IR.
Definition: AsmState.h:533
Attributes are known-constant values of operations.
Definition: Attributes.h:25
MLIRContext * getContext() const
Return the context this attribute belongs to.
Definition: Attributes.cpp:37
Block represents an ordered list of Operations.
Definition: Block.h:30
OpListType::iterator iterator
Definition: Block.h:133
bool empty()
Definition: Block.h:141
Operation & back()
Definition: Block.h:145
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
Definition: Block.cpp:26
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
Definition: Block.cpp:147
OpListType & getOperations()
Definition: Block.h:130
Operation & front()
Definition: Block.h:146
iterator begin()
Definition: Block.h:136
This class contains the configuration used for the bytecode writer.
void print(raw_ostream &os) const
Outputs this diagnostic to a stream.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Location objects represent source locations information in MLIR.
Definition: Location.h:31
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
void reserve(size_type N)
NamedAttribute represents a combination of a name and an Attribute value.
Definition: Attributes.h:198
StringAttr getName() const
Return the name of the attribute.
Definition: Attributes.cpp:49
Attribute getValue() const
Return the value of the attribute.
Definition: Attributes.h:212
This class represents an operand of an operation.
Definition: Value.h:261
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.
Definition: OpDefinition.h:757
Simple wrapper around a void* in order to express generically how to pass in op properties through AP...
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Definition: Operation.h:728
unsigned getNumRegions()
Returns the number of regions held by this operation.
Definition: Operation.h:652
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, OpaqueProperties properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
Definition: Operation.cpp:66
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Definition: Operation.h:234
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
Definition: Operation.h:665
OpTy release()
Release the referenced op.
Definition: OwningOpRef.h:66
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
unsigned getRegionNumber()
Return the number of this region in the parent operation.
Definition: Region.cpp:62
Operation * getParentOp()
Return the parent operation this region is attached to.
Definition: Region.h:200
bool empty()
Definition: Region.h:60
iterator begin()
Definition: Region.h:55
BlockListType & getBlocks()
Definition: Region.h:45
Block & front()
Definition: Region.h:65
BlockListType::iterator iterator
Definition: Region.h:52
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Definition: SymbolTable.h:24
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
Definition: SymbolTable.h:59
static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol, StringAttr newSymbol, Operation *from)
Attempt to replace all uses of the given symbol 'oldSymbol' with the provided symbol 'newSymbol' that...
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
Definition: SymbolTable.h:65
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.
Definition: UseDefLists.h:304
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:93
bool use_empty() const
Returns true if this value has no uses.
Definition: Value.h:212
void printAsOperand(raw_ostream &os, AsmState &state)
Print this value as if it were an operand.
Location getLoc() const
Return the location of this value.
Definition: Value.cpp:26
use_iterator use_begin() const
Definition: Value.h:202
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
Definition: Utils.h:30
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
Definition: IR.h:769
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
Definition: IR.h:283
static bool mlirOperationIsNull(MlirOperation op)
Checks whether the underlying operation is null.
Definition: IR.h:508
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:105
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:68
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
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:90
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
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:421
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
A logical result value, essentially a boolean with named states.
Definition: Support.h:116
Named MLIR attribute.
Definition: IR.h:77
An auxiliary class for constructing operations.
Definition: IR.h:341
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73
const char * data
Pointer to the first symbol.
Definition: Support.h:74
size_t length
Length of the fragment.
Definition: Support.h:75
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
This represents an operation in an abstracted form, suitable for use with the builder APIs.
void addOperands(ValueRange newOperands)
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
void addSuccessors(Block *successor)
void addTypes(ArrayRef< Type > newTypes)
NamedAttrList attributes
SmallVector< Type, 4 > types
Types of the results of this operation.
Region * addRegion()
Create a region that should be attached to the operation.