MLIR  21.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"
24 namespace mlir {
25 namespace affine {
26 
27 class AffineApplyOp;
28 class AffineBound;
29 class AffineMaxOp;
30 class AffineMinOp;
31 class 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.
37 bool 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.
43 bool 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.
47 Region *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.
54 Region *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> {
107 public:
108  using Op::Op;
109  static ArrayRef<StringRef> getAttributeNames() { return {}; }
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  /// Returns the operand index of the source memref.
118  unsigned getSrcMemRefOperandIndex() { return 0; }
119 
120  /// Returns the source MemRefType for this DMA operation.
121  Value getSrcMemRef() { return getOperand(getSrcMemRefOperandIndex()); }
124  }
125  MemRefType getSrcMemRefType() {
126  return cast<MemRefType>(getSrcMemRef().getType());
127  }
128 
129  /// Returns the rank (number of indices) of the source MemRefType.
130  unsigned getSrcMemRefRank() { return getSrcMemRefType().getRank(); }
131 
132  /// Returns the affine map used to access the source memref.
133  AffineMap getSrcMap() { return getSrcMapAttr().getValue(); }
134  AffineMapAttr getSrcMapAttr() {
135  return cast<AffineMapAttr>(
136  *(*this)->getInherentAttr(getSrcMapAttrStrName()));
137  }
138 
139  /// Returns the source memref affine map indices for this DMA operation.
140  operand_range getSrcIndices() {
141  return {operand_begin() + getSrcMemRefOperandIndex() + 1,
142  operand_begin() + getSrcMemRefOperandIndex() + 1 +
143  getSrcMap().getNumInputs()};
144  }
145 
146  /// Returns the memory space of the source memref.
147  unsigned getSrcMemorySpace() {
148  return cast<MemRefType>(getSrcMemRef().getType()).getMemorySpaceAsInt();
149  }
150 
151  /// Returns the operand index of the destination memref.
154  }
155 
156  /// Returns the destination MemRefType for this DMA operation.
157  Value getDstMemRef() { return getOperand(getDstMemRefOperandIndex()); }
160  }
161  MemRefType getDstMemRefType() {
162  return cast<MemRefType>(getDstMemRef().getType());
163  }
164 
165  /// Returns the rank (number of indices) of the destination MemRefType.
166  unsigned getDstMemRefRank() {
167  return cast<MemRefType>(getDstMemRef().getType()).getRank();
168  }
169 
170  /// Returns the memory space of the source memref.
171  unsigned getDstMemorySpace() {
172  return cast<MemRefType>(getDstMemRef().getType()).getMemorySpaceAsInt();
173  }
174 
175  /// Returns the affine map used to access the destination memref.
176  AffineMap getDstMap() { return getDstMapAttr().getValue(); }
177  AffineMapAttr getDstMapAttr() {
178  return cast<AffineMapAttr>(
179  *(*this)->getInherentAttr(getDstMapAttrStrName()));
180  }
181 
182  /// Returns the destination memref indices for this DMA operation.
183  operand_range getDstIndices() {
184  return {operand_begin() + getDstMemRefOperandIndex() + 1,
185  operand_begin() + getDstMemRefOperandIndex() + 1 +
186  getDstMap().getNumInputs()};
187  }
188 
189  /// Returns the operand index of the tag memref.
192  }
193 
194  /// Returns the Tag MemRef for this DMA operation.
195  Value getTagMemRef() { return getOperand(getTagMemRefOperandIndex()); }
198  }
199  MemRefType getTagMemRefType() {
200  return cast<MemRefType>(getTagMemRef().getType());
201  }
202 
203  /// Returns the rank (number of indices) of the tag MemRefType.
204  unsigned getTagMemRefRank() {
205  return cast<MemRefType>(getTagMemRef().getType()).getRank();
206  }
207 
208  /// Returns the affine map used to access the tag memref.
209  AffineMap getTagMap() { return getTagMapAttr().getValue(); }
210  AffineMapAttr getTagMapAttr() {
211  return cast<AffineMapAttr>(
212  *(*this)->getInherentAttr(getTagMapAttrStrName()));
213  }
214 
215  /// Returns the tag memref indices for this DMA operation.
216  operand_range getTagIndices() {
217  return {operand_begin() + getTagMemRefOperandIndex() + 1,
218  operand_begin() + getTagMemRefOperandIndex() + 1 +
219  getTagMap().getNumInputs()};
220  }
221 
222  /// Returns the number of elements being transferred by this DMA operation.
224  return getOperand(getTagMemRefOperandIndex() + 1 +
225  getTagMap().getNumInputs());
226  }
227 
228  /// Impelements the AffineMapAccessInterface.
229  /// Returns the AffineMapAttr associated with 'memref'.
231  if (memref == getSrcMemRef())
233  getSrcMapAttr()};
234  if (memref == getDstMemRef())
236  getDstMapAttr()};
237  assert(memref == getTagMemRef() &&
238  "DmaStartOp expected source, destination or tag memref");
240  getTagMapAttr()};
241  }
242 
243  /// Returns true if this is a DMA from a faster memory space to a slower one.
245  return (getSrcMemorySpace() < getDstMemorySpace());
246  }
247 
248  /// Returns true if this is a DMA from a slower memory space to a faster one.
250  // Assumes that a lower number is for a slower memory space.
251  return (getDstMemorySpace() < getSrcMemorySpace());
252  }
253 
254  /// Given a DMA start operation, returns the operand position of either the
255  /// source or destination memref depending on the one that is at the higher
256  /// level of the memory hierarchy. Asserts failure if neither is true.
257  unsigned getFasterMemPos() {
260  }
261 
262  void
264  &effects);
265 
266  static StringRef getSrcMapAttrStrName() { return "src_map"; }
267  static StringRef getDstMapAttrStrName() { return "dst_map"; }
268  static StringRef getTagMapAttrStrName() { return "tag_map"; }
269 
270  static StringRef getOperationName() { return "affine.dma_start"; }
271  static ParseResult parse(OpAsmParser &parser, OperationState &result);
272  void print(OpAsmPrinter &p);
273  LogicalResult verifyInvariantsImpl();
274  LogicalResult verifyInvariants() { return verifyInvariantsImpl(); }
275  LogicalResult fold(ArrayRef<Attribute> cstOperands,
277 
278  /// Returns true if this DMA operation is strided, returns false otherwise.
279  bool isStrided() {
280  return getNumOperands() !=
282  }
283 
284  /// Returns the stride value for this DMA operation.
286  if (!isStrided())
287  return nullptr;
288  return getOperand(getNumOperands() - 1 - 1);
289  }
290 
291  /// Returns the number of elements to transfer per stride for this DMA op.
293  if (!isStrided())
294  return nullptr;
295  return getOperand(getNumOperands() - 1);
296  }
297 };
298 
299 /// AffineDmaWaitOp blocks until the completion of a DMA operation associated
300 /// with the tag element '%tag[%index]'. %tag is a memref, and %index has to be
301 /// an index with the same restrictions as any load/store index. In particular,
302 /// index for each memref dimension must be an affine expression of loop
303 /// induction variables and symbols. %num_elements is the number of elements
304 /// associated with the DMA operation. For example:
305 //
306 // affine.dma_start %src[%i, %j], %dst[%k, %l], %tag[%index], %num_elements :
307 // memref<2048xf32, 0>, memref<256xf32, 1>, memref<1xi32, 2>
308 // ...
309 // ...
310 // affine.dma_wait %tag[%index], %num_elements : memref<1xi32, 2>
311 //
313  : public Op<AffineDmaWaitOp, OpTrait::MemRefsNormalizable,
314  OpTrait::VariadicOperands, OpTrait::ZeroResults,
315  OpTrait::OpInvariants, AffineMapAccessInterface::Trait> {
316 public:
317  using Op::Op;
318  static ArrayRef<StringRef> getAttributeNames() { return {}; }
319 
320  static void build(OpBuilder &builder, OperationState &result, Value tagMemRef,
321  AffineMap tagMap, ValueRange tagIndices, Value numElements);
322 
323  static StringRef getOperationName() { return "affine.dma_wait"; }
324 
325  /// Returns the Tag MemRef associated with the DMA operation being waited on.
326  Value getTagMemRef() { return getOperand(0); }
328  MemRefType getTagMemRefType() {
329  return cast<MemRefType>(getTagMemRef().getType());
330  }
331 
332  /// Returns the affine map used to access the tag memref.
333  AffineMap getTagMap() { return getTagMapAttr().getValue(); }
334  AffineMapAttr getTagMapAttr() {
335  return cast<AffineMapAttr>(
336  *(*this)->getInherentAttr(getTagMapAttrStrName()));
337  }
338 
339  /// Returns the tag memref index for this DMA operation.
340  operand_range getTagIndices() {
341  return {operand_begin() + 1,
342  operand_begin() + 1 + getTagMap().getNumInputs()};
343  }
344 
345  /// Returns the rank (number of indices) of the tag memref.
346  unsigned getTagMemRefRank() {
347  return cast<MemRefType>(getTagMemRef().getType()).getRank();
348  }
349 
350  /// Impelements the AffineMapAccessInterface. Returns the AffineMapAttr
351  /// associated with 'memref'.
353  assert(memref == getTagMemRef());
355  getTagMapAttr()};
356  }
357 
358  /// Returns the number of elements transferred by the associated DMA op.
359  Value getNumElements() { return getOperand(1 + getTagMap().getNumInputs()); }
360 
361  static StringRef getTagMapAttrStrName() { return "tag_map"; }
362  static ParseResult parse(OpAsmParser &parser, OperationState &result);
363  void print(OpAsmPrinter &p);
364  LogicalResult verifyInvariantsImpl();
365  LogicalResult verifyInvariants() { return verifyInvariantsImpl(); }
366  LogicalResult fold(ArrayRef<Attribute> cstOperands,
368  void
370  &effects);
371 };
372 
373 /// Returns true if the given Value can be used as a dimension id in the region
374 /// of the closest surrounding op that has the trait `AffineScope`.
375 bool isValidDim(Value value);
376 
377 /// Returns true if the given Value can be used as a dimension id in `region`,
378 /// i.e., for all its uses in `region`.
379 bool isValidDim(Value value, Region *region);
380 
381 /// Returns true if the given value can be used as a symbol in the region of the
382 /// closest surrounding op that has the trait `AffineScope`.
383 bool isValidSymbol(Value value);
384 
385 /// Returns true if the given Value can be used as a symbol for `region`, i.e.,
386 /// for all its uses in `region`.
387 bool isValidSymbol(Value value, Region *region);
388 
389 /// Parses dimension and symbol list. `numDims` is set to the number of
390 /// dimensions in the list parsed.
391 ParseResult parseDimAndSymbolList(OpAsmParser &parser,
392  SmallVectorImpl<Value> &operands,
393  unsigned &numDims);
394 
395 /// Modifies both `map` and `operands` in-place so as to:
396 /// 1. drop duplicate operands
397 /// 2. drop unused dims and symbols from map
398 /// 3. promote valid symbols to symbolic operands in case they appeared as
399 /// dimensional operands
400 /// 4. propagate constant operands and drop them
402  SmallVectorImpl<Value> *operands);
403 
404 /// Canonicalizes an integer set the same way canonicalizeMapAndOperands does
405 /// for affine maps.
407  SmallVectorImpl<Value> *operands);
408 
409 /// Returns a composed AffineApplyOp by composing `map` and `operands` with
410 /// other AffineApplyOps supplying those operands. The operands of the resulting
411 /// AffineApplyOp do not change the length of AffineApplyOp chains.
412 AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map,
413  ArrayRef<OpFoldResult> operands);
414 AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineExpr e,
415  ArrayRef<OpFoldResult> operands);
416 
417 /// Constructs an AffineApplyOp that applies `map` to `operands` after composing
418 /// the map with the maps of any other AffineApplyOp supplying the operands,
419 /// then immediately attempts to fold it. If folding results in a constant
420 /// value, no ops are actually created. The `map` must be a single-result affine
421 /// map.
423  AffineMap map,
424  ArrayRef<OpFoldResult> operands);
425 /// Variant of `makeComposedFoldedAffineApply` that applies to an expression.
427  AffineExpr expr,
428  ArrayRef<OpFoldResult> operands);
429 /// Variant of `makeComposedFoldedAffineApply` suitable for multi-result maps.
430 /// Note that this may create as many affine.apply operations as the map has
431 /// results given that affine.apply must be single-result.
433  OpBuilder &b, Location loc, AffineMap map, ArrayRef<OpFoldResult> operands);
434 
435 /// Returns an AffineMinOp obtained by composing `map` and `operands` with
436 /// AffineApplyOps supplying those operands.
437 AffineMinOp makeComposedAffineMin(OpBuilder &b, Location loc, AffineMap map,
438  ArrayRef<OpFoldResult> operands);
439 
440 /// Constructs an AffineMinOp that computes a minimum across the results of
441 /// applying `map` to `operands`, then immediately attempts to fold it. If
442 /// folding results in a constant value, no ops are actually created.
444  AffineMap map,
445  ArrayRef<OpFoldResult> operands);
446 
447 /// Constructs an AffineMinOp that computes a maximum across the results of
448 /// applying `map` to `operands`, then immediately attempts to fold it. If
449 /// folding results in a constant value, no ops are actually created.
451  AffineMap map,
452  ArrayRef<OpFoldResult> operands);
453 
454 /// Given an affine map `map` and its input `operands`, this method composes
455 /// into `map`, maps of AffineApplyOps whose results are the values in
456 /// `operands`, iteratively until no more of `operands` are the result of an
457 /// AffineApplyOp. When this function returns, `map` becomes the composed affine
458 /// map, and each Value in `operands` is guaranteed to be either a loop IV or a
459 /// terminal symbol, i.e., a symbol defined at the top level or a block/function
460 /// argument.
462  SmallVectorImpl<Value> *operands);
463 
464 } // namespace affine
465 } // namespace mlir
466 
467 #include "mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc"
468 
469 #define GET_OP_CLASSES
470 #include "mlir/Dialect/Affine/IR/AffineOps.h.inc"
471 
472 namespace mlir {
473 namespace affine {
474 
475 /// Returns true if the provided value is the induction variable of an
476 /// AffineForOp.
477 bool isAffineForInductionVar(Value val);
478 
479 /// Returns true if `val` is the induction variable of an AffineParallelOp.
480 bool isAffineParallelInductionVar(Value val);
481 
482 /// Returns true if the provided value is the induction variable of an
483 /// AffineForOp or AffineParallelOp.
484 bool isAffineInductionVar(Value val);
485 
486 /// Returns the loop parent of an induction variable. If the provided value is
487 /// not an induction variable, then return nullptr.
488 AffineForOp getForInductionVarOwner(Value val);
489 
490 /// Returns true if the provided value is among the induction variables of an
491 /// AffineParallelOp.
492 AffineParallelOp getAffineParallelInductionVarOwner(Value val);
493 
494 /// Extracts the induction variables from a list of AffineForOps and places them
495 /// in the output argument `ivs`.
496 void extractForInductionVars(ArrayRef<AffineForOp> forInsts,
497  SmallVectorImpl<Value> *ivs);
498 
499 /// Extracts the induction variables from a list of either AffineForOp or
500 /// AffineParallelOp and places them in the output argument `ivs`.
501 void extractInductionVars(ArrayRef<Operation *> affineOps,
502  SmallVectorImpl<Value> &ivs);
503 
504 /// Builds a perfect nest of affine.for loops, i.e., each loop except the
505 /// innermost one contains only another loop and a terminator. The loops iterate
506 /// from "lbs" to "ubs" with "steps". The body of the innermost loop is
507 /// populated by calling "bodyBuilderFn" and providing it with an OpBuilder, a
508 /// Location and a list of loop induction variables.
509 void buildAffineLoopNest(OpBuilder &builder, Location loc,
510  ArrayRef<int64_t> lbs, ArrayRef<int64_t> ubs,
511  ArrayRef<int64_t> steps,
512  function_ref<void(OpBuilder &, Location, ValueRange)>
513  bodyBuilderFn = nullptr);
514 void buildAffineLoopNest(OpBuilder &builder, Location loc, ValueRange lbs,
515  ValueRange ubs, ArrayRef<int64_t> steps,
516  function_ref<void(OpBuilder &, Location, ValueRange)>
517  bodyBuilderFn = nullptr);
518 
519 /// AffineBound represents a lower or upper bound in the for operation.
520 /// This class does not own the underlying operands. Instead, it refers
521 /// to the operands stored in the AffineForOp. Its life span should not exceed
522 /// that of the for operation it refers to.
523 class AffineBound {
524 public:
525  AffineForOp getAffineForOp() { return op; }
526  AffineMap getMap() { return map; }
527 
528  unsigned getNumOperands() { return operands.size(); }
529  Value getOperand(unsigned idx) {
530  return op.getOperand(operands.getBeginOperandIndex() + idx);
531  }
532 
533  using operand_iterator = AffineForOp::operand_iterator;
534  using operand_range = AffineForOp::operand_range;
535 
536  operand_iterator operandBegin() { return operands.begin(); }
537  operand_iterator operandEnd() { return operands.end(); }
539 
540 private:
541  // 'affine.for' operation that contains this bound.
542  AffineForOp op;
543  // Operands of the affine map.
544  OperandRange operands;
545  // Affine map for this bound.
546  AffineMap map;
547 
548  AffineBound(AffineForOp op, OperandRange operands, AffineMap map)
549  : op(op), operands(operands), map(map) {}
550 
551  friend class AffineForOp;
552 };
553 
554 } // namespace affine
555 } // namespace mlir
556 
557 #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:46
unsigned getNumInputs() const
Definition: AffineMap.cpp:403
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:66
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:205
This class represents a single result from folding an operation.
Definition: OpDefinition.h:271
This class represents an operand of an operation.
Definition: Value.h:243
MLIRContext * getContext()
Return the context this operation belongs to.
Definition: OpDefinition.h:114
This provides public APIs that all operations should have.
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
unsigned getBeginOperandIndex() const
Return the operand index of the first element of this range.
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:523
Value getOperand(unsigned idx)
Definition: AffineOps.h:529
operand_iterator operandBegin()
Definition: AffineOps.h:536
AffineForOp::operand_iterator operand_iterator
Definition: AffineOps.h:533
AffineForOp::operand_range operand_range
Definition: AffineOps.h:534
AffineForOp getAffineForOp()
Definition: AffineOps.h:525
operand_range getOperands()
Definition: AffineOps.h:538
friend class AffineForOp
Definition: AffineOps.h:551
operand_iterator operandEnd()
Definition: AffineOps.h:537
AffineDmaStartOp starts a non-blocking DMA operation that transfers data from a source memref to a de...
Definition: AffineOps.h:106
Value getTagMemRef()
Returns the Tag MemRef for this DMA operation.
Definition: AffineOps.h:195
bool isSrcMemorySpaceFaster()
Returns true if this is a DMA from a slower memory space to a faster one.
Definition: AffineOps.h:249
void getEffects(SmallVectorImpl< SideEffects::EffectInstance< MemoryEffects::Effect >> &effects)
Definition: AffineOps.cpp:1782
bool isDestMemorySpaceFaster()
Returns true if this is a DMA from a faster memory space to a slower one.
Definition: AffineOps.h:244
unsigned getFasterMemPos()
Given a DMA start operation, returns the operand position of either the source or destination memref ...
Definition: AffineOps.h:257
unsigned getTagMemRefRank()
Returns the rank (number of indices) of the tag MemRefType.
Definition: AffineOps.h:204
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:1615
operand_range getDstIndices()
Returns the destination memref indices for this DMA operation.
Definition: AffineOps.h:183
Value getNumElementsPerStride()
Returns the number of elements to transfer per stride for this DMA op.
Definition: AffineOps.h:292
unsigned getSrcMemorySpace()
Returns the memory space of the source memref.
Definition: AffineOps.h:147
AffineMapAttr getTagMapAttr()
Definition: AffineOps.h:210
unsigned getSrcMemRefRank()
Returns the rank (number of indices) of the source MemRefType.
Definition: AffineOps.h:130
operand_range getSrcIndices()
Returns the source memref affine map indices for this DMA operation.
Definition: AffineOps.h:140
AffineMapAttr getSrcMapAttr()
Definition: AffineOps.h:134
bool isStrided()
Returns true if this DMA operation is strided, returns false otherwise.
Definition: AffineOps.h:279
AffineMap getDstMap()
Returns the affine map used to access the destination memref.
Definition: AffineOps.h:176
void print(OpAsmPrinter &p)
Definition: AffineOps.cpp:1637
Value getDstMemRef()
Returns the destination MemRefType for this DMA operation.
Definition: AffineOps.h:157
static StringRef getSrcMapAttrStrName()
Definition: AffineOps.h:266
AffineMapAttr getDstMapAttr()
Definition: AffineOps.h:177
unsigned getDstMemorySpace()
Returns the memory space of the source memref.
Definition: AffineOps.h:171
unsigned getSrcMemRefOperandIndex()
Returns the operand index of the source memref.
Definition: AffineOps.h:118
unsigned getTagMemRefOperandIndex()
Returns the operand index of the tag memref.
Definition: AffineOps.h:190
static StringRef getTagMapAttrStrName()
Definition: AffineOps.h:268
LogicalResult verifyInvariantsImpl()
Definition: AffineOps.cpp:1735
unsigned getDstMemRefRank()
Returns the rank (number of indices) of the destination MemRefType.
Definition: AffineOps.h:166
LogicalResult verifyInvariants()
Definition: AffineOps.h:274
AffineMap getSrcMap()
Returns the affine map used to access the source memref.
Definition: AffineOps.h:133
Value getNumElements()
Returns the number of elements being transferred by this DMA operation.
Definition: AffineOps.h:223
OpOperand & getTagMemRefMutable()
Definition: AffineOps.h:196
OpOperand & getSrcMemRefMutable()
Definition: AffineOps.h:122
static ArrayRef< StringRef > getAttributeNames()
Definition: AffineOps.h:109
AffineMap getTagMap()
Returns the affine map used to access the tag memref.
Definition: AffineOps.h:209
static ParseResult parse(OpAsmParser &parser, OperationState &result)
Definition: AffineOps.cpp:1659
Value getStride()
Returns the stride value for this DMA operation.
Definition: AffineOps.h:285
unsigned getDstMemRefOperandIndex()
Returns the operand index of the destination memref.
Definition: AffineOps.h:152
static StringRef getDstMapAttrStrName()
Definition: AffineOps.h:267
static StringRef getOperationName()
Definition: AffineOps.h:270
NamedAttribute getAffineMapAttrForMemRef(Value memref)
Impelements the AffineMapAccessInterface.
Definition: AffineOps.h:230
Value getSrcMemRef()
Returns the source MemRefType for this DMA operation.
Definition: AffineOps.h:121
operand_range getTagIndices()
Returns the tag memref indices for this DMA operation.
Definition: AffineOps.h:216
LogicalResult fold(ArrayRef< Attribute > cstOperands, SmallVectorImpl< OpFoldResult > &results)
Definition: AffineOps.cpp:1776
OpOperand & getDstMemRefMutable()
Definition: AffineOps.h:158
AffineDmaWaitOp blocks until the completion of a DMA operation associated with the tag element 'tag[i...
Definition: AffineOps.h:315
Value getNumElements()
Returns the number of elements transferred by the associated DMA op.
Definition: AffineOps.h:359
NamedAttribute getAffineMapAttrForMemRef(Value memref)
Impelements the AffineMapAccessInterface.
Definition: AffineOps.h:352
LogicalResult verifyInvariants()
Definition: AffineOps.h:365
LogicalResult verifyInvariantsImpl()
Definition: AffineOps.cpp:1852
static StringRef getOperationName()
Definition: AffineOps.h:323
static ArrayRef< StringRef > getAttributeNames()
Definition: AffineOps.h:318
Value getTagMemRef()
Returns the Tag MemRef associated with the DMA operation being waited on.
Definition: AffineOps.h:326
OpOperand & getTagMemRefMutable()
Definition: AffineOps.h:327
static ParseResult parse(OpAsmParser &parser, OperationState &result)
Definition: AffineOps.cpp:1821
static StringRef getTagMapAttrStrName()
Definition: AffineOps.h:361
LogicalResult fold(ArrayRef< Attribute > cstOperands, SmallVectorImpl< OpFoldResult > &results)
Definition: AffineOps.cpp:1866
AffineMapAttr getTagMapAttr()
Definition: AffineOps.h:334
void print(OpAsmPrinter &p)
Definition: AffineOps.cpp:1807
AffineMap getTagMap()
Returns the affine map used to access the tag memref.
Definition: AffineOps.h:333
unsigned getTagMemRefRank()
Returns the rank (number of indices) of the tag memref.
Definition: AffineOps.h:346
static void build(OpBuilder &builder, OperationState &result, Value tagMemRef, AffineMap tagMap, ValueRange tagIndices, Value numElements)
Definition: AffineOps.cpp:1798
operand_range getTagIndices()
Returns the tag memref index for this DMA operation.
Definition: AffineOps.h:340
void getEffects(SmallVectorImpl< SideEffects::EffectInstance< MemoryEffects::Effect >> &effects)
Definition: AffineOps.cpp:1872
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:2756
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:1157
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:2670
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:288
SmallVector< OpFoldResult > makeComposedFoldedMultiResultAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Variant of makeComposedFoldedAffineApply suitable for multi-result maps.
Definition: AffineOps.cpp:1263
bool isAffineInductionVar(Value val)
Returns true if the provided value is the induction variable of an AffineForOp or AffineParallelOp.
Definition: AffineOps.cpp:2642
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.
Definition: AffineOps.cpp:2646
AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Returns a composed AffineApplyOp by composing map and operands with other AffineApplyOps supplying th...
Definition: AffineOps.cpp:1167
void canonicalizeMapAndOperands(AffineMap *map, SmallVectorImpl< Value > *operands)
Modifies both map and operands in-place so as to:
Definition: AffineOps.cpp:1508
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:1328
bool isAffineForInductionVar(Value val)
Returns true if the provided value is the induction variable of an AffineForOp.
Definition: AffineOps.cpp:2634
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:1321
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:248
Region * getAffineAnalysisScope(Operation *op)
Returns the closest region enclosing op that is held by a non-affine operation; nullptr if there is n...
Definition: AffineOps.cpp:273
void canonicalizeSetAndOperands(IntegerSet *set, SmallVectorImpl< Value > *operands)
Canonicalizes an integer set the same way canonicalizeMapAndOperands does for affine maps.
Definition: AffineOps.cpp:1513
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:2677
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:402
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:1217
AffineParallelOp getAffineParallelInductionVarOwner(Value val)
Returns true if the provided value is among the induction variables of an AffineParallelOp.
Definition: AffineOps.cpp:2657
Region * getAffineScope(Operation *op)
Returns the closest region enclosing op that is held by an operation with trait AffineScope; nullptr ...
Definition: AffineOps.cpp:263
ParseResult parseDimAndSymbolList(OpAsmParser &parser, SmallVectorImpl< Value > &operands, unsigned &numDims)
Parses dimension and symbol list.
Definition: AffineOps.cpp:495
bool isAffineParallelInductionVar(Value val)
Returns true if val is the induction variable of an AffineParallelOp.
Definition: AffineOps.cpp:2638
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...
Definition: AffineOps.cpp:1283
Include the generated interface declarations.
llvm::function_ref< Fn > function_ref
Definition: LLVM.h:152
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition: Utils.cpp:305
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This represents an operation in an abstracted form, suitable for use with the builder APIs.