MLIR: include/mlir/IR/Value.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13 #ifndef MLIR_IR_VALUE_H
14 #define MLIR_IR_VALUE_H
15
19 #include "llvm/Support/PointerLikeTypeTraits.h"
20
21 namespace mlir {
22 class AsmState;
24 class BlockArgument;
25 class Operation;
26 class OpOperand;
27 class OpPrintingFlags;
28 class OpResult;
29 class Region;
31
32
33
34
35
36 namespace detail {
37
38
39
41 public:
42
43
44
46
47
48
49
51
52
53
54
56
57
58
60 };
61
62
64
65
67
68
70
71 protected:
73
74
75
76 #ifndef NDEBUG
79
80 #endif
81
82
84 };
85 }
86
87
88
89
90
91
92
93
94
95
97 public:
99
100 explicit operator bool() const { return impl; }
102 bool operator!=(const Value &other) const { return !(*this == other); }
103
104
106
107
109
110
111
112
113
114
115
117
118
119
121
122
123
124 template
126 return llvm::dyn_cast_or_null(getDefiningOp());
127 }
128
129
132
133
135
136
138
139
140
141
142
143
145
146
147
148
150 impl->replaceAllUsesWith(newValue);
151 }
152
153
154
155
158
159
160
161
163
164
165
168
169
171
172
173
174
176
177
178
179
180
183
186
187
189
190
191
192
193
195
196
198
199
200 bool hasNUses(unsigned n) const;
201
202
203
204
206
207
209
210
211
212
215
219
220
221
222
223 void print(raw_ostream &os) const;
225 void print(raw_ostream &os, AsmState &state) const;
226 void dump() const;
227
228
231
232
235 return reinterpret_cast<detail::ValueImpl *>(const_cast<void *>(pointer));
236 }
238
240
241 protected:
242
244 };
245
248 return os;
249 }
250
251
252
253
254
255
256
258 public:
259
262 }
263
264
266
267
269
270 private:
271
272
275 };
276
277
278
279
280
281 namespace detail {
282
284 public:
287 }
288
289 private:
292 loc(loc) {}
293
294
296
297
298 int64_t index;
299
300
302
303
305 };
306 }
307
308
310 public:
312
314 return llvm::isadetail::BlockArgumentImpl(value.getImpl());
315 }
316
317
319
320
321 unsigned getArgNumber() const { return getImpl()->index; }
322
323
326
327 private:
328
332 }
333
334
335 void destroy() { delete getImpl(); }
336
337
338 detail::BlockArgumentImpl *getImpl() const {
339 return reinterpret_cast<detail::BlockArgumentImpl *>(impl);
340 }
341
342
343 void setArgNumber(int64_t index) { getImpl()->index = index; }
344
345
346 friend Block;
347
348
349 friend Value;
350 };
351
352
353
354
355
356 namespace detail {
357
359 public:
361
364 }
365
366
368
369
371
372
373
374
375
376
378
379
382 }
383 };
384
385
386
388 public:
392 }
393
394
396
399 }
400 };
401
402
403
405 public:
409
412 }
413
414
417 }
418
419
420
422 };
423
424
426 if (const auto *outOfLineResult = dyn_cast(this))
427 return outOfLineResult->getResultNumber();
428 return cast(this)->getResultNumber();
429 }
430
431
432
433 template
436
438
439
442 };
443
444 }
445
446
448 public:
450
452 return llvm::isadetail::OpResultImpl(value.getImpl());
453 }
454
455
457
458
460
461 private:
462
465 }
466
467
468
469 static unsigned getNumInline(unsigned numResults);
470
471
472
473 static unsigned getNumTrailing(unsigned numResults);
474
475
476 friend Operation;
477 };
478
479
482 }
483
484 template <typename Ty, typename Value = mlir::Value>
485
486
487 using TypedValue = std::conditional_t<std::is_same_v<Ty, mlir::Type>,
489
490 }
491
492 namespace llvm {
493
494 template <>
499 }
503 }
506 }
508 };
509 template <>
514 }
518 }
519 };
520 template <>
525 }
529 }
530 };
531 template
537 }
541 }
542 };
543
544
545 template <>
546 struct PointerLikeTypeTraits<mlir::Value> {
547 public:
550 }
553 }
554 enum {
555 NumLowBitsAvailable =
556 PointerLikeTypeTraits<mlir::detail::ValueImpl *>::NumLowBitsAvailable
558 };
559 template <>
560 struct PointerLikeTypeTraits<mlir::BlockArgument>
561 : public PointerLikeTypeTraitsmlir::Value {
562 public:
565 }
566 };
567 template <>
568 struct PointerLikeTypeTraits<mlir::OpResult>
569 : public PointerLikeTypeTraitsmlir::Value {
570 public:
573 }
574 };
575 template
577 : public PointerLikeTypeTraitsmlir::Value {
578 public:
581 }
582 };
583
584
585
586 template <typename To, typename From>
588 To, From,
589 std::enable_if_t<std::is_same_v<mlir::Value, std::remove_const_t> ||
590 std::is_base_of_v<mlir::Value, From>>>
593
594
595
596
597
598
599
601
602
603 if constexpr (std::is_base_of_v<To, From>) {
604 return true;
605 } else {
606 return To::classof(ty);
607 }
608 }
610 };
611
612 }
613
614 #endif
union mlir::linalg::@1203::ArityGroupAndKind::Kind kind
This class provides management for the lifetime of the state used when printing the IR.
This class represents an argument of a Block.
Block * getOwner() const
Returns the block that owns this argument.
Location getLoc() const
Return the location for this argument.
unsigned getArgNumber() const
Returns the number of this argument.
static bool classof(Value value)
void setLoc(Location loc)
Block represents an ordered list of Operations.
This class represents a single IR object that contains a use list.
A reference to a value, suitable for use as an operand of an operation.
void set(Value newValue)
Set the current value being used by this operand.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents an operand of an operation.
unsigned getOperandNumber()
Return which operand this is in the OpOperand list of the Operation.
friend class OperandStorage
Keep the constructor private and accessible to the OperandStorage class only to avoid hard-to-debug t...
static IRObjectWithUseList< OpOperand > * getUseList(Value value)
Provide the use list that is attached to the given value.
void assign(Value value)
Set the current value being used by this operand.
Set of flags used to control the behavior of the various IR print methods (e.g.
This is a value defined by a result of an operation.
Operation * getOwner() const
Returns the operation that owns this result.
static bool classof(Value value)
unsigned getResultNumber() const
Returns the number of this result.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
An iterator over the users of an IRObject.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
bool use_empty() const
Returns true if this value has no uses.
constexpr Value(detail::ValueImpl *impl=nullptr)
use_iterator use_end() const
void setLoc(Location loc)
void dropAllUses()
Drop all uses of this object from their respective owners.
detail::ValueImpl * getImpl() const
static Value getFromOpaquePointer(const void *pointer)
bool hasNUsesOrMore(unsigned n) const
Return true if this value has n uses or more.
detail::ValueImpl * impl
A pointer to the internal implementation of the value.
void replaceUsesWithIf(Value newValue, function_ref< bool(OpOperand &)> shouldReplace)
Replace all uses of 'this' value with 'newValue' if the given callback returns true.
void setType(Type newType)
Mutate the type of this Value to be of the specified type.
void print(raw_ostream &os) const
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Type getType() const
Return the type of this value.
void shuffleUseList(ArrayRef< unsigned > indices)
Shuffle the use list order according to the provided indices.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
bool operator==(const Value &other) const
bool operator!=(const Value &other) const
user_iterator user_begin() const
void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
OpTy getDefiningOp() const
If this value is the result of an operation of type OpTy, return the operation that defines it.
user_iterator user_end() const
Block * getParentBlock()
Return the Block in which this Value is defined.
void replaceAllUsesExcept(Value newValue, const SmallPtrSetImpl< Operation * > &exceptions)
Replace all uses of 'this' value with 'newValue', updating anything in the IR that uses 'this' to use...
void printAsOperand(raw_ostream &os, AsmState &state) const
Print this value as if it were an operand.
ValueUseIterator< OpOperand > use_iterator
This class implements an iterator over the uses of a value.
unsigned getNumUses() const
This method computes the number of uses of this Value.
bool hasNUses(unsigned n) const
Return true if this Value has exactly n uses.
void replaceAllUsesWith(Value newValue)
Replace all uses of 'this' value with the new value, updating anything in the IR that uses 'this' to ...
user_range getUsers() const
bool hasOneUse() const
Returns true if this value has exactly one use.
bool isUsedOutsideOfBlock(Block *block) const
Returns true if the value is used outside of the given block.
Location getLoc() const
Return the location of this value.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
friend ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
Region * getParentRegion()
Return the Region in which this Value is defined.
use_iterator use_begin() const
The internal implementation of a BlockArgument.
static bool classof(const ValueImpl *value)
This class provides the implementation for an operation result.
unsigned getResultNumber() const
Returns the result number of this op result.
OpResultImpl * getNextResultAtOffset(intptr_t offset)
Returns the next operation result at offset after this result.
Operation * getOwner() const
Returns the parent operation of this result.
static bool classof(const ValueImpl *value)
static unsigned getMaxInlineResults()
Returns the maximum number of results that can be stored inline.
This class provides the implementation for an operation result whose index cannot be represented "inl...
uint64_t outOfLineIndex
The trailing result number, or the offset from the beginning of the OutOfLineOpResult array.
static bool classof(const OpResultImpl *value)
unsigned getResultNumber() const
Return the result number of this op result.
OutOfLineOpResult(Type type, uint64_t outOfLineIndex)
The base class for all derived Value classes.
Kind
The enumeration represents the various different kinds of values the internal representation may take...
@ OutOfLineOpResult
The next kind represents a 'out-of-line' operation result.
@ BlockArgument
The last kind represents a block argument.
ValueImpl(Type type, Kind kind)
llvm::PointerIntPair< Type, 3, Kind > typeAndKind
The type of this result and the kind.
LLVM_DUMP_METHOD Kind debug_getKind() const
void setType(Type type)
Set the type of this value.
LLVM_DUMP_METHOD Type debug_getType() const
Expose a few methods explicitly for the debugger to call for visualization.
Type getType() const
Return the type of this value.
Kind getKind() const
Return the kind of this value.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
inline ::llvm::hash_code hash_value(Value arg)
Make Value hashable.
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static To doCast(mlir::Value value)
static bool isPossible(mlir::Value ty)
Arguments are taken as mlir::Value here and not as From, because when casting from an intermediate ty...
static mlir::BlockArgument getEmptyKey()
static mlir::BlockArgument getTombstoneKey()
static mlir::OpResult getEmptyKey()
static mlir::OpResult getTombstoneKey()
static mlir::Value getEmptyKey()
static unsigned getHashValue(mlir::Value val)
static bool isEqual(mlir::Value lhs, mlir::Value rhs)
static mlir::Value getTombstoneKey()
static mlir::detail::TypedValue< T > getEmptyKey()
static mlir::detail::TypedValue< T > getTombstoneKey()
static mlir::BlockArgument getFromVoidPointer(void *pointer)
static mlir::OpResult getFromVoidPointer(void *pointer)
static mlir::Value getFromVoidPointer(void *pointer)
static void * getAsVoidPointer(mlir::Value value)
static mlir::detail::TypedValue< T > getFromVoidPointer(void *pointer)
This class provides the implementation for an operation result whose index can be represented "inline...
unsigned getResultNumber() const
Return the result number of this op result.
static bool classof(const OpResultImpl *value)
InlineOpResult(Type type, unsigned resultNo)
TypedValue is a Value with a statically know type.
static bool classof(Value value)
Ty getType() const
Return the known Type.