1 //===- IntegerSet.cpp - MLIR Integer Set class ----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "mlir/IR/IntegerSet.h"
10 #include "IntegerSetDetail.h"
13 using namespace mlir::detail
;
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
;
21 unsigned IntegerSet::getNumConstraints() const {
22 return set
->constraints
.size();
25 unsigned IntegerSet::getNumEqualities() const {
26 unsigned numEqualities
= 0;
27 for (unsigned i
= 0, e
= getNumConstraints(); i
< e
; i
++)
33 unsigned IntegerSet::getNumInequalities() const {
34 return getNumConstraints() - getNumEqualities();
37 bool IntegerSet::isEmptyIntegerSet() const {
38 return *this == getEmptySet(set
->dimCount
, set
->symbolCount
, getContext());
41 ArrayRef
<AffineExpr
> IntegerSet::getConstraints() const {
42 return set
->constraints
;
45 AffineExpr
IntegerSet::getConstraint(unsigned idx
) const {
46 return getConstraints()[idx
];
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
; }
53 /// Returns true if the idx^th constraint is an equality, false if it is an
55 bool IntegerSet::isEq(unsigned idx
) const { return getEqFlags()[idx
]; }
57 MLIRContext
*IntegerSet::getContext() const {
58 return getConstraint(0).getContext();
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())
68 IntegerSet
IntegerSet::replaceDimsAndSymbols(
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
));
77 return get(numResultDims
, numResultSyms
, constraints
, getEqFlags());