Lines Matching full:operation
1 //===- Operation.h - MLIR Operation Class -----------------------*- C++ -*-===//
9 // This file defines the Operation class.
31 /// Operation is the basic unit of execution within MLIR.
37 /// An Operation is defined first by its name, which is a unique string. The
39 /// is the dialect name this operation belongs to, and everything that follows
40 /// is this operation name within the dialect.
42 /// An Operation defines zero or more SSA `Value` that we refer to as the
43 /// Operation results. This array of Value is actually stored in memory before
44 /// the Operation itself in reverse order. That is for an Operation with 3
47 /// [Result2, Result1, Result0, Operation]
48 /// ^ this is where `Operation*` pointer points to.
63 /// An Operation also has zero or more operands: these are uses of SSA Value,
66 /// tail allocated with the operation class itself, but can be dynamically moved
69 /// An Operation may contain optionally one or multiple Regions, stored in a
76 /// An Operation may contain optionally a "Properties" object: this is a
78 /// operation and deleted with the operation. It can be converted to an
82 /// Finally an Operation also contain an optional `DictionaryAttr`, a Location,
84 class alignas(8) Operation final
85 : public llvm::ilist_node_with_parent<Operation, Block>,
86 private llvm::TrailingObjects<Operation, detail::OperandStorage,
90 /// Create a new Operation with the specific fields. This constructor
93 static Operation *create(Location location, OperationName name,
99 /// Create a new Operation with the specific fields. This constructor uses an
101 static Operation *create(Location location, OperationName name,
107 /// Create a new Operation from the fields stored in `state`.
108 static Operation *create(const OperationState &state);
110 /// Create a new Operation with the specific fields.
111 static Operation *create(Location location, OperationName name,
118 /// The name of an operation is the key identifier for it.
121 /// If this operation has a registered operation description, return it.
127 /// Returns true if this operation has a registered operation description,
131 /// Remove this operation from its parent block and delete it.
134 /// Remove the operation from its parent block, but don't delete it.
137 /// Class encompassing various options related to cloning an operation. Users
138 /// of this class should pass it to Operation's 'clone' methods.
141 /// operation or not.
142 /// * Whether cloning should also clone the operands of the operation.
146 /// parts of an operation that may optionally not be cloned, are not cloned.
154 /// when using the clone method and clones all parts of the operation.
158 /// the operation. If set to true, the operation's regions are recursively
161 /// Cloning of nested operations in the operation's regions are currently
165 /// Returns whether regions of the operation should be cloned as well.
168 /// Configures whether operation' operands should be cloned. Otherwise the
182 /// Create a deep copy of this operation, remapping any operands that use
183 /// values outside of the operation using the map that is provided (leaving
185 /// sub-operations to the corresponding operation that is copied, and adds
187 /// Optionally, one may configure what parts of the operation to clone using
191 /// process of cloning no new uses of 'Value's from outside the operation are
192 /// created. Cloning an isolated-from-above operation with no operands, such
196 Operation *clone(IRMapping &mapper,
198 Operation *clone(CloneOptions options = CloneOptions::all());
200 /// Create a partial copy of this operation without traversing into attached
201 /// regions. The new operation will have the same number of regions as the
205 Operation *cloneWithoutRegions(IRMapping &mapper);
207 /// Create a partial copy of this operation without traversing into attached
208 /// regions. The new operation will have the same number of regions as the
210 Operation *cloneWithoutRegions();
212 /// Returns the operation block that contains this operation.
215 /// Return the context this operation is associated with.
218 /// Return the dialect this operation is associated with, or nullptr if the
222 /// The source location the operation was defined or derived from.
225 /// Set the source location the operation was defined or derived from.
232 /// Returns the closest surrounding operation that contains this operation
233 /// or nullptr if this is a top-level operation.
234 Operation *getParentOp() { return block ? block->getParentOp() : nullptr; }
236 /// Return the closest surrounding parent operation that is of type 'OpTy'.
246 /// Returns the closest surrounding parent operation with trait `Trait`.
248 Operation *getParentWithTrait() {
249 Operation *op = this;
256 /// Return true if this operation is a proper ancestor of the `other`
257 /// operation.
258 bool isProperAncestor(Operation *other);
260 /// Return true if this operation is an ancestor of the `other` operation. An
261 /// operation is considered as its own ancestor, use `isProperAncestor` to
263 bool isAncestor(Operation *other) {
267 /// Replace any uses of 'from' with 'to' within this operation.
270 /// Replace all uses of results of this operation with the provided 'values'.
276 /// Replace uses of results of this operation with the provided `values` if
285 /// Destroys this operation and its subclass data.
288 /// This drops all operand uses from this operation, which is an essential
293 /// Drop uses of all values defined by this operation or its nested regions.
296 /// Unlink this operation from its current block and insert it right before
299 void moveBefore(Operation *existingOp);
301 /// Unlink this operation from its current block and insert it right before
303 void moveBefore(Block *block, llvm::iplist<Operation>::iterator iterator);
305 /// Unlink this operation from its current block and insert it right after
308 void moveAfter(Operation *existingOp);
310 /// Unlink this operation from its current block and insert it right after
312 void moveAfter(Block *block, llvm::iplist<Operation>::iterator iterator);
314 /// Given an operation 'other' that is within the same parent block, return
315 /// whether the current operation is before 'other' in the operation list
319 bool isBeforeInBlock(Operation *other);
326 // the Operation is not verified because it won't disable custom printers to
334 /// Replace the current operands of this operation with the ones provided in
403 /// Return the number of results held by this operation.
406 /// Get the 'idx'th result of this operation.
436 // the lifetime of an operation.
483 /// Return a range of all of discardable attributes on this operation. Note
499 /// Return all of the discardable attributes on this operation as a
511 /// Return all of the attributes on this operation.
514 /// Return all of the attributes on this operation as a DictionaryAttr.
517 /// Set the attributes from a dictionary on this operation.
522 /// Set the discardable attribute dictionary on this operation.
558 /// Return true if the operation has an attribute with the provided name,
632 friend Operation;
636 /// Return a range corresponding to the dialect attributes for this operation.
651 /// Set the dialect attributes for this operation, and preserve all inherent.
673 /// Returns the number of regions held by this operation.
676 /// Returns the regions held by this operation.
686 /// Returns the region held by this operation at position 'index'.
719 /// Attempt to fold this operation with the specified constant operand values
721 /// the operation, but may be null if non-constant.
724 /// * If this operation was modified in-place (but not folded away),
731 /// Attempt to fold this operation.
734 /// * If this operation was modified in-place (but not folded away),
747 /// Returns true if the operation was registered with a particular trait, e.g.
754 /// Returns true if the operation *might* have the provided trait. This
755 /// means that either the operation is unregistered, or it was registered with
763 // Operation Walkers
766 /// Walk the operation by calling the callback for each nested operation
772 /// (post-order by default). A callback on a block or operation is allowed to
773 /// erase that block or operation if either:
778 /// void(Operation*) : Walk all operations opaquely.
779 /// * op->walk([](Operation *nestedOp) { ...});
782 /// WalkResult(Operation*|OpT) : Walk operations, but allow for
802 /// Generic walker with a stage aware callback. Walk the operation by calling
803 /// the callback for each nested operation (including this one) N+1 times,
804 /// where N is the number of regions attached to that operation.
807 /// void(Operation *, const WalkStage &) : Walk all operation opaquely
808 /// * op->walk([](Operation *nestedOp, const WalkStage &stage) { ...});
812 /// WalkResult(Operation*|OpT, const WalkStage &stage) : Walk operations,
834 /// Drop all uses of results of this operation.
849 /// Returns true if this operation has exactly one use.
852 /// Returns true if this operation has no uses.
855 /// Returns true if the results of this operation are used outside of the
884 /// Emit an error about fatal conditions with this operation, reporting up to
888 /// Emit a warning about this operation, reporting up to any diagnostic
892 /// Emit a remark about this operation, reporting up to any diagnostic
921 /// operation. Returns an empty attribute if no properties are present.
925 /// This is an expensive operation that can fail if the attribute is not
926 /// matching the expectations of the properties for this operation. This is
946 /// This value represents an invalid index ordering for an operation within a
951 /// operation.
954 /// Update the order index of this operation of this operation if necessary,
958 /// Returns true if this operation has a valid order.
962 Operation(Location location, OperationName name, unsigned numResults,
969 ~Operation();
972 /// before an Operation in-memory.
978 /// Returns the additional size allocated before this Operation in-memory.
988 assert(hasOperandStorage && "expected operation to have operand storage");
1003 // Inline results are stored in reverse order before the operation in
1012 "Result number is out of range for operation");
1039 /// The operation block that contains this operation.
1042 /// This holds information about the source location the operation was defined
1046 /// Relative order of this operation in its parent block. Used for
1054 /// This bit signals whether this operation has an operand storage or not. The
1064 /// operation: this must match the bitwidth above.
1067 /// This holds the name of the operation.
1070 /// This holds general named attributes for the operation.
1074 friend struct llvm::ilist_traits<Operation>;
1083 friend class llvm::ilist_node_with_parent<Operation, Block>;
1086 friend llvm::TrailingObjects<Operation, detail::OperandStorage,
1101 inline raw_ostream &operator<<(raw_ostream &os, const Operation &op) {
1102 const_cast<Operation &>(op).print(os, OpPrintingFlags().useLocalScope());
1109 /// Cast from an (const) Operation * to a derived operation type.
1111 struct CastInfo<T, ::mlir::Operation *>
1112 : public ValueFromPointerCast<T, ::mlir::Operation,
1113 CastInfo<T, ::mlir::Operation *>> {
1114 static bool isPossible(::mlir::Operation *op) { return T::classof(op); }
1117 struct CastInfo<T, const ::mlir::Operation *>
1118 : public ConstStrippingForwardingCast<T, const ::mlir::Operation *,
1119 CastInfo<T, ::mlir::Operation *>> {};
1121 /// Cast from an (const) Operation & to a derived operation type.
1123 struct CastInfo<T, ::mlir::Operation>
1125 public DefaultDoCastIfPossible<T, ::mlir::Operation &,
1126 CastInfo<T, ::mlir::Operation>> {
1129 static bool isPossible(::mlir::Operation &val) { return T::classof(&val); }
1130 static T doCast(::mlir::Operation &val) { return T(&val); }
1133 struct CastInfo<T, const ::mlir::Operation>
1134 : public ConstStrippingForwardingCast<T, const ::mlir::Operation,
1135 CastInfo<T, ::mlir::Operation>> {};
1137 /// Cast (const) Operation * to itself. This is helpful to avoid SFINAE in
1139 /// operation types.
1141 struct CastInfo<::mlir::Operation *, ::mlir::Operation *>
1142 : public NullableValueCastFailed<::mlir::Operation *>,
1144 ::mlir::Operation *, ::mlir::Operation *,
1145 CastInfo<::mlir::Operation *, ::mlir::Operation *>> {
1146 static bool isPossible(::mlir::Operation *op) { return true; }
1147 static ::mlir::Operation *doCast(::mlir::Operation *op) { return op; }
1150 struct CastInfo<const ::mlir::Operation *, const ::mlir::Operation *>
1152 const ::mlir::Operation *, const ::mlir::Operation *,
1153 CastInfo<::mlir::Operation *, ::mlir::Operation *>> {};