MLIR  16.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  /// The type of this result and the kind.
75  llvm::PointerIntPair<Type, 3, Kind> typeAndKind;
76 };
77 } // namespace detail
78 
79 /// This class represents an instance of an SSA value in the MLIR system,
80 /// representing a computable value that has a type and a set of users. An SSA
81 /// value is either a BlockArgument or the result of an operation. Note: This
82 /// class has value-type semantics and is just a simple wrapper around a
83 /// ValueImpl that is either owner by a block(in the case of a BlockArgument) or
84 /// an Operation(in the case of an OpResult).
85 class Value {
86 public:
87  constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {}
88 
89  template <typename U>
90  bool isa() const {
91  return llvm::isa<U>(*this);
92  }
93 
94  template <typename U>
95  U dyn_cast() const {
96  return llvm::dyn_cast<U>(*this);
97  }
98 
99  template <typename U>
100  U dyn_cast_or_null() const {
101  return llvm::dyn_cast_if_present<U>(*this);
102  }
103 
104  template <typename U>
105  U cast() const {
106  return llvm::cast<U>(*this);
107  }
108 
109  explicit operator bool() const { return impl; }
110  bool operator==(const Value &other) const { return impl == other.impl; }
111  bool operator!=(const Value &other) const { return !(*this == other); }
112 
113  /// Return the type of this value.
114  Type getType() const { return impl->getType(); }
115 
116  /// Utility to get the associated MLIRContext that this value is defined in.
117  MLIRContext *getContext() const { return getType().getContext(); }
118 
119  /// Mutate the type of this Value to be of the specified type.
120  ///
121  /// Note that this is an extremely dangerous operation which can create
122  /// completely invalid IR very easily. It is strongly recommended that you
123  /// recreate IR objects with the right types instead of mutating them in
124  /// place.
125  void setType(Type newType) { impl->setType(newType); }
126 
127  /// If this value is the result of an operation, return the operation that
128  /// defines it.
129  Operation *getDefiningOp() const;
130 
131  /// If this value is the result of an operation of type OpTy, return the
132  /// operation that defines it.
133  template <typename OpTy>
134  OpTy getDefiningOp() const {
135  return llvm::dyn_cast_or_null<OpTy>(getDefiningOp());
136  }
137 
138  /// Return the location of this value.
139  Location getLoc() const;
140  void setLoc(Location loc);
141 
142  /// Return the Region in which this Value is defined.
144 
145  /// Return the Block in which this Value is defined.
147 
148  //===--------------------------------------------------------------------===//
149  // UseLists
150  //===--------------------------------------------------------------------===//
151 
152  /// Drop all uses of this object from their respective owners.
153  void dropAllUses() const { return impl->dropAllUses(); }
154 
155  /// Replace all uses of 'this' value with the new value, updating anything in
156  /// the IR that uses 'this' to use the other value instead. When this returns
157  /// there are zero uses of 'this'.
158  void replaceAllUsesWith(Value newValue) const {
159  impl->replaceAllUsesWith(newValue);
160  }
161 
162  /// Replace all uses of 'this' value with 'newValue', updating anything in the
163  /// IR that uses 'this' to use the other value instead except if the user is
164  /// listed in 'exceptions' .
165  void
166  replaceAllUsesExcept(Value newValue,
167  const SmallPtrSetImpl<Operation *> &exceptions) const;
168 
169  /// Replace all uses of 'this' value with 'newValue', updating anything in the
170  /// IR that uses 'this' to use the other value instead except if the user is
171  /// 'exceptedUser'.
172  void replaceAllUsesExcept(Value newValue, Operation *exceptedUser) const;
173 
174  /// Replace all uses of 'this' value with 'newValue' if the given callback
175  /// returns true.
176  void replaceUsesWithIf(Value newValue,
177  function_ref<bool(OpOperand &)> shouldReplace);
178 
179  /// Returns true if the value is used outside of the given block.
180  bool isUsedOutsideOfBlock(Block *block);
181 
182  //===--------------------------------------------------------------------===//
183  // Uses
184 
185  /// This class implements an iterator over the uses of a value.
188 
189  use_iterator use_begin() const { return impl->use_begin(); }
190  use_iterator use_end() const { return use_iterator(); }
191 
192  /// Returns a range of all uses, which is useful for iterating over all uses.
193  use_range getUses() const { return {use_begin(), use_end()}; }
194 
195  /// Returns true if this value has exactly one use.
196  bool hasOneUse() const { return impl->hasOneUse(); }
197 
198  /// Returns true if this value has no uses.
199  bool use_empty() const { return impl->use_empty(); }
200 
201  //===--------------------------------------------------------------------===//
202  // Users
203 
206 
207  user_iterator user_begin() const { return use_begin(); }
208  user_iterator user_end() const { return use_end(); }
209  user_range getUsers() const { return {user_begin(), user_end()}; }
210 
211  //===--------------------------------------------------------------------===//
212  // Utilities
213 
214  void print(raw_ostream &os);
215  void print(raw_ostream &os, const OpPrintingFlags &flags);
216  void print(raw_ostream &os, AsmState &state);
217  void dump();
218 
219  /// Print this value as if it were an operand.
220  void printAsOperand(raw_ostream &os, AsmState &state);
221 
222  /// Methods for supporting PointerLikeTypeTraits.
223  void *getAsOpaquePointer() const { return impl; }
224  static Value getFromOpaquePointer(const void *pointer) {
225  return reinterpret_cast<detail::ValueImpl *>(const_cast<void *>(pointer));
226  }
227  detail::ValueImpl *getImpl() const { return impl; }
228 
229  friend ::llvm::hash_code hash_value(Value arg);
230 
231 protected:
232  /// A pointer to the internal implementation of the value.
234 };
235 
236 inline raw_ostream &operator<<(raw_ostream &os, Value value) {
237  value.print(os);
238  return os;
239 }
240 
241 //===----------------------------------------------------------------------===//
242 // OpOperand
243 //===----------------------------------------------------------------------===//
244 
245 /// This class represents an operand of an operation. Instances of this class
246 /// contain a reference to a specific `Value`.
247 class OpOperand : public IROperand<OpOperand, Value> {
248 public:
249  /// Provide the use list that is attached to the given value.
251  return value.getImpl();
252  }
253 
254  /// Return which operand this is in the OpOperand list of the Operation.
255  unsigned getOperandNumber();
256 
257 private:
258  /// Keep the constructor private and accessible to the OperandStorage class
259  /// only to avoid hard-to-debug typo/programming mistakes.
260  friend class OperandStorage;
262 };
263 
264 //===----------------------------------------------------------------------===//
265 // BlockArgument
266 //===----------------------------------------------------------------------===//
267 
268 namespace detail {
269 /// The internal implementation of a BlockArgument.
270 class BlockArgumentImpl : public ValueImpl {
271 public:
272  static bool classof(const ValueImpl *value) {
273  return value->getKind() == ValueImpl::Kind::BlockArgument;
274  }
275 
276 private:
277  BlockArgumentImpl(Type type, Block *owner, int64_t index, Location loc)
278  : ValueImpl(type, Kind::BlockArgument), owner(owner), index(index),
279  loc(loc) {}
280 
281  /// The owner of this argument.
282  Block *owner;
283 
284  /// The position in the argument list.
285  int64_t index;
286 
287  /// The source location of this argument.
288  Location loc;
289 
290  /// Allow access to owner and constructor.
291  friend BlockArgument;
292 };
293 } // namespace detail
294 
295 /// This class represents an argument of a Block.
296 class BlockArgument : public Value {
297 public:
298  using Value::Value;
299 
300  static bool classof(Value value) {
301  return llvm::isa<detail::BlockArgumentImpl>(value.getImpl());
302  }
303 
304  /// Returns the block that owns this argument.
305  Block *getOwner() const { return getImpl()->owner; }
306 
307  /// Returns the number of this argument.
308  unsigned getArgNumber() const { return getImpl()->index; }
309 
310  /// Return the location for this argument.
311  Location getLoc() const { return getImpl()->loc; }
312  void setLoc(Location loc) { getImpl()->loc = loc; }
313 
314 private:
315  /// Allocate a new argument with the given type and owner.
316  static BlockArgument create(Type type, Block *owner, int64_t index,
317  Location loc) {
318  return new detail::BlockArgumentImpl(type, owner, index, loc);
319  }
320 
321  /// Destroy and deallocate this argument.
322  void destroy() { delete getImpl(); }
323 
324  /// Get a raw pointer to the internal implementation.
325  detail::BlockArgumentImpl *getImpl() const {
326  return reinterpret_cast<detail::BlockArgumentImpl *>(impl);
327  }
328 
329  /// Cache the position in the block argument list.
330  void setArgNumber(int64_t index) { getImpl()->index = index; }
331 
332  /// Allow access to `create`, `destroy` and `setArgNumber`.
333  friend Block;
334 
335  /// Allow access to 'getImpl'.
336  friend Value;
337 };
338 
339 //===----------------------------------------------------------------------===//
340 // OpResult
341 //===----------------------------------------------------------------------===//
342 
343 namespace detail {
344 /// This class provides the implementation for an operation result.
345 class alignas(8) OpResultImpl : public ValueImpl {
346 public:
347  using ValueImpl::ValueImpl;
348 
349  static bool classof(const ValueImpl *value) {
350  return value->getKind() != ValueImpl::Kind::BlockArgument;
351  }
352 
353  /// Returns the parent operation of this result.
354  Operation *getOwner() const;
355 
356  /// Returns the result number of this op result.
357  unsigned getResultNumber() const;
358 
359  /// Returns the next operation result at `offset` after this result. This
360  /// method is useful when indexing the result storage of an operation, given
361  /// that there is more than one kind of operation result (with the different
362  /// kinds having different sizes) and that operations are stored in reverse
363  /// order.
364  OpResultImpl *getNextResultAtOffset(intptr_t offset);
365 
366  /// Returns the maximum number of results that can be stored inline.
367  static unsigned getMaxInlineResults() {
368  return static_cast<unsigned>(Kind::OutOfLineOpResult);
369  }
370 };
371 
372 /// This class provides the implementation for an operation result whose index
373 /// can be represented "inline" in the underlying ValueImpl.
374 struct InlineOpResult : public OpResultImpl {
375 public:
376  InlineOpResult(Type type, unsigned resultNo)
377  : OpResultImpl(type, static_cast<ValueImpl::Kind>(resultNo)) {
378  assert(resultNo < getMaxInlineResults());
379  }
380 
381  /// Return the result number of this op result.
382  unsigned getResultNumber() const { return static_cast<unsigned>(getKind()); }
383 
384  static bool classof(const OpResultImpl *value) {
385  return value->getKind() != ValueImpl::Kind::OutOfLineOpResult;
386  }
387 };
388 
389 /// This class provides the implementation for an operation result whose index
390 /// cannot be represented "inline", and thus requires an additional index field.
392 public:
396 
397  static bool classof(const OpResultImpl *value) {
398  return value->getKind() == ValueImpl::Kind::OutOfLineOpResult;
399  }
400 
401  /// Return the result number of this op result.
402  unsigned getResultNumber() const {
404  }
405 
406  /// The trailing result number, or the offset from the beginning of the
407  /// `OutOfLineOpResult` array.
408  uint64_t outOfLineIndex;
409 };
410 
411 /// Return the result number of this op result.
412 inline unsigned OpResultImpl::getResultNumber() const {
413  if (const auto *outOfLineResult = dyn_cast<OutOfLineOpResult>(this))
414  return outOfLineResult->getResultNumber();
415  return cast<InlineOpResult>(this)->getResultNumber();
416 }
417 
418 /// TypedValue is a Value with a statically know type.
419 /// TypedValue can be null/empty
420 template <typename Ty>
421 struct TypedValue : Value {
422  /// Return the known Type
423  Ty getType() { return Value::getType().template cast<Ty>(); }
424  void setType(mlir::Type ty) {
425  assert(ty.template isa<Ty>());
426  Value::setType(ty);
427  }
428 
429  TypedValue(Value val) : Value(val) {
430  assert(!val || val.getType().template isa<Ty>());
431  }
432  TypedValue &operator=(const Value &other) {
433  assert(!other || other.getType().template isa<Ty>());
434  Value::operator=(other);
435  return *this;
436  }
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  return std::is_same_v<To, std::remove_const_t<From>> ||
579  std::is_base_of_v<To, From> || To::classof(ty);
580  }
581  static inline To doCast(mlir::Value value) { return To(value.getImpl()); }
582 };
583 
584 } // namespace llvm
585 
586 #endif
static constexpr const bool value
This class provides management for the lifetime of the state used when printing the IR.
Definition: AsmState.h:524
This class represents an argument of a Block.
Definition: Value.h:296
Block * getOwner() const
Returns the block that owns this argument.
Definition: Value.h:305
Location getLoc() const
Return the location for this argument.
Definition: Value.h:311
unsigned getArgNumber() const
Returns the number of this argument.
Definition: Value.h:308
static bool classof(Value value)
Definition: Value.h:300
void setLoc(Location loc)
Definition: Value.h:312
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:64
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
This class represents an operand of an operation.
Definition: Value.h:247
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:260
static IRObjectWithUseList< OpOperand > * getUseList(Value value)
Provide the use list that is attached to the given value.
Definition: Value.h:250
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 a basic unit of execution within MLIR.
Definition: Operation.h:31
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:19
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:85
bool use_empty() const
Returns true if this value has no uses.
Definition: Value.h:199
constexpr Value(detail::ValueImpl *impl=nullptr)
Definition: Value.h:87
use_iterator use_end() const
Definition: Value.h:190
void setLoc(Location loc)
Definition: Value.cpp:33
void print(raw_ostream &os)
detail::ValueImpl * getImpl() const
Definition: Value.h:227
bool isa() const
Definition: Value.h:90
static Value getFromOpaquePointer(const void *pointer)
Definition: Value.h:224
detail::ValueImpl * impl
A pointer to the internal implementation of the value.
Definition: Value.h:233
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:125
void dropAllUses() const
Drop all uses of this object from their respective owners.
Definition: Value.h:153
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Definition: Value.h:117
Type getType() const
Return the type of this value.
Definition: Value.h:114
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Definition: Value.h:193
bool operator==(const Value &other) const
Definition: Value.h:110
bool operator!=(const Value &other) const
Definition: Value.h:111
user_iterator user_begin() const
Definition: Value.h:207
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:95
void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
Definition: Value.h:223
OpTy getDefiningOp() const
If this value is the result of an operation of type OpTy, return the operation that defines it.
Definition: Value.h:134
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:208
Block * getParentBlock()
Return the Block in which this Value is defined.
Definition: Value.cpp:48
U dyn_cast_or_null() const
Definition: Value.h:100
void printAsOperand(raw_ostream &os, AsmState &state)
Print this value as if it were an operand.
U cast() const
Definition: Value.h:105
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
Definition: Value.h:186
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:158
user_range getUsers() const
Definition: Value.h:209
bool hasOneUse() const
Returns true if this value has exactly one use.
Definition: Value.h:196
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:189
The internal implementation of a BlockArgument.
Definition: Value.h:270
static bool classof(const ValueImpl *value)
Definition: Value.h:272
This class provides the implementation for an operation result.
Definition: Value.h:345
unsigned getResultNumber() const
Returns the result number of this op result.
Definition: Value.h:412
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:349
static unsigned getMaxInlineResults()
Returns the maximum number of results that can be stored inline.
Definition: Value.h:367
This class provides the implementation for an operation result whose index cannot be represented "inl...
Definition: Value.h:391
uint64_t outOfLineIndex
The trailing result number, or the offset from the beginning of the OutOfLineOpResult array.
Definition: Value.h:408
static bool classof(const OpResultImpl *value)
Definition: Value.h:397
unsigned getResultNumber() const
Return the result number of this op result.
Definition: Value.h:402
OutOfLineOpResult(Type type, uint64_t outOfLineIndex)
Definition: Value.h:393
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:75
void setType(Type type)
Set the type of this value.
Definition: Value.h:66
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: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:374
unsigned getResultNumber() const
Return the result number of this op result.
Definition: Value.h:382
static bool classof(const OpResultImpl *value)
Definition: Value.h:384
InlineOpResult(Type type, unsigned resultNo)
Definition: Value.h:376
TypedValue is a Value with a statically know type.
Definition: Value.h:421
TypedValue & operator=(const Value &other)
Definition: Value.h:432
void setType(mlir::Type ty)
Definition: Value.h:424
Ty getType()
Return the known Type.
Definition: Value.h:423
TypedValue(Value val)
Definition: Value.h:429