Lines Matching full:operation
1 //===- Operation.cpp - Operation support code -----------------------------===//
9 #include "mlir/IR/Operation.h"
30 // Operation
33 /// Create a new Operation from operation state.
34 Operation *Operation::create(const OperationState &state) {
35 Operation *op =
50 /// Create a new Operation with the specific fields.
51 Operation *Operation::create(Location location, OperationName name,
57 Operation *op =
66 /// Create a new Operation with the specific fields.
67 Operation *Operation::create(Location location, OperationName name,
82 Operation *Operation::create(Location location, OperationName name,
98 // If the operation is known to have no operands, don't allocate an operand
103 // Compute the byte size for the operation and the operand storage. This takes
104 // into account the size of the operation, its trailing objects, and its
112 Operation::prefixAllocSize(numTrailingResults, numInlineResults),
113 alignof(Operation));
117 // Create the new Operation.
118 Operation *op = ::new (rawMem) Operation(
123 "unexpected successors in a non-terminator operation");
155 Operation::Operation(Location location, OperationName name, unsigned numResults,
179 Operation::~Operation() {
180 assert(block == nullptr && "operation destroyed but still in a block");
185 emitOpError("operation destroyed but still has uses");
186 for (Operation *user : getUsers())
189 llvm::report_fatal_error("operation destroyed but still has uses");
207 /// Destroy this operation or one of its subclasses.
208 void Operation::destroy() {
212 llvm::alignTo(prefixAllocSize(), alignof(Operation));
213 this->~Operation();
217 /// Return true if this operation is a proper ancestor of the `other`
218 /// operation.
219 bool Operation::isProperAncestor(Operation *other) {
226 /// Replace any uses of 'from' with 'to' within this operation.
227 void Operation::replaceUsesOfWith(Value from, Value to) {
235 /// Replace the current operands of this operation with the ones provided in
237 void Operation::setOperands(ValueRange operands) {
246 void Operation::setOperands(unsigned start, unsigned length,
256 void Operation::insertOperands(unsigned index, ValueRange operands) {
266 /// Emit an error about fatal conditions with this operation, reporting up to
268 InFlightDiagnostic Operation::emitError(const Twine &message) {
272 .append("see current operation: ")
278 /// Emit a warning about this operation, reporting up to any diagnostic
280 InFlightDiagnostic Operation::emitWarning(const Twine &message) {
283 diag.attachNote(getLoc()) << "see current operation: " << *this;
287 /// Emit a remark about this operation, reporting up to any diagnostic
289 InFlightDiagnostic Operation::emitRemark(const Twine &message) {
292 diag.attachNote(getLoc()) << "see current operation: " << *this;
296 DictionaryAttr Operation::getAttrDictionary() {
305 void Operation::setAttrs(DictionaryAttr newAttrs) {
323 void Operation::setAttrs(ArrayRef<NamedAttribute> newAttrs) {
341 std::optional<Attribute> Operation::getInherentAttr(StringRef name) {
345 void Operation::setInherentAttr(StringAttr name, Attribute value) {
349 Attribute Operation::getPropertiesAsAttribute() {
355 LogicalResult Operation::setPropertiesFromAttribute(
366 void Operation::copyProperties(OpaqueProperties rhs) {
370 llvm::hash_code Operation::hashProperties() {
375 // Operation Ordering
378 constexpr unsigned Operation::kInvalidOrderIdx;
379 constexpr unsigned Operation::kOrderStride;
381 /// Given an operation 'other' that is within the same parent block, return
382 /// whether the current operation is before 'other' in the operation list
386 bool Operation::isBeforeInBlock(Operation *other) {
389 "Expected other operation to have the same parent block.");
395 // Update the order either operation if necessary.
403 /// Update the order index of this operation of this operation if necessary,
405 void Operation::updateOrderIfNecessary() {
408 // If the order is valid for this operation there is nothing to do.
411 Operation *blockFront = &block->front();
412 Operation *blockBack = &block->back();
415 // operation.
416 assert(blockFront != blockBack && "expected more than one operation");
418 // If the operation is at the end of the block.
420 Operation *prevNode = getPrevNode();
424 // Add the stride to the previous operation.
429 // If this is the first operation try to use the next operation to compute the
432 Operation *nextNode = getNextNode();
435 // There is no order to give this operation.
448 // Otherwise, this operation is between two others. Place this operation in
450 Operation *prevNode = getPrevNode(), *nextNode = getNextNode();
462 // ilist_traits for Operation
467 ::mlir::Operation>::type>::getNodePtr(pointer n) -> node_type * {
473 ::mlir::Operation>::type>::getNodePtr(const_pointer n)
480 ::mlir::Operation>::type>::getValuePtr(node_type *n) -> pointer {
486 ::mlir::Operation>::type>::getValuePtr(const node_type *n)
491 void llvm::ilist_traits<::mlir::Operation>::deleteNode(Operation *op) {
495 Block *llvm::ilist_traits<::mlir::Operation>::getContainingBlock() {
497 iplist<Operation> *anchor(static_cast<iplist<Operation> *>(this));
501 /// This is a trait method invoked when an operation is added to a block. We
503 void llvm::ilist_traits<::mlir::Operation>::addNodeToList(Operation *op) {
504 assert(!op->getBlock() && "already in an operation block!");
507 // Invalidate the order on the operation.
508 op->orderIndex = Operation::kInvalidOrderIdx;
511 /// This is a trait method invoked when an operation is removed from a block.
513 void llvm::ilist_traits<::mlir::Operation>::removeNodeFromList(Operation *op) {
514 assert(op->block && "not already in an operation block!");
518 /// This is a trait method invoked when an operation is moved from one block
520 void llvm::ilist_traits<::mlir::Operation>::transferNodesFromList(
521 ilist_traits<Operation> &otherList, op_iterator first, op_iterator last) {
532 // Update the 'block' member of each operation.
537 /// Remove this operation (and its descendants) from its Block and delete
539 void Operation::erase() {
546 /// Remove the operation from its parent block, but don't delete it.
547 void Operation::remove() {
552 /// Unlink this operation from its current block and insert it right before
555 void Operation::moveBefore(Operation *existingOp) {
559 /// Unlink this operation from its current basic block and insert it right
561 void Operation::moveBefore(Block *block,
562 llvm::iplist<Operation>::iterator iterator) {
567 /// Unlink this operation from its current block and insert it right after
569 void Operation::moveAfter(Operation *existingOp) {
573 /// Unlink this operation from its current block and insert it right after
575 void Operation::moveAfter(Block *block,
576 llvm::iplist<Operation>::iterator iterator) {
581 /// This drops all operand uses from this operation, which is an essential
584 void Operation::dropAllReferences() {
595 /// This drops all uses of any values defined by this operation or its nested
597 void Operation::dropAllDefinedValueUses() {
605 void Operation::setSuccessor(Block *block, unsigned index) {
613 static void checkFoldResultTypes(Operation *op,
631 /// Attempt to fold this operation using the Op's registered foldHook.
632 LogicalResult Operation::fold(ArrayRef<Attribute> operands,
634 // If we have a registered operation definition matching this one, use it to
635 // try to constant fold the operation.
660 LogicalResult Operation::fold(SmallVectorImpl<OpFoldResult> &results) {
671 InFlightDiagnostic Operation::emitOpError(const Twine &message) {
676 // Operation Cloning
679 Operation::CloneOptions::CloneOptions()
682 Operation::CloneOptions::CloneOptions(bool cloneRegions, bool cloneOperands)
685 Operation::CloneOptions Operation::CloneOptions::all() {
689 Operation::CloneOptions &Operation::CloneOptions::cloneRegions(bool enable) {
694 Operation::CloneOptions &Operation::CloneOptions::cloneOperands(bool enable) {
699 /// Create a deep copy of this operation but keep the operation regions empty.
702 /// of the cloned operation should be added to the map.
703 Operation *Operation::cloneWithoutRegions(IRMapping &mapper) {
707 Operation *Operation::cloneWithoutRegions() {
712 /// Create a deep copy of this operation, remapping any operands that use
713 /// values outside of the operation using the map that is provided (leaving
715 /// sub-operations to the corresponding operation that is copied, and adds
717 Operation *Operation::clone(IRMapping &mapper, CloneOptions options) {
733 // Create the new operation.
751 Operation *Operation::clone(CloneOptions options) {
760 // The fallback for the parser is to try for a dialect operation parser.
769 // The fallback for the printer is to try for a dialect operation printer.
771 void OpState::print(Operation *op, OpAsmPrinter &p, StringRef defaultDialect) {
780 /// Print an operation name, eliding the dialect prefix if necessary and doesn't
782 void OpState::printOpName(Operation *op, OpAsmPrinter &p,
824 /// Emit an error about fatal conditions with this operation, reporting up to
836 /// Emit a warning about this operation, reporting up to any diagnostic
842 /// Emit a remark about this operation, reporting up to any diagnostic
853 OpTrait::impl::foldCommutative(Operation *op, ArrayRef<Attribute> operands,
870 OpFoldResult OpTrait::impl::foldIdempotent(Operation *op) {
874 // Replace the outer operation output with the inner operation.
884 OpFoldResult OpTrait::impl::foldInvolution(Operation *op) {
894 LogicalResult OpTrait::impl::verifyZeroOperands(Operation *op) {
900 LogicalResult OpTrait::impl::verifyOneOperand(Operation *op) {
906 LogicalResult OpTrait::impl::verifyNOperands(Operation *op,
915 LogicalResult OpTrait::impl::verifyAtLeastNOperands(Operation *op,
936 LogicalResult OpTrait::impl::verifyIsIdempotent(Operation *op) {
937 // FIXME: Add back check for no side effects on operation.
944 LogicalResult OpTrait::impl::verifyIsInvolution(Operation *op) {
945 // FIXME: Add back check for no side effects on operation.
953 OpTrait::impl::verifyOperandsAreSignlessIntegerLike(Operation *op) {
962 LogicalResult OpTrait::impl::verifyOperandsAreFloatLike(Operation *op) {
971 LogicalResult OpTrait::impl::verifySameTypeOperands(Operation *op) {
984 LogicalResult OpTrait::impl::verifyZeroRegions(Operation *op) {
990 LogicalResult OpTrait::impl::verifyOneRegion(Operation *op) {
996 LogicalResult OpTrait::impl::verifyNRegions(Operation *op,
1003 LogicalResult OpTrait::impl::verifyAtLeastNRegions(Operation *op,
1010 LogicalResult OpTrait::impl::verifyZeroResults(Operation *op) {
1016 LogicalResult OpTrait::impl::verifyOneResult(Operation *op) {
1022 LogicalResult OpTrait::impl::verifyNResults(Operation *op,
1029 LogicalResult OpTrait::impl::verifyAtLeastNResults(Operation *op,
1037 LogicalResult OpTrait::impl::verifySameOperandsShape(Operation *op) {
1047 LogicalResult OpTrait::impl::verifySameOperandsAndResultShape(Operation *op) {
1062 LogicalResult OpTrait::impl::verifySameOperandsElementType(Operation *op) {
1076 OpTrait::impl::verifySameOperandsAndResultElementType(Operation *op) {
1100 LogicalResult OpTrait::impl::verifySameOperandsAndResultType(Operation *op) {
1135 LogicalResult OpTrait::impl::verifySameOperandsAndResultRank(Operation *op) {
1180 LogicalResult OpTrait::impl::verifyIsTerminator(Operation *op) {
1182 // Verify that the operation is at the end of the respective parent block.
1184 return op->emitOpError("must be the last operation in the parent block");
1188 static LogicalResult verifyTerminatorSuccessors(Operation *op) {
1198 LogicalResult OpTrait::impl::verifyZeroSuccessors(Operation *op) {
1206 LogicalResult OpTrait::impl::verifyOneSuccessor(Operation *op) {
1213 LogicalResult OpTrait::impl::verifyNSuccessors(Operation *op,
1222 LogicalResult OpTrait::impl::verifyAtLeastNSuccessors(Operation *op,
1232 LogicalResult OpTrait::impl::verifyResultsAreBoolLike(Operation *op) {
1243 LogicalResult OpTrait::impl::verifyResultsAreFloatLike(Operation *op) {
1252 OpTrait::impl::verifyResultsAreSignlessIntegerLike(Operation *op) {
1259 LogicalResult OpTrait::impl::verifyValueSizeAttr(Operation *op,
1285 LogicalResult OpTrait::impl::verifyOperandSizeAttr(Operation *op,
1290 LogicalResult OpTrait::impl::verifyResultSizeAttr(Operation *op,
1295 LogicalResult OpTrait::impl::verifyNoRegionArguments(Operation *op) {
1310 LogicalResult OpTrait::impl::verifyElementwise(Operation *op) {
1350 /// specified "IsIsolatedFromAbove" operation defined outside of it.
1351 LogicalResult OpTrait::impl::verifyIsIsolatedFromAbove(Operation *isolatedOp) {
1364 for (Operation &op : pendingRegions.pop_back_val()->getOps()) {
1366 // Check that any value that is used by an operation is defined in the
1367 // same region as either an operation result.
1370 return op.emitError("operation's operand is unlinked");
1378 // Schedule any regions in the operation for further checking. Don't
1393 bool OpTrait::hasElementwiseMappableTraits(Operation *op) {
1402 /// Insert an operation, generated by `buildTerminatorOp`, at the end of the
1405 /// terminator operation to insert.
1408 function_ref<Operation *(OpBuilder &, Location)> buildTerminatorOp) {
1425 function_ref<Operation *(OpBuilder &, Location)> buildTerminatorOp) {