constexpr static unsigned kExplosionFactor = 32;
};
-/// Simplify an affine expression by flattening and some amount of
-/// simple analysis. This has complexity linear in the number of nodes in
-/// 'expr'. Returns the simplified expression, which is the same as the input
-/// expression if it can't be simplified.
-AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims,
- unsigned numSymbols);
-
/// Flattens 'expr' into 'flattenedExpr', which contains the coefficients of the
/// dimensions, symbols, and additional variables that represent floor divisions
/// of dimensions, symbols, and in turn other floor divisions. Returns failure
AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims,
unsigned numSymbols);
-/// Flattens 'expr' into 'flattenedExpr'. Returns true on success or false
-/// if 'expr' could not be flattened (i.e., semi-affine is not yet handled).
-/// See documentation for AffineExprFlattener on how mod's and div's are
-/// flattened.
-bool getFlattenedAffineExpr(AffineExpr expr, unsigned numDims,
- unsigned numSymbols,
- SmallVectorImpl<int64_t> *flattenedExpr);
-
-/// Flattens the result expressions of the map to their corresponding flattened
-/// forms and set in 'flattenedExprs'. Returns true on success or false
-/// if any expression in the map could not be flattened (i.e., semi-affine is
-/// not yet handled). For all affine expressions that share the same operands
-/// (like those of an affine map), this method should be used instead of
-/// repeatedly calling getFlattenedAffineExpr since local variables added to
-/// deal with div's and mod's will be reused across expressions.
-bool getFlattenedAffineExprs(
- AffineMap map, std::vector<SmallVector<int64_t, 8>> *flattenedExprs);
-bool getFlattenedAffineExprs(
- IntegerSet set, std::vector<SmallVector<int64_t, 8>> *flattenedExprs);
-
namespace detail {
template <int N> void bindDims(MLIRContext *ctx) {}
return simplifiedExpr;
}
-
-// Flattens the expressions in map. Returns true on success or false
-// if 'expr' was unable to be flattened (i.e., semi-affine expressions not
-// handled yet).
-static bool
-getFlattenedAffineExprs(ArrayRef<AffineExpr> exprs, unsigned numDims,
- unsigned numSymbols,
- std::vector<SmallVector<int64_t, 8>> *flattenedExprs) {
- if (exprs.empty()) {
- return true;
- }
-
- SimpleAffineExprFlattener flattener(numDims, numSymbols);
- // Use the same flattener to simplify each expression successively. This way
- // local identifiers / expressions are shared.
- for (auto expr : exprs) {
- if (!expr.isPureAffine())
- return false;
-
- flattener.walkPostOrder(expr);
- }
-
- flattenedExprs->clear();
- assert(flattener.operandExprStack.size() == exprs.size());
- flattenedExprs->assign(flattener.operandExprStack.begin(),
- flattener.operandExprStack.end());
-
- return true;
-}
-
-// Flattens 'expr' into 'flattenedExpr'. Returns true on success or false
-// if 'expr' was unable to be flattened (semi-affine expressions not handled
-// yet).
-bool mlir::getFlattenedAffineExpr(AffineExpr expr, unsigned numDims,
- unsigned numSymbols,
- SmallVectorImpl<int64_t> *flattenedExpr) {
- std::vector<SmallVector<int64_t, 8>> flattenedExprs;
- bool ret =
- ::getFlattenedAffineExprs({expr}, numDims, numSymbols, &flattenedExprs);
- *flattenedExpr = flattenedExprs[0];
- return ret;
-}
-
-/// Flattens the expressions in map. Returns true on success or false
-/// if 'expr' was unable to be flattened (i.e., semi-affine expressions not
-/// handled yet).
-bool mlir::getFlattenedAffineExprs(
- AffineMap map, std::vector<SmallVector<int64_t, 8>> *flattenedExprs) {
- if (map.getNumResults() == 0) {
- return true;
- }
- return ::getFlattenedAffineExprs(map.getResults(), map.getNumDims(),
- map.getNumSymbols(), flattenedExprs);
-}
-
-bool mlir::getFlattenedAffineExprs(
- IntegerSet set, std::vector<SmallVector<int64_t, 8>> *flattenedExprs) {
- if (set.getNumConstraints() == 0) {
- return true;
- }
- return ::getFlattenedAffineExprs(set.getConstraints(), set.getNumDims(),
- set.getNumSymbols(), flattenedExprs);
-}