Lines Matching defs:operation
71 R"(Creates a new operation.
74 name: Operation name (e.g. "dialect.operation").
77 successors: List of Block for the operation's successors.
90 R"(Prints the assembly form of the operation to a file like object.
117 R"(Prints the assembly form of the operation to a file like object.
122 state: AsmState capturing the operation numbering and flags.
126 R"(Gets the assembly form of the operation with all options available.
139 R"(Write the bytecode form of the operation to a file like object.
149 R"(Gets the assembly form of the operation with default options.
170 position in the argument list. If the value is an operation result, this is
171 equivalent to printing the operation that produced it.
185 in 'exceptions'. 'exceptions' can be either a single operation or a list of
334 PyRegionIterator(PyOperationRef operation)
335 : operation(std::move(operation)) {}
340 operation->checkValid();
341 if (nextIndex >= mlirOperationGetNumRegions(operation->get())) {
344 MlirRegion region = mlirOperationGetRegion(operation->get(), nextIndex++);
345 return PyRegion(operation, region);
355 PyOperationRef operation;
363 PyRegionList(PyOperationRef operation) : operation(std::move(operation)) {}
366 operation->checkValid();
367 return PyRegionIterator(operation);
371 operation->checkValid();
372 return mlirOperationGetNumRegions(operation->get());
380 MlirRegion region = mlirOperationGetRegion(operation->get(), index);
381 return PyRegion(operation, region);
392 PyOperationRef operation;
397 PyBlockIterator(PyOperationRef operation, MlirBlock next)
398 : operation(std::move(operation)), next(next) {}
403 operation->checkValid();
408 PyBlock returnBlock(operation, next);
420 PyOperationRef operation;
429 PyBlockList(PyOperationRef operation, MlirRegion region)
430 : operation(std::move(operation)), region(region) {}
433 operation->checkValid();
434 return PyBlockIterator(operation, mlirRegionGetFirstBlock(region));
438 operation->checkValid();
449 operation->checkValid();
456 return PyBlock(operation, block);
466 operation->checkValid();
470 return PyBlock(operation, block);
484 PyOperationRef operation;
547 throw nb::index_error("attempt to access out of bounds operation");
558 throw nb::index_error("attempt to access out of bounds operation");
1185 PyOperation::PyOperation(PyMlirContextRef contextRef, MlirOperation operation)
1186 : BaseContextObject(std::move(contextRef)), operation(operation) {}
1189 // If the operation has already been invalidated there is nothing to do.
1193 // Otherwise, invalidate the operation and remove it from live map when it is
1222 MlirOperation operation,
1226 makeObjectRef<PyOperation>(std::move(contextRef), operation);
1235 MlirOperation operation,
1239 auto it = liveOperations.find(operation.ptr);
1242 PyOperationRef result = createInstance(std::move(contextRef), operation,
1244 liveOperations[operation.ptr] =
1255 MlirOperation operation,
1259 assert(liveOperations.count(operation.ptr) == 0 &&
1260 "cannot create detached operation that already exists");
1262 PyOperationRef created = createInstance(std::move(contextRef), operation,
1264 liveOperations[operation.ptr] =
1278 throw MLIRError("Unable to parse operation assembly", errors.take());
1284 throw std::runtime_error("the operation has been invalidated");
1293 PyOperation &operation = getOperation();
1294 operation.checkValid();
1314 mlirOperationPrintWithFlags(operation, flags, accum.getCallback(),
1321 PyOperation &operation = getOperation();
1322 operation.checkValid();
1326 mlirOperationPrintWithState(operation, state.get(), accum.getCallback(),
1332 PyOperation &operation = getOperation();
1333 operation.checkValid();
1337 return mlirOperationWriteBytecode(operation, accum.getCallback(),
1343 operation, config, accum.getCallback(), accum.getUserData());
1355 PyOperation &operation = getOperation();
1356 operation.checkValid();
1376 mlirOperationWalk(operation, walkCallback, &userData, walkOrder);
1409 PyOperation &operation = getOperation();
1411 operation.checkValid();
1413 mlirOperationMoveAfter(operation, otherOp);
1414 operation.parentKeepAlive = otherOp.parentKeepAlive;
1418 PyOperation &operation = getOperation();
1420 operation.checkValid();
1422 mlirOperationMoveBefore(operation, otherOp);
1423 operation.parentKeepAlive = otherOp.parentKeepAlive;
1438 MlirOperation operation = mlirOperationGetParentOperation(get());
1439 if (mlirOperationIsNull(operation))
1441 return PyOperation::forOperation(getContext(), operation);
1448 assert(!mlirBlockIsNull(block) && "Attached operation has null parent");
1516 "attempting to create the operation \"" +
1526 "\" when attempting to create the operation \"" +
1533 "\" when attempting to create the operation \"" +
1550 // Apply unpacked/validated to the operation state. Beyond this
1586 // Construct the operation.
1587 MlirOperation operation = mlirOperationCreate(&state);
1588 if (!operation.ptr)
1591 PyOperation::createDetached(location->getContext(), operation);
1598 MlirOperation clonedOperation = mlirOperationClone(operation);
1620 mlirOperationDestroy(operation);
1711 /// A list of operation results. Internally, these are stored as consecutive
1713 /// with the operation whose results these are, and thus extends the lifetime of
1714 /// this operation.
1720 PyOpResultList(PyOperationRef operation, intptr_t startIndex = 0,
1723 length == -1 ? mlirOperationGetNumResults(operation->get())
1726 operation(std::move(operation)) {}
1730 return getValueTypes(self, self.operation->getContext());
1733 return self.operation->createOpView();
1737 PyOperationRef &getOperation() { return operation; }
1744 operation->checkValid();
1745 return mlirOperationGetNumResults(operation->get());
1749 PyValue value(operation, mlirOperationGetResult(operation->get(), index));
1754 return PyOpResultList(operation, startIndex, length, step);
1757 PyOperationRef operation;
1778 llvm::Twine(it.index()) + " of operation \"" +
1813 " of operation \"" + name +
1820 llvm::Twine(it.index()) + " of operation \"" +
1848 llvm::Twine(it.index()) + " of operation \"" +
1861 static MlirValue getUniqueResult(MlirOperation operation) {
1862 auto numResults = mlirOperationGetNumResults(operation);
1864 auto name = mlirIdentifierStr(mlirOperationGetName(operation));
1865 throw nb::value_error((Twine("Cannot call .result on operation ") +
1873 return mlirOperationGetResult(operation, 0);
1905 // Class level operation construction metadata.
1954 llvm::Twine(it.index()) + " of operation \"" +
1986 " of operation \"" + name +
1999 " of operation \"" + name +
2023 llvm::Twine(it.index()) + " of operation \"" +
2080 const nb::object &operation) {
2083 opViewType.attr("__init__")(instance, operation);
2090 : operation(nb::cast<PyOperationBase &>(operationObject).getOperation()),
2091 operationObject(operation.getRef().getObject()) {}
2104 PyOperation &operation = operationBase.getOperation();
2105 if (operation.isAttached())
2107 "Attempt to insert operation that is already attached");
2111 // Insert before operation.
2119 throw nb::index_error("Cannot insert operation at the end of a block "
2125 mlirBlockInsertOwnedOperationBefore(block.get(), beforeOp, operation);
2126 operation.setAttached();
2275 PySymbolTable::PySymbolTable(PyOperationBase &operation)
2276 : operation(operation.getOperation().getRef()) {
2277 symbolTable = mlirSymbolTableCreate(operation.getOperation().get());
2284 operation->checkValid();
2291 return PyOperation::forOperation(operation->getContext(), symbol,
2292 operation.getObject())
2297 operation->checkValid();
2300 // The operation is also erased, so we must invalidate it. There may be Python
2301 // references to this operation so we don't want to delete it from the list of
2307 nb::object operation = dunderGetItem(name);
2308 erase(nb::cast<PyOperationBase &>(operation));
2312 operation->checkValid();
2317 throw nb::value_error("Expected operation to have a symbol name.");
2323 PyOperation &operation = symbol.getOperation();
2324 operation.checkValid();
2327 mlirOperationGetAttributeByName(operation.get(), attrName);
2329 throw nb::value_error("Expected operation to have a symbol name.");
2336 PyOperation &operation = symbol.getOperation();
2337 operation.checkValid();
2340 mlirOperationGetAttributeByName(operation.get(), attrName);
2342 throw nb::value_error("Expected operation to have a symbol name.");
2344 mlirStringAttrGet(operation.getContext()->get(), toMlirStringRef(name));
2345 mlirOperationSetAttributeByName(operation.get(), attrName, newNameAttr);
2349 PyOperation &operation = symbol.getOperation();
2350 operation.checkValid();
2353 mlirOperationGetAttributeByName(operation.get(), attrName);
2355 throw nb::value_error("Expected operation to have a symbol visibility.");
2365 PyOperation &operation = symbol.getOperation();
2366 operation.checkValid();
2369 mlirOperationGetAttributeByName(operation.get(), attrName);
2371 throw nb::value_error("Expected operation to have a symbol visibility.");
2372 MlirAttribute newVisAttr = mlirStringAttrGet(operation.getContext()->get(),
2374 mlirOperationSetAttributeByName(operation.get(), attrName, newVisAttr);
2455 /// operation that contains the block (detached blocks are not allowed in
2463 PyBlockArgumentList(PyOperationRef operation, MlirBlock block,
2469 operation(std::move(operation)), block(block) {}
2473 return getValueTypes(self, self.operation->getContext());
2483 operation->checkValid();
2490 return PyBlockArgument(operation, argument);
2496 return PyBlockArgumentList(operation, block, startIndex, length, step);
2499 PyOperationRef operation;
2503 /// A list of operation operands. Internally, these are stored as consecutive
2505 /// with the operation whose operands these are, and thus extends the lifetime
2506 /// of this operation.
2512 PyOpOperandList(PyOperationRef operation, intptr_t startIndex = 0,
2515 length == -1 ? mlirOperationGetNumOperands(operation->get())
2518 operation(operation) {}
2522 mlirOperationSetOperand(operation->get(), index, value.get());
2534 operation->checkValid();
2535 return mlirOperationGetNumOperands(operation->get());
2539 MlirValue operand = mlirOperationGetOperand(operation->get(), pos);
2548 PyOperation::forOperation(operation->getContext(), owner);
2553 return PyOpOperandList(operation, startIndex, length, step);
2556 PyOperationRef operation;
2559 /// A list of operation successors. Internally, these are stored as consecutive
2561 /// associated with the operation whose successors these are, and thus extends
2562 /// the lifetime of this operation.
2567 PyOpSuccessors(PyOperationRef operation, intptr_t startIndex = 0,
2570 length == -1 ? mlirOperationGetNumSuccessors(operation->get())
2573 operation(operation) {}
2577 mlirOperationSetSuccessor(operation->get(), index, block.get());
2589 operation->checkValid();
2590 return mlirOperationGetNumSuccessors(operation->get());
2594 MlirBlock block = mlirOperationGetSuccessor(operation->get(), pos);
2595 return PyBlock(operation, block);
2599 return PyOpSuccessors(operation, startIndex, length, step);
2602 PyOperationRef operation;
2605 /// A list of operation attributes. Can be indexed by name, producing
2609 PyOpAttributeMap(PyOperationRef operation)
2610 : operation(std::move(operation)) {}
2613 MlirAttribute attr = mlirOperationGetAttributeByName(operation->get(),
2626 mlirOperationGetAttribute(operation->get(), index);
2634 mlirOperationSetAttributeByName(operation->get(), toMlirStringRef(name),
2639 int removed = mlirOperationRemoveAttributeByName(operation->get(),
2646 return mlirOperationGetNumAttributes(operation->get());
2651 operation->get(), toMlirStringRef(name)));
2665 PyOperationRef operation;
3062 "operation",
3069 "Accesses the module as an operation")
3089 // Defer to the operation's __str__.
3090 return self.attr("operation").attr("__str__")();
3128 MlirOperation operation = concreteOperation.get();
3130 mlirIdentifierStr(mlirOperationGetName(operation));
3150 auto &operation = self.getOperation();
3151 return PyOpResult(operation.getRef(), getUniqueResult(operation))
3159 PyOperation &operation = self.getOperation();
3160 return PyLocation(operation.getContext(),
3161 mlirOperationGetLocation(operation.get()));
3163 "Returns the source location the operation was defined or derived "
3184 "Returns the assembly form of the operation.")
3217 "Verify the operation. Raises MLIRError if verification fails, and "
3220 "Puts self immediately after the other operation in its parent "
3223 "Puts self immediately before the other operation in its parent "
3234 PyOperation &operation = self.getOperation();
3235 operation.checkValid();
3236 if (!operation.isAttached())
3237 throw nb::value_error("Detached operation has no parent.");
3239 operation.detachFromParent();
3240 return operation.createOpView();
3242 "Detaches the operation from its parent block.")
3287 "Parses an operation. Supports both text assembly format and binary "
3291 .def_prop_ro("operation", [](nb::object self) { return self; })
3302 .def(nb::init<nb::object>(), nb::arg("operation"))
3330 .def_prop_ro("operation", &PyOpView::getOperationObject)
3376 // Check if the expected operation was parsed, and cast to to the
3410 "Returns the operation owning this region.")
3435 "Returns the owning operation of this block.")
3551 [](PyBlock &self, PyOperationBase &operation) {
3552 if (operation.getOperation().isAttached())
3553 operation.getOperation().detachFromParent();
3555 MlirOperation mlirOperation = operation.getOperation().get();
3557 operation.getOperation().setAttached(
3560 nb::arg("operation"),
3561 "Appends an operation to this block. If the operation is currently "
3570 "Inserts after the last operation but still inside the block.")
3586 "Inserts before a referenced operation.")
3591 .def("insert", &PyInsertionPoint::insert, nb::arg("operation"),
3592 "Inserts an operation.")
3604 "The reference operation before which new operations are "
3967 .def("insert", &PySymbolTable::insert, nb::arg("operation"))
3968 .def("erase", &PySymbolTable::erase, nb::arg("operation"))