13 #ifndef MLIR_IR_OPERATION_H 14 #define MLIR_IR_OPERATION_H 20 #include "llvm/ADT/Twine.h" 29 public llvm::ilist_node_with_parent<Operation, Block>,
30 private llvm::TrailingObjects<Operation, detail::TrailingOpResult,
32 detail::OperandStorage> {
39 bool resizableOperandList);
47 bool resizableOperandList);
58 bool resizableOperandList =
false);
123 while ((op = op->getParentOp()))
124 if (
auto parentOp = dyn_cast<OpTy>(op))
144 template <
typename ValuesT,
145 typename = decltype(std::declval<ValuesT>().begin())>
147 assert(std::distance(values.begin(), values.end()) ==
getNumResults() &&
148 "expected 'values' to correspond 1-1 with the number of results");
150 auto valueIt = values.begin();
180 void moveBefore(
Block *block, llvm::iplist<Operation>::iterator iterator);
307 return attrs.
remove(name);
312 :
public llvm::filter_iterator<ArrayRef<NamedAttribute>::iterator,
313 bool (*)(NamedAttribute)> {
316 return attr.first.strref().count(
'.');
321 : llvm::filter_iterator<ArrayRef<NamedAttribute>::iterator,
345 template <
typename DialectAttrT>
348 attrs.assign(std::begin(dialectAttrs), std::end(dialectAttrs));
350 if (!attr.first.strref().count(
'.'))
351 attrs.push_back(attr);
352 setAttrs(llvm::makeArrayRef(attrs));
364 auto *regions = getTrailingObjects<Region>();
365 return {regions, numRegions};
370 assert(index < numRegions &&
"invalid region index");
379 return {getTrailingObjects<BlockOperand>(), numSuccs};
439 if (!decomposed.hasValue())
505 template <
template <
typename T>
class Trait>
bool hasTrait() {
507 return absOp ? absOp->hasTrait<Trait>() :
false;
529 template <
typename FnT,
typename RetT = detail::walkResultType<FnT>>
561 static constexpr
unsigned kInvalidOrderIdx = -1;
565 static constexpr
unsigned kOrderStride = 5;
569 void updateOrderIfNecessary();
572 bool hasValidOrder() {
return orderIndex != kInvalidOrderIdx; }
576 unsigned numSuccessors,
unsigned numRegions,
585 return *getTrailingObjects<detail::OperandStorage>();
593 return getTrailingObjects<detail::TrailingOpResult>() +
594 trailingResultNumber;
602 Block *getParent()
const {
return block; }
605 Block *block =
nullptr;
613 mutable unsigned orderIndex = 0;
615 const unsigned numSuccs;
616 const unsigned numRegions : 31;
625 bool hasSingleResult : 1;
649 size_t numTrailingObjects(OverloadToken<detail::TrailingOpResult>)
const {
650 return OpResult::getNumTrailing(
653 size_t numTrailingObjects(OverloadToken<BlockOperand>)
const {
656 size_t numTrailingObjects(OverloadToken<Region>)
const {
return numRegions; }
659 inline raw_ostream &
operator<<(raw_ostream &os, Operation &op) {
669 static inline bool doit(const ::mlir::Operation &op) {
670 return T::classof(const_cast<::mlir::Operation *>(&op));
692 #endif // MLIR_IR_OPERATION_H NamedAttributeList::RemoveResult removeAttr(Identifier name)
Definition: Operation.h:306
operand_range::iterator operand_iterator
Definition: Operation.h:214
void moveBefore(Operation *existingOp)
Definition: Operation.cpp:511
AttrClass getAttrOfType(Identifier name)
Definition: Operation.h:289
Definition: InferTypeOpInterface.cpp:20
void setAttr(Identifier name, Attribute value)
Definition: Operation.h:299
TerminatorStatus getTerminatorStatus()
Returns the status of whether this operation is a terminator or not.
Definition: Operation.h:468
Attribute getAttr(Identifier name)
Return the specified attribute if present, null otherwise.
Definition: Operation.h:286
bool hasSuccessors()
Definition: Operation.h:399
void eraseOperand(unsigned index)
Erase an operand held by the storage.
Definition: OperationSupport.cpp:107
U dyn_cast_or_null() const
Definition: Attributes.h:1350
Definition: PassRegistry.cpp:413
Definition: Operation.h:27
operand_range getSuccessorOperands(unsigned index)
Definition: Operation.cpp:597
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition: Operation.h:363
bool isAncestor(Operation *other)
Definition: Operation.h:136
This is a value defined by a result of an operation.
Definition: Value.h:287
operand_range getOperands()
Returns an iterator on the underlying Value's (Value ).
Definition: Operation.h:220
unsigned getNumRegions()
Returns the number of regions held by this operation.
Definition: Operation.h:360
Definition: Diagnostics.h:320
void setOperands(ValueRange operands)
Definition: Operation.cpp:290
Block represents an ordered list of Operations.
Definition: Block.h:21
TerminatorStatus
Definition: Operation.h:465
void replaceAllUsesWith(Value newValue) const
Definition: Value.cpp:111
void set(Value value)
Set the operand to the given value.
Definition: Value.cpp:212
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
Definition: Operation.h:275
Value getOperand(unsigned idx)
Definition: Operation.h:207
Dialect * getDialect()
Definition: Operation.cpp:252
unsigned getNumOperands()
Definition: Operation.h:205
static Identifier get(StringRef str, MLIRContext *context)
Return an identifier for the specified string.
Definition: MLIRContext.cpp:426
Definition: Identifier.h:26
Terminator operations can have Block operands to represent successors.
Definition: UseDefLists.h:288
operand_type_range getOperandTypes()
Definition: Operation.h:236
bool isBeforeInBlock(Operation *other)
Definition: Operation.cpp:348
This class implements the result iterators for the Operation class.
Definition: OperationSupport.h:588
bool isResizable() const
Returns if this storage is resizable.
Definition: OperationSupport.h:420
unsigned getNumSuccessors()
Definition: Operation.h:400
bool isRegistered()
Definition: Operation.h:71
Block * getBlock()
Returns the operation block that contains this operation.
Definition: Operation.h:97
MLIRContext * getContext()
Return the context this operation is associated with.
Definition: Operation.cpp:248
void destroy()
Destroys this operation and its subclass data.
Definition: Operation.cpp:242
BlockArgument getArgument(unsigned i)
Definition: Block.h:96
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Definition: Operation.h:121
void replaceAllUsesWith(Operation *op)
Replace all uses of results of this operation with results of 'op'.
Definition: Operation.h:156
void erase()
Remove this operation from its parent block and delete it.
Definition: Operation.cpp:501
void setSuccessor(Block *block, unsigned index)
Definition: Operation.cpp:554
Definition: Location.h:52
std::pair< Identifier, Attribute > NamedAttribute
Definition: Attributes.h:264
operand_range getNonSuccessorOperands()
Return the operands of this operation that are not successor arguments.
Definition: Operation.cpp:559
unsigned getNumResults()
Return the number of results held by this operation.
Definition: Operation.cpp:548
MutableArrayRef< OpOperand > getOpOperands()
Definition: Operation.h:225
AttrClass getAttrOfType(StringRef name)
Definition: Operation.h:293
RemoveResult remove(Identifier name)
Definition: Attributes.cpp:1082
This class implements iteration on the types of a given range of values.
Definition: OperationSupport.h:540
bool hasNoSideEffect()
Returns whether the operation has side-effects.
Definition: Operation.h:456
Definition: LogicalResult.h:18
succ_iterator successor_end()
Definition: Operation.h:385
Operation * clone()
Definition: Operation.cpp:702
Block * getSuccessor(unsigned index)
Definition: Operation.h:407
bool hasResizableOperandsList()
Definition: Operation.h:198
dialect_attr_iterator dialect_attr_begin()
Definition: Operation.h:335
SuccessorRange::iterator succ_iterator
Definition: Operation.h:383
static T doit(::mlir::Operation &val)
Definition: Operation.h:684
void setAttrs(NamedAttributeList newAttrs)
Definition: Operation.h:283
Region * getParentRegion()
Definition: Operation.cpp:261
Definition: Attributes.h:53
dialect_attr_iterator dialect_attr_end()
Definition: Operation.h:339
iterator_range< type_iterator > getTypes() const
Definition: OperationSupport.h:598
bool hasTrait()
Definition: Operation.h:505
T ret_type
Definition: Operation.h:680
Attribute get(StringRef name) const
Return the specified attribute if present, null otherwise.
Definition: Attributes.cpp:1051
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Definition: Operation.h:246
succ_iterator successor_begin()
Definition: Operation.h:384
Definition: OperationSupport.h:83
iterator begin() const
Definition: STLExtras.h:228
void walkOperations(Operation *op, function_ref< void(Operation *op)> callback)
Walk all of the operations nested under and including the given operation.
Definition: Visitors.cpp:15
This class provides the implementation for a trailing operation result.
Definition: OperationSupport.h:461
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:107
Definition: OperationSupport.h:261
MutableArrayRef< BlockOperand > getBlockOperands()
Definition: Operation.h:378
unsigned size() const
Return the number of operands held in the storage.
Definition: OperationSupport.h:411
Definition: Attributes.h:1374
result_type_iterator result_type_end()
Definition: Operation.h:263
void dropAllDefinedValueUses()
Drop uses of all values defined by this operation or its nested regions.
Definition: Operation.cpp:539
InFlightDiagnostic emitWarning(const Twine &message={})
Definition: Operation.cpp:320
operand_type_iterator operand_type_begin()
Definition: Operation.h:234
ArrayRef< NamedAttribute > getAttrs() const
Return all of the attributes on this operation.
Definition: Attributes.cpp:1037
InFlightDiagnostic emitRemark(const Twine &message={})
Definition: Operation.cpp:329
bool isKnownNonTerminator()
Returns if the operation is known to not be a terminator.
Definition: Operation.h:483
result_range getOpResults()
Definition: Operation.h:256
void setOperand(unsigned idx, Value value)
Definition: Operation.h:208
This class implements the successor iterators for Block.
Definition: BlockSupport.h:56
void replaceAllUsesWith(ValuesT &&values)
Replace all uses of results of this operation with the provided 'values'.
Definition: Operation.h:146
bool isCommutative()
Returns whether the operation is commutative.
Definition: Operation.h:449
ValueTypeIterator< iterator > type_iterator
Returns the types of the values within this range.
Definition: OperationSupport.h:567
void print(raw_ostream &os, OpPrintingFlags flags=llvm::None)
Definition: AsmPrinter.cpp:2122
Definition: BlockAndValueMapping.h:26
operand_type_iterator operand_type_end()
Definition: Operation.h:235
static Operation * create(Location location, OperationName name, ArrayRef< Type > resultTypes, ArrayRef< Value > operands, ArrayRef< NamedAttribute > attributes, ArrayRef< Block *> successors, unsigned numRegions, bool resizableOperandList)
Create a new Operation with the specific fields.
Definition: Operation.cpp:71
void eraseOperand(unsigned idx)
Erase the operand at position idx.
Definition: Operation.h:223
void dropAllReferences()
Definition: Operation.cpp:526
operand_iterator operand_begin()
Definition: Operation.h:216
Optional< std::pair< unsigned, unsigned > > decomposeSuccessorOperandIndex(unsigned operandIndex)
Definition: Operation.cpp:583
SuccessorRange getSuccessors()
Definition: Operation.h:386
Definition: OperationSupport.h:474
result_iterator result_end()
Definition: Operation.h:253
void setAttr(StringRef name, Attribute value)
Definition: Operation.h:300
iterator end() const
Definition: STLExtras.h:229
result_type_iterator result_type_begin()
Definition: Operation.h:262
void setLoc(Location loc)
Set the source location the operation was defined or derived from.
Definition: Operation.h:110
A utility iterator that filters out non-dialect attributes.
Definition: Operation.h:311
OperandRange operand_range
Definition: Operation.h:213
ValueTypeIterator< iterator > type_iterator
Returns the types of the values within this range.
Definition: OperationSupport.h:597
OpOperand & getOpOperand(unsigned idx)
Definition: Operation.h:229
Definition: UseDefLists.h:109
OpResult getOpResult(unsigned idx)
Definition: Operation.h:257
T ret_type
Definition: Operation.h:677
Definition: MLIRContext.h:34
Operation * getParentOp()
Definition: Operation.cpp:265
A reference to a value, suitable for use as an operand of an operation.
Definition: UseDefLists.h:330
unsigned getSuccessorOperandIndex(unsigned index)
Definition: Operation.cpp:566
void setDialectAttrs(DialectAttrT &&dialectAttrs)
Set the dialect attributes for this operation, and preserve all dependent.
Definition: Operation.h:346
Value get() const
Return the current value being used by this operand.
Definition: Value.cpp:207
This class implements the operand iterators for the Operation class.
Definition: OperationSupport.h:559
Optional< BlockArgument > getSuccessorBlockArgument(unsigned operandIndex)
Definition: Operation.h:437
result_range::iterator result_iterator
Definition: Operation.h:250
bool isKnownTerminator()
Returns if the operation is known to be a terminator.
Definition: Operation.h:478
Attribute getAttr(StringRef name)
Definition: Operation.h:287
LogicalResult fold(ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
Attempt to fold this operation using the Op's registered foldHook.
Definition: Operation.cpp:603
Definition: StandardTypes.h:63
RemoveResult
Definition: Attributes.h:1405
Value getSuccessorOperand(unsigned succIndex, unsigned opIndex)
Definition: Operation.h:393
dialect_attr_range getDialectAttrs()
Return a range corresponding to the dialect attributes for this operation.
Definition: Operation.h:330
ResultRange result_range
Support result iteration.
Definition: Operation.h:249
MutableArrayRef< OpOperand > getOperands()
Get the operation operands held by the storage.
Definition: OperationSupport.h:406
unsigned getNumSuccessorOperands(unsigned index)
Definition: Operation.h:401
static bool doit(const ::mlir::Operation &op)
Definition: Operation.h:669
raw_ostream & operator<<(raw_ostream &os, SubViewOp::Range &range)
Definition: Ops.cpp:2759
bool isKnownIsolatedFromAbove()
Definition: Operation.h:490
operand_iterator operand_end()
Definition: Operation.h:217
InFlightDiagnostic emitOpError(const Twine &message={})
Definition: Operation.cpp:625
OperationName getName()
The name of an operation is the key identifier for it.
Definition: Operation.h:61
const AbstractOperation * getAbstractOperation() const
Definition: Operation.cpp:58
void dump()
Definition: AsmPrinter.cpp:2146
InFlightDiagnostic emitError(const Twine &message={})
Definition: Operation.cpp:300
void set(Identifier name, Attribute value)
Definition: Attributes.cpp:1062
void replaceUsesOfWith(Value from, Value to)
Replace any uses of 'from' with 'to' within this operation.
Definition: Operation.cpp:279
Definition: OperationSupport.h:203
result_range getResults()
Definition: Operation.h:254
Definition: OperationSupport.h:640
result_type_range getResultTypes()
Definition: Operation.h:264
static T doit(::mlir::Operation *val)
Definition: Operation.h:688
iterator_range< type_iterator > getTypes() const
Definition: OperationSupport.h:568
bool isProperAncestor(Operation *other)
Definition: Operation.cpp:271
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
Definition: Operation.h:369
result_iterator result_begin()
Definition: Operation.h:252
RetT walk(FnT &&callback)
Definition: Operation.h:530
NamedAttributeList & getAttrList()
Return the internal attribute list on this operation.
Definition: Operation.h:278
Operation * cloneWithoutRegions()
Definition: Operation.cpp:682
void eraseSuccessorOperand(unsigned succIndex, unsigned opIndex)
Definition: Operation.h:415
const AbstractOperation * getAbstractOperation()
Definition: Operation.h:65
Definition: OperationSupport.h:375