13 #ifndef MLIR_IR_VALUE_H
14 #define MLIR_IR_VALUE_H
19 #include "llvm/Support/PointerLikeTypeTraits.h"
27 class OpPrintingFlags;
99 return llvm::isa<U>(*
this);
102 template <
typename U>
104 return llvm::dyn_cast<U>(*
this);
107 template <
typename U>
109 return llvm::dyn_cast_if_present<U>(*
this);
112 template <
typename U>
114 return llvm::cast<U>(*
this);
117 explicit operator bool()
const {
return impl; }
141 template <
typename OpTy>
167 impl->replaceAllUsesWith(newValue);
222 void print(raw_ostream &os);
309 return llvm::isa<detail::BlockArgumentImpl>(value.
getImpl());
330 void destroy() {
delete getImpl(); }
333 detail::BlockArgumentImpl *getImpl()
const {
334 return reinterpret_cast<detail::BlockArgumentImpl *
>(
impl);
338 void setArgNumber(int64_t index) { getImpl()->index = index; }
421 if (
const auto *outOfLineResult = dyn_cast<OutOfLineOpResult>(
this))
422 return outOfLineResult->getResultNumber();
423 return cast<InlineOpResult>(
this)->getResultNumber();
428 template <
typename Ty>
447 return llvm::isa<detail::OpResultImpl>(value.
getImpl());
464 static unsigned getNumInline(
unsigned numResults);
468 static unsigned getNumTrailing(
unsigned numResults);
479 template <
typename Ty,
typename Value = mlir::Value>
482 using TypedValue = std::conditional_t<std::is_same_v<Ty, mlir::Type>,
529 struct PointerLikeTypeTraits<
mlir::Value> {
538 NumLowBitsAvailable =
539 PointerLikeTypeTraits<mlir::detail::ValueImpl *>::NumLowBitsAvailable
543 struct PointerLikeTypeTraits<
mlir::BlockArgument>
544 :
public PointerLikeTypeTraits<mlir::Value> {
551 struct PointerLikeTypeTraits<
mlir::OpResult>
552 :
public PointerLikeTypeTraits<mlir::Value> {
561 template <
typename To,
typename From>
564 std::enable_if_t<std::is_same_v<mlir::Value, std::remove_const_t<From>> ||
565 std::is_base_of_v<mlir::Value, From>>>
578 if constexpr (std::is_base_of_v<To, From>) {
582 return To::classof(ty);
This class provides management for the lifetime of the state used when printing the IR.
This class represents an argument of a Block.
Block * getOwner() const
Returns the block that owns this argument.
Location getLoc() const
Return the location for this argument.
unsigned getArgNumber() const
Returns the number of this argument.
static bool classof(Value value)
void setLoc(Location loc)
Block represents an ordered list of Operations.
This class represents a single IR object that contains a use list.
A reference to a value, suitable for use as an operand of an operation.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents an operand of an operation.
unsigned getOperandNumber()
Return which operand this is in the OpOperand list of the Operation.
friend class OperandStorage
Keep the constructor private and accessible to the OperandStorage class only to avoid hard-to-debug t...
static IRObjectWithUseList< OpOperand > * getUseList(Value value)
Provide the use list that is attached to the given value.
Set of flags used to control the behavior of the various IR print methods (e.g.
This is a value defined by a result of an operation.
Operation * getOwner() const
Returns the operation that owns this result.
static bool classof(Value value)
unsigned getResultNumber() const
Returns the number of this result.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
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.
constexpr Value(detail::ValueImpl *impl=nullptr)
use_iterator use_end() const
void setLoc(Location loc)
void print(raw_ostream &os)
detail::ValueImpl * getImpl() const
static Value getFromOpaquePointer(const void *pointer)
detail::ValueImpl * impl
A pointer to the internal implementation of the value.
void replaceUsesWithIf(Value newValue, function_ref< bool(OpOperand &)> shouldReplace)
Replace all uses of 'this' value with 'newValue' if the given callback returns true.
void setType(Type newType)
Mutate the type of this Value to be of the specified type.
void dropAllUses() const
Drop all uses of this object from their respective owners.
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Type getType() const
Return the type of this value.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
bool operator==(const Value &other) const
bool operator!=(const Value &other) const
user_iterator user_begin() const
void replaceAllUsesExcept(Value newValue, const SmallPtrSetImpl< Operation * > &exceptions) const
Replace all uses of 'this' value with 'newValue', updating anything in the IR that uses 'this' to use...
void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
OpTy getDefiningOp() const
If this value is the result of an operation of type OpTy, return the operation that defines it.
bool isUsedOutsideOfBlock(Block *block)
Returns true if the value is used outside of the given block.
user_iterator user_end() const
Block * getParentBlock()
Return the Block in which this Value is defined.
U dyn_cast_or_null() const
void printAsOperand(raw_ostream &os, AsmState &state)
Print this value as if it were an operand.
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
void replaceAllUsesWith(Value newValue) const
Replace all uses of 'this' value with the new value, updating anything in the IR that uses 'this' to ...
user_range getUsers() const
bool hasOneUse() const
Returns true if this value has exactly one use.
Location getLoc() const
Return the location of this value.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
friend ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
Region * getParentRegion()
Return the Region in which this Value is defined.
use_iterator use_begin() const
The internal implementation of a BlockArgument.
static bool classof(const ValueImpl *value)
This class provides the implementation for an operation result.
unsigned getResultNumber() const
Returns the result number of this op result.
OpResultImpl * getNextResultAtOffset(intptr_t offset)
Returns the next operation result at offset after this result.
Operation * getOwner() const
Returns the parent operation of this result.
static bool classof(const ValueImpl *value)
static unsigned getMaxInlineResults()
Returns the maximum number of results that can be stored inline.
This class provides the implementation for an operation result whose index cannot be represented "inl...
uint64_t outOfLineIndex
The trailing result number, or the offset from the beginning of the OutOfLineOpResult array.
static bool classof(const OpResultImpl *value)
unsigned getResultNumber() const
Return the result number of this op result.
OutOfLineOpResult(Type type, uint64_t outOfLineIndex)
The base class for all derived Value classes.
Kind
The enumeration represents the various different kinds of values the internal representation may take...
@ OutOfLineOpResult
The next kind represents a 'out-of-line' operation result.
@ BlockArgument
The last kind represents a block argument.
ValueImpl(Type type, Kind kind)
llvm::PointerIntPair< Type, 3, Kind > typeAndKind
The type of this result and the kind.
LLVM_DUMP_METHOD Kind debug_getKind() const
void setType(Type type)
Set the type of this value.
LLVM_DUMP_METHOD Type debug_getType() const
Expose a few methods explicitly for the debugger to call for visualization.
Type getType() const
Return the type of this value.
Kind getKind() const
Return the kind of this value.
Include the generated interface declarations.
This header declares functions that assit transformations in the MemRef dialect.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
inline ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static To doCast(mlir::Value value)
static bool isPossible(mlir::Value ty)
Arguments are taken as mlir::Value here and not as From, because when casting from an intermediate ty...
static mlir::BlockArgument getEmptyKey()
static mlir::BlockArgument getTombstoneKey()
static mlir::OpResult getEmptyKey()
static mlir::OpResult getTombstoneKey()
static mlir::Value getEmptyKey()
static unsigned getHashValue(mlir::Value val)
static bool isEqual(mlir::Value lhs, mlir::Value rhs)
static mlir::Value getTombstoneKey()
static mlir::BlockArgument getFromVoidPointer(void *pointer)
static mlir::OpResult getFromVoidPointer(void *pointer)
static mlir::Value getFromVoidPointer(void *pointer)
static void * getAsVoidPointer(mlir::Value value)
This class provides the implementation for an operation result whose index can be represented "inline...
unsigned getResultNumber() const
Return the result number of this op result.
static bool classof(const OpResultImpl *value)
InlineOpResult(Type type, unsigned resultNo)
TypedValue is a Value with a statically know type.
static bool classof(Value value)
Ty getType()
Return the known Type.