MLIR 22.0.0git
AffineOps.h
Go to the documentation of this file.
1//===- AffineOps.h - MLIR Affine Operations -------------------------------===//
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 convenience types for working with Affine operations
10// in the MLIR operation set.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_AFFINE_IR_AFFINEOPS_H
15#define MLIR_DIALECT_AFFINE_IR_AFFINEOPS_H
16
20#include "mlir/IR/AffineMap.h"
21#include "mlir/IR/Builders.h"
24namespace mlir {
25namespace affine {
26
27class AffineApplyOp;
28class AffineBound;
29class AffineMaxOp;
30class AffineMinOp;
31class AffineValueMap;
32
33/// A utility function to check if a value is defined at the top level of an
34/// op with trait `AffineScope` or is a region argument for such an op. A value
35/// of index type defined at the top level is always a valid symbol for all its
36/// uses.
37bool isTopLevelValue(Value value);
38
39/// A utility function to check if a value is defined at the top level of
40/// `region` or is an argument of `region`. A value of index type defined at the
41/// top level of a `AffineScope` region is always a valid symbol for all
42/// uses in that region.
43bool isTopLevelValue(Value value, Region *region);
44
45/// Returns the closest region enclosing `op` that is held by an operation with
46/// trait `AffineScope`; `nullptr` if there is no such region.
47Region *getAffineScope(Operation *op);
48
49/// Returns the closest region enclosing `op` that is held by a non-affine
50/// operation; `nullptr` if there is no such region. This method is meant to
51/// be used by affine analysis methods (e.g. dependence analysis) which are
52/// only meaningful when performed among/between operations from the same
53/// analysis scope.
54Region *getAffineAnalysisScope(Operation *op);
55
56/// Return the product of `terms`, creating an `affine.apply` if any of them are
57/// non-constant values. If any of `terms` is `nullptr`, return `nullptr`.
60
61/// AffineDmaStartOp starts a non-blocking DMA operation that transfers data
62/// from a source memref to a destination memref. The source and destination
63/// memref need not be of the same dimensionality, but need to have the same
64/// elemental type. The operands include the source and destination memref's
65/// each followed by its indices, size of the data transfer in terms of the
66/// number of elements (of the elemental type of the memref), a tag memref with
67/// its indices, and optionally at the end, a stride and a
68/// number_of_elements_per_stride arguments. The tag location is used by an
69/// AffineDmaWaitOp to check for completion. The indices of the source memref,
70/// destination memref, and the tag memref have the same restrictions as any
71/// affine.load/store. In particular, index for each memref dimension must be an
72/// affine expression of loop induction variables and symbols.
73/// The optional stride arguments should be of 'index' type, and specify a
74/// stride for the slower memory space (memory space with a lower memory space
75/// id), transferring chunks of number_of_elements_per_stride every stride until
76/// %num_elements are transferred. Either both or no stride arguments should be
77/// specified. The value of 'num_elements' must be a multiple of
78/// 'number_of_elements_per_stride'. If the source and destination locations
79/// overlap the behavior of this operation is not defined.
80//
81// For example, an AffineDmaStartOp operation that transfers 256 elements of a
82// memref '%src' in memory space 0 at indices [%i + 3, %j] to memref '%dst' in
83// memory space 1 at indices [%k + 7, %l], would be specified as follows:
84//
85// %num_elements = arith.constant 256
86// %idx = arith.constant 0 : index
87// %tag = memref.alloc() : memref<1xi32, 4>
88// affine.dma_start %src[%i + 3, %j], %dst[%k + 7, %l], %tag[%idx],
89// %num_elements :
90// memref<40x128xf32, 0>, memref<2x1024xf32, 1>, memref<1xi32, 2>
91//
92// If %stride and %num_elt_per_stride are specified, the DMA is expected to
93// transfer %num_elt_per_stride elements every %stride elements apart from
94// memory space 0 until %num_elements are transferred.
95//
96// affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%idx], %num_elements,
97// %stride, %num_elt_per_stride : ...
98//
99// TODO: add additional operands to allow source and destination striding, and
100// multiple stride levels (possibly using AffineMaps to specify multiple levels
101// of striding).
103 : public Op<AffineDmaStartOp, OpTrait::MemRefsNormalizable,
104 OpTrait::VariadicOperands, OpTrait::ZeroResults,
105 OpTrait::OpInvariants, AffineMapAccessInterface::Trait,
106 MemoryEffectOpInterface::Trait> {
107public:
108 using Op::Op;
110
111 static void build(OpBuilder &builder, OperationState &result, Value srcMemRef,
112 AffineMap srcMap, ValueRange srcIndices, Value destMemRef,
113 AffineMap dstMap, ValueRange destIndices, Value tagMemRef,
114 AffineMap tagMap, ValueRange tagIndices, Value numElements,
115 Value stride = nullptr, Value elementsPerStride = nullptr);
116
117 static AffineDmaStartOp
118 create(OpBuilder &builder, Location location, Value srcMemRef,
119 AffineMap srcMap, ValueRange srcIndices, Value destMemRef,
120 AffineMap dstMap, ValueRange destIndices, Value tagMemRef,
121 AffineMap tagMap, ValueRange tagIndices, Value numElements,
122 Value stride = nullptr, Value elementsPerStride = nullptr);
123
124 static AffineDmaStartOp create(ImplicitLocOpBuilder &builder, Value srcMemRef,
125 AffineMap srcMap, ValueRange srcIndices,
126 Value destMemRef, AffineMap dstMap,
127 ValueRange destIndices, Value tagMemRef,
128 AffineMap tagMap, ValueRange tagIndices,
129 Value numElements, Value stride = nullptr,
130 Value elementsPerStride = nullptr);
131
132 /// Returns the operand index of the source memref.
133 unsigned getSrcMemRefOperandIndex() { return 0; }
134
135 /// Returns the source MemRefType for this DMA operation.
136 Value getSrcMemRef() { return getOperand(getSrcMemRefOperandIndex()); }
140 MemRefType getSrcMemRefType() {
141 return cast<MemRefType>(getSrcMemRef().getType());
142 }
143
144 /// Returns the rank (number of indices) of the source MemRefType.
145 unsigned getSrcMemRefRank() { return getSrcMemRefType().getRank(); }
146
147 /// Returns the affine map used to access the source memref.
148 AffineMap getSrcMap() { return getSrcMapAttr().getValue(); }
149 AffineMapAttr getSrcMapAttr() {
150 return cast<AffineMapAttr>(
151 *(*this)->getInherentAttr(getSrcMapAttrStrName()));
152 }
153
154 /// Returns the source memref affine map indices for this DMA operation.
155 operand_range getSrcIndices() {
156 return {operand_begin() + getSrcMemRefOperandIndex() + 1,
157 operand_begin() + getSrcMemRefOperandIndex() + 1 +
159 }
160
161 /// Returns the memory space of the source memref.
162 unsigned getSrcMemorySpace() {
163 return cast<MemRefType>(getSrcMemRef().getType()).getMemorySpaceAsInt();
164 }
165
166 /// Returns the operand index of the destination memref.
170
171 /// Returns the destination MemRefType for this DMA operation.
172 Value getDstMemRef() { return getOperand(getDstMemRefOperandIndex()); }
176 MemRefType getDstMemRefType() {
177 return cast<MemRefType>(getDstMemRef().getType());
178 }
179
180 /// Returns the rank (number of indices) of the destination MemRefType.
181 unsigned getDstMemRefRank() {
182 return cast<MemRefType>(getDstMemRef().getType()).getRank();
183 }
184
185 /// Returns the memory space of the source memref.
186 unsigned getDstMemorySpace() {
187 return cast<MemRefType>(getDstMemRef().getType()).getMemorySpaceAsInt();
188 }
189
190 /// Returns the affine map used to access the destination memref.
191 AffineMap getDstMap() { return getDstMapAttr().getValue(); }
192 AffineMapAttr getDstMapAttr() {
193 return cast<AffineMapAttr>(
194 *(*this)->getInherentAttr(getDstMapAttrStrName()));
195 }
196
197 /// Returns the destination memref indices for this DMA operation.
198 operand_range getDstIndices() {
199 return {operand_begin() + getDstMemRefOperandIndex() + 1,
200 operand_begin() + getDstMemRefOperandIndex() + 1 +
202 }
203
204 /// Returns the operand index of the tag memref.
208
209 /// Returns the Tag MemRef for this DMA operation.
210 Value getTagMemRef() { return getOperand(getTagMemRefOperandIndex()); }
214 MemRefType getTagMemRefType() {
215 return cast<MemRefType>(getTagMemRef().getType());
216 }
217
218 /// Returns the rank (number of indices) of the tag MemRefType.
219 unsigned getTagMemRefRank() {
220 return cast<MemRefType>(getTagMemRef().getType()).getRank();
221 }
222
223 /// Returns the affine map used to access the tag memref.
224 AffineMap getTagMap() { return getTagMapAttr().getValue(); }
225 AffineMapAttr getTagMapAttr() {
226 return cast<AffineMapAttr>(
227 *(*this)->getInherentAttr(getTagMapAttrStrName()));
228 }
229
230 /// Returns the tag memref indices for this DMA operation.
231 operand_range getTagIndices() {
232 return {operand_begin() + getTagMemRefOperandIndex() + 1,
233 operand_begin() + getTagMemRefOperandIndex() + 1 +
235 }
236
237 /// Returns the number of elements being transferred by this DMA operation.
239 return getOperand(getTagMemRefOperandIndex() + 1 +
240 getTagMap().getNumInputs());
241 }
242
243 /// Impelements the AffineMapAccessInterface.
244 /// Returns the AffineMapAttr associated with 'memref'.
246 if (memref == getSrcMemRef())
247 return {StringAttr::get(getContext(), getSrcMapAttrStrName()),
248 getSrcMapAttr()};
249 if (memref == getDstMemRef())
250 return {StringAttr::get(getContext(), getDstMapAttrStrName()),
251 getDstMapAttr()};
252 assert(memref == getTagMemRef() &&
253 "DmaStartOp expected source, destination or tag memref");
254 return {StringAttr::get(getContext(), getTagMapAttrStrName()),
255 getTagMapAttr()};
256 }
257
258 /// Returns true if this is a DMA from a faster memory space to a slower one.
262
263 /// Returns true if this is a DMA from a slower memory space to a faster one.
265 // Assumes that a lower number is for a slower memory space.
267 }
268
269 /// Given a DMA start operation, returns the operand position of either the
270 /// source or destination memref depending on the one that is at the higher
271 /// level of the memory hierarchy. Asserts failure if neither is true.
276
277 void
279 &effects);
280
281 static StringRef getSrcMapAttrStrName() { return "src_map"; }
282 static StringRef getDstMapAttrStrName() { return "dst_map"; }
283 static StringRef getTagMapAttrStrName() { return "tag_map"; }
284
285 static StringRef getOperationName() { return "affine.dma_start"; }
286 static ParseResult parse(OpAsmParser &parser, OperationState &result);
287 void print(OpAsmPrinter &p);
288 LogicalResult verifyInvariantsImpl();
289 LogicalResult verifyInvariants() { return verifyInvariantsImpl(); }
290 LogicalResult fold(ArrayRef<Attribute> cstOperands,
292
293 /// Returns true if this DMA operation is strided, returns false otherwise.
294 bool isStrided() {
295 return getNumOperands() !=
297 }
298
299 /// Returns the stride value for this DMA operation.
301 if (!isStrided())
302 return nullptr;
303 return getOperand(getNumOperands() - 1 - 1);
304 }
305
306 /// Returns the number of elements to transfer per stride for this DMA op.
308 if (!isStrided())
309 return nullptr;
310 return getOperand(getNumOperands() - 1);
311 }
312};
313
314/// AffineDmaWaitOp blocks until the completion of a DMA operation associated
315/// with the tag element '%tag[%index]'. %tag is a memref, and %index has to be
316/// an index with the same restrictions as any load/store index. In particular,
317/// index for each memref dimension must be an affine expression of loop
318/// induction variables and symbols. %num_elements is the number of elements
319/// associated with the DMA operation. For example:
320//
321// affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%index], %num_elements :
322// memref<2048xf32, 0>, memref<256xf32, 1>, memref<1xi32, 2>
323// ...
324// ...
325// affine.dma_wait %tag[%index], %num_elements : memref<1xi32, 2>
326//
328 : public Op<AffineDmaWaitOp, OpTrait::MemRefsNormalizable,
329 OpTrait::VariadicOperands, OpTrait::ZeroResults,
330 OpTrait::OpInvariants, AffineMapAccessInterface::Trait> {
331public:
332 using Op::Op;
334
335 static void build(OpBuilder &builder, OperationState &result, Value tagMemRef,
336 AffineMap tagMap, ValueRange tagIndices, Value numElements);
337 static AffineDmaWaitOp create(OpBuilder &builder, Location location,
338 Value tagMemRef, AffineMap tagMap,
339 ValueRange tagIndices, Value numElements);
340 static AffineDmaWaitOp create(ImplicitLocOpBuilder &builder, Value tagMemRef,
341 AffineMap tagMap, ValueRange tagIndices,
342 Value numElements);
343
344 static StringRef getOperationName() { return "affine.dma_wait"; }
345
346 /// Returns the Tag MemRef associated with the DMA operation being waited on.
347 Value getTagMemRef() { return getOperand(0); }
349 MemRefType getTagMemRefType() {
350 return cast<MemRefType>(getTagMemRef().getType());
351 }
352
353 /// Returns the affine map used to access the tag memref.
354 AffineMap getTagMap() { return getTagMapAttr().getValue(); }
355 AffineMapAttr getTagMapAttr() {
356 return cast<AffineMapAttr>(
357 *(*this)->getInherentAttr(getTagMapAttrStrName()));
358 }
359
360 /// Returns the tag memref index for this DMA operation.
361 operand_range getTagIndices() {
362 return {operand_begin() + 1,
363 operand_begin() + 1 + getTagMap().getNumInputs()};
364 }
365
366 /// Returns the rank (number of indices) of the tag memref.
367 unsigned getTagMemRefRank() {
368 return cast<MemRefType>(getTagMemRef().getType()).getRank();
369 }
370
371 /// Impelements the AffineMapAccessInterface. Returns the AffineMapAttr
372 /// associated with 'memref'.
374 assert(memref == getTagMemRef());
375 return {StringAttr::get(getContext(), getTagMapAttrStrName()),
376 getTagMapAttr()};
377 }
378
379 /// Returns the number of elements transferred by the associated DMA op.
380 Value getNumElements() { return getOperand(1 + getTagMap().getNumInputs()); }
381
382 static StringRef getTagMapAttrStrName() { return "tag_map"; }
383 static ParseResult parse(OpAsmParser &parser, OperationState &result);
384 void print(OpAsmPrinter &p);
385 LogicalResult verifyInvariantsImpl();
386 LogicalResult verifyInvariants() { return verifyInvariantsImpl(); }
387 LogicalResult fold(ArrayRef<Attribute> cstOperands,
389 void
391 &effects);
392};
393
394/// Returns true if the given Value can be used as a dimension id in the region
395/// of the closest surrounding op that has the trait `AffineScope`.
396bool isValidDim(Value value);
397
398/// Returns true if the given Value can be used as a dimension id in `region`,
399/// i.e., for all its uses in `region`.
400bool isValidDim(Value value, Region *region);
401
402/// Returns true if the given value can be used as a symbol in the region of the
403/// closest surrounding op that has the trait `AffineScope`.
404bool isValidSymbol(Value value);
405
406/// Returns true if the given Value can be used as a symbol for `region`, i.e.,
407/// for all its uses in `region`.
408bool isValidSymbol(Value value, Region *region);
409
410/// Parses dimension and symbol list. `numDims` is set to the number of
411/// dimensions in the list parsed.
412ParseResult parseDimAndSymbolList(OpAsmParser &parser,
413 SmallVectorImpl<Value> &operands,
414 unsigned &numDims);
415
416/// Modifies both `map` and `operands` in-place so as to:
417/// 1. drop duplicate operands
418/// 2. drop unused dims and symbols from map
419/// 3. promote valid symbols to symbolic operands in case they appeared as
420/// dimensional operands
421/// 4. propagate constant operands and drop them
423 SmallVectorImpl<Value> *operands);
424
425/// Canonicalizes an integer set the same way canonicalizeMapAndOperands does
426/// for affine maps.
428 SmallVectorImpl<Value> *operands);
429
430/// Returns a composed AffineApplyOp by composing `map` and `operands` with
431/// other AffineApplyOps supplying those operands. The operands of the resulting
432/// AffineApplyOp do not change the length of AffineApplyOp chains.
433AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map,
434 ArrayRef<OpFoldResult> operands,
435 bool composeAffineMin = false);
437 ArrayRef<OpFoldResult> operands,
438 bool composeAffineMin = false);
439
440/// Constructs an AffineApplyOp that applies `map` to `operands` after composing
441/// the map with the maps of any other AffineApplyOp supplying the operands,
442/// then immediately attempts to fold it. If folding results in a constant
443/// value, no ops are actually created. The `map` must be a single-result affine
444/// map.
446 AffineMap map,
447 ArrayRef<OpFoldResult> operands,
448 bool composeAffineMin = false);
449/// Variant of `makeComposedFoldedAffineApply` that applies to an expression.
451 AffineExpr expr,
452 ArrayRef<OpFoldResult> operands,
453 bool composeAffineMin = false);
454/// Variant of `makeComposedFoldedAffineApply` suitable for multi-result maps.
455/// Note that this may create as many affine.apply operations as the map has
456/// results given that affine.apply must be single-result.
459 bool composeAffineMin = false);
460
461/// Returns an AffineMinOp obtained by composing `map` and `operands` with
462/// AffineApplyOps supplying those operands.
463AffineMinOp makeComposedAffineMin(OpBuilder &b, Location loc, AffineMap map,
464 ArrayRef<OpFoldResult> operands);
465
466/// Constructs an AffineMinOp that computes a minimum across the results of
467/// applying `map` to `operands`, then immediately attempts to fold it. If
468/// folding results in a constant value, no ops are actually created.
470 AffineMap map,
471 ArrayRef<OpFoldResult> operands);
472
473/// Constructs an AffineMinOp that computes a maximum across the results of
474/// applying `map` to `operands`, then immediately attempts to fold it. If
475/// folding results in a constant value, no ops are actually created.
477 AffineMap map,
478 ArrayRef<OpFoldResult> operands);
479
480/// Given an affine map `map` and its input `operands`, this method composes
481/// into `map`, maps of AffineApplyOps whose results are the values in
482/// `operands`, iteratively until no more of `operands` are the result of an
483/// AffineApplyOp. When this function returns, `map` becomes the composed affine
484/// map, and each Value in `operands` is guaranteed to be either a loop IV or a
485/// terminal symbol, i.e., a symbol defined at the top level or a block/function
486/// argument.
488 SmallVectorImpl<Value> *operands,
489 bool composeAffineMin = false);
490
491} // namespace affine
492} // namespace mlir
493
494#include "mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc"
495
496#define GET_OP_CLASSES
497#include "mlir/Dialect/Affine/IR/AffineOps.h.inc"
498
499namespace mlir {
500namespace affine {
501
502/// Returns true if the provided value is the induction variable of an
503/// AffineForOp.
504bool isAffineForInductionVar(Value val);
505
506/// Returns true if `val` is the induction variable of an AffineParallelOp.
507bool isAffineParallelInductionVar(Value val);
508
509/// Returns true if the provided value is the induction variable of an
510/// AffineForOp or AffineParallelOp.
511bool isAffineInductionVar(Value val);
512
513/// Returns the loop parent of an induction variable. If the provided value is
514/// not an induction variable, then return nullptr.
515AffineForOp getForInductionVarOwner(Value val);
516
517/// Returns true if the provided value is among the induction variables of an
518/// AffineParallelOp.
519AffineParallelOp getAffineParallelInductionVarOwner(Value val);
520
521/// Extracts the induction variables from a list of AffineForOps and places them
522/// in the output argument `ivs`.
523void extractForInductionVars(ArrayRef<AffineForOp> forInsts,
524 SmallVectorImpl<Value> *ivs);
525
526/// Extracts the induction variables from a list of either AffineForOp or
527/// AffineParallelOp and places them in the output argument `ivs`.
528void extractInductionVars(ArrayRef<Operation *> affineOps,
529 SmallVectorImpl<Value> &ivs);
530
531/// Builds a perfect nest of affine.for loops, i.e., each loop except the
532/// innermost one contains only another loop and a terminator. The loops iterate
533/// from "lbs" to "ubs" with "steps". The body of the innermost loop is
534/// populated by calling "bodyBuilderFn" and providing it with an OpBuilder, a
535/// Location and a list of loop induction variables.
536void buildAffineLoopNest(OpBuilder &builder, Location loc,
537 ArrayRef<int64_t> lbs, ArrayRef<int64_t> ubs,
538 ArrayRef<int64_t> steps,
539 function_ref<void(OpBuilder &, Location, ValueRange)>
540 bodyBuilderFn = nullptr);
541void buildAffineLoopNest(OpBuilder &builder, Location loc, ValueRange lbs,
542 ValueRange ubs, ArrayRef<int64_t> steps,
543 function_ref<void(OpBuilder &, Location, ValueRange)>
544 bodyBuilderFn = nullptr);
545
546/// AffineBound represents a lower or upper bound in the for operation.
547/// This class does not own the underlying operands. Instead, it refers
548/// to the operands stored in the AffineForOp. Its life span should not exceed
549/// that of the for operation it refers to.
550class AffineBound {
551public:
553 AffineMap getMap() { return map; }
554
555 unsigned getNumOperands() { return operands.size(); }
556 Value getOperand(unsigned idx) {
557 return op.getOperand(operands.getBeginOperandIndex() + idx);
558 }
559
560 using operand_iterator = AffineForOp::operand_iterator;
561 using operand_range = AffineForOp::operand_range;
562
563 operand_iterator operandBegin() { return operands.begin(); }
564 operand_iterator operandEnd() { return operands.end(); }
566
567private:
568 // 'affine.for' operation that contains this bound.
569 AffineForOp op;
570 // Operands of the affine map.
571 OperandRange operands;
572 // Affine map for this bound.
573 AffineMap map;
574
575 AffineBound(AffineForOp op, OperandRange operands, AffineMap map)
576 : op(op), operands(operands), map(map) {}
577
578 friend class AffineForOp;
579};
580
581} // namespace affine
582} // namespace mlir
583
584#endif
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
Base type for affine expression.
Definition AffineExpr.h:68
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
unsigned getNumInputs() const
ImplicitLocOpBuilder maintains a 'current location', allowing use of the create<> method without spec...
Definition Builders.h:630
An integer set representing a conjunction of one or more affine equalities and inequalities.
Definition IntegerSet.h:44
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
NamedAttribute represents a combination of a name and an Attribute value.
Definition Attributes.h:164
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class helps build Operations.
Definition Builders.h:207
This class represents a single result from folding an operation.
This class represents an operand of an operation.
Definition Value.h:257
MLIRContext * getContext()
Return the context this operation belongs to.
Op()
This is a public constructor. Any op can be initialized to null.
This class implements the operand iterators for the Operation class.
Definition ValueRange.h:43
OpOperand & getOpOperand(unsigned idx)
Definition Operation.h:388
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
This class represents a specific instance of an effect.
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
AffineBound represents a lower or upper bound in the for operation.
Definition AffineOps.h:550
Value getOperand(unsigned idx)
Definition AffineOps.h:556
operand_iterator operandBegin()
Definition AffineOps.h:563
AffineForOp::operand_iterator operand_iterator
Definition AffineOps.h:560
AffineForOp::operand_range operand_range
Definition AffineOps.h:561
AffineForOp getAffineForOp()
Definition AffineOps.h:552
operand_range getOperands()
Definition AffineOps.h:565
operand_iterator operandEnd()
Definition AffineOps.h:564
AffineDmaStartOp starts a non-blocking DMA operation that transfers data from a source memref to a de...
Definition AffineOps.h:106
OpOperand & getTagMemRefMutable()
Definition AffineOps.h:211
Value getTagMemRef()
Returns the Tag MemRef for this DMA operation.
Definition AffineOps.h:210
bool isSrcMemorySpaceFaster()
Returns true if this is a DMA from a slower memory space to a faster one.
Definition AffineOps.h:264
bool isDestMemorySpaceFaster()
Returns true if this is a DMA from a faster memory space to a slower one.
Definition AffineOps.h:259
unsigned getFasterMemPos()
Given a DMA start operation, returns the operand position of either the source or destination memref ...
Definition AffineOps.h:272
unsigned getTagMemRefRank()
Returns the rank (number of indices) of the tag MemRefType.
Definition AffineOps.h:219
static void build(OpBuilder &builder, OperationState &result, Value srcMemRef, AffineMap srcMap, ValueRange srcIndices, Value destMemRef, AffineMap dstMap, ValueRange destIndices, Value tagMemRef, AffineMap tagMap, ValueRange tagIndices, Value numElements, Value stride=nullptr, Value elementsPerStride=nullptr)
operand_range getDstIndices()
Returns the destination memref indices for this DMA operation.
Definition AffineOps.h:198
Value getNumElementsPerStride()
Returns the number of elements to transfer per stride for this DMA op.
Definition AffineOps.h:307
unsigned getSrcMemorySpace()
Returns the memory space of the source memref.
Definition AffineOps.h:162
AffineMapAttr getTagMapAttr()
Definition AffineOps.h:225
unsigned getSrcMemRefRank()
Returns the rank (number of indices) of the source MemRefType.
Definition AffineOps.h:145
operand_range getSrcIndices()
Returns the source memref affine map indices for this DMA operation.
Definition AffineOps.h:155
AffineMapAttr getSrcMapAttr()
Definition AffineOps.h:149
bool isStrided()
Returns true if this DMA operation is strided, returns false otherwise.
Definition AffineOps.h:294
AffineMap getDstMap()
Returns the affine map used to access the destination memref.
Definition AffineOps.h:191
void print(OpAsmPrinter &p)
OpOperand & getDstMemRefMutable()
Definition AffineOps.h:173
Value getDstMemRef()
Returns the destination MemRefType for this DMA operation.
Definition AffineOps.h:172
static ArrayRef< StringRef > getAttributeNames()
Definition AffineOps.h:109
static StringRef getSrcMapAttrStrName()
Definition AffineOps.h:281
AffineMapAttr getDstMapAttr()
Definition AffineOps.h:192
unsigned getDstMemorySpace()
Returns the memory space of the source memref.
Definition AffineOps.h:186
unsigned getSrcMemRefOperandIndex()
Returns the operand index of the source memref.
Definition AffineOps.h:133
unsigned getTagMemRefOperandIndex()
Returns the operand index of the tag memref.
Definition AffineOps.h:205
static StringRef getTagMapAttrStrName()
Definition AffineOps.h:283
LogicalResult verifyInvariantsImpl()
void getEffects(SmallVectorImpl< SideEffects::EffectInstance< MemoryEffects::Effect > > &effects)
unsigned getDstMemRefRank()
Returns the rank (number of indices) of the destination MemRefType.
Definition AffineOps.h:181
LogicalResult verifyInvariants()
Definition AffineOps.h:289
AffineMap getSrcMap()
Returns the affine map used to access the source memref.
Definition AffineOps.h:148
Value getNumElements()
Returns the number of elements being transferred by this DMA operation.
Definition AffineOps.h:238
static AffineDmaStartOp create(OpBuilder &builder, Location location, Value srcMemRef, AffineMap srcMap, ValueRange srcIndices, Value destMemRef, AffineMap dstMap, ValueRange destIndices, Value tagMemRef, AffineMap tagMap, ValueRange tagIndices, Value numElements, Value stride=nullptr, Value elementsPerStride=nullptr)
Op()
This is a public constructor. Any op can be initialized to null.
AffineMap getTagMap()
Returns the affine map used to access the tag memref.
Definition AffineOps.h:224
static ParseResult parse(OpAsmParser &parser, OperationState &result)
Value getStride()
Returns the stride value for this DMA operation.
Definition AffineOps.h:300
unsigned getDstMemRefOperandIndex()
Returns the operand index of the destination memref.
Definition AffineOps.h:167
static StringRef getDstMapAttrStrName()
Definition AffineOps.h:282
static StringRef getOperationName()
Definition AffineOps.h:285
NamedAttribute getAffineMapAttrForMemRef(Value memref)
Impelements the AffineMapAccessInterface.
Definition AffineOps.h:245
Value getSrcMemRef()
Returns the source MemRefType for this DMA operation.
Definition AffineOps.h:136
OpOperand & getSrcMemRefMutable()
Definition AffineOps.h:137
operand_range getTagIndices()
Returns the tag memref indices for this DMA operation.
Definition AffineOps.h:231
LogicalResult fold(ArrayRef< Attribute > cstOperands, SmallVectorImpl< OpFoldResult > &results)
AffineDmaWaitOp blocks until the completion of a DMA operation associated with the tag element 'tag[i...
Definition AffineOps.h:330
Value getNumElements()
Returns the number of elements transferred by the associated DMA op.
Definition AffineOps.h:380
NamedAttribute getAffineMapAttrForMemRef(Value memref)
Impelements the AffineMapAccessInterface.
Definition AffineOps.h:373
LogicalResult verifyInvariants()
Definition AffineOps.h:386
LogicalResult verifyInvariantsImpl()
static StringRef getOperationName()
Definition AffineOps.h:344
Value getTagMemRef()
Returns the Tag MemRef associated with the DMA operation being waited on.
Definition AffineOps.h:347
static ParseResult parse(OpAsmParser &parser, OperationState &result)
static StringRef getTagMapAttrStrName()
Definition AffineOps.h:382
void getEffects(SmallVectorImpl< SideEffects::EffectInstance< MemoryEffects::Effect > > &effects)
LogicalResult fold(ArrayRef< Attribute > cstOperands, SmallVectorImpl< OpFoldResult > &results)
AffineMapAttr getTagMapAttr()
Definition AffineOps.h:355
void print(OpAsmPrinter &p)
static AffineDmaWaitOp create(OpBuilder &builder, Location location, Value tagMemRef, AffineMap tagMap, ValueRange tagIndices, Value numElements)
AffineMap getTagMap()
Returns the affine map used to access the tag memref.
Definition AffineOps.h:354
unsigned getTagMemRefRank()
Returns the rank (number of indices) of the tag memref.
Definition AffineOps.h:367
Op()
This is a public constructor. Any op can be initialized to null.
static ArrayRef< StringRef > getAttributeNames()
Definition AffineOps.h:333
static void build(OpBuilder &builder, OperationState &result, Value tagMemRef, AffineMap tagMap, ValueRange tagIndices, Value numElements)
OpOperand & getTagMemRefMutable()
Definition AffineOps.h:348
operand_range getTagIndices()
Returns the tag memref index for this DMA operation.
Definition AffineOps.h:361
An AffineValueMap is an affine map plus its ML value operands and results for analysis purposes.
void buildAffineLoopNest(OpBuilder &builder, Location loc, ArrayRef< int64_t > lbs, ArrayRef< int64_t > ubs, ArrayRef< int64_t > steps, function_ref< void(OpBuilder &, Location, ValueRange)> bodyBuilderFn=nullptr)
Builds a perfect nest of affine.for loops, i.e., each loop except the innermost one contains only ano...
AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands, bool composeAffineMin=false)
Returns a composed AffineApplyOp by composing map and operands with other AffineApplyOps supplying th...
void extractForInductionVars(ArrayRef< AffineForOp > forInsts, SmallVectorImpl< Value > *ivs)
Extracts the induction variables from a list of AffineForOps and places them in the output argument i...
bool isValidDim(Value value)
Returns true if the given Value can be used as a dimension id in the region of the closest surroundin...
bool isAffineInductionVar(Value val)
Returns true if the provided value is the induction variable of an AffineForOp or AffineParallelOp.
SmallVector< OpFoldResult > makeComposedFoldedMultiResultAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands, bool composeAffineMin=false)
Variant of makeComposedFoldedAffineApply suitable for multi-result maps.
OpFoldResult computeProduct(Location loc, OpBuilder &builder, ArrayRef< OpFoldResult > terms)
Return the product of terms, creating an affine.apply if any of them are non-constant values.
AffineForOp getForInductionVarOwner(Value val)
Returns the loop parent of an induction variable.
void canonicalizeMapAndOperands(AffineMap *map, SmallVectorImpl< Value > *operands)
Modifies both map and operands in-place so as to:
OpFoldResult makeComposedFoldedAffineMax(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineMinOp that computes a maximum across the results of applying map to operands,...
bool isAffineForInductionVar(Value val)
Returns true if the provided value is the induction variable of an AffineForOp.
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands, bool composeAffineMin=false)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
OpFoldResult makeComposedFoldedAffineMin(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineMinOp that computes a minimum across the results of applying map to operands,...
bool isTopLevelValue(Value value)
A utility function to check if a value is defined at the top level of an op with trait AffineScope or...
Region * getAffineAnalysisScope(Operation *op)
Returns the closest region enclosing op that is held by a non-affine operation; nullptr if there is n...
void fullyComposeAffineMapAndOperands(AffineMap *map, SmallVectorImpl< Value > *operands, bool composeAffineMin=false)
Given an affine map map and its input operands, this method composes into map, maps of AffineApplyOps...
void canonicalizeSetAndOperands(IntegerSet *set, SmallVectorImpl< Value > *operands)
Canonicalizes an integer set the same way canonicalizeMapAndOperands does for affine maps.
void extractInductionVars(ArrayRef< Operation * > affineOps, SmallVectorImpl< Value > &ivs)
Extracts the induction variables from a list of either AffineForOp or AffineParallelOp and places the...
bool isValidSymbol(Value value)
Returns true if the given value can be used as a symbol in the region of the closest surrounding op t...
AffineParallelOp getAffineParallelInductionVarOwner(Value val)
Returns true if the provided value is among the induction variables of an AffineParallelOp.
Region * getAffineScope(Operation *op)
Returns the closest region enclosing op that is held by an operation with trait AffineScope; nullptr ...
ParseResult parseDimAndSymbolList(OpAsmParser &parser, SmallVectorImpl< Value > &operands, unsigned &numDims)
Parses dimension and symbol list.
bool isAffineParallelInductionVar(Value val)
Returns true if val is the induction variable of an AffineParallelOp.
AffineMinOp makeComposedAffineMin(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Returns an AffineMinOp obtained by composing map and operands with AffineApplyOps supplying those ope...
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition Utils.cpp:304
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152
This represents an operation in an abstracted form, suitable for use with the builder APIs.