14 #ifndef MLIR_IR_OPERATION_SUPPORT_H 15 #define MLIR_IR_OPERATION_SUPPORT_H 23 #include "llvm/ADT/PointerUnion.h" 24 #include "llvm/Support/TrailingObjects.h" 31 struct OperationState;
33 class OpAsmParserResult;
143 return reinterpret_cast<typename T::Concept *
>(
144 getRawInterface(T::getInterfaceID()));
148 template <
template <
typename T>
class Trait>
bool hasTrait()
const {
149 return hasRawTrait(ClassID::getID<Trait>());
161 T::getOperationName(), dialect, T::getOperationProperties(), T::classof,
162 T::parseAssembly, T::printAssembly, T::verifyInvariants, T::foldHook,
163 T::getCanonicalizationPatterns, T::getRawInterface, T::hasTrait);
177 void *(&getRawInterface)(
ClassID *interfaceID),
178 bool (&hasTrait)(
ClassID *traitID))
179 : name(name), dialect(dialect), classof(classof),
180 parseAssembly(parseAssembly), printAssembly(printAssembly),
181 verifyInvariants(verifyInvariants), foldHook(foldHook),
182 getCanonicalizationPatterns(getCanonicalizationPatterns),
183 opProperties(opProperties), getRawInterface(getRawInterface),
184 hasRawTrait(hasTrait) {}
192 void *(&getRawInterface)(
ClassID *interfaceID);
196 bool (&hasRawTrait)(
ClassID *traitID);
212 StringRef getDialect()
const;
215 StringRef getStringRef()
const;
221 void print(raw_ostream &os)
const;
225 return static_cast<void *
>(representation.getOpaqueValue());
232 : representation(representation) {}
236 identifier.
print(os);
273 bool resizableOperandList =
false;
284 bool resizableOperandList =
false);
289 types.append(newTypes.begin(), newTypes.end());
299 attributes.push_back({name, attr});
304 attributes.append(newAttributes.begin(), newAttributes.end());
317 void addRegion(std::unique_ptr<Region> &®ion);
321 resizableOperandList = isResizable;
337 : firstOpAndIsDynamic(opBegin, false), capacity(numOperands) {}
344 if (isStorageDynamic())
345 free(firstOpAndIsDynamic.getPointer());
352 firstOpAndIsDynamic.setPointerAndInt(opBegin,
true);
376 :
private llvm::TrailingObjects<OperandStorage, ResizableStorage,
380 : numOperands(numOperands), resizable(resizable) {
383 new (&getResizableStorage())
390 for (
auto &operand : getOperands())
391 operand.~OpOperand();
395 getResizableStorage().~ResizableStorage();
403 void eraseOperand(
unsigned index);
407 return {getRawOperands(), size()};
411 unsigned size()
const {
return numOperands; }
415 return additionalSizeToAlloc<ResizableStorage, OpOperand>(resizable ? 1 : 0,
424 void clear() { numOperands = 0; }
428 return resizable ? getResizableStorage().getPointer()
429 : getTrailingObjects<OpOperand>();
435 return *getTrailingObjects<ResizableStorage>();
442 unsigned numOperands : 31;
448 friend llvm::TrailingObjects<OperandStorage, ResizableStorage, OpOperand>;
449 size_t numTrailingObjects(OverloadToken<ResizableStorage>)
const {
450 return resizable ? 1 : 0;
484 OpPrintingFlags &elideLargeElementsAttrs(int64_t largeElementLimit = 16);
504 bool shouldPrintDebugInfo()
const;
507 bool shouldPrintDebugInfoPrettyForm()
const;
510 bool shouldPrintGenericOpForm()
const;
513 bool shouldUseLocalScope()
const;
521 bool printDebugInfoFlag : 1;
522 bool printDebugInfoPrettyFormFlag : 1;
525 bool printGenericOpFormFlag : 1;
528 bool printLocalScope : 1;
539 template <
typename ValueIteratorT>
541 :
public llvm::mapped_iterator<ValueIteratorT, Type (*)(Value)> {
552 :
llvm::mapped_iterator<ValueIteratorT,
Type (*)(
Value)>(it, &unwrap) {}
561 Value, Value, Value> {
573 return object + index;
576 static Value dereference_iterator(
OpOperand *
object, ptrdiff_t index) {
577 return object[index].get();
590 OpResult, OpResult> {
594 ResultRange(Operation *op);
602 static OpResult dereference(Operation *op, ptrdiff_t index);
619 : ptr(owner), startIndex(startIndex) {}
642 ValueRange, detail::ValueRangeOwner, Value, Value, Value> {
646 template <
typename Arg,
647 typename =
typename std::enable_if_t<
648 std::is_constructible<ArrayRef<Value>, Arg>::value &&
649 !std::is_convertible<Arg, Value>::value>>
670 static OwnerT offset_base(
const OwnerT &owner, ptrdiff_t index);
672 static Value dereference_iterator(
const OwnerT &owner, ptrdiff_t index);
701 template <>
struct PointerLikeTypeTraits<
mlir::OperationName> {
710 NumLowBitsAvailable = PointerLikeTypeTraits<
void addAttribute(Identifier name, Attribute attr)
Add an attribute with the specified name.
Definition: OperationSupport.h:298
Definition: InferTypeOpInterface.cpp:20
ValueRange(const Value &value)
Definition: OperationSupport.h:651
Definition: STLExtras.h:293
void print(raw_ostream &os) const
Definition: AsmPrinter.cpp:44
~OperandStorage()
Definition: OperationSupport.h:388
Definition: STLExtras.h:95
Definition: PassRegistry.cpp:413
Definition: Operation.h:27
SmallVector< Block *, 1 > successors
Successors of this operation and their respective operands.
Definition: OperationSupport.h:269
MLIRContext * getContext()
Get the context held by this operation state.
Definition: OperationSupport.h:325
static mlir::OperationName getEmptyKey()
Definition: OperationSupport.h:682
void * getAsOpaquePointer() const
Definition: OperationSupport.h:224
This is a value defined by a result of an operation.
Definition: Value.h:287
Definition: Attributes.h:139
ValueTypeIterator(ValueIteratorT it)
Initializes the type iterator to the specified value iterator.
Definition: OperationSupport.h:551
Block represents an ordered list of Operations.
Definition: Block.h:21
~ResizableStorage()
Definition: OperationSupport.h:339
bool operator==(const ValueRangeOwner &rhs) const
Definition: OperationSupport.h:620
bool operator!=(IntInfty lhs, IntInfty rhs)
Definition: SDBM.h:94
static Identifier get(StringRef str, MLIRContext *context)
Return an identifier for the specified string.
Definition: MLIRContext.cpp:426
Definition: Identifier.h:26
static OperationName getFromOpaquePointer(void *pointer)
Definition: Operation.cpp:62
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
Definition: OpImplementation.h:214
ValueRangeOwner(OpOperand *owner)
Definition: OperationSupport.h:617
PointerUnion< const Value *, OpOperand *, void * > ptr
Definition: OperationSupport.h:628
ValueRangeOwner(const Value *owner)
Definition: OperationSupport.h:616
bool isStorageDynamic() const
Definition: OperationSupport.h:360
SmallVector< Value, 4 > operands
Definition: OperationSupport.h:264
Definition: Location.h:52
Definition: STLExtras.h:196
bool hasProperty(OperationProperty property) const
Returns whether the operation has a particular property.
Definition: OperationSupport.h:135
ResizableStorage(OpOperand *opBegin, unsigned numOperands)
Definition: OperationSupport.h:336
Location location
Definition: OperationSupport.h:262
This class implements iteration on the types of a given range of values.
Definition: OperationSupport.h:540
Definition: LogicalResult.h:18
static unsigned getHashValue(mlir::OperationName Val)
Definition: OperationSupport.h:690
llvm::PointerIntPair< OpOperand *, 1, bool > firstOpAndIsDynamic
Definition: OperationSupport.h:364
void cleanupStorage()
Cleanup any allocated storage.
Definition: OperationSupport.h:342
Type getType() const
Return the type of this value.
Definition: Value.cpp:34
static mlir::OperationName getFromVoidPointer(void *P)
Definition: OperationSupport.h:706
MLIRContext * getContext() const
Return the context this attribute belongs to.
Definition: Attributes.cpp:46
static void * getAsVoidPointer(mlir::OperationName I)
Definition: OperationSupport.h:703
OperationName(AbstractOperation *op)
Definition: OperationSupport.h:208
Definition: Attributes.h:53
iterator_range< type_iterator > getTypes() const
Definition: OperationSupport.h:598
void addAttributes(ArrayRef< NamedAttribute > newAttributes)
Add an array of named attributes.
Definition: OperationSupport.h:303
Type operator*() const
Provide a const dereference method.
Definition: OperationSupport.h:548
T::Concept * getInterface() const
Definition: OperationSupport.h:142
void addTypes(ArrayRef< Type > newTypes)
Definition: OperationSupport.h:288
Definition: OperationSupport.h:83
Definition: OpImplementation.h:32
static bool isEqual(mlir::OperationName LHS, mlir::OperationName RHS)
Definition: OperationSupport.h:693
ValueRangeOwner(Operation *owner, unsigned startIndex)
Definition: OperationSupport.h:618
This class provides the implementation for a trailing operation result.
Definition: OperationSupport.h:461
Definition: OperationSupport.h:261
static size_t additionalAllocSize(unsigned numOperands, bool resizable)
Returns the additional size necessary for allocating this object.
Definition: OperationSupport.h:414
unsigned size() const
Return the number of operands held in the storage.
Definition: OperationSupport.h:411
void setOperandListToResizable(bool isResizable=true)
Sets the operand list of the operation as resizable.
Definition: OperationSupport.h:320
ValueRange(iterator_range< ResultRange::iterator > values)
Definition: OperationSupport.h:656
bool operator==(IntInfty lhs, IntInfty rhs)
Definition: SDBM.h:90
bool hasTrait() const
Returns if the operation has a particular trait.
Definition: OperationSupport.h:148
uint32_t OperationProperties
Definition: OperationSupport.h:85
unsigned capacity
Definition: OperationSupport.h:367
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
Definition: OperationSupport.h:293
ValueRange(iterator_range< OperandRange::iterator > values)
Definition: OperationSupport.h:654
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:201
OperationName name
Definition: OperationSupport.h:263
ValueRange(Arg &&arg)
Definition: OperationSupport.h:650
Definition: OperationSupport.h:474
Definition: PatternMatch.h:418
iterator_range< type_iterator > getTypes() const
Definition: OperationSupport.h:664
Definition: OperationSupport.h:615
Definition: MLIRContext.h:34
void print(OpAsmPrinter &p, AffineIfOp op)
Definition: AffineOps.cpp:1671
A reference to a value, suitable for use as an operand of an operation.
Definition: UseDefLists.h:330
This class implements the operand iterators for the Operation class.
Definition: OperationSupport.h:559
OpOperand * getPointer()
Returns the current storage pointer.
Definition: OperationSupport.h:356
const StringRef name
This is the name of the operation.
Definition: OperationSupport.h:88
Definition: StandardTypes.h:63
Dialect & dialect
This is the dialect that this operation belongs to.
Definition: OperationSupport.h:91
OperationProperty
Definition: OperationSupport.h:58
MutableArrayRef< OpOperand > getOperands()
Get the operation operands held by the storage.
Definition: OperationSupport.h:406
llvm::hash_code hash_value(OperationName arg)
Definition: OperationSupport.h:249
typename OpTy::OperandAdaptor OperandAdaptor
Definition: OperationSupport.h:50
SmallVector< std::unique_ptr< Region >, 1 > regions
Regions that the op will hold.
Definition: OperationSupport.h:271
raw_ostream & operator<<(raw_ostream &os, SubViewOp::Range &range)
Definition: Ops.cpp:2759
uint64_t trailingResultNumber
Definition: OperationSupport.h:464
ValueRange(const std::initializer_list< Value > &values)
Definition: OperationSupport.h:652
unsigned startIndex
Ths start index into the range. This is only used for Operation* owners.
Definition: OperationSupport.h:631
Definition: OpDefinition.h:36
SmallVector< NamedAttribute, 4 > attributes
Definition: OperationSupport.h:267
Definition: OperationSupport.h:203
Definition: Attributes.h:559
static mlir::OperationName getTombstoneKey()
Definition: OperationSupport.h:686
Definition: OperationSupport.h:640
OperandStorage(unsigned numOperands, bool resizable)
Definition: OperationSupport.h:379
iterator_range< type_iterator > getTypes() const
Definition: OperationSupport.h:568
OpPrintingFlags(llvm::NoneType)
Definition: OperationSupport.h:477
Definition: OperationSupport.h:335
SmallVector< Type, 4 > types
Types of the results of this operation.
Definition: OperationSupport.h:266
void setDynamicStorage(OpOperand *opBegin)
Sets the storage pointer to a new dynamically allocated block.
Definition: OperationSupport.h:349
Definition: OperationSupport.h:375