xref: /llvm-project/mlir/lib/IR/IntegerSet.cpp (revision 54132393500708e79649530eb87ae6411de987a7)
1 //===- IntegerSet.cpp - MLIR Integer Set class ----------------------------===//
2 //
3 // Copyright 2019 The MLIR Authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //   http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // =============================================================================
17 
18 #include "mlir/IR/IntegerSet.h"
19 #include "IntegerSetDetail.h"
20 #include "mlir/IR/AffineExpr.h"
21 
22 using namespace mlir;
23 using namespace mlir::detail;
24 
25 unsigned IntegerSet::getNumDims() const { return set->dimCount; }
26 unsigned IntegerSet::getNumSymbols() const { return set->symbolCount; }
27 unsigned IntegerSet::getNumOperands() const {
28   return set->dimCount + set->symbolCount;
29 }
30 unsigned IntegerSet::getNumConstraints() const { return set->numConstraints; }
31 
32 unsigned IntegerSet::getNumEqualities() const {
33   unsigned numEqualities = 0;
34   for (unsigned i = 0, e = getNumConstraints(); i < e; i++)
35     if (isEq(i))
36       ++numEqualities;
37   return numEqualities;
38 }
39 
40 unsigned IntegerSet::getNumInequalities() const {
41   return getNumConstraints() - getNumEqualities();
42 }
43 
44 ArrayRef<AffineExpr> IntegerSet::getConstraints() const {
45   return set->constraints;
46 }
47 
48 AffineExpr IntegerSet::getConstraint(unsigned idx) const {
49   return getConstraints()[idx];
50 }
51 
52 /// Returns the equality bits, which specify whether each of the constraints
53 /// is an equality or inequality.
54 ArrayRef<bool> IntegerSet::getEqFlags() const { return set->eqFlags; }
55 
56 /// Returns true if the idx^th constraint is an equality, false if it is an
57 /// inequality.
58 bool IntegerSet::isEq(unsigned idx) const { return getEqFlags()[idx]; }
59 
60 MLIRContext *IntegerSet::getContext() const {
61   return getConstraint(0).getContext();
62 }
63