13#ifndef MLIR_IR_VALUERANGE_H
14#define MLIR_IR_VALUERANGE_H
19#include "llvm/ADT/PointerUnion.h"
20#include "llvm/ADT/Sequence.h"
25template <
typename ValueRangeT>
28template <
typename ValueIteratorT>
43 OperandRange, OpOperand *, Value, Value, Value> {
45 using RangeBaseT::RangeBaseT;
64 return object +
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;
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)
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.
Operation * getOwner() const
Returns the owning operation.
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.
MutableArrayRef< OpOperand >::iterator begin() const
Iterators enumerate OpOperands.
MutableOperandRange(Operation *owner, unsigned start, unsigned length, ArrayRef< OperandSegment > operandSegments={})
Construct a new mutable range from the given operand, operand start index, and range length.
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,...
ValueTypeRange< OperandRange > type_range
ValueTypeIterator< iterator > type_iterator
Returns the types of the values within this range.
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.
UseIterator & operator++()
OpOperand & operator*() const
OpOperand * operator->() const
bool operator==(const UseIterator &rhs) const
This class implements the result iterators for the Operation class.
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.
iterator_range< user_iterator > user_range
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.
ValueTypeRange< ResultRange > type_range
use_iterator use_begin() const
ValueTypeIterator< iterator > type_iterator
Returns the types of the values within this range.
user_range getUsers()
Returns a range of all users.
ValueUserIterator< use_iterator, OpOperand > user_iterator
ResultRange(OpResult result)
use_iterator use_end() const
type_range getTypes() const
user_iterator user_begin()
iterator_range< use_iterator > use_range
type_range getType() 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'.
This class provides an abstraction for a range of TypeRange.
This class provides an abstraction over the different types of ranges over Values.
ValueTypeIterator< iterator > type_iterator
Returns the types of the values within this range.
ValueRange(ResultRange values)
ValueRange(iterator_range< OperandRange::iterator > values)
ValueRange(OperandRange values)
PointerUnion< const Value *, OpOperand *, detail::OpResultImpl * > OwnerT
The type representing the owner of a ValueRange.
ValueRange(iterator_range< ResultRange::iterator > values)
ValueTypeRange< ValueRange > type_range
ValueRange(ArrayRef< BlockArgument > values)
ValueRange(const Value &value LLVM_LIFETIME_BOUND)
type_range getType() const
type_range getTypes() const
ValueRange(const std::initializer_list< Value > &values LLVM_LIFETIME_BOUND)
ValueRange(Arg &&arg LLVM_LIFETIME_BOUND)
ValueRange(ArrayRef< Value > values={})
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.
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...
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
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.
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
llvm::function_ref< Fn > function_ref