diff --git a/mlir/include/mlir/Analysis/AffineStructures.h b/mlir/include/mlir/Analysis/AffineStructures.h --- a/mlir/include/mlir/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Analysis/AffineStructures.h @@ -660,13 +660,6 @@ 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 diff --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h --- a/mlir/include/mlir/IR/AffineExpr.h +++ b/mlir/include/mlir/IR/AffineExpr.h @@ -79,10 +79,14 @@ bool operator!() const { return expr == nullptr; } - template bool isa() const; - template U dyn_cast() const; - template U dyn_cast_or_null() const; - template U cast() const; + template + bool isa() const; + template + U dyn_cast() const; + template + U dyn_cast_or_null() const; + template + U cast() const; MLIRContext *getContext() const; @@ -220,7 +224,8 @@ raw_ostream &operator<<(raw_ostream &os, AffineExpr &expr); -template bool AffineExpr::isa() const { +template +bool AffineExpr::isa() const { if (std::is_same::value) return getKind() <= AffineExprKind::LAST_AFFINE_BINARY_OP; if (std::is_same::value) @@ -230,15 +235,18 @@ if (std::is_same::value) return getKind() == AffineExprKind::Constant; } -template U AffineExpr::dyn_cast() const { +template +U AffineExpr::dyn_cast() const { if (isa()) return U(expr); return U(nullptr); } -template U AffineExpr::dyn_cast_or_null() const { +template +U AffineExpr::dyn_cast_or_null() const { return (!*this || !isa()) ? U(nullptr) : U(expr); } -template U AffineExpr::cast() const { +template +U AffineExpr::cast() const { assert(isa()); return U(expr); } @@ -250,28 +258,9 @@ 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 *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> *flattenedExprs); -bool getFlattenedAffineExprs( - IntegerSet set, std::vector> *flattenedExprs); - namespace detail { -template void bindDims(MLIRContext *ctx) {} +template +void bindDims(MLIRContext *ctx) {} template void bindDims(MLIRContext *ctx, AffineExprTy &e, AffineExprTy2 &... exprs) { @@ -292,7 +281,8 @@ namespace llvm { // AffineExpr hash just like pointers -template <> struct DenseMapInfo { +template <> +struct DenseMapInfo { static mlir::AffineExpr getEmptyKey() { auto pointer = llvm::DenseMapInfo::getEmptyKey(); return mlir::AffineExpr(static_cast(pointer)); diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -853,66 +853,3 @@ 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 exprs, unsigned numDims, - unsigned numSymbols, - std::vector> *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 *flattenedExpr) { - std::vector> 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> *flattenedExprs) { - if (map.getNumResults() == 0) { - return true; - } - return ::getFlattenedAffineExprs(map.getResults(), map.getNumDims(), - map.getNumSymbols(), flattenedExprs); -} - -bool mlir::getFlattenedAffineExprs( - IntegerSet set, std::vector> *flattenedExprs) { - if (set.getNumConstraints() == 0) { - return true; - } - return ::getFlattenedAffineExprs(set.getConstraints(), set.getNumDims(), - set.getNumSymbols(), flattenedExprs); -}