MLIR  20.0.0git
IntegerSet.cpp
Go to the documentation of this file.
1 //===- IntegerSet.cpp - MLIR Integer Set class ----------------------------===//
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 #include "mlir/IR/IntegerSet.h"
10 #include "IntegerSetDetail.h"
11 
12 using namespace mlir;
13 using namespace mlir::detail;
14 
15 unsigned IntegerSet::getNumDims() const { return set->dimCount; }
16 unsigned IntegerSet::getNumSymbols() const { return set->symbolCount; }
17 unsigned IntegerSet::getNumInputs() const {
18  return set->dimCount + set->symbolCount;
19 }
20 
22  return set->constraints.size();
23 }
24 
25 unsigned IntegerSet::getNumEqualities() const {
26  unsigned numEqualities = 0;
27  for (unsigned i = 0, e = getNumConstraints(); i < e; i++)
28  if (isEq(i))
29  ++numEqualities;
30  return numEqualities;
31 }
32 
34  return getNumConstraints() - getNumEqualities();
35 }
36 
38  return *this == getEmptySet(set->dimCount, set->symbolCount, getContext());
39 }
40 
42  return set->constraints;
43 }
44 
46  return getConstraints()[idx];
47 }
48 
49 /// Returns the equality bits, which specify whether each of the constraints
50 /// is an equality or inequality.
51 ArrayRef<bool> IntegerSet::getEqFlags() const { return set->eqFlags; }
52 
53 /// Returns true if the idx^th constraint is an equality, false if it is an
54 /// inequality.
55 bool IntegerSet::isEq(unsigned idx) const { return getEqFlags()[idx]; }
56 
58  return getConstraint(0).getContext();
59 }
60 
61 /// Walk all of the AffineExpr's in this set. Each node in an expression
62 /// tree is visited in postorder.
63 void IntegerSet::walkExprs(function_ref<void(AffineExpr)> callback) const {
64  for (auto expr : getConstraints())
65  expr.walk(callback);
66 }
67 
69  ArrayRef<AffineExpr> dimReplacements, ArrayRef<AffineExpr> symReplacements,
70  unsigned numResultDims, unsigned numResultSyms) {
71  SmallVector<AffineExpr, 8> constraints;
72  constraints.reserve(getNumConstraints());
73  for (auto cst : getConstraints())
74  constraints.push_back(
75  cst.replaceDimsAndSymbols(dimReplacements, symReplacements));
76 
77  return get(numResultDims, numResultSyms, constraints, getEqFlags());
78 }
static MLIRContext * getContext(OpFoldResult val)
Base type for affine expression.
Definition: AffineExpr.h:68
An integer set representing a conjunction of one or more affine equalities and inequalities.
Definition: IntegerSet.h:44
void walkExprs(function_ref< void(AffineExpr)> callback) const
Walk all of the AffineExpr's in this set's constraints.
Definition: IntegerSet.cpp:63
IntegerSet replaceDimsAndSymbols(ArrayRef< AffineExpr > dimReplacements, ArrayRef< AffineExpr > symReplacements, unsigned numResultDims, unsigned numResultSyms)
This method substitutes any uses of dimensions and symbols (e.g.
Definition: IntegerSet.cpp:68
unsigned getNumDims() const
Definition: IntegerSet.cpp:15
MLIRContext * getContext() const
Definition: IntegerSet.cpp:57
unsigned getNumInputs() const
Definition: IntegerSet.cpp:17
unsigned getNumConstraints() const
Definition: IntegerSet.cpp:21
ArrayRef< AffineExpr > getConstraints() const
Definition: IntegerSet.cpp:41
unsigned getNumEqualities() const
Definition: IntegerSet.cpp:25
bool isEmptyIntegerSet() const
Returns true if this is the canonical integer set.
Definition: IntegerSet.cpp:37
AffineExpr getConstraint(unsigned idx) const
Definition: IntegerSet.cpp:45
unsigned getNumInequalities() const
Definition: IntegerSet.cpp:33
bool isEq(unsigned idx) const
Returns true if the idx^th constraint is an equality, false if it is an inequality.
Definition: IntegerSet.cpp:55
ArrayRef< bool > getEqFlags() const
Returns the equality bits, which specify whether each of the constraints is an equality or inequality...
Definition: IntegerSet.cpp:51
unsigned getNumSymbols() const
Definition: IntegerSet.cpp:16
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
AttrTypeReplacer.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...