MLIR  19.0.0git
Value.h
Go to the documentation of this file.
1 //===- Value.h - Base of the SSA Value hierarchy ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines generic Value type and manipulation utilities.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_IR_VALUE_H
14 #define MLIR_IR_VALUE_H
15 
16 #include "mlir/IR/Types.h"
17 #include "mlir/IR/UseDefLists.h"
18 #include "mlir/Support/LLVM.h"
19 #include "llvm/Support/PointerLikeTypeTraits.h"
20 
21 namespace mlir {
22 class AsmState;
23 class Block;
24 class BlockArgument;
25 class Operation;
26 class OpOperand;
27 class OpPrintingFlags;
28 class OpResult;
29 class Region;
30 class Value;
31 
32 //===----------------------------------------------------------------------===//
33 // Value
34 //===----------------------------------------------------------------------===//
35 
36 namespace detail {
37 
38 /// The base class for all derived Value classes. It contains all of the
39 /// components that are shared across Value classes.
40 class alignas(8) ValueImpl : public IRObjectWithUseList<OpOperand> {
41 public:
42  /// The enumeration represents the various different kinds of values the
43  /// internal representation may take. We use all of the bits from Type that we
44  /// can to store indices inline.
45  enum class Kind {
46  /// The first N kinds are all inline operation results. An inline operation
47  /// result means that the kind represents the result number. This removes
48  /// the need to store an additional index value. The derived class here is
49  /// an `OpResultImpl`.
50  InlineOpResult = 0,
51 
52  /// The next kind represents a 'out-of-line' operation result. This is for
53  /// results with numbers larger than we can represent inline. The derived
54  /// class here is an `OpResultImpl`.
56 
57  /// The last kind represents a block argument. The derived class here is an
58  /// `BlockArgumentImpl`.
59  BlockArgument = 7
60  };
61 
62  /// Return the type of this value.
63  Type getType() const { return typeAndKind.getPointer(); }
64 
65  /// Set the type of this value.
66  void setType(Type type) { return typeAndKind.setPointer(type); }
67 
68  /// Return the kind of this value.
69  Kind getKind() const { return typeAndKind.getInt(); }
70 
71 protected:
72  ValueImpl(Type type, Kind kind) : typeAndKind(type, kind) {}
73 
74  /// Expose a few methods explicitly for the debugger to call for
75  /// visualization.
76 #ifndef NDEBUG
77  LLVM_DUMP_METHOD Type debug_getType() const { return getType(); }
78  LLVM_DUMP_METHOD Kind debug_getKind() const { return getKind(); }
79 
80 #endif
81 
82  /// The type of this result and the kind.
83  llvm::PointerIntPair<Type, 3, Kind> typeAndKind;
84 };
85 } // namespace detail
86 
87 /// This class represents an instance of an SSA value in the MLIR system,
88 /// representing a computable value that has a type and a set of users. An SSA
89 /// value is either a BlockArgument or the result of an operation. Note: This
90 /// class has value-type semantics and is just a simple wrapper around a
91 /// ValueImpl that is either owner by a block(in the case of a BlockArgument) or
92 /// an Operation(in the case of an OpResult).
93 /// As most IR constructs, this isn't const-correct, but we keep method
94 /// consistent and as such method that immediately modify this Value aren't
95 /// marked `const` (include modifying the Value use-list).
96 class Value {
97 public:
98  constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {}
99 
100  template <typename U>
101  bool isa() const {
102  return llvm::isa<U>(*this);
103  }
104 
105  template <typename U>
106  U dyn_cast() const {
107  return llvm::dyn_cast<U>(*this);
108  }
109 
110  template <typename U>
111  U dyn_cast_or_null() const {
112  return llvm::dyn_cast_if_present<U>(*this);
113  }
114 
115  template <typename U>
116  U cast() const {
117  return llvm::cast<U>(*this);
118  }
119 
120  explicit operator bool() const { return impl; }
121  bool operator==(const Value &other) const { return impl == other.impl; }
122  bool operator!=(const Value &other) const { return !(*this == other); }
123 
124  /// Return the type of this value.
125  Type getType() const { return impl->getType(); }
126 
127  /// Utility to get the associated MLIRContext that this value is defined in.
128  MLIRContext *getContext() const { return getType().getContext(); }
129 
130  /// Mutate the type of this Value to be of the specified type.
131  ///
132  /// Note that this is an extremely dangerous operation which can create
133  /// completely invalid IR very easily. It is strongly recommended that you
134  /// recreate IR objects with the right types instead of mutating them in
135  /// place.
136  void setType(Type newType) { impl->setType(newType); }
137 
138  /// If this value is the result of an operation, return the operation that
139  /// defines it.
140  Operation *getDefiningOp() const;
141 
142  /// If this value is the result of an operation of type OpTy, return the
143  /// operation that defines it.
144  template <typename OpTy>
145  OpTy getDefiningOp() const {
146  return llvm::dyn_cast_or_null<OpTy>(getDefiningOp());
147  }
148 
149  /// Return the location of this value.
150  Location getLoc() const;
151  void setLoc(Location loc);
152 
153  /// Return the Region in which this Value is defined.
155 
156  /// Return the Block in which this Value is defined.
158 
159  //===--------------------------------------------------------------------===//
160  // UseLists
161  //===--------------------------------------------------------------------===//
162 
163  /// Drop all uses of this object from their respective owners.
164  void dropAllUses() { return impl->dropAllUses(); }
165 
166  /// Replace all uses of 'this' value with the new value, updating anything in
167  /// the IR that uses 'this' to use the other value instead. When this returns
168  /// there are zero uses of 'this'.
169  void replaceAllUsesWith(Value newValue) {
170  impl->replaceAllUsesWith(newValue);
171  }
172 
173  /// Replace all uses of 'this' value with 'newValue', updating anything in the
174  /// IR that uses 'this' to use the other value instead except if the user is
175  /// listed in 'exceptions' .
176  void replaceAllUsesExcept(Value newValue,
177  const SmallPtrSetImpl<Operation *> &exceptions);
178 
179  /// Replace all uses of 'this' value with 'newValue', updating anything in the
180  /// IR that uses 'this' to use the other value instead except if the user is
181  /// 'exceptedUser'.
182  void replaceAllUsesExcept(Value newValue, Operation *exceptedUser);
183 
184  /// Replace all uses of 'this' value with 'newValue' if the given callback
185  /// returns true.
186  void replaceUsesWithIf(Value newValue,
187  function_ref<bool(OpOperand &)> shouldReplace);
188 
189  /// Returns true if the value is used outside of the given block.
190  bool isUsedOutsideOfBlock(Block *block) const;
191 
192  /// Shuffle the use list order according to the provided indices. It is
193  /// responsibility of the caller to make sure that the indices map the current
194  /// use-list chain to another valid use-list chain.
195  void shuffleUseList(ArrayRef<unsigned> indices);
196 
197  //===--------------------------------------------------------------------===//
198  // Uses
199 
200  /// This class implements an iterator over the uses of a value.
203 
204  use_iterator use_begin() const { return impl->use_begin(); }
205  use_iterator use_end() const { return use_iterator(); }
206 
207  /// Returns a range of all uses, which is useful for iterating over all uses.
208  use_range getUses() const { return {use_begin(), use_end()}; }
209 
210  /// Returns true if this value has exactly one use.
211  bool hasOneUse() const { return impl->hasOneUse(); }
212 
213  /// Returns true if this value has no uses.
214  bool use_empty() const { return impl->use_empty(); }
215 
216  //===--------------------------------------------------------------------===//
217  // Users
218 
221 
222  user_iterator user_begin() const { return use_begin(); }
223  user_iterator user_end() const { return use_end(); }
224  user_range getUsers() const { return {user_begin(), user_end()}; }
225 
226  //===--------------------------------------------------------------------===//
227  // Utilities
228 
229  void print(raw_ostream &os) const;
230  void print(raw_ostream &os, const OpPrintingFlags &flags) const;
231  void print(raw_ostream &os, AsmState &state) const;
232  void dump() const;
233 
234  /// Print this value as if it were an operand.
235  void printAsOperand(raw_ostream &os, AsmState &state) const;
236  void printAsOperand(raw_ostream &os, const OpPrintingFlags &flags) const;
237 
238  /// Methods for supporting PointerLikeTypeTraits.
239  void *getAsOpaquePointer() const { return impl; }
240  static Value getFromOpaquePointer(const void *pointer) {
241  return reinterpret_cast<detail::ValueImpl *>(const_cast<void *>(pointer));
242  }
243  detail::ValueImpl *getImpl() const { return impl; }
244 
245  friend ::llvm::hash_code hash_value(Value arg);
246 
247 protected:
248  /// A pointer to the internal implementation of the value.
250 };
251 
252 inline raw_ostream &operator<<(raw_ostream &os, Value value) {
253  value.print(os);
254  return os;
255 }
256 
257 //===----------------------------------------------------------------------===//
258 // OpOperand
259 //===----------------------------------------------------------------------===//
260 
261 /// This class represents an operand of an operation. Instances of this class
262 /// contain a reference to a specific `Value`.
263 class OpOperand : public IROperand<OpOperand, Value> {
264 public:
265  /// Provide the use list that is attached to the given value.
267  return value.getImpl();
268  }
269 
270  /// Return which operand this is in the OpOperand list of the Operation.
271  unsigned getOperandNumber();
272 
273  /// Set the current value being used by this operand.
274  void assign(Value value) { set(value); }
275 
276 private:
277  /// Keep the constructor private and accessible to the OperandStorage class
278  /// only to avoid hard-to-debug typo/programming mistakes.
279  friend class OperandStorage;
281 };
282 
283 //===----------------------------------------------------------------------===//
284 // BlockArgument
285 //===----------------------------------------------------------------------===//
286 
287 namespace detail {
288 /// The internal implementation of a BlockArgument.
289 class BlockArgumentImpl : public ValueImpl {
290 public:
291  static bool classof(const ValueImpl *value) {
292  return value->getKind() == ValueImpl::Kind::BlockArgument;
293  }
294 
295 private:
296  BlockArgumentImpl(Type type, Block *owner, int64_t index, Location loc)
297  : ValueImpl(type, Kind::BlockArgument), owner(owner), index(index),
298  loc(loc) {}
299 
300  /// The owner of this argument.
301  Block *owner;
302 
303  /// The position in the argument list.
304  int64_t index;
305 
306  /// The source location of this argument.
307  Location loc;
308 
309  /// Allow access to owner and constructor.
310  friend BlockArgument;
311 };
312 } // namespace detail
313 
314 /// This class represents an argument of a Block.
315 class BlockArgument : public Value {
316 public:
317  using Value::Value;
318 
319  static bool classof(Value value) {
320  return llvm::isa<detail::BlockArgumentImpl>(value.getImpl());
321  }
322 
323  /// Returns the block that owns this argument.
324  Block *getOwner() const { return getImpl()->owner; }
325 
326  /// Returns the number of this argument.
327  unsigned getArgNumber() const { return getImpl()->index; }
328 
329  /// Return the location for this argument.
330  Location getLoc() const { return getImpl()->loc; }
331  void setLoc(Location loc) { getImpl()->loc = loc; }
332 
333 private:
334  /// Allocate a new argument with the given type and owner.
335  static BlockArgument create(Type type, Block *owner, int64_t index,
336  Location loc) {
337  return new detail::BlockArgumentImpl(type, owner, index, loc);
338  }
339 
340  /// Destroy and deallocate this argument.
341  void destroy() { delete getImpl(); }
342 
343  /// Get a raw pointer to the internal implementation.
344  detail::BlockArgumentImpl *getImpl() const {
345  return reinterpret_cast<detail::BlockArgumentImpl *>(impl);
346  }
347 
348  /// Cache the position in the block argument list.
349  void setArgNumber(int64_t index) { getImpl()->index = index; }
350 
351  /// Allow access to `create`, `destroy` and `setArgNumber`.
352  friend Block;
353 
354  /// Allow access to 'getImpl'.
355  friend Value;
356 };
357 
358 //===----------------------------------------------------------------------===//
359 // OpResult
360 //===----------------------------------------------------------------------===//
361 
362 namespace detail {
363 /// This class provides the implementation for an operation result.
364 class alignas(8) OpResultImpl : public ValueImpl {
365 public:
366  using ValueImpl::ValueImpl;
367 
368  static bool classof(const ValueImpl *value) {
369  return value->getKind() != ValueImpl::Kind::BlockArgument;
370  }
371 
372  /// Returns the parent operation of this result.
373  Operation *getOwner() const;
374 
375  /// Returns the result number of this op result.
376  unsigned getResultNumber() const;
377 
378  /// Returns the next operation result at `offset` after this result. This
379  /// method is useful when indexing the result storage of an operation, given
380  /// that there is more than one kind of operation result (with the different
381  /// kinds having different sizes) and that operations are stored in reverse
382  /// order.
383  OpResultImpl *getNextResultAtOffset(intptr_t offset);
384 
385  /// Returns the maximum number of results that can be stored inline.
386  static unsigned getMaxInlineResults() {
387  return static_cast<unsigned>(Kind::OutOfLineOpResult);
388  }
389 };
390 
391 /// This class provides the implementation for an operation result whose index
392 /// can be represented "inline" in the underlying ValueImpl.
393 struct InlineOpResult : public OpResultImpl {
394 public:
395  InlineOpResult(Type type, unsigned resultNo)
396  : OpResultImpl(type, static_cast<ValueImpl::Kind>(resultNo)) {
397  assert(resultNo < getMaxInlineResults());
398  }
399 
400  /// Return the result number of this op result.
401  unsigned getResultNumber() const { return static_cast<unsigned>(getKind()); }
402 
403  static bool classof(const OpResultImpl *value) {
404  return value->getKind() != ValueImpl::Kind::OutOfLineOpResult;
405  }
406 };
407 
408 /// This class provides the implementation for an operation result whose index
409 /// cannot be represented "inline", and thus requires an additional index field.
411 public:
415 
416  static bool classof(const OpResultImpl *value) {
417  return value->getKind() == ValueImpl::Kind::OutOfLineOpResult;
418  }
419 
420  /// Return the result number of this op result.
421  unsigned getResultNumber() const {
423  }
424 
425  /// The trailing result number, or the offset from the beginning of the
426  /// `OutOfLineOpResult` array.
427  uint64_t outOfLineIndex;
428 };
429 
430 /// Return the result number of this op result.
431 inline unsigned OpResultImpl::getResultNumber() const {
432  if (const auto *outOfLineResult = dyn_cast<OutOfLineOpResult>(this))
433  return outOfLineResult->getResultNumber();
434  return cast<InlineOpResult>(this)->getResultNumber();
435 }
436 
437 /// TypedValue is a Value with a statically know type.
438 /// TypedValue can be null/empty
439 template <typename Ty>
440 struct TypedValue : Value {
441  using Value::Value;
442 
443  static bool classof(Value value) { return llvm::isa<Ty>(value.getType()); }
444 
445  /// Return the known Type
446  Ty getType() const { return llvm::cast<Ty>(Value::getType()); }
447  void setType(Ty ty) { Value::setType(ty); }
448 };
449 
450 } // namespace detail
451 
452 /// This is a value defined by a result of an operation.
453 class OpResult : public Value {
454 public:
455  using Value::Value;
456 
457  static bool classof(Value value) {
458  return llvm::isa<detail::OpResultImpl>(value.getImpl());
459  }
460 
461  /// Returns the operation that owns this result.
462  Operation *getOwner() const { return getImpl()->getOwner(); }
463 
464  /// Returns the number of this result.
465  unsigned getResultNumber() const { return getImpl()->getResultNumber(); }
466 
467 private:
468  /// Get a raw pointer to the internal implementation.
469  detail::OpResultImpl *getImpl() const {
470  return reinterpret_cast<detail::OpResultImpl *>(impl);
471  }
472 
473  /// Given a number of operation results, returns the number that need to be
474  /// stored inline.
475  static unsigned getNumInline(unsigned numResults);
476 
477  /// Given a number of operation results, returns the number that need to be
478  /// stored as trailing.
479  static unsigned getNumTrailing(unsigned numResults);
480 
481  /// Allow access to constructor.
482  friend Operation;
483 };
484 
485 /// Make Value hashable.
486 inline ::llvm::hash_code hash_value(Value arg) {
488 }
489 
490 template <typename Ty, typename Value = mlir::Value>
491 /// If Ty is mlir::Type this will select `Value` instead of having a wrapper
492 /// around it. This helps resolve ambiguous conversion issues.
493 using TypedValue = std::conditional_t<std::is_same_v<Ty, mlir::Type>,
495 
496 } // namespace mlir
497 
498 namespace llvm {
499 
500 template <>
501 struct DenseMapInfo<mlir::Value> {
503  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
504  return mlir::Value::getFromOpaquePointer(pointer);
505  }
508  return mlir::Value::getFromOpaquePointer(pointer);
509  }
510  static unsigned getHashValue(mlir::Value val) {
511  return mlir::hash_value(val);
512  }
513  static bool isEqual(mlir::Value lhs, mlir::Value rhs) { return lhs == rhs; }
514 };
515 template <>
516 struct DenseMapInfo<mlir::BlockArgument> : public DenseMapInfo<mlir::Value> {
518  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
519  return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
520  }
523  return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
524  }
525 };
526 template <>
527 struct DenseMapInfo<mlir::OpResult> : public DenseMapInfo<mlir::Value> {
529  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
530  return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
531  }
534  return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
535  }
536 };
537 template <typename T>
539  : public DenseMapInfo<mlir::Value> {
541  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
542  return reinterpret_cast<mlir::detail::ValueImpl *>(pointer);
543  }
546  return reinterpret_cast<mlir::detail::ValueImpl *>(pointer);
547  }
548 };
549 
550 /// Allow stealing the low bits of a value.
551 template <>
552 struct PointerLikeTypeTraits<mlir::Value> {
553 public:
554  static inline void *getAsVoidPointer(mlir::Value value) {
555  return const_cast<void *>(value.getAsOpaquePointer());
556  }
557  static inline mlir::Value getFromVoidPointer(void *pointer) {
558  return mlir::Value::getFromOpaquePointer(pointer);
559  }
560  enum {
561  NumLowBitsAvailable =
562  PointerLikeTypeTraits<mlir::detail::ValueImpl *>::NumLowBitsAvailable
563  };
564 };
565 template <>
566 struct PointerLikeTypeTraits<mlir::BlockArgument>
567  : public PointerLikeTypeTraits<mlir::Value> {
568 public:
569  static inline mlir::BlockArgument getFromVoidPointer(void *pointer) {
570  return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
571  }
572 };
573 template <>
574 struct PointerLikeTypeTraits<mlir::OpResult>
575  : public PointerLikeTypeTraits<mlir::Value> {
576 public:
577  static inline mlir::OpResult getFromVoidPointer(void *pointer) {
578  return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
579  }
580 };
581 template <typename T>
582 struct PointerLikeTypeTraits<mlir::detail::TypedValue<T>>
583  : public PointerLikeTypeTraits<mlir::Value> {
584 public:
585  static inline mlir::detail::TypedValue<T> getFromVoidPointer(void *pointer) {
586  return reinterpret_cast<mlir::detail::ValueImpl *>(pointer);
587  }
588 };
589 
590 /// Add support for llvm style casts. We provide a cast between To and From if
591 /// From is mlir::Value or derives from it.
592 template <typename To, typename From>
593 struct CastInfo<
594  To, From,
595  std::enable_if_t<std::is_same_v<mlir::Value, std::remove_const_t<From>> ||
596  std::is_base_of_v<mlir::Value, From>>>
598  DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
599  /// Arguments are taken as mlir::Value here and not as `From`, because
600  /// when casting from an intermediate type of the hierarchy to one of its
601  /// children, the val.getKind() inside T::classof will use the static
602  /// getKind() of the parent instead of the non-static ValueImpl::getKind()
603  /// that returns the dynamic type. This means that T::classof would end up
604  /// comparing the static Kind of the children to the static Kind of its
605  /// parent, making it impossible to downcast from the parent to the child.
606  static inline bool isPossible(mlir::Value ty) {
607  /// Return a constant true instead of a dynamic true when casting to self or
608  /// up the hierarchy.
609  if constexpr (std::is_base_of_v<To, From>) {
610  return true;
611  } else {
612  return To::classof(ty);
613  }
614  }
615  static inline To doCast(mlir::Value value) { return To(value.getImpl()); }
616 };
617 
618 } // namespace llvm
619 
620 #endif
This class provides management for the lifetime of the state used when printing the IR.
Definition: AsmState.h:533
This class represents an argument of a Block.
Definition: Value.h:315
Block * getOwner() const
Returns the block that owns this argument.
Definition: Value.h:324
Location getLoc() const
Return the location for this argument.
Definition: Value.h:330
unsigned getArgNumber() const
Returns the number of this argument.
Definition: Value.h:327
static bool classof(Value value)
Definition: Value.h:319
void setLoc(Location loc)
Definition: Value.h:331
Block represents an ordered list of Operations.
Definition: Block.h:30
This class represents a single IR object that contains a use list.
Definition: UseDefLists.h:195
A reference to a value, suitable for use as an operand of an operation.
Definition: UseDefLists.h:127
void set(Value newValue)
Set the current value being used by this operand.
Definition: UseDefLists.h:163
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This class represents an operand of an operation.
Definition: Value.h:263
unsigned getOperandNumber()
Return which operand this is in the OpOperand list of the Operation.
Definition: Value.cpp:216
friend class OperandStorage
Keep the constructor private and accessible to the OperandStorage class only to avoid hard-to-debug t...
Definition: Value.h:279
static IRObjectWithUseList< OpOperand > * getUseList(Value value)
Provide the use list that is attached to the given value.
Definition: Value.h:266
void assign(Value value)
Set the current value being used by this operand.
Definition: Value.h:274
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.
Definition: Value.h:453
Operation * getOwner() const
Returns the operation that owns this result.
Definition: Value.h:462
static bool classof(Value value)
Definition: Value.h:457
unsigned getResultNumber() const
Returns the number of this result.
Definition: Value.h:465
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition: Types.cpp:35
An iterator over the users of an IRObject.
Definition: UseDefLists.h:344
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
bool use_empty() const
Returns true if this value has no uses.
Definition: Value.h:214
constexpr Value(detail::ValueImpl *impl=nullptr)
Definition: Value.h:98
void dump() const
use_iterator use_end() const
Definition: Value.h:205
void setLoc(Location loc)
Definition: Value.cpp:33
void dropAllUses()
Drop all uses of this object from their respective owners.
Definition: Value.h:164
detail::ValueImpl * getImpl() const
Definition: Value.h:243
bool isa() const
Definition: Value.h:101
static Value getFromOpaquePointer(const void *pointer)
Definition: Value.h:240
detail::ValueImpl * impl
A pointer to the internal implementation of the value.
Definition: Value.h:249
void replaceUsesWithIf(Value newValue, function_ref< bool(OpOperand &)> shouldReplace)
Replace all uses of 'this' value with 'newValue' if the given callback returns true.
Definition: Value.cpp:81
void setType(Type newType)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:136
void print(raw_ostream &os) const
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Definition: Value.h:128
Type getType() const
Return the type of this value.
Definition: Value.h:125
void shuffleUseList(ArrayRef< unsigned > indices)
Shuffle the use list order according to the provided indices.
Definition: Value.cpp:96
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Definition: Value.h:208
bool operator==(const Value &other) const
Definition: Value.h:121
bool operator!=(const Value &other) const
Definition: Value.h:122
user_iterator user_begin() const
Definition: Value.h:222
U dyn_cast() const
Definition: Value.h:106
void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
Definition: Value.h:239
OpTy getDefiningOp() const
If this value is the result of an operation of type OpTy, return the operation that defines it.
Definition: Value.h:145
user_iterator user_end() const
Definition: Value.h:223
Block * getParentBlock()
Return the Block in which this Value is defined.
Definition: Value.cpp:48
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...
Definition: Value.cpp:61
void printAsOperand(raw_ostream &os, AsmState &state) const
Print this value as if it were an operand.
U dyn_cast_or_null() const
Definition: Value.h:111
U cast() const
Definition: Value.h:116
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
Definition: Value.h:201
void replaceAllUsesWith(Value newValue)
Replace all uses of 'this' value with the new value, updating anything in the IR that uses 'this' to ...
Definition: Value.h:169
user_range getUsers() const
Definition: Value.h:224
bool hasOneUse() const
Returns true if this value has exactly one use.
Definition: Value.h:211
bool isUsedOutsideOfBlock(Block *block) const
Returns true if the value is used outside of the given block.
Definition: Value.cpp:89
Location getLoc() const
Return the location of this value.
Definition: Value.cpp:26
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Definition: Value.cpp:20
friend ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
Definition: Value.h:486
Region * getParentRegion()
Return the Region in which this Value is defined.
Definition: Value.cpp:41
use_iterator use_begin() const
Definition: Value.h:204
The internal implementation of a BlockArgument.
Definition: Value.h:289
static bool classof(const ValueImpl *value)
Definition: Value.h:291
This class provides the implementation for an operation result.
Definition: Value.h:364
unsigned getResultNumber() const
Returns the result number of this op result.
Definition: Value.h:431
OpResultImpl * getNextResultAtOffset(intptr_t offset)
Returns the next operation result at offset after this result.
Definition: Value.cpp:134
Operation * getOwner() const
Returns the parent operation of this result.
Definition: Value.cpp:105
static bool classof(const ValueImpl *value)
Definition: Value.h:368
static unsigned getMaxInlineResults()
Returns the maximum number of results that can be stored inline.
Definition: Value.h:386
This class provides the implementation for an operation result whose index cannot be represented "inl...
Definition: Value.h:410
uint64_t outOfLineIndex
The trailing result number, or the offset from the beginning of the OutOfLineOpResult array.
Definition: Value.h:427
static bool classof(const OpResultImpl *value)
Definition: Value.h:416
unsigned getResultNumber() const
Return the result number of this op result.
Definition: Value.h:421
OutOfLineOpResult(Type type, uint64_t outOfLineIndex)
Definition: Value.h:412
The base class for all derived Value classes.
Definition: Value.h:40
Kind
The enumeration represents the various different kinds of values the internal representation may take...
Definition: Value.h:45
@ OutOfLineOpResult
The next kind represents a 'out-of-line' operation result.
@ BlockArgument
The last kind represents a block argument.
ValueImpl(Type type, Kind kind)
Definition: Value.h:72
llvm::PointerIntPair< Type, 3, Kind > typeAndKind
The type of this result and the kind.
Definition: Value.h:83
LLVM_DUMP_METHOD Kind debug_getKind() const
Definition: Value.h:78
void setType(Type type)
Set the type of this value.
Definition: Value.h:66
LLVM_DUMP_METHOD Type debug_getType() const
Expose a few methods explicitly for the debugger to call for visualization.
Definition: Value.h:77
Type getType() const
Return the type of this value.
Definition: Value.h:63
Kind getKind() const
Return the kind of this value.
Definition: Value.h:69
Include the generated interface declarations.
Definition: CallGraph.h:229
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.
Definition: Value.h:494
inline ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
Definition: Value.h:486
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:261
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
Definition: AliasAnalysis.h:78
static bool isPossible(mlir::Value ty)
Arguments are taken as mlir::Value here and not as From, because when casting from an intermediate ty...
Definition: Value.h:606
static mlir::BlockArgument getEmptyKey()
Definition: Value.h:517
static mlir::BlockArgument getTombstoneKey()
Definition: Value.h:521
static mlir::OpResult getEmptyKey()
Definition: Value.h:528
static mlir::OpResult getTombstoneKey()
Definition: Value.h:532
static mlir::Value getEmptyKey()
Definition: Value.h:502
static unsigned getHashValue(mlir::Value val)
Definition: Value.h:510
static bool isEqual(mlir::Value lhs, mlir::Value rhs)
Definition: Value.h:513
static mlir::Value getTombstoneKey()
Definition: Value.h:506
static mlir::detail::TypedValue< T > getEmptyKey()
Definition: Value.h:540
static mlir::detail::TypedValue< T > getTombstoneKey()
Definition: Value.h:544
static mlir::BlockArgument getFromVoidPointer(void *pointer)
Definition: Value.h:569
static mlir::OpResult getFromVoidPointer(void *pointer)
Definition: Value.h:577
static mlir::Value getFromVoidPointer(void *pointer)
Definition: Value.h:557
static void * getAsVoidPointer(mlir::Value value)
Definition: Value.h:554
static mlir::detail::TypedValue< T > getFromVoidPointer(void *pointer)
Definition: Value.h:585
This class provides the implementation for an operation result whose index can be represented "inline...
Definition: Value.h:393
unsigned getResultNumber() const
Return the result number of this op result.
Definition: Value.h:401
static bool classof(const OpResultImpl *value)
Definition: Value.h:403
InlineOpResult(Type type, unsigned resultNo)
Definition: Value.h:395
TypedValue is a Value with a statically know type.
Definition: Value.h:440
static bool classof(Value value)
Definition: Value.h:443
Ty getType() const
Return the known Type.
Definition: Value.h:446
void setType(Ty ty)
Definition: Value.h:447