/home/arjun/llvm-project/mlir/lib/IR/IntegerSet.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | unsigned IntegerSet::getNumDims() const { return set->dimCount; } |
16 | 0 | unsigned IntegerSet::getNumSymbols() const { return set->symbolCount; } |
17 | 0 | unsigned IntegerSet::getNumInputs() const { |
18 | 0 | return set->dimCount + set->symbolCount; |
19 | 0 | } |
20 | | |
21 | 0 | unsigned IntegerSet::getNumConstraints() const { |
22 | 0 | return set->constraints.size(); |
23 | 0 | } |
24 | | |
25 | 0 | unsigned IntegerSet::getNumEqualities() const { |
26 | 0 | unsigned numEqualities = 0; |
27 | 0 | for (unsigned i = 0, e = getNumConstraints(); i < e; i++) |
28 | 0 | if (isEq(i)) |
29 | 0 | ++numEqualities; |
30 | 0 | return numEqualities; |
31 | 0 | } |
32 | | |
33 | 0 | unsigned IntegerSet::getNumInequalities() const { |
34 | 0 | return getNumConstraints() - getNumEqualities(); |
35 | 0 | } |
36 | | |
37 | 0 | bool IntegerSet::isEmptyIntegerSet() const { |
38 | 0 | // This will only work if uniquing is on. |
39 | 0 | static_assert(kUniquingThreshold >= 1, |
40 | 0 | "uniquing threshold should be at least one"); |
41 | 0 | return *this == getEmptySet(set->dimCount, set->symbolCount, getContext()); |
42 | 0 | } |
43 | | |
44 | 0 | ArrayRef<AffineExpr> IntegerSet::getConstraints() const { |
45 | 0 | return set->constraints; |
46 | 0 | } |
47 | | |
48 | 0 | AffineExpr IntegerSet::getConstraint(unsigned idx) const { |
49 | 0 | return getConstraints()[idx]; |
50 | 0 | } |
51 | | |
52 | | /// Returns the equality bits, which specify whether each of the constraints |
53 | | /// is an equality or inequality. |
54 | 0 | 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 | 0 | bool IntegerSet::isEq(unsigned idx) const { return getEqFlags()[idx]; } |
59 | | |
60 | 0 | MLIRContext *IntegerSet::getContext() const { |
61 | 0 | return getConstraint(0).getContext(); |
62 | 0 | } |
63 | | |
64 | | /// Walk all of the AffineExpr's in this set. Each node in an expression |
65 | | /// tree is visited in postorder. |
66 | 0 | void IntegerSet::walkExprs(function_ref<void(AffineExpr)> callback) const { |
67 | 0 | for (auto expr : getConstraints()) |
68 | 0 | expr.walk(callback); |
69 | 0 | } |
70 | | |
71 | | IntegerSet IntegerSet::replaceDimsAndSymbols( |
72 | | ArrayRef<AffineExpr> dimReplacements, ArrayRef<AffineExpr> symReplacements, |
73 | 0 | unsigned numResultDims, unsigned numResultSyms) { |
74 | 0 | SmallVector<AffineExpr, 8> constraints; |
75 | 0 | constraints.reserve(getNumConstraints()); |
76 | 0 | for (auto cst : getConstraints()) |
77 | 0 | constraints.push_back( |
78 | 0 | cst.replaceDimsAndSymbols(dimReplacements, symReplacements)); |
79 | 0 |
|
80 | 0 | return get(numResultDims, numResultSyms, constraints, getEqFlags()); |
81 | 0 | } |