Rename SDBMPositiveExpr to SDBMTermExpr
This better reflects how this kind of expressions is used and avoids the potential confusion since the expression can take negative values. Term expressions comprise dimensions, symbols and stripe expressions. In an SDBM domain, a stripe expression always corresponds to a variable, input or temporary. This expression can appear anywhere an input variable can, including on the LHS of other stripe expressions. PiperOrigin-RevId: 268486066
This commit is contained in:
parent
9037f28cb4
commit
e15356f8ed
|
@ -31,7 +31,7 @@ namespace mlir {
|
||||||
class MLIRContext;
|
class MLIRContext;
|
||||||
class SDBMDialect;
|
class SDBMDialect;
|
||||||
class SDBMExpr;
|
class SDBMExpr;
|
||||||
class SDBMPositiveExpr;
|
class SDBMTermExpr;
|
||||||
|
|
||||||
/// A utility class for SDBM to represent an integer with potentially infinite
|
/// A utility class for SDBM to represent an integer with potentially infinite
|
||||||
/// positive value. This uses the largest value of int64_t to represent infinity
|
/// positive value. This uses the largest value of int64_t to represent infinity
|
||||||
|
@ -130,14 +130,14 @@ private:
|
||||||
/// and at(col,row) of the DBM. Depending on the values being finite and
|
/// and at(col,row) of the DBM. Depending on the values being finite and
|
||||||
/// being subsumed by stripe expressions, this may or may not add elements to
|
/// being subsumed by stripe expressions, this may or may not add elements to
|
||||||
/// the lists of equalities and inequalities.
|
/// the lists of equalities and inequalities.
|
||||||
void convertDBMElement(unsigned row, unsigned col, SDBMPositiveExpr rowExpr,
|
void convertDBMElement(unsigned row, unsigned col, SDBMTermExpr rowExpr,
|
||||||
SDBMPositiveExpr colExpr,
|
SDBMTermExpr colExpr,
|
||||||
SmallVectorImpl<SDBMExpr> &inequalities,
|
SmallVectorImpl<SDBMExpr> &inequalities,
|
||||||
SmallVectorImpl<SDBMExpr> &equalities);
|
SmallVectorImpl<SDBMExpr> &equalities);
|
||||||
|
|
||||||
/// Populate `inequalities` based on the value at(pos,pos) of the DBM. Only
|
/// Populate `inequalities` based on the value at(pos,pos) of the DBM. Only
|
||||||
/// adds new inequalities if the inequality is not trivially true.
|
/// adds new inequalities if the inequality is not trivially true.
|
||||||
void convertDBMDiagonalElement(unsigned pos, SDBMPositiveExpr expr,
|
void convertDBMDiagonalElement(unsigned pos, SDBMTermExpr expr,
|
||||||
SmallVectorImpl<SDBMExpr> &inequalities);
|
SmallVectorImpl<SDBMExpr> &inequalities);
|
||||||
|
|
||||||
/// Get the total number of elements in the matrix.
|
/// Get the total number of elements in the matrix.
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace detail {
|
||||||
struct SDBMExprStorage;
|
struct SDBMExprStorage;
|
||||||
struct SDBMBinaryExprStorage;
|
struct SDBMBinaryExprStorage;
|
||||||
struct SDBMDiffExprStorage;
|
struct SDBMDiffExprStorage;
|
||||||
struct SDBMPositiveExprStorage;
|
struct SDBMTermExprStorage;
|
||||||
struct SDBMConstantExprStorage;
|
struct SDBMConstantExprStorage;
|
||||||
struct SDBMNegExprStorage;
|
struct SDBMNegExprStorage;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -176,10 +176,12 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// SDBM positive variable expression can be one of:
|
/// SDBM term expression can be one of:
|
||||||
/// - single variable expression;
|
/// - single variable expression;
|
||||||
/// - stripe expression.
|
/// - stripe expression.
|
||||||
class SDBMPositiveExpr : public SDBMVaryingExpr {
|
/// Stripe expressions are treated as terms since, in the SDBM domain, they are
|
||||||
|
/// attached to temporary variables and can appear anywhere a variable can.
|
||||||
|
class SDBMTermExpr : public SDBMVaryingExpr {
|
||||||
public:
|
public:
|
||||||
using SDBMVaryingExpr::SDBMVaryingExpr;
|
using SDBMVaryingExpr::SDBMVaryingExpr;
|
||||||
|
|
||||||
|
@ -209,40 +211,38 @@ public:
|
||||||
SDBMConstantExpr getRHS() const;
|
SDBMConstantExpr getRHS() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// SDBM difference expression. Both LHS and RHS are positive variable
|
/// SDBM difference expression. Both LHS and RHS are SDBM term expressions.
|
||||||
/// expressions.
|
|
||||||
class SDBMDiffExpr : public SDBMVaryingExpr {
|
class SDBMDiffExpr : public SDBMVaryingExpr {
|
||||||
public:
|
public:
|
||||||
using ImplType = detail::SDBMDiffExprStorage;
|
using ImplType = detail::SDBMDiffExprStorage;
|
||||||
using SDBMVaryingExpr::SDBMVaryingExpr;
|
using SDBMVaryingExpr::SDBMVaryingExpr;
|
||||||
|
|
||||||
/// Obtain or create a difference expression unique'ed in the given context.
|
/// Obtain or create a difference expression unique'ed in the given context.
|
||||||
static SDBMDiffExpr get(SDBMPositiveExpr lhs, SDBMPositiveExpr rhs);
|
static SDBMDiffExpr get(SDBMTermExpr lhs, SDBMTermExpr rhs);
|
||||||
|
|
||||||
static bool isClassFor(const SDBMExpr &expr) {
|
static bool isClassFor(const SDBMExpr &expr) {
|
||||||
return expr.getKind() == SDBMExprKind::Diff;
|
return expr.getKind() == SDBMExprKind::Diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr getLHS() const;
|
SDBMTermExpr getLHS() const;
|
||||||
SDBMPositiveExpr getRHS() const;
|
SDBMTermExpr getRHS() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// SDBM stripe expression "x # C" where "x" is a positive variable expression,
|
/// SDBM stripe expression "x # C" where "x" is a term expression, "C" is a
|
||||||
/// "C" is a constant expression and "#" is the stripe operator defined as:
|
/// constant expression and "#" is the stripe operator defined as:
|
||||||
/// x # C = x - x mod C.
|
/// x # C = x - x mod C.
|
||||||
class SDBMStripeExpr : public SDBMPositiveExpr {
|
class SDBMStripeExpr : public SDBMTermExpr {
|
||||||
public:
|
public:
|
||||||
using ImplType = detail::SDBMBinaryExprStorage;
|
using ImplType = detail::SDBMBinaryExprStorage;
|
||||||
using SDBMPositiveExpr::SDBMPositiveExpr;
|
using SDBMTermExpr::SDBMTermExpr;
|
||||||
|
|
||||||
static bool isClassFor(const SDBMExpr &expr) {
|
static bool isClassFor(const SDBMExpr &expr) {
|
||||||
return expr.getKind() == SDBMExprKind::Stripe;
|
return expr.getKind() == SDBMExprKind::Stripe;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDBMStripeExpr get(SDBMPositiveExpr var,
|
static SDBMStripeExpr get(SDBMTermExpr var, SDBMConstantExpr stripeFactor);
|
||||||
SDBMConstantExpr stripeFactor);
|
|
||||||
|
|
||||||
SDBMPositiveExpr getVar() const;
|
SDBMTermExpr getVar() const;
|
||||||
SDBMConstantExpr getStripeFactor() const;
|
SDBMConstantExpr getStripeFactor() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -250,10 +250,10 @@ public:
|
||||||
/// a symbol identifier. When used to define SDBM functions, dimensions are
|
/// a symbol identifier. When used to define SDBM functions, dimensions are
|
||||||
/// interpreted as function arguments while symbols are treated as unknown but
|
/// interpreted as function arguments while symbols are treated as unknown but
|
||||||
/// constant values, hence the name.
|
/// constant values, hence the name.
|
||||||
class SDBMInputExpr : public SDBMPositiveExpr {
|
class SDBMInputExpr : public SDBMTermExpr {
|
||||||
public:
|
public:
|
||||||
using ImplType = detail::SDBMPositiveExprStorage;
|
using ImplType = detail::SDBMTermExprStorage;
|
||||||
using SDBMPositiveExpr::SDBMPositiveExpr;
|
using SDBMTermExpr::SDBMTermExpr;
|
||||||
|
|
||||||
static bool isClassFor(const SDBMExpr &expr) {
|
static bool isClassFor(const SDBMExpr &expr) {
|
||||||
return expr.getKind() == SDBMExprKind::DimId ||
|
return expr.getKind() == SDBMExprKind::DimId ||
|
||||||
|
@ -267,7 +267,7 @@ public:
|
||||||
/// when defining functions using SDBM expressions.
|
/// when defining functions using SDBM expressions.
|
||||||
class SDBMDimExpr : public SDBMInputExpr {
|
class SDBMDimExpr : public SDBMInputExpr {
|
||||||
public:
|
public:
|
||||||
using ImplType = detail::SDBMPositiveExprStorage;
|
using ImplType = detail::SDBMTermExprStorage;
|
||||||
using SDBMInputExpr::SDBMInputExpr;
|
using SDBMInputExpr::SDBMInputExpr;
|
||||||
|
|
||||||
/// Obtain or create a dimension expression unique'ed in the given dialect
|
/// Obtain or create a dimension expression unique'ed in the given dialect
|
||||||
|
@ -283,7 +283,7 @@ public:
|
||||||
/// defining functions using SDBM expressions.
|
/// defining functions using SDBM expressions.
|
||||||
class SDBMSymbolExpr : public SDBMInputExpr {
|
class SDBMSymbolExpr : public SDBMInputExpr {
|
||||||
public:
|
public:
|
||||||
using ImplType = detail::SDBMPositiveExprStorage;
|
using ImplType = detail::SDBMTermExprStorage;
|
||||||
using SDBMInputExpr::SDBMInputExpr;
|
using SDBMInputExpr::SDBMInputExpr;
|
||||||
|
|
||||||
/// Obtain or create a symbol expression unique'ed in the given dialect (which
|
/// Obtain or create a symbol expression unique'ed in the given dialect (which
|
||||||
|
@ -303,13 +303,13 @@ public:
|
||||||
using SDBMVaryingExpr::SDBMVaryingExpr;
|
using SDBMVaryingExpr::SDBMVaryingExpr;
|
||||||
|
|
||||||
/// Obtain or create a negation expression unique'ed in the given context.
|
/// Obtain or create a negation expression unique'ed in the given context.
|
||||||
static SDBMNegExpr get(SDBMPositiveExpr var);
|
static SDBMNegExpr get(SDBMTermExpr var);
|
||||||
|
|
||||||
static bool isClassFor(const SDBMExpr &expr) {
|
static bool isClassFor(const SDBMExpr &expr) {
|
||||||
return expr.getKind() == SDBMExprKind::Neg;
|
return expr.getKind() == SDBMExprKind::Neg;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr getVar() const;
|
SDBMTermExpr getVar() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A visitor class for SDBM expressions. Calls the kind-specific function
|
/// A visitor class for SDBM expressions. Calls the kind-specific function
|
||||||
|
@ -352,10 +352,10 @@ protected:
|
||||||
void visitNeg(SDBMNegExpr) {}
|
void visitNeg(SDBMNegExpr) {}
|
||||||
void visitConstant(SDBMConstantExpr) {}
|
void visitConstant(SDBMConstantExpr) {}
|
||||||
|
|
||||||
/// Default implementation of visitPositive dispatches to the special
|
/// Default implementation of visitTerm dispatches to the special
|
||||||
/// functions for stripes and other variables. Concrete visitors can override
|
/// functions for stripes and other variables. Concrete visitors can override
|
||||||
/// it.
|
/// it.
|
||||||
Result visitPositive(SDBMPositiveExpr expr) {
|
Result visitTerm(SDBMTermExpr expr) {
|
||||||
auto *derived = static_cast<Derived *>(this);
|
auto *derived = static_cast<Derived *>(this);
|
||||||
if (expr.getKind() == SDBMExprKind::Stripe)
|
if (expr.getKind() == SDBMExprKind::Stripe)
|
||||||
return derived->visitStripe(expr.cast<SDBMStripeExpr>());
|
return derived->visitStripe(expr.cast<SDBMStripeExpr>());
|
||||||
|
@ -379,8 +379,8 @@ protected:
|
||||||
/// override it to visit all variables and negations instead.
|
/// override it to visit all variables and negations instead.
|
||||||
Result visitVarying(SDBMVaryingExpr expr) {
|
Result visitVarying(SDBMVaryingExpr expr) {
|
||||||
auto *derived = static_cast<Derived *>(this);
|
auto *derived = static_cast<Derived *>(this);
|
||||||
if (auto var = expr.dyn_cast<SDBMPositiveExpr>())
|
if (auto var = expr.dyn_cast<SDBMTermExpr>())
|
||||||
return derived->visitPositive(var);
|
return derived->visitTerm(var);
|
||||||
else if (auto neg = expr.dyn_cast<SDBMNegExpr>())
|
else if (auto neg = expr.dyn_cast<SDBMNegExpr>())
|
||||||
return derived->visitNeg(neg);
|
return derived->visitNeg(neg);
|
||||||
else if (auto sum = expr.dyn_cast<SDBMSumExpr>())
|
else if (auto sum = expr.dyn_cast<SDBMSumExpr>())
|
||||||
|
@ -486,22 +486,20 @@ template <> struct DenseMapInfo<mlir::SDBMVaryingExpr> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// SDBMPositiveExpr hash just like pointers.
|
// SDBMTermExpr hash just like pointers.
|
||||||
template <> struct DenseMapInfo<mlir::SDBMPositiveExpr> {
|
template <> struct DenseMapInfo<mlir::SDBMTermExpr> {
|
||||||
static mlir::SDBMPositiveExpr getEmptyKey() {
|
static mlir::SDBMTermExpr getEmptyKey() {
|
||||||
auto *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
|
auto *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
|
||||||
return mlir::SDBMPositiveExpr(
|
return mlir::SDBMTermExpr(static_cast<mlir::SDBMExpr::ImplType *>(pointer));
|
||||||
static_cast<mlir::SDBMExpr::ImplType *>(pointer));
|
|
||||||
}
|
}
|
||||||
static mlir::SDBMPositiveExpr getTombstoneKey() {
|
static mlir::SDBMTermExpr getTombstoneKey() {
|
||||||
auto *pointer = llvm::DenseMapInfo<void *>::getTombstoneKey();
|
auto *pointer = llvm::DenseMapInfo<void *>::getTombstoneKey();
|
||||||
return mlir::SDBMPositiveExpr(
|
return mlir::SDBMTermExpr(static_cast<mlir::SDBMExpr::ImplType *>(pointer));
|
||||||
static_cast<mlir::SDBMExpr::ImplType *>(pointer));
|
|
||||||
}
|
}
|
||||||
static unsigned getHashValue(mlir::SDBMPositiveExpr expr) {
|
static unsigned getHashValue(mlir::SDBMTermExpr expr) {
|
||||||
return expr.hash_value();
|
return expr.hash_value();
|
||||||
}
|
}
|
||||||
static bool isEqual(mlir::SDBMPositiveExpr lhs, mlir::SDBMPositiveExpr rhs) {
|
static bool isEqual(mlir::SDBMTermExpr lhs, mlir::SDBMTermExpr rhs) {
|
||||||
return lhs == rhs;
|
return lhs == rhs;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -354,8 +354,8 @@ SDBM SDBM::get(ArrayRef<SDBMExpr> inequalities, ArrayRef<SDBMExpr> equalities) {
|
||||||
// If one of the expressions is derived from another using a stripe operation,
|
// If one of the expressions is derived from another using a stripe operation,
|
||||||
// check if the inequalities induced by the stripe operation subsume the
|
// check if the inequalities induced by the stripe operation subsume the
|
||||||
// inequalities defined in the DBM and if so, elide these inequalities.
|
// inequalities defined in the DBM and if so, elide these inequalities.
|
||||||
void SDBM::convertDBMElement(unsigned row, unsigned col,
|
void SDBM::convertDBMElement(unsigned row, unsigned col, SDBMTermExpr rowExpr,
|
||||||
SDBMPositiveExpr rowExpr, SDBMPositiveExpr colExpr,
|
SDBMTermExpr colExpr,
|
||||||
SmallVectorImpl<SDBMExpr> &inequalities,
|
SmallVectorImpl<SDBMExpr> &inequalities,
|
||||||
SmallVectorImpl<SDBMExpr> &equalities) {
|
SmallVectorImpl<SDBMExpr> &equalities) {
|
||||||
using ops_assertions::operator+;
|
using ops_assertions::operator+;
|
||||||
|
@ -388,13 +388,13 @@ void SDBM::convertDBMElement(unsigned row, unsigned col,
|
||||||
SDBMExpr x1Expr, int64_t value) {
|
SDBMExpr x1Expr, int64_t value) {
|
||||||
if (stripeToPoint.count(x0)) {
|
if (stripeToPoint.count(x0)) {
|
||||||
auto stripe = stripeToPoint[x0].cast<SDBMStripeExpr>();
|
auto stripe = stripeToPoint[x0].cast<SDBMStripeExpr>();
|
||||||
SDBMPositiveExpr var = stripe.getVar();
|
SDBMTermExpr var = stripe.getVar();
|
||||||
if (x1Expr == var && value >= 0)
|
if (x1Expr == var && value >= 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (stripeToPoint.count(x1)) {
|
if (stripeToPoint.count(x1)) {
|
||||||
auto stripe = stripeToPoint[x1].cast<SDBMStripeExpr>();
|
auto stripe = stripeToPoint[x1].cast<SDBMStripeExpr>();
|
||||||
SDBMPositiveExpr var = stripe.getVar();
|
SDBMTermExpr var = stripe.getVar();
|
||||||
if (x0Expr == var && value >= stripe.getStripeFactor().getValue() - 1)
|
if (x0Expr == var && value >= stripe.getStripeFactor().getValue() - 1)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ void SDBM::convertDBMElement(unsigned row, unsigned col,
|
||||||
// to -C <= 0. Only construct the inequalities when C is negative, which
|
// to -C <= 0. Only construct the inequalities when C is negative, which
|
||||||
// are trivially false but necessary for the returned system of inequalities
|
// are trivially false but necessary for the returned system of inequalities
|
||||||
// to indicate that the set it defines is empty.
|
// to indicate that the set it defines is empty.
|
||||||
void SDBM::convertDBMDiagonalElement(unsigned pos, SDBMPositiveExpr expr,
|
void SDBM::convertDBMDiagonalElement(unsigned pos, SDBMTermExpr expr,
|
||||||
SmallVectorImpl<SDBMExpr> &inequalities) {
|
SmallVectorImpl<SDBMExpr> &inequalities) {
|
||||||
auto selfDifference = at(pos, pos);
|
auto selfDifference = at(pos, pos);
|
||||||
if (selfDifference.isFinite() && selfDifference < 0) {
|
if (selfDifference.isFinite() && selfDifference < 0) {
|
||||||
|
|
|
@ -166,20 +166,20 @@ void SDBMExpr::print(raw_ostream &os) const {
|
||||||
visitConstant(expr.getRHS());
|
visitConstant(expr.getRHS());
|
||||||
}
|
}
|
||||||
void visitDiff(SDBMDiffExpr expr) {
|
void visitDiff(SDBMDiffExpr expr) {
|
||||||
visitPositive(expr.getLHS());
|
visitTerm(expr.getLHS());
|
||||||
prn << " - ";
|
prn << " - ";
|
||||||
visitPositive(expr.getRHS());
|
visitTerm(expr.getRHS());
|
||||||
}
|
}
|
||||||
void visitDim(SDBMDimExpr expr) { prn << 'd' << expr.getPosition(); }
|
void visitDim(SDBMDimExpr expr) { prn << 'd' << expr.getPosition(); }
|
||||||
void visitSymbol(SDBMSymbolExpr expr) { prn << 's' << expr.getPosition(); }
|
void visitSymbol(SDBMSymbolExpr expr) { prn << 's' << expr.getPosition(); }
|
||||||
void visitStripe(SDBMStripeExpr expr) {
|
void visitStripe(SDBMStripeExpr expr) {
|
||||||
visitPositive(expr.getVar());
|
visitTerm(expr.getVar());
|
||||||
prn << " # ";
|
prn << " # ";
|
||||||
visitConstant(expr.getStripeFactor());
|
visitConstant(expr.getStripeFactor());
|
||||||
}
|
}
|
||||||
void visitNeg(SDBMNegExpr expr) {
|
void visitNeg(SDBMNegExpr expr) {
|
||||||
prn << '-';
|
prn << '-';
|
||||||
visitPositive(expr.getVar());
|
visitTerm(expr.getVar());
|
||||||
}
|
}
|
||||||
void visitConstant(SDBMConstantExpr expr) { prn << expr.getValue(); }
|
void visitConstant(SDBMConstantExpr expr) { prn << expr.getValue(); }
|
||||||
|
|
||||||
|
@ -197,11 +197,9 @@ void SDBMExpr::dump() const {
|
||||||
namespace {
|
namespace {
|
||||||
// Helper class to perform negation of an SDBM expression.
|
// Helper class to perform negation of an SDBM expression.
|
||||||
struct SDBMNegator : public SDBMVisitor<SDBMNegator, SDBMExpr> {
|
struct SDBMNegator : public SDBMVisitor<SDBMNegator, SDBMExpr> {
|
||||||
// Any positive expression is wrapped into a negation expression.
|
// Any term expression is wrapped into a negation expression.
|
||||||
// -(x) = -x
|
// -(x) = -x
|
||||||
SDBMExpr visitPositive(SDBMPositiveExpr expr) {
|
SDBMExpr visitTerm(SDBMTermExpr expr) { return SDBMNegExpr::get(expr); }
|
||||||
return SDBMNegExpr::get(expr);
|
|
||||||
}
|
|
||||||
// A negation expression is unwrapped.
|
// A negation expression is unwrapped.
|
||||||
// -(-x) = x
|
// -(-x) = x
|
||||||
SDBMExpr visitNeg(SDBMNegExpr expr) { return expr.getVar(); }
|
SDBMExpr visitNeg(SDBMNegExpr expr) { return expr.getVar(); }
|
||||||
|
@ -305,7 +303,7 @@ Optional<SDBMExpr> SDBMExpr::tryConvertAffineExpr(AffineExpr affine) {
|
||||||
if (auto convertedLHS = visit(x.matched())) {
|
if (auto convertedLHS = visit(x.matched())) {
|
||||||
// TODO(ntv): return convertedLHS.stripe(C);
|
// TODO(ntv): return convertedLHS.stripe(C);
|
||||||
return SDBMStripeExpr::get(
|
return SDBMStripeExpr::get(
|
||||||
convertedLHS.cast<SDBMPositiveExpr>(),
|
convertedLHS.cast<SDBMTermExpr>(),
|
||||||
visit(C.matched()).cast<SDBMConstantExpr>());
|
visit(C.matched()).cast<SDBMConstantExpr>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,8 +326,8 @@ Optional<SDBMExpr> SDBMExpr::tryConvertAffineExpr(AffineExpr affine) {
|
||||||
// difference, supported as a special kind in SDBM. Because AffineExprs
|
// difference, supported as a special kind in SDBM. Because AffineExprs
|
||||||
// don't have first-class difference kind, check both LHS and RHS for
|
// don't have first-class difference kind, check both LHS and RHS for
|
||||||
// negation.
|
// negation.
|
||||||
auto lhsPos = lhs.dyn_cast<SDBMPositiveExpr>();
|
auto lhsPos = lhs.dyn_cast<SDBMTermExpr>();
|
||||||
auto rhsPos = rhs.dyn_cast<SDBMPositiveExpr>();
|
auto rhsPos = rhs.dyn_cast<SDBMTermExpr>();
|
||||||
auto lhsNeg = lhs.dyn_cast<SDBMNegExpr>();
|
auto lhsNeg = lhs.dyn_cast<SDBMNegExpr>();
|
||||||
auto rhsNeg = rhs.dyn_cast<SDBMNegExpr>();
|
auto rhsNeg = rhs.dyn_cast<SDBMNegExpr>();
|
||||||
if (lhsNeg && rhsVar)
|
if (lhsNeg && rhsVar)
|
||||||
|
@ -347,7 +345,7 @@ Optional<SDBMExpr> SDBMExpr::tryConvertAffineExpr(AffineExpr affine) {
|
||||||
AffineExprMatcher pattern = (x.floorDiv(C)) * C;
|
AffineExprMatcher pattern = (x.floorDiv(C)) * C;
|
||||||
if (pattern.match(expr)) {
|
if (pattern.match(expr)) {
|
||||||
if (SDBMExpr converted = visit(x.matched())) {
|
if (SDBMExpr converted = visit(x.matched())) {
|
||||||
if (auto varConverted = converted.dyn_cast<SDBMPositiveExpr>())
|
if (auto varConverted = converted.dyn_cast<SDBMTermExpr>())
|
||||||
// TODO(ntv): return varConverted.stripe(C.getConstantValue());
|
// TODO(ntv): return varConverted.stripe(C.getConstantValue());
|
||||||
return SDBMStripeExpr::get(
|
return SDBMStripeExpr::get(
|
||||||
varConverted,
|
varConverted,
|
||||||
|
@ -369,7 +367,7 @@ Optional<SDBMExpr> SDBMExpr::tryConvertAffineExpr(AffineExpr affine) {
|
||||||
|
|
||||||
// The only supported "multiplication" expression is an SDBM is dimension
|
// The only supported "multiplication" expression is an SDBM is dimension
|
||||||
// negation, that is a product of dimension and constant -1.
|
// negation, that is a product of dimension and constant -1.
|
||||||
auto lhsVar = lhs.dyn_cast<SDBMPositiveExpr>();
|
auto lhsVar = lhs.dyn_cast<SDBMTermExpr>();
|
||||||
if (lhsVar && rhsConstant.getValue() == -1)
|
if (lhsVar && rhsConstant.getValue() == -1)
|
||||||
return SDBMNegExpr::get(lhsVar);
|
return SDBMNegExpr::get(lhsVar);
|
||||||
|
|
||||||
|
@ -385,7 +383,7 @@ Optional<SDBMExpr> SDBMExpr::tryConvertAffineExpr(AffineExpr affine) {
|
||||||
// 'mod' can only be converted to SDBM if its LHS is a variable
|
// 'mod' can only be converted to SDBM if its LHS is a variable
|
||||||
// and its RHS is a constant. Then it `x mod c = x - x stripe c`.
|
// and its RHS is a constant. Then it `x mod c = x - x stripe c`.
|
||||||
auto rhsConstant = rhs.dyn_cast<SDBMConstantExpr>();
|
auto rhsConstant = rhs.dyn_cast<SDBMConstantExpr>();
|
||||||
auto lhsVar = rhs.dyn_cast<SDBMPositiveExpr>();
|
auto lhsVar = rhs.dyn_cast<SDBMTermExpr>();
|
||||||
if (!lhsVar || !rhsConstant)
|
if (!lhsVar || !rhsConstant)
|
||||||
return {};
|
return {};
|
||||||
return SDBMDiffExpr::get(lhsVar,
|
return SDBMDiffExpr::get(lhsVar,
|
||||||
|
@ -420,7 +418,7 @@ Optional<SDBMExpr> SDBMExpr::tryConvertAffineExpr(AffineExpr affine) {
|
||||||
// SDBMDiffExpr
|
// SDBMDiffExpr
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
SDBMDiffExpr SDBMDiffExpr::get(SDBMPositiveExpr lhs, SDBMPositiveExpr rhs) {
|
SDBMDiffExpr SDBMDiffExpr::get(SDBMTermExpr lhs, SDBMTermExpr rhs) {
|
||||||
assert(lhs && "expected SDBM dimension");
|
assert(lhs && "expected SDBM dimension");
|
||||||
assert(rhs && "expected SDBM dimension");
|
assert(rhs && "expected SDBM dimension");
|
||||||
|
|
||||||
|
@ -429,11 +427,11 @@ SDBMDiffExpr SDBMDiffExpr::get(SDBMPositiveExpr lhs, SDBMPositiveExpr rhs) {
|
||||||
/*initFn=*/{}, static_cast<unsigned>(SDBMExprKind::Diff), lhs, rhs);
|
/*initFn=*/{}, static_cast<unsigned>(SDBMExprKind::Diff), lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr SDBMDiffExpr::getLHS() const {
|
SDBMTermExpr SDBMDiffExpr::getLHS() const {
|
||||||
return static_cast<ImplType *>(impl)->lhs;
|
return static_cast<ImplType *>(impl)->lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr SDBMDiffExpr::getRHS() const {
|
SDBMTermExpr SDBMDiffExpr::getRHS() const {
|
||||||
return static_cast<ImplType *>(impl)->rhs;
|
return static_cast<ImplType *>(impl)->rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +439,7 @@ SDBMPositiveExpr SDBMDiffExpr::getRHS() const {
|
||||||
// SDBMStripeExpr
|
// SDBMStripeExpr
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
SDBMStripeExpr SDBMStripeExpr::get(SDBMPositiveExpr var,
|
SDBMStripeExpr SDBMStripeExpr::get(SDBMTermExpr var,
|
||||||
SDBMConstantExpr stripeFactor) {
|
SDBMConstantExpr stripeFactor) {
|
||||||
assert(var && "expected SDBM variable expression");
|
assert(var && "expected SDBM variable expression");
|
||||||
assert(stripeFactor && "expected non-null stripe factor");
|
assert(stripeFactor && "expected non-null stripe factor");
|
||||||
|
@ -454,9 +452,9 @@ SDBMStripeExpr SDBMStripeExpr::get(SDBMPositiveExpr var,
|
||||||
stripeFactor);
|
stripeFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr SDBMStripeExpr::getVar() const {
|
SDBMTermExpr SDBMStripeExpr::getVar() const {
|
||||||
if (SDBMVaryingExpr lhs = static_cast<ImplType *>(impl)->lhs)
|
if (SDBMVaryingExpr lhs = static_cast<ImplType *>(impl)->lhs)
|
||||||
return lhs.cast<SDBMPositiveExpr>();
|
return lhs.cast<SDBMTermExpr>();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,12 +477,12 @@ unsigned SDBMInputExpr::getPosition() const {
|
||||||
SDBMDimExpr SDBMDimExpr::get(SDBMDialect *dialect, unsigned position) {
|
SDBMDimExpr SDBMDimExpr::get(SDBMDialect *dialect, unsigned position) {
|
||||||
assert(dialect && "expected non-null dialect");
|
assert(dialect && "expected non-null dialect");
|
||||||
|
|
||||||
auto assignDialect = [dialect](detail::SDBMPositiveExprStorage *storage) {
|
auto assignDialect = [dialect](detail::SDBMTermExprStorage *storage) {
|
||||||
storage->dialect = dialect;
|
storage->dialect = dialect;
|
||||||
};
|
};
|
||||||
|
|
||||||
StorageUniquer &uniquer = dialect->getUniquer();
|
StorageUniquer &uniquer = dialect->getUniquer();
|
||||||
return uniquer.get<detail::SDBMPositiveExprStorage>(
|
return uniquer.get<detail::SDBMTermExprStorage>(
|
||||||
assignDialect, static_cast<unsigned>(SDBMExprKind::DimId), position);
|
assignDialect, static_cast<unsigned>(SDBMExprKind::DimId), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,12 +493,12 @@ SDBMDimExpr SDBMDimExpr::get(SDBMDialect *dialect, unsigned position) {
|
||||||
SDBMSymbolExpr SDBMSymbolExpr::get(SDBMDialect *dialect, unsigned position) {
|
SDBMSymbolExpr SDBMSymbolExpr::get(SDBMDialect *dialect, unsigned position) {
|
||||||
assert(dialect && "expected non-null dialect");
|
assert(dialect && "expected non-null dialect");
|
||||||
|
|
||||||
auto assignDialect = [dialect](detail::SDBMPositiveExprStorage *storage) {
|
auto assignDialect = [dialect](detail::SDBMTermExprStorage *storage) {
|
||||||
storage->dialect = dialect;
|
storage->dialect = dialect;
|
||||||
};
|
};
|
||||||
|
|
||||||
StorageUniquer &uniquer = dialect->getUniquer();
|
StorageUniquer &uniquer = dialect->getUniquer();
|
||||||
return uniquer.get<detail::SDBMPositiveExprStorage>(
|
return uniquer.get<detail::SDBMTermExprStorage>(
|
||||||
assignDialect, static_cast<unsigned>(SDBMExprKind::SymbolId), position);
|
assignDialect, static_cast<unsigned>(SDBMExprKind::SymbolId), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +526,7 @@ int64_t SDBMConstantExpr::getValue() const {
|
||||||
// SDBMNegExpr
|
// SDBMNegExpr
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
SDBMNegExpr SDBMNegExpr::get(SDBMPositiveExpr var) {
|
SDBMNegExpr SDBMNegExpr::get(SDBMTermExpr var) {
|
||||||
assert(var && "expected non-null SDBM variable expression");
|
assert(var && "expected non-null SDBM variable expression");
|
||||||
|
|
||||||
StorageUniquer &uniquer = var.getDialect()->getUniquer();
|
StorageUniquer &uniquer = var.getDialect()->getUniquer();
|
||||||
|
@ -536,7 +534,7 @@ SDBMNegExpr SDBMNegExpr::get(SDBMPositiveExpr var) {
|
||||||
/*initFn=*/{}, static_cast<unsigned>(SDBMExprKind::Neg), var);
|
/*initFn=*/{}, static_cast<unsigned>(SDBMExprKind::Neg), var);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr SDBMNegExpr::getVar() const {
|
SDBMTermExpr SDBMNegExpr::getVar() const {
|
||||||
return static_cast<ImplType *>(impl)->dim;
|
return static_cast<ImplType *>(impl)->dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,8 +625,7 @@ SDBMExpr operator-(SDBMExpr lhs, SDBMExpr rhs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This calls into operator+ for futher simplification in case value == 0.
|
// This calls into operator+ for futher simplification in case value == 0.
|
||||||
return SDBMDiffExpr::get(lhs.cast<SDBMPositiveExpr>(),
|
return SDBMDiffExpr::get(lhs.cast<SDBMTermExpr>(), rhs.cast<SDBMTermExpr>()) +
|
||||||
rhs.cast<SDBMPositiveExpr>()) +
|
|
||||||
value;
|
value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +637,7 @@ SDBMExpr stripe(SDBMExpr expr, SDBMExpr factor) {
|
||||||
if (constantFactor.getValue() == 1)
|
if (constantFactor.getValue() == 1)
|
||||||
return expr;
|
return expr;
|
||||||
|
|
||||||
return SDBMStripeExpr::get(expr.cast<SDBMPositiveExpr>(), constantFactor);
|
return SDBMStripeExpr::get(expr.cast<SDBMTermExpr>(), constantFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ops_assertions
|
} // namespace ops_assertions
|
||||||
|
|
|
@ -64,7 +64,7 @@ struct SDBMBinaryExprStorage : public SDBMExprStorage {
|
||||||
|
|
||||||
// Storage class for SDBM difference expressions.
|
// Storage class for SDBM difference expressions.
|
||||||
struct SDBMDiffExprStorage : public SDBMExprStorage {
|
struct SDBMDiffExprStorage : public SDBMExprStorage {
|
||||||
using KeyTy = std::pair<SDBMPositiveExpr, SDBMPositiveExpr>;
|
using KeyTy = std::pair<SDBMTermExpr, SDBMTermExpr>;
|
||||||
|
|
||||||
bool operator==(const KeyTy &key) const {
|
bool operator==(const KeyTy &key) const {
|
||||||
return std::get<0>(key) == lhs && std::get<1>(key) == rhs;
|
return std::get<0>(key) == lhs && std::get<1>(key) == rhs;
|
||||||
|
@ -79,8 +79,8 @@ struct SDBMDiffExprStorage : public SDBMExprStorage {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr lhs;
|
SDBMTermExpr lhs;
|
||||||
SDBMPositiveExpr rhs;
|
SDBMTermExpr rhs;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Storage class for SDBM constant expressions.
|
// Storage class for SDBM constant expressions.
|
||||||
|
@ -100,14 +100,14 @@ struct SDBMConstantExprStorage : public SDBMExprStorage {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Storage class for SDBM dimension and symbol expressions.
|
// Storage class for SDBM dimension and symbol expressions.
|
||||||
struct SDBMPositiveExprStorage : public SDBMExprStorage {
|
struct SDBMTermExprStorage : public SDBMExprStorage {
|
||||||
using KeyTy = unsigned;
|
using KeyTy = unsigned;
|
||||||
|
|
||||||
bool operator==(const KeyTy &key) const { return position == key; }
|
bool operator==(const KeyTy &key) const { return position == key; }
|
||||||
|
|
||||||
static SDBMPositiveExprStorage *
|
static SDBMTermExprStorage *
|
||||||
construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
|
construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
|
||||||
auto *result = allocator.allocate<SDBMPositiveExprStorage>();
|
auto *result = allocator.allocate<SDBMTermExprStorage>();
|
||||||
result->position = key;
|
result->position = key;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ struct SDBMPositiveExprStorage : public SDBMExprStorage {
|
||||||
|
|
||||||
// Storage class for SDBM negation expressions.
|
// Storage class for SDBM negation expressions.
|
||||||
struct SDBMNegExprStorage : public SDBMExprStorage {
|
struct SDBMNegExprStorage : public SDBMExprStorage {
|
||||||
using KeyTy = SDBMPositiveExpr;
|
using KeyTy = SDBMTermExpr;
|
||||||
|
|
||||||
bool operator==(const KeyTy &key) const { return key == dim; }
|
bool operator==(const KeyTy &key) const { return key == dim; }
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ struct SDBMNegExprStorage : public SDBMExprStorage {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBMPositiveExpr dim;
|
SDBMTermExpr dim;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace detail
|
} // end namespace detail
|
||||||
|
|
|
@ -173,7 +173,7 @@ TEST(SDBMExpr, Dim) {
|
||||||
auto generic = static_cast<SDBMExpr>(expr);
|
auto generic = static_cast<SDBMExpr>(expr);
|
||||||
EXPECT_TRUE(generic.isa<SDBMDimExpr>());
|
EXPECT_TRUE(generic.isa<SDBMDimExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMInputExpr>());
|
EXPECT_TRUE(generic.isa<SDBMInputExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMPositiveExpr>());
|
EXPECT_TRUE(generic.isa<SDBMTermExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMVaryingExpr>());
|
EXPECT_TRUE(generic.isa<SDBMVaryingExpr>());
|
||||||
|
|
||||||
// Dimensions are not Symbols.
|
// Dimensions are not Symbols.
|
||||||
|
@ -195,7 +195,7 @@ TEST(SDBMExpr, Symbol) {
|
||||||
auto generic = static_cast<SDBMExpr>(expr);
|
auto generic = static_cast<SDBMExpr>(expr);
|
||||||
EXPECT_TRUE(generic.isa<SDBMSymbolExpr>());
|
EXPECT_TRUE(generic.isa<SDBMSymbolExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMInputExpr>());
|
EXPECT_TRUE(generic.isa<SDBMInputExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMPositiveExpr>());
|
EXPECT_TRUE(generic.isa<SDBMTermExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMVaryingExpr>());
|
EXPECT_TRUE(generic.isa<SDBMVaryingExpr>());
|
||||||
|
|
||||||
// Dimensions are not Symbols.
|
// Dimensions are not Symbols.
|
||||||
|
@ -228,7 +228,7 @@ TEST(SDBMExpr, Stripe) {
|
||||||
// Hierarchy is okay.
|
// Hierarchy is okay.
|
||||||
auto generic = static_cast<SDBMExpr>(expr);
|
auto generic = static_cast<SDBMExpr>(expr);
|
||||||
EXPECT_TRUE(generic.isa<SDBMStripeExpr>());
|
EXPECT_TRUE(generic.isa<SDBMStripeExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMPositiveExpr>());
|
EXPECT_TRUE(generic.isa<SDBMTermExpr>());
|
||||||
EXPECT_TRUE(generic.isa<SDBMVaryingExpr>());
|
EXPECT_TRUE(generic.isa<SDBMVaryingExpr>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue