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;
43 OperandRange, OpOperand *, Value, Value, Value> {
45 using RangeBaseT::RangeBaseT;
64 return object + index;
67 static Value dereference_iterator(
OpOperand *
object, ptrdiff_t index) {
68 return object[index].get();
82 :
public llvm::indexed_accessor_range<
83 OperandRangeRange, std::pair<OpOperand *, Attribute>, OperandRange,
84 OperandRange, OperandRange> {
85 using OwnerT = std::pair<OpOperand *, Attribute>;
91 using RangeBaseT::RangeBaseT;
106 static OperandRange dereference(
const OwnerT &
object, ptrdiff_t index);
137 slice(
unsigned subStart,
unsigned subLen,
138 std::optional<OperandSegment> segment = std::nullopt)
const;
150 void erase(
unsigned subStart,
unsigned subLen = 1);
156 unsigned size()
const {
return length; }
186 void updateLength(
unsigned newLength);
193 unsigned start, length;
207 :
public llvm::indexed_accessor_range<
208 MutableOperandRangeRange,
209 std::pair<MutableOperandRange, NamedAttribute>, MutableOperandRange,
210 MutableOperandRange, MutableOperandRange> {
211 using OwnerT = std::pair<MutableOperandRange, NamedAttribute>;
218 using RangeBaseT::RangeBaseT;
247 ResultRange, detail::OpResultImpl *, OpResult, OpResult, OpResult> {
249 using RangeBaseT::RangeBaseT;
278 return llvm::all_of(*
this,
284 template <
typename ValuesT>
285 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
287 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
289 "expected 'values' to correspond 1-1 with the number of results");
291 for (
auto it : llvm::zip(*
this, values))
292 std::get<0>(it).replaceAllUsesWith(std::get<1>(it));
301 template <
typename ValuesT>
302 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
305 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
307 "expected 'values' to correspond 1-1 with the number of results");
309 for (
auto it : llvm::zip(*
this, values))
310 std::get<0>(it).replaceUsesWithIf(std::get<1>(it), shouldReplace);
339 return offset_base(
object, index);
349 :
public llvm::iterator_facade_base<UseIterator, std::forward_iterator_tag,
356 using llvm::iterator_facade_base<
UseIterator, std::forward_iterator_tag,
366 void skipOverResultsWithNoUsers();
369 ResultRange::iterator it, endIt;
386 PointerUnion<const Value *, OpOperand *, detail::OpResultImpl *>,
387 Value, Value, Value> {
394 using RangeBaseT::RangeBaseT;
396 template <
typename Arg,
397 typename = std::enable_if_t<
398 std::is_constructible<ArrayRef<Value>, Arg>::value &&
399 !std::is_convertible<Arg, Value>::value>>
404 ValueRange(
const std::initializer_list<Value> &values LLVM_LIFETIME_BOUND)
424 static OwnerT offset_base(
const OwnerT &owner, ptrdiff_t index);
426 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)
ValueRange(const Value &value LLVM_LIFETIME_BOUND)
type_range getType() const
type_range getTypes() const
ValueRange(ArrayRef< Value > values=std::nullopt)
ValueRange(const std::initializer_list< Value > &values LLVM_LIFETIME_BOUND)
ValueRange(Arg &&arg LLVM_LIFETIME_BOUND)
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.