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);
131 slice(
unsigned subStart,
unsigned subLen,
132 std::optional<OperandSegment> segment = std::nullopt)
const;
144 void erase(
unsigned subStart,
unsigned subLen = 1);
150 unsigned size()
const {
return length; }
172 void updateLength(
unsigned newLength);
179 unsigned start, length;
192 :
public llvm::indexed_accessor_range<
193 MutableOperandRangeRange,
194 std::pair<MutableOperandRange, NamedAttribute>, MutableOperandRange,
195 MutableOperandRange, MutableOperandRange> {
196 using OwnerT = std::pair<MutableOperandRange, NamedAttribute>;
203 using RangeBaseT::RangeBaseT;
231 ResultRange, detail::OpResultImpl *, OpResult, OpResult, OpResult> {
233 using RangeBaseT::RangeBaseT;
262 return llvm::all_of(*
this,
268 template <
typename ValuesT>
269 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
271 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
273 "expected 'values' to correspond 1-1 with the number of results");
275 for (
auto it : llvm::zip(*
this, values))
276 std::get<0>(it).replaceAllUsesWith(std::get<1>(it));
285 template <
typename ValuesT>
286 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
289 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
291 "expected 'values' to correspond 1-1 with the number of results");
293 for (
auto it : llvm::zip(*
this, values))
294 std::get<0>(it).replaceUsesWithIf(std::get<1>(it), shouldReplace);
323 return offset_base(
object, index);
333 :
public llvm::iterator_facade_base<UseIterator, std::forward_iterator_tag,
340 using llvm::iterator_facade_base<
UseIterator, std::forward_iterator_tag,
350 void skipOverResultsWithNoUsers();
353 ResultRange::iterator it, endIt;
369 PointerUnion<const Value *, OpOperand *, detail::OpResultImpl *>,
370 Value, Value, Value> {
377 using RangeBaseT::RangeBaseT;
379 template <
typename Arg,
380 typename = std::enable_if_t<
381 std::is_constructible<ArrayRef<Value>, Arg>::value &&
382 !std::is_convertible<Arg, Value>::value>>
405 static OwnerT offset_base(
const OwnerT &owner, ptrdiff_t index);
407 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.
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.
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.
Value operator[](unsigned index) const
Returns the value at the given index.
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.
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,...
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.
This header declares functions that assit transformations in the MemRef dialect.