MLIR  17.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 class Value {
94 public:
95  constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {}
96 
97  template <typename U>
98  bool isa() const {
99  return llvm::isa<U>(*this);
100  }
101 
102  template <typename U>
103  U dyn_cast() const {
104  return llvm::dyn_cast<U>(*this);
105  }
106 
107  template <typename U>
108  U dyn_cast_or_null() const {
109  return llvm::dyn_cast_if_present<U>(*this);
110  }
111 
112  template <typename U>
113  U cast() const {
114  return llvm::cast<U>(*this);
115  }
116 
117  explicit operator bool() const { return impl; }
118  bool operator==(const Value &other) const { return impl == other.impl; }
119  bool operator!=(const Value &other) const { return !(*this == other); }
120 
121  /// Return the type of this value.
122  Type getType() const { return impl->getType(); }
123 
124  /// Utility to get the associated MLIRContext that this value is defined in.
125  MLIRContext *getContext() const { return getType().getContext(); }
126 
127  /// Mutate the type of this Value to be of the specified type.
128  ///
129  /// Note that this is an extremely dangerous operation which can create
130  /// completely invalid IR very easily. It is strongly recommended that you
131  /// recreate IR objects with the right types instead of mutating them in
132  /// place.
133  void setType(Type newType) { impl->setType(newType); }
134 
135  /// If this value is the result of an operation, return the operation that
136  /// defines it.
137  Operation *getDefiningOp() const;
138 
139  /// If this value is the result of an operation of type OpTy, return the
140  /// operation that defines it.
141  template <typename OpTy>
142  OpTy getDefiningOp() const {
143  return llvm::dyn_cast_or_null<OpTy>(getDefiningOp());
144  }
145 
146  /// Return the location of this value.
147  Location getLoc() const;
148  void setLoc(Location loc);
149 
150  /// Return the Region in which this Value is defined.
152 
153  /// Return the Block in which this Value is defined.
155 
156  //===--------------------------------------------------------------------===//
157  // UseLists
158  //===--------------------------------------------------------------------===//
159 
160  /// Drop all uses of this object from their respective owners.
161  void dropAllUses() const { return impl->dropAllUses(); }
162 
163  /// Replace all uses of 'this' value with the new value, updating anything in
164  /// the IR that uses 'this' to use the other value instead. When this returns
165  /// there are zero uses of 'this'.
166  void replaceAllUsesWith(Value newValue) const {
167  impl->replaceAllUsesWith(newValue);
168  }
169 
170  /// Replace all uses of 'this' value with 'newValue', updating anything in the
171  /// IR that uses 'this' to use the other value instead except if the user is
172  /// listed in 'exceptions' .
173  void
174  replaceAllUsesExcept(Value newValue,
175  const SmallPtrSetImpl<Operation *> &exceptions) const;
176 
177  /// Replace all uses of 'this' value with 'newValue', updating anything in the
178  /// IR that uses 'this' to use the other value instead except if the user is
179  /// 'exceptedUser'.
180  void replaceAllUsesExcept(Value newValue, Operation *exceptedUser) const;
181 
182  /// Replace all uses of 'this' value with 'newValue' if the given callback
183  /// returns true.
184  void replaceUsesWithIf(Value newValue,
185  function_ref<bool(OpOperand &)> shouldReplace);
186 
187  /// Returns true if the value is used outside of the given block.
188  bool isUsedOutsideOfBlock(Block *block);
189 
190  //===--------------------------------------------------------------------===//
191  // Uses
192 
193  /// This class implements an iterator over the uses of a value.
196 
197  use_iterator use_begin() const { return impl->use_begin(); }
198  use_iterator use_end() const { return use_iterator(); }
199 
200  /// Returns a range of all uses, which is useful for iterating over all uses.
201  use_range getUses() const { return {use_begin(), use_end()}; }
202 
203  /// Returns true if this value has exactly one use.
204  bool hasOneUse() const { return impl->hasOneUse(); }
205 
206  /// Returns true if this value has no uses.
207  bool use_empty() const { return impl->use_empty(); }
208 
209  //===--------------------------------------------------------------------===//
210  // Users
211 
214 
215  user_iterator user_begin() const { return use_begin(); }
216  user_iterator user_end() const { return use_end(); }
217  user_range getUsers() const { return {user_begin(), user_end()}; }
218 
219  //===--------------------------------------------------------------------===//
220  // Utilities
221 
222  void print(raw_ostream &os);
223  void print(raw_ostream &os, const OpPrintingFlags &flags);
224  void print(raw_ostream &os, AsmState &state);
225  void dump();
226 
227  /// Print this value as if it were an operand.
228  void printAsOperand(raw_ostream &os, AsmState &state);
229 
230  /// Methods for supporting PointerLikeTypeTraits.
231  void *getAsOpaquePointer() const { return impl; }
232  static Value getFromOpaquePointer(const void *pointer) {
233  return reinterpret_cast<detail::ValueImpl *>(const_cast<void *>(pointer));
234  }
235  detail::ValueImpl *getImpl() const { return impl; }
236 
237  friend ::llvm::hash_code hash_value(Value arg);
238 
239 protected:
240  /// A pointer to the internal implementation of the value.
242 };
243 
244 inline raw_ostream &operator<<(raw_ostream &os, Value value) {
245  value.print(os);
246  return os;
247 }
248 
249 //===----------------------------------------------------------------------===//
250 // OpOperand
251 //===----------------------------------------------------------------------===//
252 
253 /// This class represents an operand of an operation. Instances of this class
254 /// contain a reference to a specific `Value`.
255 class OpOperand : public IROperand<OpOperand, Value> {
256 public:
257  /// Provide the use list that is attached to the given value.
259  return value.getImpl();
260  }
261 
262  /// Return which operand this is in the OpOperand list of the Operation.
263  unsigned getOperandNumber();
264 
265 private:
266  /// Keep the constructor private and accessible to the OperandStorage class
267  /// only to avoid hard-to-debug typo/programming mistakes.
268  friend class OperandStorage;
270 };
271 
272 //===----------------------------------------------------------------------===//
273 // BlockArgument
274 //===----------------------------------------------------------------------===//
275 
276 namespace detail {
277 /// The internal implementation of a BlockArgument.
278 class BlockArgumentImpl : public ValueImpl {
279 public:
280  static bool classof(const ValueImpl *value) {
281  return value->getKind() == ValueImpl::Kind::BlockArgument;
282  }
283 
284 private:
285  BlockArgumentImpl(Type type, Block *owner, int64_t index, Location loc)
286  : ValueImpl(type, Kind::BlockArgument), owner(owner), index(index),
287  loc(loc) {}
288 
289  /// The owner of this argument.
290  Block *owner;
291 
292  /// The position in the argument list.
293  int64_t index;
294 
295  /// The source location of this argument.
296  Location loc;
297 
298  /// Allow access to owner and constructor.
299  friend BlockArgument;
300 };
301 } // namespace detail
302 
303 /// This class represents an argument of a Block.
304 class BlockArgument : public Value {
305 public:
306  using Value::Value;
307 
308  static bool classof(Value value) {
309  return llvm::isa<detail::BlockArgumentImpl>(value.getImpl());
310  }
311 
312  /// Returns the block that owns this argument.
313  Block *getOwner() const { return getImpl()->owner; }
314 
315  /// Returns the number of this argument.
316  unsigned getArgNumber() const { return getImpl()->index; }
317 
318  /// Return the location for this argument.
319  Location getLoc() const { return getImpl()->loc; }
320  void setLoc(Location loc) { getImpl()->loc = loc; }
321 
322 private:
323  /// Allocate a new argument with the given type and owner.
324  static BlockArgument create(Type type, Block *owner, int64_t index,
325  Location loc) {
326  return new detail::BlockArgumentImpl(type, owner, index, loc);
327  }
328 
329  /// Destroy and deallocate this argument.
330  void destroy() { delete getImpl(); }
331 
332  /// Get a raw pointer to the internal implementation.
333  detail::BlockArgumentImpl *getImpl() const {
334  return reinterpret_cast<detail::BlockArgumentImpl *>(impl);
335  }
336 
337  /// Cache the position in the block argument list.
338  void setArgNumber(int64_t index) { getImpl()->index = index; }
339 
340  /// Allow access to `create`, `destroy` and `setArgNumber`.
341  friend Block;
342 
343  /// Allow access to 'getImpl'.
344  friend Value;
345 };
346 
347 //===----------------------------------------------------------------------===//
348 // OpResult
349 //===----------------------------------------------------------------------===//
350 
351 namespace detail {
352 /// This class provides the implementation for an operation result.
353 class alignas(8) OpResultImpl : public ValueImpl {
354 public:
355  using ValueImpl::ValueImpl;
356 
357  static bool classof(const ValueImpl *value) {
358  return value->getKind() != ValueImpl::Kind::BlockArgument;
359  }
360 
361  /// Returns the parent operation of this result.
362  Operation *getOwner() const;
363 
364  /// Returns the result number of this op result.
365  unsigned getResultNumber() const;
366 
367  /// Returns the next operation result at `offset` after this result. This
368  /// method is useful when indexing the result storage of an operation, given
369  /// that there is more than one kind of operation result (with the different
370  /// kinds having different sizes) and that operations are stored in reverse
371  /// order.
372  OpResultImpl *getNextResultAtOffset(intptr_t offset);
373 
374  /// Returns the maximum number of results that can be stored inline.
375  static unsigned getMaxInlineResults() {
376  return static_cast<unsigned>(Kind::OutOfLineOpResult);
377  }
378 };
379 
380 /// This class provides the implementation for an operation result whose index
381 /// can be represented "inline" in the underlying ValueImpl.
382 struct InlineOpResult : public OpResultImpl {
383 public:
384  InlineOpResult(Type type, unsigned resultNo)
385  : OpResultImpl(type, static_cast<ValueImpl::Kind>(resultNo)) {
386  assert(resultNo < getMaxInlineResults());
387  }
388 
389  /// Return the result number of this op result.
390  unsigned getResultNumber() const { return static_cast<unsigned>(getKind()); }
391 
392  static bool classof(const OpResultImpl *value) {
393  return value->getKind() != ValueImpl::Kind::OutOfLineOpResult;
394  }
395 };
396 
397 /// This class provides the implementation for an operation result whose index
398 /// cannot be represented "inline", and thus requires an additional index field.
400 public:
404 
405  static bool classof(const OpResultImpl *value) {
406  return value->getKind() == ValueImpl::Kind::OutOfLineOpResult;
407  }
408 
409  /// Return the result number of this op result.
410  unsigned getResultNumber() const {
412  }
413 
414  /// The trailing result number, or the offset from the beginning of the
415  /// `OutOfLineOpResult` array.
416  uint64_t outOfLineIndex;
417 };
418 
419 /// Return the result number of this op result.
420 inline unsigned OpResultImpl::getResultNumber() const {
421  if (const auto *outOfLineResult = dyn_cast<OutOfLineOpResult>(this))
422  return outOfLineResult->getResultNumber();
423  return cast<InlineOpResult>(this)->getResultNumber();
424 }
425 
426 /// TypedValue is a Value with a statically know type.
427 /// TypedValue can be null/empty
428 template <typename Ty>
429 struct TypedValue : Value {
430  using Value::Value;
431 
432  static bool classof(Value value) { return llvm::isa<Ty>(value.getType()); }
433 
434  /// Return the known Type
435  Ty getType() { return Value::getType().template cast<Ty>(); }
436  void setType(Ty ty) { Value::setType(ty); }
437 };
438 
439 } // namespace detail
440 
441 /// This is a value defined by a result of an operation.
442 class OpResult : public Value {
443 public:
444  using Value::Value;
445 
446  static bool classof(Value value) {
447  return llvm::isa<detail::OpResultImpl>(value.getImpl());
448  }
449 
450  /// Returns the operation that owns this result.
451  Operation *getOwner() const { return getImpl()->getOwner(); }
452 
453  /// Returns the number of this result.
454  unsigned getResultNumber() const { return getImpl()->getResultNumber(); }
455 
456 private:
457  /// Get a raw pointer to the internal implementation.
458  detail::OpResultImpl *getImpl() const {
459  return reinterpret_cast<detail::OpResultImpl *>(impl);
460  }
461 
462  /// Given a number of operation results, returns the number that need to be
463  /// stored inline.
464  static unsigned getNumInline(unsigned numResults);
465 
466  /// Given a number of operation results, returns the number that need to be
467  /// stored as trailing.
468  static unsigned getNumTrailing(unsigned numResults);
469 
470  /// Allow access to constructor.
471  friend Operation;
472 };
473 
474 /// Make Value hashable.
475 inline ::llvm::hash_code hash_value(Value arg) {
477 }
478 
479 template <typename Ty, typename Value = mlir::Value>
480 /// If Ty is mlir::Type this will select `Value` instead of having a wrapper
481 /// around it. This helps resolve ambiguous conversion issues.
482 using TypedValue = std::conditional_t<std::is_same_v<Ty, mlir::Type>,
484 
485 } // namespace mlir
486 
487 namespace llvm {
488 
489 template <>
490 struct DenseMapInfo<mlir::Value> {
492  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
493  return mlir::Value::getFromOpaquePointer(pointer);
494  }
497  return mlir::Value::getFromOpaquePointer(pointer);
498  }
499  static unsigned getHashValue(mlir::Value val) {
500  return mlir::hash_value(val);
501  }
502  static bool isEqual(mlir::Value lhs, mlir::Value rhs) { return lhs == rhs; }
503 };
504 template <>
505 struct DenseMapInfo<mlir::BlockArgument> : public DenseMapInfo<mlir::Value> {
507  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
508  return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
509  }
512  return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
513  }
514 };
515 template <>
516 struct DenseMapInfo<mlir::OpResult> : public DenseMapInfo<mlir::Value> {
518  void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
519  return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
520  }
523  return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
524  }
525 };
526 
527 /// Allow stealing the low bits of a value.
528 template <>
529 struct PointerLikeTypeTraits<mlir::Value> {
530 public:
531  static inline void *getAsVoidPointer(mlir::Value value) {
532  return const_cast<void *>(value.getAsOpaquePointer());
533  }
534  static inline mlir::Value getFromVoidPointer(void *pointer) {
535  return mlir::Value::getFromOpaquePointer(pointer);
536  }
537  enum {
538  NumLowBitsAvailable =
539  PointerLikeTypeTraits<mlir::detail::ValueImpl *>::NumLowBitsAvailable
540  };
541 };
542 template <>
543 struct PointerLikeTypeTraits<mlir::BlockArgument>
544  : public PointerLikeTypeTraits<mlir::Value> {
545 public:
546  static inline mlir::BlockArgument getFromVoidPointer(void *pointer) {
547  return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
548  }
549 };
550 template <>
551 struct PointerLikeTypeTraits<mlir::OpResult>
552  : public PointerLikeTypeTraits<mlir::Value> {
553 public:
554  static inline mlir::OpResult getFromVoidPointer(void *pointer) {
555  return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
556  }
557 };
558 
559 /// Add support for llvm style casts. We provide a cast between To and From if
560 /// From is mlir::Value or derives from it.
561 template <typename To, typename From>
562 struct CastInfo<
563  To, 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>>>
567  DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
568  /// Arguments are taken as mlir::Value here and not as `From`, because
569  /// when casting from an intermediate type of the hierarchy to one of its
570  /// children, the val.getKind() inside T::classof will use the static
571  /// getKind() of the parent instead of the non-static ValueImpl::getKind()
572  /// that returns the dynamic type. This means that T::classof would end up
573  /// comparing the static Kind of the children to the static Kind of its
574  /// parent, making it impossible to downcast from the parent to the child.
575  static inline bool isPossible(mlir::Value ty) {
576  /// Return a constant true instead of a dynamic true when casting to self or
577  /// up the hierarchy.
578  if constexpr (std::is_base_of_v<To, From>) {
579  (void)ty;
580  return true;
581  } else {
582  return To::classof(ty);
583  }
584  }
585  static inline To doCast(mlir::Value value) { return To(value.getImpl()); }
586 };
587 
588 } // namespace llvm
589 
590 #endif
This class provides management for the lifetime of the state used when printing the IR.
Definition: AsmState.h:525
This class represents an argument of a Block.
Definition: Value.h:304
Block * getOwner() const
Returns the block that owns this argument.
Definition: Value.h:313
Location getLoc() const
Return the location for this argument.
Definition: Value.h:319
unsigned getArgNumber() const
Returns the number of this argument.
Definition: Value.h:316
static bool classof(Value value)
Definition: Value.h:308
void setLoc(Location loc)
Definition: Value.h:320
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:172
A reference to a value, suitable for use as an operand of an operation.
Definition: UseDefLists.h:114
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:255
unsigned getOperandNumber()
Return which operand this is in the OpOperand list of the Operation.
Definition: Value.cpp:212
friend class OperandStorage
Keep the constructor private and accessible to the OperandStorage class only to avoid hard-to-debug t...
Definition: Value.h:268
static IRObjectWithUseList< OpOperand > * getUseList(Value value)
Provide the use list that is attached to the given value.
Definition: Value.h:258
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:442
Operation * getOwner() const
Returns the operation that owns this result.
Definition: Value.h:451
static bool classof(Value value)
Definition: Value.h:446
unsigned getResultNumber() const
Returns the number of this result.
Definition: Value.h:454
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:75
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:291
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:93
bool use_empty() const
Returns true if this value has no uses.
Definition: Value.h:207
constexpr Value(detail::ValueImpl *impl=nullptr)
Definition: Value.h:95
use_iterator use_end() const
Definition: Value.h:198
void setLoc(Location loc)
Definition: Value.cpp:33
void print(raw_ostream &os)
detail::ValueImpl * getImpl() const
Definition: Value.h:235
bool isa() const
Definition: Value.h:98
static Value getFromOpaquePointer(const void *pointer)
Definition: Value.h:232
detail::ValueImpl * impl
A pointer to the internal implementation of the value.
Definition: Value.h:241
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:82
void setType(Type newType)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:133
void dropAllUses() const
Drop all uses of this object from their respective owners.
Definition: Value.h:161
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Definition: Value.h:125
Type getType() const
Return the type of this value.
Definition: Value.h:122
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Definition: Value.h:201
bool operator==(const Value &other) const
Definition: Value.h:118
bool operator!=(const Value &other) const
Definition: Value.h:119
user_iterator user_begin() const
Definition: Value.h:215
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...
Definition: Value.cpp:61
U dyn_cast() const
Definition: Value.h:103
void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
Definition: Value.h:231
OpTy getDefiningOp() const
If this value is the result of an operation of type OpTy, return the operation that defines it.
Definition: Value.h:142
bool isUsedOutsideOfBlock(Block *block)
Returns true if the value is used outside of the given block.
Definition: Value.cpp:90
user_iterator user_end() const
Definition: Value.h:216
Block * getParentBlock()
Return the Block in which this Value is defined.
Definition: Value.cpp:48
U dyn_cast_or_null() const
Definition: Value.h:108
void printAsOperand(raw_ostream &os, AsmState &state)
Print this value as if it were an operand.
U cast() const
Definition: Value.h:113
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
Definition: Value.h:194
void replaceAllUsesWith(Value newValue) const
Replace all uses of 'this' value with the new value, updating anything in the IR that uses 'this' to ...
Definition: Value.h:166
user_range getUsers() const
Definition: Value.h:217
bool hasOneUse() const
Returns true if this value has exactly one use.
Definition: Value.h:204
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:475
Region * getParentRegion()
Return the Region in which this Value is defined.
Definition: Value.cpp:41
use_iterator use_begin() const
Definition: Value.h:197
The internal implementation of a BlockArgument.
Definition: Value.h:278
static bool classof(const ValueImpl *value)
Definition: Value.h:280
This class provides the implementation for an operation result.
Definition: Value.h:353
unsigned getResultNumber() const
Returns the result number of this op result.
Definition: Value.h:420
OpResultImpl * getNextResultAtOffset(intptr_t offset)
Returns the next operation result at offset after this result.
Definition: Value.cpp:130
Operation * getOwner() const
Returns the parent operation of this result.
Definition: Value.cpp:101
static bool classof(const ValueImpl *value)
Definition: Value.h:357
static unsigned getMaxInlineResults()
Returns the maximum number of results that can be stored inline.
Definition: Value.h:375
This class provides the implementation for an operation result whose index cannot be represented "inl...
Definition: Value.h:399
uint64_t outOfLineIndex
The trailing result number, or the offset from the beginning of the OutOfLineOpResult array.
Definition: Value.h:416
static bool classof(const OpResultImpl *value)
Definition: Value.h:405
unsigned getResultNumber() const
Return the result number of this op result.
Definition: Value.h:410
OutOfLineOpResult(Type type, uint64_t outOfLineIndex)
Definition: Value.h:401
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
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.
Definition: Value.h:483
inline ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
Definition: Value.h:475
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:240
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:575
static mlir::BlockArgument getEmptyKey()
Definition: Value.h:506
static mlir::BlockArgument getTombstoneKey()
Definition: Value.h:510
static mlir::OpResult getEmptyKey()
Definition: Value.h:517
static mlir::OpResult getTombstoneKey()
Definition: Value.h:521
static mlir::Value getEmptyKey()
Definition: Value.h:491
static unsigned getHashValue(mlir::Value val)
Definition: Value.h:499
static bool isEqual(mlir::Value lhs, mlir::Value rhs)
Definition: Value.h:502
static mlir::Value getTombstoneKey()
Definition: Value.h:495
static mlir::BlockArgument getFromVoidPointer(void *pointer)
Definition: Value.h:546
static mlir::OpResult getFromVoidPointer(void *pointer)
Definition: Value.h:554
static mlir::Value getFromVoidPointer(void *pointer)
Definition: Value.h:534
static void * getAsVoidPointer(mlir::Value value)
Definition: Value.h:531
This class provides the implementation for an operation result whose index can be represented "inline...
Definition: Value.h:382
unsigned getResultNumber() const
Return the result number of this op result.
Definition: Value.h:390
static bool classof(const OpResultImpl *value)
Definition: Value.h:392
InlineOpResult(Type type, unsigned resultNo)
Definition: Value.h:384
TypedValue is a Value with a statically know type.
Definition: Value.h:429
static bool classof(Value value)
Definition: Value.h:432
Ty getType()
Return the known Type.
Definition: Value.h:435
void setType(Ty ty)
Definition: Value.h:436