2018-08-08 05:24:38 +08:00
|
|
|
//===- IntegerSet.cpp - MLIR Integer Set class ----------------------------===//
|
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-08 05:24:38 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-08-08 05:24:38 +08:00
|
|
|
|
|
|
|
#include "mlir/IR/IntegerSet.h"
|
2018-10-11 00:45:59 +08:00
|
|
|
#include "IntegerSetDetail.h"
|
2018-08-08 05:24:38 +08:00
|
|
|
|
|
|
|
using namespace mlir;
|
2018-10-11 00:45:59 +08:00
|
|
|
using namespace mlir::detail;
|
|
|
|
|
|
|
|
unsigned IntegerSet::getNumDims() const { return set->dimCount; }
|
|
|
|
unsigned IntegerSet::getNumSymbols() const { return set->symbolCount; }
|
2019-09-06 14:12:01 +08:00
|
|
|
unsigned IntegerSet::getNumInputs() const {
|
2018-10-11 00:45:59 +08:00
|
|
|
return set->dimCount + set->symbolCount;
|
|
|
|
}
|
2018-10-25 23:33:02 +08:00
|
|
|
|
|
|
|
unsigned IntegerSet::getNumConstraints() const {
|
|
|
|
return set->constraints.size();
|
|
|
|
}
|
2018-10-11 00:45:59 +08:00
|
|
|
|
2018-10-25 02:30:06 +08:00
|
|
|
unsigned IntegerSet::getNumEqualities() const {
|
|
|
|
unsigned numEqualities = 0;
|
|
|
|
for (unsigned i = 0, e = getNumConstraints(); i < e; i++)
|
|
|
|
if (isEq(i))
|
|
|
|
++numEqualities;
|
|
|
|
return numEqualities;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned IntegerSet::getNumInequalities() const {
|
|
|
|
return getNumConstraints() - getNumEqualities();
|
|
|
|
}
|
|
|
|
|
2018-10-25 23:33:02 +08:00
|
|
|
bool IntegerSet::isEmptyIntegerSet() const {
|
2019-10-04 19:37:14 +08:00
|
|
|
// This will only work if uniquing is on.
|
2018-10-25 23:33:02 +08:00
|
|
|
static_assert(kUniquingThreshold >= 1,
|
|
|
|
"uniquing threshold should be at least one");
|
|
|
|
return *this == getEmptySet(set->dimCount, set->symbolCount, getContext());
|
|
|
|
}
|
|
|
|
|
2018-10-11 00:45:59 +08:00
|
|
|
ArrayRef<AffineExpr> IntegerSet::getConstraints() const {
|
|
|
|
return set->constraints;
|
|
|
|
}
|
|
|
|
|
|
|
|
AffineExpr IntegerSet::getConstraint(unsigned idx) const {
|
|
|
|
return getConstraints()[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the equality bits, which specify whether each of the constraints
|
|
|
|
/// is an equality or inequality.
|
|
|
|
ArrayRef<bool> IntegerSet::getEqFlags() const { return set->eqFlags; }
|
2018-08-08 05:24:38 +08:00
|
|
|
|
2018-10-11 00:45:59 +08:00
|
|
|
/// Returns true if the idx^th constraint is an equality, false if it is an
|
|
|
|
/// inequality.
|
|
|
|
bool IntegerSet::isEq(unsigned idx) const { return getEqFlags()[idx]; }
|
2018-10-25 02:30:06 +08:00
|
|
|
|
|
|
|
MLIRContext *IntegerSet::getContext() const {
|
|
|
|
return getConstraint(0).getContext();
|
|
|
|
}
|
2019-09-06 14:12:01 +08:00
|
|
|
|
|
|
|
/// Walk all of the AffineExpr's in this set. Each node in an expression
|
|
|
|
/// tree is visited in postorder.
|
2019-12-19 01:28:48 +08:00
|
|
|
void IntegerSet::walkExprs(function_ref<void(AffineExpr)> callback) const {
|
2019-09-06 14:12:01 +08:00
|
|
|
for (auto expr : getConstraints())
|
|
|
|
expr.walk(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntegerSet IntegerSet::replaceDimsAndSymbols(
|
|
|
|
ArrayRef<AffineExpr> dimReplacements, ArrayRef<AffineExpr> symReplacements,
|
|
|
|
unsigned numResultDims, unsigned numResultSyms) {
|
|
|
|
SmallVector<AffineExpr, 8> constraints;
|
|
|
|
constraints.reserve(getNumConstraints());
|
|
|
|
for (auto cst : getConstraints())
|
|
|
|
constraints.push_back(
|
|
|
|
cst.replaceDimsAndSymbols(dimReplacements, symReplacements));
|
|
|
|
|
|
|
|
return get(numResultDims, numResultSyms, constraints, getEqFlags());
|
|
|
|
}
|