13 #ifndef MLIR_IR_VALUERANGE_H
14 #define MLIR_IR_VALUERANGE_H
19 #include "llvm/ADT/PointerUnion.h"
20 #include "llvm/ADT/Sequence.h"
25 template <
typename ValueRangeT>
28 template <
typename ValueIteratorT>
29 class ValueTypeIterator;
30 class OperandRangeRange;
31 class MutableOperandRangeRange;
42 OperandRange, OpOperand *, Value, Value, Value> {
44 using RangeBaseT::RangeBaseT;
63 return object + index;
66 static Value dereference_iterator(
OpOperand *
object, ptrdiff_t index) {
67 return object[index].get();
80 :
public llvm::indexed_accessor_range<
81 OperandRangeRange, std::pair<OpOperand *, Attribute>, OperandRange,
82 OperandRange, OperandRange> {
83 using OwnerT = std::pair<OpOperand *, Attribute>;
89 using RangeBaseT::RangeBaseT;
104 static OperandRange dereference(
const OwnerT &
object, ptrdiff_t index);
134 slice(
unsigned subStart,
unsigned subLen,
135 std::optional<OperandSegment> segment = std::nullopt)
const;
147 void erase(
unsigned subStart,
unsigned subLen = 1);
153 unsigned size()
const {
return length; }
183 void updateLength(
unsigned newLength);
190 unsigned start, length;
203 :
public llvm::indexed_accessor_range<
204 MutableOperandRangeRange,
205 std::pair<MutableOperandRange, NamedAttribute>, MutableOperandRange,
206 MutableOperandRange, MutableOperandRange> {
207 using OwnerT = std::pair<MutableOperandRange, NamedAttribute>;
214 using RangeBaseT::RangeBaseT;
242 ResultRange, detail::OpResultImpl *, OpResult, OpResult, OpResult> {
244 using RangeBaseT::RangeBaseT;
273 return llvm::all_of(*
this,
279 template <
typename ValuesT>
280 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
282 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
284 "expected 'values' to correspond 1-1 with the number of results");
286 for (
auto it : llvm::zip(*
this, values))
287 std::get<0>(it).replaceAllUsesWith(std::get<1>(it));
296 template <
typename ValuesT>
297 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
300 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
302 "expected 'values' to correspond 1-1 with the number of results");
304 for (
auto it : llvm::zip(*
this, values))
305 std::get<0>(it).replaceUsesWithIf(std::get<1>(it), shouldReplace);
334 return offset_base(
object, index);
344 :
public llvm::iterator_facade_base<UseIterator, std::forward_iterator_tag,
351 using llvm::iterator_facade_base<
UseIterator, std::forward_iterator_tag,
361 void skipOverResultsWithNoUsers();
364 ResultRange::iterator it, endIt;
380 PointerUnion<const Value *, OpOperand *, detail::OpResultImpl *>,
381 Value, Value, Value> {
388 using RangeBaseT::RangeBaseT;
390 template <
typename Arg,
391 typename = std::enable_if_t<
392 std::is_constructible<ArrayRef<Value>, Arg>::value &&
393 !std::is_convertible<Arg, Value>::value>>
416 static OwnerT offset_base(
const OwnerT &owner, ptrdiff_t index);
418 static Value dereference_iterator(
const OwnerT &owner, ptrdiff_t index);
Attributes are known-constant values of operations.
This class represents a contiguous range of mutable operand ranges, e.g.
MutableOperandRange join() const
Flatten all of the sub ranges into a single contiguous mutable operand range.
MutableOperandRangeRange(const MutableOperandRange &operands, NamedAttribute operandSegmentAttr)
Construct a range given a parent set of operands, and an I32 tensor elements attribute containing the...
This class provides a mutable adaptor for a range of operands.
unsigned size() const
Returns the current size of the range.
OperandRange getAsOperandRange() const
Explicit conversion to an OperandRange.
void assign(ValueRange values)
Assign this range to the given values.
MutableOperandRange slice(unsigned subStart, unsigned subLen, std::optional< OperandSegment > segment=std::nullopt) const
Slice this range into a sub range, with the additional operand segment.
MutableArrayRef< OpOperand >::iterator end() const
void erase(unsigned subStart, unsigned subLen=1)
Erase the operands within the given sub-range.
void append(ValueRange values)
Append the given values to the range.
bool empty() const
Returns if the current range is empty.
void clear()
Clear this range and erase all of the operands.
MutableOperandRange(Operation *owner, unsigned start, unsigned length, ArrayRef< OperandSegment > operandSegments=std::nullopt)
Construct a new mutable range from the given operand, operand start index, and range length.
MutableArrayRef< OpOperand >::iterator begin() const
Iterators enumerate OpOperands.
Operation * getOwner() const
Returns the owning operation.
std::pair< unsigned, NamedAttribute > OperandSegment
A pair of a named attribute corresponding to an operand segment attribute, and the index within that ...
MutableOperandRangeRange split(NamedAttribute segmentSizes) const
Split this range into a set of contiguous subranges using the given elements attribute,...
OpOperand & operator[](unsigned index) const
Returns the OpOperand at the given index.
NamedAttribute represents a combination of a name and an Attribute value.
This class represents an operand of an operation.
This is a value defined by a result of an operation.
This class represents a contiguous range of operand ranges, e.g.
OperandRangeRange(OperandRange operands, Attribute operandSegments)
Construct a range given a parent set of operands, and an I32 elements attribute containing the sizes ...
OperandRange join() const
Flatten all of the sub ranges into a single contiguous operand range.
TypeRangeRange getTypes() const
Returns the range of types of the values within this range.
TypeRangeRange getType() const
This class implements the operand iterators for the Operation class.
unsigned getBeginOperandIndex() const
Return the operand index of the first element of this range.
type_range getType() const
type_range getTypes() const
OperandRangeRange split(DenseI32ArrayAttr segmentSizes) const
Split this range into a set of contiguous subranges using the given elements attribute,...
Operation is the basic unit of execution within MLIR.
This class implements a use iterator for a range of operation results.
bool operator!=(const UseIterator &rhs) const
UseIterator(ResultRange results, bool end=false)
Initialize the UseIterator.
OpOperand * operator->() const
UseIterator & operator++()
bool operator==(const UseIterator &rhs) const
OpOperand & operator*() const
This class implements the result iterators for the Operation class.
use_range getUses() const
Returns a range of all uses of results within this range, which is useful for iterating over all uses...
bool use_empty() const
Returns true if no results in this range have uses.
use_iterator use_begin() const
user_range getUsers()
Returns a range of all users.
ResultRange(OpResult result)
use_iterator use_end() const
std::enable_if_t<!std::is_convertible< ValuesT, Operation * >::value > replaceUsesWithIf(ValuesT &&values, function_ref< bool(OpOperand &)> shouldReplace)
Replace uses of results of this range with the provided 'values' if the given callback returns true.
type_range getTypes() const
std::enable_if_t<!std::is_convertible< ValuesT, Operation * >::value > replaceAllUsesWith(ValuesT &&values)
Replace all uses of results of this range with the provided 'values'.
user_iterator user_begin()
type_range getType() const
This class provides an abstraction for a range of TypeRange.
This class provides an abstraction over the different types of ranges over Values.
ValueRange(ResultRange values)
ValueRange(iterator_range< OperandRange::iterator > values)
ValueRange(OperandRange values)
ValueRange(iterator_range< ResultRange::iterator > values)
ValueRange(ArrayRef< BlockArgument > values)
type_range getType() const
type_range getTypes() const
ValueRange(ArrayRef< Value > values=std::nullopt)
ValueRange(const std::initializer_list< Value > &values)
ValueRange(const Value &value)
This class implements iteration on the types of a given range of values.
This class implements iteration on the types of a given range of values.
OperandType * getOperand() const
Returns the current operands.
An iterator over the users of an IRObject.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
bool use_empty() const
Returns true if this value has no uses.
This class provides the implementation for an operation result.
OpResultImpl * getNextResultAtOffset(intptr_t offset)
Returns the next operation result at offset after this result.
Include the generated interface declarations.