MLIR  17.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 
19 #include "mlir/IR/AffineMap.h"
20 #include "mlir/IR/Builders.h"
23 
24 namespace mlir {
25 namespace affine {
26 
27 class AffineApplyOp;
28 class AffineBound;
29 class AffineValueMap;
30 
31 /// A utility function to check if a value is defined at the top level of an
32 /// op with trait `AffineScope` or is a region argument for such an op. A value
33 /// of index type defined at the top level is always a valid symbol for all its
34 /// uses.
35 bool isTopLevelValue(Value value);
36 
37 /// A utility function to check if a value is defined at the top level of
38 /// `region` or is an argument of `region`. A value of index type defined at the
39 /// top level of a `AffineScope` region is always a valid symbol for all
40 /// uses in that region.
41 bool isTopLevelValue(Value value, Region *region);
42 
43 /// Returns the closest region enclosing `op` that is held by an operation with
44 /// trait `AffineScope`; `nullptr` if there is no such region.
45 Region *getAffineScope(Operation *op);
46 
47 /// AffineDmaStartOp starts a non-blocking DMA operation that transfers data
48 /// from a source memref to a destination memref. The source and destination
49 /// memref need not be of the same dimensionality, but need to have the same
50 /// elemental type. The operands include the source and destination memref's
51 /// each followed by its indices, size of the data transfer in terms of the
52 /// number of elements (of the elemental type of the memref), a tag memref with
53 /// its indices, and optionally at the end, a stride and a
54 /// number_of_elements_per_stride arguments. The tag location is used by an
55 /// AffineDmaWaitOp to check for completion. The indices of the source memref,
56 /// destination memref, and the tag memref have the same restrictions as any
57 /// affine.load/store. In particular, index for each memref dimension must be an
58 /// affine expression of loop induction variables and symbols.
59 /// The optional stride arguments should be of 'index' type, and specify a
60 /// stride for the slower memory space (memory space with a lower memory space
61 /// id), transferring chunks of number_of_elements_per_stride every stride until
62 /// %num_elements are transferred. Either both or no stride arguments should be
63 /// specified. The value of 'num_elements' must be a multiple of
64 /// 'number_of_elements_per_stride'. If the source and destination locations
65 /// overlap the behavior of this operation is not defined.
66 //
67 // For example, an AffineDmaStartOp operation that transfers 256 elements of a
68 // memref '%src' in memory space 0 at indices [%i + 3, %j] to memref '%dst' in
69 // memory space 1 at indices [%k + 7, %l], would be specified as follows:
70 //
71 // %num_elements = arith.constant 256
72 // %idx = arith.constant 0 : index
73 // %tag = memref.alloc() : memref<1xi32, 4>
74 // affine.dma_start %src[%i + 3, %j], %dst[%k + 7, %l], %tag[%idx],
75 // %num_elements :
76 // memref<40x128xf32, 0>, memref<2x1024xf32, 1>, memref<1xi32, 2>
77 //
78 // If %stride and %num_elt_per_stride are specified, the DMA is expected to
79 // transfer %num_elt_per_stride elements every %stride elements apart from
80 // memory space 0 until %num_elements are transferred.
81 //
82 // affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%idx], %num_elements,
83 // %stride, %num_elt_per_stride : ...
84 //
85 // TODO: add additional operands to allow source and destination striding, and
86 // multiple stride levels (possibly using AffineMaps to specify multiple levels
87 // of striding).
89  : public Op<AffineDmaStartOp, OpTrait::MemRefsNormalizable,
90  OpTrait::VariadicOperands, OpTrait::ZeroResults,
91  OpTrait::OpInvariants, AffineMapAccessInterface::Trait,
92  MemoryEffectOpInterface::Trait> {
93 public:
94  using Op::Op;
95  static ArrayRef<StringRef> getAttributeNames() { return {}; }
96 
97  static void build(OpBuilder &builder, OperationState &result, Value srcMemRef,
98  AffineMap srcMap, ValueRange srcIndices, Value destMemRef,
99  AffineMap dstMap, ValueRange destIndices, Value tagMemRef,
100  AffineMap tagMap, ValueRange tagIndices, Value numElements,
101  Value stride = nullptr, Value elementsPerStride = nullptr);
102 
103  /// Returns the operand index of the source memref.
104  unsigned getSrcMemRefOperandIndex() { return 0; }
105 
106  /// Returns the source MemRefType for this DMA operation.
107  Value getSrcMemRef() { return getOperand(getSrcMemRefOperandIndex()); }
108  MemRefType getSrcMemRefType() {
109  return cast<MemRefType>(getSrcMemRef().getType());
110  }
111 
112  /// Returns the rank (number of indices) of the source MemRefType.
113  unsigned getSrcMemRefRank() { return getSrcMemRefType().getRank(); }
114 
115  /// Returns the affine map used to access the source memref.
116  AffineMap getSrcMap() { return getSrcMapAttr().getValue(); }
117  AffineMapAttr getSrcMapAttr() {
118  return cast<AffineMapAttr>((*this)->getAttr(getSrcMapAttrStrName()));
119  }
120 
121  /// Returns the source memref affine map indices for this DMA operation.
122  operand_range getSrcIndices() {
123  return {operand_begin() + getSrcMemRefOperandIndex() + 1,
124  operand_begin() + getSrcMemRefOperandIndex() + 1 +
125  getSrcMap().getNumInputs()};
126  }
127 
128  /// Returns the memory space of the source memref.
129  unsigned getSrcMemorySpace() {
130  return cast<MemRefType>(getSrcMemRef().getType()).getMemorySpaceAsInt();
131  }
132 
133  /// Returns the operand index of the destination memref.
136  }
137 
138  /// Returns the destination MemRefType for this DMA operation.
139  Value getDstMemRef() { return getOperand(getDstMemRefOperandIndex()); }
140  MemRefType getDstMemRefType() {
141  return cast<MemRefType>(getDstMemRef().getType());
142  }
143 
144  /// Returns the rank (number of indices) of the destination MemRefType.
145  unsigned getDstMemRefRank() {
146  return cast<MemRefType>(getDstMemRef().getType()).getRank();
147  }
148 
149  /// Returns the memory space of the source memref.
150  unsigned getDstMemorySpace() {
151  return cast<MemRefType>(getDstMemRef().getType()).getMemorySpaceAsInt();
152  }
153 
154  /// Returns the affine map used to access the destination memref.
155  AffineMap getDstMap() { return getDstMapAttr().getValue(); }
156  AffineMapAttr getDstMapAttr() {
157  return cast<AffineMapAttr>((*this)->getAttr(getDstMapAttrStrName()));
158  }
159 
160  /// Returns the destination memref indices for this DMA operation.
161  operand_range getDstIndices() {
162  return {operand_begin() + getDstMemRefOperandIndex() + 1,
163  operand_begin() + getDstMemRefOperandIndex() + 1 +
164  getDstMap().getNumInputs()};
165  }
166 
167  /// Returns the operand index of the tag memref.
170  }
171 
172  /// Returns the Tag MemRef for this DMA operation.
173  Value getTagMemRef() { return getOperand(getTagMemRefOperandIndex()); }
174  MemRefType getTagMemRefType() {
175  return cast<MemRefType>(getTagMemRef().getType());
176  }
177 
178  /// Returns the rank (number of indices) of the tag MemRefType.
179  unsigned getTagMemRefRank() {
180  return cast<MemRefType>(getTagMemRef().getType()).getRank();
181  }
182 
183  /// Returns the affine map used to access the tag memref.
184  AffineMap getTagMap() { return getTagMapAttr().getValue(); }
185  AffineMapAttr getTagMapAttr() {
186  return cast<AffineMapAttr>((*this)->getAttr(getTagMapAttrStrName()));
187  }
188 
189  /// Returns the tag memref indices for this DMA operation.
190  operand_range getTagIndices() {
191  return {operand_begin() + getTagMemRefOperandIndex() + 1,
192  operand_begin() + getTagMemRefOperandIndex() + 1 +
193  getTagMap().getNumInputs()};
194  }
195 
196  /// Returns the number of elements being transferred by this DMA operation.
198  return getOperand(getTagMemRefOperandIndex() + 1 +
199  getTagMap().getNumInputs());
200  }
201 
202  /// Impelements the AffineMapAccessInterface.
203  /// Returns the AffineMapAttr associated with 'memref'.
205  if (memref == getSrcMemRef())
207  getSrcMapAttr()};
208  if (memref == getDstMemRef())
210  getDstMapAttr()};
211  assert(memref == getTagMemRef() &&
212  "DmaStartOp expected source, destination or tag memref");
214  getTagMapAttr()};
215  }
216 
217  /// Returns true if this is a DMA from a faster memory space to a slower one.
219  return (getSrcMemorySpace() < getDstMemorySpace());
220  }
221 
222  /// Returns true if this is a DMA from a slower memory space to a faster one.
224  // Assumes that a lower number is for a slower memory space.
225  return (getDstMemorySpace() < getSrcMemorySpace());
226  }
227 
228  /// Given a DMA start operation, returns the operand position of either the
229  /// source or destination memref depending on the one that is at the higher
230  /// level of the memory hierarchy. Asserts failure if neither is true.
231  unsigned getFasterMemPos() {
234  }
235 
236  void
238  &effects);
239 
240  static StringRef getSrcMapAttrStrName() { return "src_map"; }
241  static StringRef getDstMapAttrStrName() { return "dst_map"; }
242  static StringRef getTagMapAttrStrName() { return "tag_map"; }
243 
244  static StringRef getOperationName() { return "affine.dma_start"; }
245  static ParseResult parse(OpAsmParser &parser, OperationState &result);
246  void print(OpAsmPrinter &p);
251 
252  /// Returns true if this DMA operation is strided, returns false otherwise.
253  bool isStrided() {
254  return getNumOperands() !=
256  }
257 
258  /// Returns the stride value for this DMA operation.
260  if (!isStrided())
261  return nullptr;
262  return getOperand(getNumOperands() - 1 - 1);
263  }
264 
265  /// Returns the number of elements to transfer per stride for this DMA op.
267  if (!isStrided())
268  return nullptr;
269  return getOperand(getNumOperands() - 1);
270  }
271 };
272 
273 /// AffineDmaWaitOp blocks until the completion of a DMA operation associated
274 /// with the tag element '%tag[%index]'. %tag is a memref, and %index has to be
275 /// an index with the same restrictions as any load/store index. In particular,
276 /// index for each memref dimension must be an affine expression of loop
277 /// induction variables and symbols. %num_elements is the number of elements
278 /// associated with the DMA operation. For example:
279 //
280 // affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%index], %num_elements :
281 // memref<2048xf32, 0>, memref<256xf32, 1>, memref<1xi32, 2>
282 // ...
283 // ...
284 // affine.dma_wait %tag[%index], %num_elements : memref<1xi32, 2>
285 //
287  : public Op<AffineDmaWaitOp, OpTrait::MemRefsNormalizable,
288  OpTrait::VariadicOperands, OpTrait::ZeroResults,
289  OpTrait::OpInvariants, AffineMapAccessInterface::Trait> {
290 public:
291  using Op::Op;
292  static ArrayRef<StringRef> getAttributeNames() { return {}; }
293 
294  static void build(OpBuilder &builder, OperationState &result, Value tagMemRef,
295  AffineMap tagMap, ValueRange tagIndices, Value numElements);
296 
297  static StringRef getOperationName() { return "affine.dma_wait"; }
298 
299  /// Returns the Tag MemRef associated with the DMA operation being waited on.
300  Value getTagMemRef() { return getOperand(0); }
301  MemRefType getTagMemRefType() {
302  return cast<MemRefType>(getTagMemRef().getType());
303  }
304 
305  /// Returns the affine map used to access the tag memref.
306  AffineMap getTagMap() { return getTagMapAttr().getValue(); }
307  AffineMapAttr getTagMapAttr() {
308  return cast<AffineMapAttr>((*this)->getAttr(getTagMapAttrStrName()));
309  }
310 
311  /// Returns the tag memref index for this DMA operation.
312  operand_range getTagIndices() {
313  return {operand_begin() + 1,
314  operand_begin() + 1 + getTagMap().getNumInputs()};
315  }
316 
317  /// Returns the rank (number of indices) of the tag memref.
318  unsigned getTagMemRefRank() {
319  return cast<MemRefType>(getTagMemRef().getType()).getRank();
320  }
321 
322  /// Impelements the AffineMapAccessInterface. Returns the AffineMapAttr
323  /// associated with 'memref'.
325  assert(memref == getTagMemRef());
327  getTagMapAttr()};
328  }
329 
330  /// Returns the number of elements transferred by the associated DMA op.
331  Value getNumElements() { return getOperand(1 + getTagMap().getNumInputs()); }
332 
333  static StringRef getTagMapAttrStrName() { return "tag_map"; }
334  static ParseResult parse(OpAsmParser &parser, OperationState &result);
335  void print(OpAsmPrinter &p);
340  void
342  &effects);
343 };
344 
345 /// Returns true if the given Value can be used as a dimension id in the region
346 /// of the closest surrounding op that has the trait `AffineScope`.
347 bool isValidDim(Value value);
348 
349 /// Returns true if the given Value can be used as a dimension id in `region`,
350 /// i.e., for all its uses in `region`.
351 bool isValidDim(Value value, Region *region);
352 
353 /// Returns true if the given value can be used as a symbol in the region of the
354 /// closest surrounding op that has the trait `AffineScope`.
355 bool isValidSymbol(Value value);
356 
357 /// Returns true if the given Value can be used as a symbol for `region`, i.e.,
358 /// for all its uses in `region`.
359 bool isValidSymbol(Value value, Region *region);
360 
361 /// Parses dimension and symbol list. `numDims` is set to the number of
362 /// dimensions in the list parsed.
364  SmallVectorImpl<Value> &operands,
365  unsigned &numDims);
366 
367 /// Modifies both `map` and `operands` in-place so as to:
368 /// 1. drop duplicate operands
369 /// 2. drop unused dims and symbols from map
370 /// 3. promote valid symbols to symbolic operands in case they appeared as
371 /// dimensional operands
372 /// 4. propagate constant operands and drop them
374  SmallVectorImpl<Value> *operands);
375 
376 /// Canonicalizes an integer set the same way canonicalizeMapAndOperands does
377 /// for affine maps.
379  SmallVectorImpl<Value> *operands);
380 
381 /// Returns a composed AffineApplyOp by composing `map` and `operands` with
382 /// other AffineApplyOps supplying those operands. The operands of the resulting
383 /// AffineApplyOp do not change the length of AffineApplyOp chains.
384 AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map,
385  ValueRange operands);
386 /// Variant of `makeComposedAffineApply` which infers the AffineMap from `e`.
387 AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineExpr e,
388  ValueRange values);
389 
390 /// Constructs an AffineApplyOp that applies `map` to `operands` after composing
391 /// the map with the maps of any other AffineApplyOp supplying the operands,
392 /// then immediately attempts to fold it. If folding results in a constant
393 /// value, no ops are actually created. The `map` must be a single-result affine
394 /// map.
396  AffineMap map,
397  ArrayRef<OpFoldResult> operands);
398 /// Variant of `makeComposedFoldedAffineApply` that applies to an expression.
400  AffineExpr expr,
401  ArrayRef<OpFoldResult> operands);
402 /// Variant of `makeComposedFoldedAffineApply` suitable for multi-result maps.
403 /// Note that this may create as many affine.apply operations as the map has
404 /// results given that affine.apply must be single-result.
406  OpBuilder &b, Location loc, AffineMap map, ArrayRef<OpFoldResult> operands);
407 
408 /// Returns an AffineMinOp obtained by composing `map` and `operands` with
409 /// AffineApplyOps supplying those operands.
411  ValueRange operands);
412 
413 /// Constructs an AffineMinOp that computes a minimum across the results of
414 /// applying `map` to `operands`, then immediately attempts to fold it. If
415 /// folding results in a constant value, no ops are actually created.
417  AffineMap map,
418  ArrayRef<OpFoldResult> operands);
419 
420 /// Constructs an AffineMinOp that computes a maximum across the results of
421 /// applying `map` to `operands`, then immediately attempts to fold it. If
422 /// folding results in a constant value, no ops are actually created.
424  AffineMap map,
425  ArrayRef<OpFoldResult> operands);
426 
427 /// Returns the values obtained by applying `map` to the list of values.
429  AffineMap map, ValueRange values);
430 
431 /// Given an affine map `map` and its input `operands`, this method composes
432 /// into `map`, maps of AffineApplyOps whose results are the values in
433 /// `operands`, iteratively until no more of `operands` are the result of an
434 /// AffineApplyOp. When this function returns, `map` becomes the composed affine
435 /// map, and each Value in `operands` is guaranteed to be either a loop IV or a
436 /// terminal symbol, i.e., a symbol defined at the top level or a block/function
437 /// argument.
439  SmallVectorImpl<Value> *operands);
440 
441 } // namespace affine
442 } // namespace mlir
443 
444 #include "mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc"
445 
446 #define GET_OP_CLASSES
447 #include "mlir/Dialect/Affine/IR/AffineOps.h.inc"
448 
449 namespace mlir {
450 namespace affine {
451 
452 /// Returns true if the provided value is the induction variable of an
453 /// AffineForOp.
454 bool isAffineForInductionVar(Value val);
455 
456 /// Returns true if `val` is the induction variable of an AffineParallelOp.
457 bool isAffineParallelInductionVar(Value val);
458 
459 /// Returns true if the provided value is the induction variable of an
460 /// AffineForOp or AffineParallelOp.
461 bool isAffineInductionVar(Value val);
462 
463 /// Returns the loop parent of an induction variable. If the provided value is
464 /// not an induction variable, then return nullptr.
465 AffineForOp getForInductionVarOwner(Value val);
466 
467 /// Returns true if the provided value is among the induction variables of an
468 /// AffineParallelOp.
469 AffineParallelOp getAffineParallelInductionVarOwner(Value val);
470 
471 /// Extracts the induction variables from a list of AffineForOps and places them
472 /// in the output argument `ivs`.
473 void extractForInductionVars(ArrayRef<AffineForOp> forInsts,
474  SmallVectorImpl<Value> *ivs);
475 
476 /// Extracts the induction variables from a list of either AffineForOp or
477 /// AffineParallelOp and places them in the output argument `ivs`.
478 void extractInductionVars(ArrayRef<Operation *> affineOps,
479  SmallVectorImpl<Value> &ivs);
480 
481 /// Builds a perfect nest of affine.for loops, i.e., each loop except the
482 /// innermost one contains only another loop and a terminator. The loops iterate
483 /// from "lbs" to "ubs" with "steps". The body of the innermost loop is
484 /// populated by calling "bodyBuilderFn" and providing it with an OpBuilder, a
485 /// Location and a list of loop induction variables.
486 void buildAffineLoopNest(OpBuilder &builder, Location loc,
487  ArrayRef<int64_t> lbs, ArrayRef<int64_t> ubs,
488  ArrayRef<int64_t> steps,
489  function_ref<void(OpBuilder &, Location, ValueRange)>
490  bodyBuilderFn = nullptr);
491 void buildAffineLoopNest(OpBuilder &builder, Location loc, ValueRange lbs,
492  ValueRange ubs, ArrayRef<int64_t> steps,
493  function_ref<void(OpBuilder &, Location, ValueRange)>
494  bodyBuilderFn = nullptr);
495 
496 /// Replace `loop` with a new loop where `newIterOperands` are appended with
497 /// new initialization values and `newYieldedValues` are added as new yielded
498 /// values. The returned ForOp has `newYieldedValues.size()` new result values.
499 /// Additionally, if `replaceLoopResults` is true, all uses of
500 /// `loop.getResults()` are replaced with the first `loop.getNumResults()`
501 /// return values of the original loop respectively. The original loop is
502 /// deleted and the new loop returned.
503 /// Prerequisite: `newIterOperands.size() == newYieldedValues.size()`.
504 AffineForOp replaceForOpWithNewYields(OpBuilder &b, AffineForOp loop,
505  ValueRange newIterOperands,
506  ValueRange newYieldedValues,
507  ValueRange newIterArgs,
508  bool replaceLoopResults = true);
509 
510 /// AffineBound represents a lower or upper bound in the for operation.
511 /// This class does not own the underlying operands. Instead, it refers
512 /// to the operands stored in the AffineForOp. Its life span should not exceed
513 /// that of the for operation it refers to.
514 class AffineBound {
515 public:
516  AffineForOp getAffineForOp() { return op; }
517  AffineMap getMap() { return map; }
518 
519  unsigned getNumOperands() { return opEnd - opStart; }
520  Value getOperand(unsigned idx) { return op.getOperand(opStart + idx); }
521 
522  using operand_iterator = AffineForOp::operand_iterator;
523  using operand_range = AffineForOp::operand_range;
524 
525  operand_iterator operandBegin() { return op.operand_begin() + opStart; }
526  operand_iterator operandEnd() { return op.operand_begin() + opEnd; }
528 
529 private:
530  // 'affine.for' operation that contains this bound.
531  AffineForOp op;
532  // Start and end positions of this affine bound operands in the list of
533  // the containing 'affine.for' operation operands.
534  unsigned opStart, opEnd;
535  // Affine map for this bound.
536  AffineMap map;
537 
538  AffineBound(AffineForOp op, unsigned opStart, unsigned opEnd, AffineMap map)
539  : op(op), opStart(opStart), opEnd(opEnd), map(map) {}
540 
541  friend class AffineForOp;
542 };
543 
544 } // namespace affine
545 } // namespace mlir
546 
547 #endif
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:44
unsigned getNumInputs() const
Definition: AffineMap.cpp:333
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:63
NamedAttribute represents a combination of a name and an Attribute value.
Definition: Attributes.h:189
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:202
This class represents a single result from folding an operation.
Definition: OpDefinition.h:265
MLIRContext * getContext()
Return the context this operation belongs to.
Definition: OpDefinition.h:110
This provides public APIs that all operations should have.
Op()
This is a public constructor. Any op can be initialized to null.
This class represents success/failure for parsing-like operations that find it important to chain tog...
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:370
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:93
AffineBound represents a lower or upper bound in the for operation.
Definition: AffineOps.h:514
Value getOperand(unsigned idx)
Definition: AffineOps.h:520
operand_iterator operandBegin()
Definition: AffineOps.h:525
AffineForOp::operand_iterator operand_iterator
Definition: AffineOps.h:522
AffineForOp::operand_range operand_range
Definition: AffineOps.h:523
AffineForOp getAffineForOp()
Definition: AffineOps.h:516
operand_range getOperands()
Definition: AffineOps.h:527
friend class AffineForOp
Definition: AffineOps.h:541
operand_iterator operandEnd()
Definition: AffineOps.h:526
AffineDmaStartOp starts a non-blocking DMA operation that transfers data from a source memref to a de...
Definition: AffineOps.h:92
Value getTagMemRef()
Returns the Tag MemRef for this DMA operation.
Definition: AffineOps.h:173
bool isSrcMemorySpaceFaster()
Returns true if this is a DMA from a slower memory space to a faster one.
Definition: AffineOps.h:223
void getEffects(SmallVectorImpl< SideEffects::EffectInstance< MemoryEffects::Effect >> &effects)
Definition: AffineOps.cpp:1832
bool isDestMemorySpaceFaster()
Returns true if this is a DMA from a faster memory space to a slower one.
Definition: AffineOps.h:218
unsigned getFasterMemPos()
Given a DMA start operation, returns the operand position of either the source or destination memref ...
Definition: AffineOps.h:231
unsigned getTagMemRefRank()
Returns the rank (number of indices) of the tag MemRefType.
Definition: AffineOps.h:179
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)
Definition: AffineOps.cpp:1668
operand_range getDstIndices()
Returns the destination memref indices for this DMA operation.
Definition: AffineOps.h:161
Value getNumElementsPerStride()
Returns the number of elements to transfer per stride for this DMA op.
Definition: AffineOps.h:266
unsigned getSrcMemorySpace()
Returns the memory space of the source memref.
Definition: AffineOps.h:129
AffineMapAttr getTagMapAttr()
Definition: AffineOps.h:185
unsigned getSrcMemRefRank()
Returns the rank (number of indices) of the source MemRefType.
Definition: AffineOps.h:113
operand_range getSrcIndices()
Returns the source memref affine map indices for this DMA operation.
Definition: AffineOps.h:122
AffineMapAttr getSrcMapAttr()
Definition: AffineOps.h:117
bool isStrided()
Returns true if this DMA operation is strided, returns false otherwise.
Definition: AffineOps.h:253
AffineMap getDstMap()
Returns the affine map used to access the destination memref.
Definition: AffineOps.h:155
void print(OpAsmPrinter &p)
Definition: AffineOps.cpp:1690
Value getDstMemRef()
Returns the destination MemRefType for this DMA operation.
Definition: AffineOps.h:139
static StringRef getSrcMapAttrStrName()
Definition: AffineOps.h:240
AffineMapAttr getDstMapAttr()
Definition: AffineOps.h:156
unsigned getDstMemorySpace()
Returns the memory space of the source memref.
Definition: AffineOps.h:150
unsigned getSrcMemRefOperandIndex()
Returns the operand index of the source memref.
Definition: AffineOps.h:104
unsigned getTagMemRefOperandIndex()
Returns the operand index of the tag memref.
Definition: AffineOps.h:168
static StringRef getTagMapAttrStrName()
Definition: AffineOps.h:242
LogicalResult verifyInvariantsImpl()
Definition: AffineOps.cpp:1788
unsigned getDstMemRefRank()
Returns the rank (number of indices) of the destination MemRefType.
Definition: AffineOps.h:145
LogicalResult verifyInvariants()
Definition: AffineOps.h:248
AffineMap getSrcMap()
Returns the affine map used to access the source memref.
Definition: AffineOps.h:116
Value getNumElements()
Returns the number of elements being transferred by this DMA operation.
Definition: AffineOps.h:197
static ArrayRef< StringRef > getAttributeNames()
Definition: AffineOps.h:95
AffineMap getTagMap()
Returns the affine map used to access the tag memref.
Definition: AffineOps.h:184
static ParseResult parse(OpAsmParser &parser, OperationState &result)
Definition: AffineOps.cpp:1712
Value getStride()
Returns the stride value for this DMA operation.
Definition: AffineOps.h:259
unsigned getDstMemRefOperandIndex()
Returns the operand index of the destination memref.
Definition: AffineOps.h:134
static StringRef getDstMapAttrStrName()
Definition: AffineOps.h:241
static StringRef getOperationName()
Definition: AffineOps.h:244
NamedAttribute getAffineMapAttrForMemRef(Value memref)
Impelements the AffineMapAccessInterface.
Definition: AffineOps.h:204
Value getSrcMemRef()
Returns the source MemRefType for this DMA operation.
Definition: AffineOps.h:107
operand_range getTagIndices()
Returns the tag memref indices for this DMA operation.
Definition: AffineOps.h:190
LogicalResult fold(ArrayRef< Attribute > cstOperands, SmallVectorImpl< OpFoldResult > &results)
Definition: AffineOps.cpp:1826
AffineDmaWaitOp blocks until the completion of a DMA operation associated with the tag element 'tag[i...
Definition: AffineOps.h:289
Value getNumElements()
Returns the number of elements transferred by the associated DMA op.
Definition: AffineOps.h:331
NamedAttribute getAffineMapAttrForMemRef(Value memref)
Impelements the AffineMapAccessInterface.
Definition: AffineOps.h:324
LogicalResult verifyInvariants()
Definition: AffineOps.h:337
LogicalResult verifyInvariantsImpl()
Definition: AffineOps.cpp:1902
static StringRef getOperationName()
Definition: AffineOps.h:297
static ArrayRef< StringRef > getAttributeNames()
Definition: AffineOps.h:292
Value getTagMemRef()
Returns the Tag MemRef associated with the DMA operation being waited on.
Definition: AffineOps.h:300
static ParseResult parse(OpAsmParser &parser, OperationState &result)
Definition: AffineOps.cpp:1871
static StringRef getTagMapAttrStrName()
Definition: AffineOps.h:333
LogicalResult fold(ArrayRef< Attribute > cstOperands, SmallVectorImpl< OpFoldResult > &results)
Definition: AffineOps.cpp:1915
AffineMapAttr getTagMapAttr()
Definition: AffineOps.h:307
void print(OpAsmPrinter &p)
Definition: AffineOps.cpp:1857
AffineMap getTagMap()
Returns the affine map used to access the tag memref.
Definition: AffineOps.h:306
unsigned getTagMemRefRank()
Returns the rank (number of indices) of the tag memref.
Definition: AffineOps.h:318
static void build(OpBuilder &builder, OperationState &result, Value tagMemRef, AffineMap tagMap, ValueRange tagIndices, Value numElements)
Definition: AffineOps.cpp:1848
operand_range getTagIndices()
Returns the tag memref index for this DMA operation.
Definition: AffineOps.h:312
void getEffects(SmallVectorImpl< SideEffects::EffectInstance< MemoryEffects::Effect >> &effects)
Definition: AffineOps.cpp:1921
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...
Definition: AffineOps.cpp:2769
void fullyComposeAffineMapAndOperands(AffineMap *map, SmallVectorImpl< Value > *operands)
Given an affine map map and its input operands, this method composes into map, maps of AffineApplyOps...
Definition: AffineOps.cpp:1187
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...
Definition: AffineOps.cpp:2683
bool isValidDim(Value value)
Returns true if the given Value can be used as a dimension id in the region of the closest surroundin...
Definition: AffineOps.cpp:266
SmallVector< OpFoldResult > makeComposedFoldedMultiResultAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Variant of makeComposedFoldedAffineApply suitable for multi-result maps.
Definition: AffineOps.cpp:1362
bool isAffineInductionVar(Value val)
Returns true if the provided value is the induction variable of an AffineForOp or AffineParallelOp.
Definition: AffineOps.cpp:2655
AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map, ValueRange operands)
Returns a composed AffineApplyOp by composing map and operands with other AffineApplyOps supplying th...
Definition: AffineOps.cpp:1285
AffineForOp getForInductionVarOwner(Value val)
Returns the loop parent of an induction variable.
Definition: AffineOps.cpp:2659
void canonicalizeMapAndOperands(AffineMap *map, SmallVectorImpl< Value > *operands)
Modifies both map and operands in-place so as to:
Definition: AffineOps.cpp:1560
Value makeComposedAffineMin(OpBuilder &b, Location loc, AffineMap map, ValueRange operands)
Returns an AffineMinOp obtained by composing map and operands with AffineApplyOps supplying those ope...
Definition: AffineOps.cpp:1372
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,...
Definition: AffineOps.cpp:1405
bool isAffineForInductionVar(Value val)
Returns true if the provided value is the induction variable of an AffineForOp.
Definition: AffineOps.cpp:2647
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,...
Definition: AffineOps.cpp:1398
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...
Definition: AffineOps.cpp:236
void canonicalizeSetAndOperands(IntegerSet *set, SmallVectorImpl< Value > *operands)
Canonicalizes an integer set the same way canonicalizeMapAndOperands does for affine maps.
Definition: AffineOps.cpp:1565
void extractInductionVars(ArrayRef< Operation * > affineOps, SmallVectorImpl< Value > &ivs)
Extracts the induction variables from a list of either AffineForOp or AffineParallelOp and places the...
Definition: AffineOps.cpp:2690
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...
Definition: AffineOps.cpp:363
AffineForOp replaceForOpWithNewYields(OpBuilder &b, AffineForOp loop, ValueRange newIterOperands, ValueRange newYieldedValues, ValueRange newIterArgs, bool replaceLoopResults=true)
Replace loop with a new loop where newIterOperands are appended with new initialization values and ne...
Definition: AffineOps.cpp:2785
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
Definition: AffineOps.cpp:1334
AffineParallelOp getAffineParallelInductionVarOwner(Value val)
Returns true if the provided value is among the induction variables of an AffineParallelOp.
Definition: AffineOps.cpp:2670
SmallVector< Value, 4 > applyMapToValues(OpBuilder &b, Location loc, AffineMap map, ValueRange values)
Returns the values obtained by applying map to the list of values.
Definition: AffineOps.cpp:1422
Region * getAffineScope(Operation *op)
Returns the closest region enclosing op that is held by an operation with trait AffineScope; nullptr ...
Definition: AffineOps.cpp:251
ParseResult parseDimAndSymbolList(OpAsmParser &parser, SmallVectorImpl< Value > &operands, unsigned &numDims)
Parses dimension and symbol list.
Definition: AffineOps.cpp:452
bool isAffineParallelInductionVar(Value val)
Returns true if val is the induction variable of an AffineParallelOp.
Definition: AffineOps.cpp:2651
This header declares functions that assit transformations in the MemRef dialect.
llvm::function_ref< Fn > function_ref
Definition: LLVM.h:147
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
This represents an operation in an abstracted form, suitable for use with the builder APIs.