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