13 #ifndef MLIR_IR_VALUE_H
14 #define MLIR_IR_VALUE_H
19 #include "llvm/Support/PointerLikeTypeTraits.h"
27 class OpPrintingFlags;
100 template <
typename U>
101 [[deprecated(
"Use mlir::isa<U>() instead")]]
103 return llvm::isa<U>(*
this);
106 template <
typename U>
107 [[deprecated(
"Use mlir::dyn_cast<U>() instead")]]
109 return llvm::dyn_cast<U>(*
this);
112 template <
typename U>
113 [[deprecated(
"Use mlir::dyn_cast_or_null<U>() instead")]]
115 return llvm::dyn_cast_or_null<U>(*
this);
118 template <
typename U>
119 [[deprecated(
"Use mlir::cast<U>() instead")]]
121 return llvm::cast<U>(*
this);
124 explicit operator bool()
const {
return impl; }
148 template <
typename OpTy>
174 impl->replaceAllUsesWith(newValue);
233 void print(raw_ostream &os)
const;
324 return llvm::isa<detail::BlockArgumentImpl>(value.
getImpl());
345 void destroy() {
delete getImpl(); }
348 detail::BlockArgumentImpl *getImpl()
const {
349 return reinterpret_cast<detail::BlockArgumentImpl *
>(
impl);
353 void setArgNumber(int64_t index) { getImpl()->index = index; }
436 if (
const auto *outOfLineResult = dyn_cast<OutOfLineOpResult>(
this))
437 return outOfLineResult->getResultNumber();
438 return cast<InlineOpResult>(
this)->getResultNumber();
443 template <
typename Ty>
462 return llvm::isa<detail::OpResultImpl>(value.
getImpl());
479 static unsigned getNumInline(
unsigned numResults);
483 static unsigned getNumTrailing(
unsigned numResults);
494 template <
typename Ty,
typename Value = mlir::Value>
497 using TypedValue = std::conditional_t<std::is_same_v<Ty, mlir::Type>,
541 template <
typename T>
556 struct PointerLikeTypeTraits<
mlir::Value> {
565 NumLowBitsAvailable =
566 PointerLikeTypeTraits<mlir::detail::ValueImpl *>::NumLowBitsAvailable
570 struct PointerLikeTypeTraits<
mlir::BlockArgument>
571 :
public PointerLikeTypeTraits<mlir::Value> {
578 struct PointerLikeTypeTraits<
mlir::OpResult>
579 :
public PointerLikeTypeTraits<mlir::Value> {
585 template <
typename T>
587 :
public PointerLikeTypeTraits<mlir::Value> {
596 template <
typename To,
typename From>
599 std::enable_if_t<std::is_same_v<mlir::Value, std::remove_const_t<From>> ||
600 std::is_base_of_v<mlir::Value, From>>>
613 if constexpr (std::is_base_of_v<To, From>) {
616 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.
void set(Value newValue)
Set the current value being used by this operand.
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.
void assign(Value value)
Set the current value being used by this operand.
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 dropAllUses()
Drop all uses of this object from their respective owners.
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 print(raw_ostream &os) const
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Type getType() const
Return the type of this value.
void shuffleUseList(ArrayRef< unsigned > indices)
Shuffle the use list order according to the provided indices.
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 * 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.
user_iterator user_end() const
Block * getParentBlock()
Return the Block in which this Value is defined.
void replaceAllUsesExcept(Value newValue, const SmallPtrSetImpl< Operation * > &exceptions)
Replace all uses of 'this' value with 'newValue', updating anything in the IR that uses 'this' to use...
void printAsOperand(raw_ostream &os, AsmState &state) const
Print this value as if it were an operand.
U dyn_cast_or_null() const
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
void replaceAllUsesWith(Value newValue)
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.
bool isUsedOutsideOfBlock(Block *block) const
Returns true if the value is used outside of the given block.
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.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
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::detail::TypedValue< T > getEmptyKey()
static mlir::detail::TypedValue< T > 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)
static mlir::detail::TypedValue< T > getFromVoidPointer(void *pointer)
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() const
Return the known Type.