MLIR  17.0.0git
AffineValueMap.h
Go to the documentation of this file.
1 //===- AffineValueMap.h - MLIR Affine Value Map Class -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // An AffineValueMap is an affine map plus its ML value operands and results for
10 // analysis purposes.
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
14 #define MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
15 
16 #include "mlir/IR/AffineMap.h"
18 #include "mlir/IR/Value.h"
19 
20 namespace mlir {
21 
22 /// An AffineValueMap is an affine map plus its ML value operands and
23 /// results for analysis purposes. The structure is still a tree form that is
24 /// same as that of an affine map or an AffineApplyOp. However, its operands,
25 /// results, and its map can themselves change as a result of
26 /// substitutions, simplifications, and other analysis.
27 // An affine value map can readily be constructed from an AffineApplyOp, or an
28 // AffineBound of a AffineForOp. It can be further transformed, substituted
29 // into, or simplified. Unlike AffineMap's, AffineValueMap's are created and
30 // destroyed during analysis. Only the AffineMap expressions that are pointed by
31 // them are unique'd. An affine value map, and the operations on it, maintain
32 // the invariant that operands are always positionally aligned with the
33 // AffineDimExpr and AffineSymbolExpr in the underlying AffineMap.
35 public:
36  // Creates an empty AffineValueMap (users should call 'reset' to reset map
37  // and operands).
38  AffineValueMap() = default;
39  AffineValueMap(AffineMap map, ValueRange operands, ValueRange results = {});
40 
42 
43  // Resets this AffineValueMap with 'map', 'operands', and 'results'.
44  void reset(AffineMap map, ValueRange operands, ValueRange results = {});
45 
46  /// Return the value map that is the difference of value maps 'a' and 'b',
47  /// represented as an affine map and its operands. The output map + operands
48  /// are canonicalized and simplified.
49  static void difference(const AffineValueMap &a, const AffineValueMap &b,
50  AffineValueMap *res);
51 
52  /// Return true if the idx^th result can be proved to be a multiple of
53  /// 'factor', false otherwise.
54  inline bool isMultipleOf(unsigned idx, int64_t factor) const;
55 
56  /// Return true if the idx^th result depends on 'value', false otherwise.
57  bool isFunctionOf(unsigned idx, Value value) const;
58 
59  /// Return true if the result at 'idx' is a constant, false
60  /// otherwise.
61  bool isConstant(unsigned idx) const;
62 
63  /// Return true if this is an identity map.
64  bool isIdentity() const;
65 
66  void setResult(unsigned i, AffineExpr e) { map.setResult(i, e); }
67  AffineExpr getResult(unsigned i) { return map.getResult(i); }
68  inline unsigned getNumOperands() const { return operands.size(); }
69  inline unsigned getNumDims() const { return map.getNumDims(); }
70  inline unsigned getNumSymbols() const { return map.getNumSymbols(); }
71  inline unsigned getNumResults() const { return map.getNumResults(); }
72 
73  Value getOperand(unsigned i) const;
75  AffineMap getAffineMap() const;
76 
77  /// Attempts to canonicalize the map and operands. Return success if the map
78  /// and/or operands have been modified.
80 
81 private:
82  // A mutable affine map.
83  MutableAffineMap map;
84 
85  // TODO: make these trailing objects?
86  /// The SSA operands binding to the dim's and symbols of 'map'.
87  SmallVector<Value, 4> operands;
88  /// The SSA results binding to the results of 'map'.
89  SmallVector<Value, 4> results;
90 };
91 
92 } // namespace mlir
93 
94 #endif // MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
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:43
unsigned getNumSymbols() const
Definition: AffineMap.cpp:323
unsigned getNumDims() const
Definition: AffineMap.cpp:319
unsigned getNumResults() const
Definition: AffineMap.cpp:327
AffineExpr getResult(unsigned idx) const
Definition: AffineMap.cpp:336
An AffineValueMap is an affine map plus its ML value operands and results for analysis purposes.
unsigned getNumResults() const
void setResult(unsigned i, AffineExpr e)
Value getOperand(unsigned i) const
unsigned getNumDims() const
AffineValueMap()=default
LogicalResult canonicalize()
Attempts to canonicalize the map and operands.
Definition: AffineOps.cpp:3680
bool isMultipleOf(unsigned idx, int64_t factor) const
Return true if the idx^th result can be proved to be a multiple of 'factor', false otherwise.
unsigned getNumOperands() const
ArrayRef< Value > getOperands() const
unsigned getNumSymbols() const
AffineMap getAffineMap() const
bool isIdentity() const
Return true if this is an identity map.
bool isFunctionOf(unsigned idx, Value value) const
Return true if the idx^th result depends on 'value', false otherwise.
AffineExpr getResult(unsigned i)
bool isConstant(unsigned idx) const
Return true if the result at 'idx' is a constant, false otherwise.
void reset(AffineMap map, ValueRange operands, ValueRange results={})
static void difference(const AffineValueMap &a, const AffineValueMap &b, AffineValueMap *res)
Return the value map that is the difference of value maps 'a' and 'b', represented as an affine map a...
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:350
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:93
Include the generated interface declarations.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
A mutable affine map. Its affine expressions are however unique.
Definition: AffineMap.h:364