MLIR  19.0.0git
ScalableValueBoundsConstraintSet.h
Go to the documentation of this file.
1 //===- ScalableValueBoundsConstraintSet.h - Scalable Value Bounds ---------===//
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 #ifndef MLIR_DIALECT_VECTOR_IR_SCALABLEVALUEBOUNDSCONSTRAINTSET_H
10 #define MLIR_DIALECT_VECTOR_IR_SCALABLEVALUEBOUNDSCONSTRAINTSET_H
11 
15 
16 namespace mlir::vector {
17 
18 namespace detail {
19 
20 /// Parent class for the value bounds RTTIExtends. Uses protected inheritance to
21 /// hide all ValueBoundsConstraintSet methods by default (as some do not use the
22 /// ScalableValueBoundsConstraintSet, so may produce unexpected results).
24  using ::mlir::ValueBoundsConstraintSet::ValueBoundsConstraintSet;
25 };
26 } // namespace detail
27 
28 /// A version of `ValueBoundsConstraintSet` that can solve for scalable bounds.
30  : public llvm::RTTIExtends<ScalableValueBoundsConstraintSet,
31  detail::ValueBoundsConstraintSet> {
33  MLIRContext *context,
35  unsigned vscaleMin, unsigned vscaleMax)
36  : RTTIExtends(context, stopCondition), vscaleMin(vscaleMin),
37  vscaleMax(vscaleMax) {};
38 
39  using RTTIExtends::bound;
41 
42  /// A thin wrapper over an `AffineMap` which can represent a constant bound,
43  /// or a scalable bound (in terms of vscale). The `AffineMap` will always
44  /// take at most one parameter, vscale, and returns a single result, which is
45  /// the bound of value.
48 
49  struct BoundSize {
50  int64_t baseSize{0};
51  bool scalable{false};
52  };
53 
54  /// Get the (possibly) scalable size of the bound, returns failure if
55  /// the bound cannot be represented as a single quantity.
57  };
58 
59  /// Computes a (possibly) scalable bound for a given value. This is
60  /// similar to `ValueBoundsConstraintSet::computeConstantBound()`, but
61  /// uses knowledge of the range of vscale to compute either a constant
62  /// bound, an expression in terms of vscale, or failure if no bound can
63  /// be computed.
64  ///
65  /// The resulting `AffineMap` will always take at most one parameter,
66  /// vscale, and return a single result, which is the bound of `value`.
67  ///
68  /// Note: `vscaleMin` must be `<=` to `vscaleMax`. If `vscaleMin` ==
69  /// `vscaleMax`, the resulting bound (if found), will be constant.
71  computeScalableBound(Value value, std::optional<int64_t> dim,
72  unsigned vscaleMin, unsigned vscaleMax,
73  presburger::BoundType boundType, bool closedUB = true,
74  StopConditionFn stopCondition = nullptr);
75 
76  /// Get the value of vscale. Returns `nullptr` vscale as not been encountered.
77  Value getVscaleValue() const { return vscale; }
78 
79  /// Sets the value of vscale. Asserts if vscale has already been set.
80  void setVscale(vector::VectorScaleOp vscaleOp) {
81  assert(!vscale && "expected vscale to be unset");
82  vscale = vscaleOp.getResult();
83  }
84 
85  /// The minimum possible value of vscale.
86  unsigned getVscaleMin() const { return vscaleMin; }
87 
88  /// The maximum possible value of vscale.
89  unsigned getVscaleMax() const { return vscaleMax; }
90 
91  static char ID;
92 
93 private:
94  const unsigned vscaleMin;
95  const unsigned vscaleMax;
96 
97  // This will be set when the first `vector.vscale` operation is found within
98  // the `ValueBoundsOpInterface` implementation then reused from there on.
99  Value vscale = nullptr;
100 };
101 
104 
105 } // namespace mlir::vector
106 
107 #endif // MLIR_DIALECT_VECTOR_IR_SCALABLEVALUEBOUNDSCONSTRAINTSET_H
function_ref< bool(Region *, ArrayRef< bool > visited)> StopConditionFn
Stop condition for traverseRegionGraph.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition: AffineMap.h:47
This class provides support for representing a failure result, or a valid value of type T.
Definition: LogicalResult.h:78
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
A helper class to be used with ValueBoundsOpInterface.
std::function< bool(Value, std::optional< int64_t >, ValueBoundsConstraintSet &cstr)> StopConditionFn
The stop condition when traversing the backward slice of a shaped value/ index-type value.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
BoundType
The type of bound: equal, lower bound or upper bound.
ScalableValueBoundsConstraintSet::ConstantOrScalableBound ConstantOrScalableBound
A thin wrapper over an AffineMap which can represent a constant bound, or a scalable bound (in terms ...
FailureOr< BoundSize > getSize() const
Get the (possibly) scalable size of the bound, returns failure if the bound cannot be represented as ...
A version of ValueBoundsConstraintSet that can solve for scalable bounds.
static FailureOr< ConstantOrScalableBound > computeScalableBound(Value value, std::optional< int64_t > dim, unsigned vscaleMin, unsigned vscaleMax, presburger::BoundType boundType, bool closedUB=true, StopConditionFn stopCondition=nullptr)
Computes a (possibly) scalable bound for a given value.
unsigned getVscaleMin() const
The minimum possible value of vscale.
Value getVscaleValue() const
Get the value of vscale. Returns nullptr vscale as not been encountered.
ScalableValueBoundsConstraintSet(MLIRContext *context, ValueBoundsConstraintSet::StopConditionFn stopCondition, unsigned vscaleMin, unsigned vscaleMax)
unsigned getVscaleMax() const
The maximum possible value of vscale.
void setVscale(vector::VectorScaleOp vscaleOp)
Sets the value of vscale. Asserts if vscale has already been set.
Parent class for the value bounds RTTIExtends.