13#ifndef MLIR_IR_VALUERANGE_H
14#define MLIR_IR_VALUERANGE_H
19#include "llvm/ADT/PointerUnion.h"
20#include "llvm/ADT/Repeated.h"
21#include "llvm/ADT/Sequence.h"
26template <
typename ValueRangeT>
29template <
typename ValueIteratorT>
44 OperandRange, OpOperand *, Value, Value, Value> {
46 using RangeBaseT::RangeBaseT;
65 return object +
index;
69 return object[
index].get();
83 :
public llvm::indexed_accessor_range<
84 OperandRangeRange, std::pair<OpOperand *, Attribute>, OperandRange,
85 OperandRange, OperandRange> {
86 using OwnerT = std::pair<OpOperand *, Attribute>;
92 using RangeBaseT::RangeBaseT;
138 slice(
unsigned subStart,
unsigned subLen,
139 std::optional<OperandSegment> segment = std::nullopt)
const;
151 void erase(
unsigned subStart,
unsigned subLen = 1);
157 unsigned size()
const {
return length; }
187 void updateLength(
unsigned newLength);
194 unsigned start, length;
208 :
public llvm::indexed_accessor_range<
209 MutableOperandRangeRange,
210 std::pair<MutableOperandRange, NamedAttribute>, MutableOperandRange,
211 MutableOperandRange, MutableOperandRange> {
212 using OwnerT = std::pair<MutableOperandRange, NamedAttribute>;
219 using RangeBaseT::RangeBaseT;
248 ResultRange, detail::OpResultImpl *, OpResult, OpResult, OpResult> {
250 using RangeBaseT::RangeBaseT;
279 return llvm::all_of(*
this,
285 template <
typename ValuesT>
286 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
288 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
290 "expected 'values' to correspond 1-1 with the number of results");
292 for (
auto it : llvm::zip(*
this, values))
293 std::get<0>(it).replaceAllUsesWith(std::get<1>(it));
302 template <
typename ValuesT>
303 std::enable_if_t<!std::is_convertible<ValuesT, Operation *>::value>
306 assert(
static_cast<size_t>(std::distance(values.begin(), values.end())) ==
308 "expected 'values' to correspond 1-1 with the number of results");
310 for (
auto it : llvm::zip(*
this, values))
311 std::get<0>(it).replaceUsesWithIf(std::get<1>(it), shouldReplace);
340 return offset_base(
object,
index);
350 :
public llvm::iterator_facade_base<UseIterator, std::forward_iterator_tag,
357 using llvm::iterator_facade_base<
UseIterator, std::forward_iterator_tag,
367 void skipOverResultsWithNoUsers();
370 ResultRange::iterator it, endIt;
387 PointerUnion<const Value *, OpOperand *, detail::OpResultImpl *,
388 const Repeated<Value> *>,
389 Value, Value, Value> {
396 using RangeBaseT::RangeBaseT;
398 template <
typename Arg,
399 typename = std::enable_if_t<
400 std::is_constructible<ArrayRef<Value>, Arg>::value &&
401 !std::is_convertible<Arg, Value>::value>>
406 ValueRange(
const std::initializer_list<Value> &values LLVM_LIFETIME_BOUND)
420 : RangeBaseT(&repeatedValue, repeatedValue.count) {}
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(const Repeated< Value > &repeatedValue LLVM_LIFETIME_BOUND)
Constructs a range from a repeated value.
ValueRange(iterator_range< OperandRange::iterator > values)
ValueRange(OperandRange values)
ValueRange(iterator_range< ResultRange::iterator > values)
ValueTypeRange< ValueRange > type_range
ValueRange(ArrayRef< BlockArgument > values)
ValueRange(const Value &value LLVM_LIFETIME_BOUND)
PointerUnion< const Value *, OpOperand *, detail::OpResultImpl *, const Repeated< Value > * > OwnerT
The type representing the owner of a ValueRange.
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