Rename mlir::match to mlir::matchPattern and add m_Op()

- We already have Pattern::match(). Using mlir::match() in Pattern::match()
  confuses the compiler.
- Created m_Op() to avoid using detailed matcher implementation in
  StandardOps.cpp.

PiperOrigin-RevId: 219328823
This commit is contained in:
Lei Zhang 2018-10-30 10:57:50 -07:00 committed by jpienaar
parent af7f56fdf8
commit 5ffb211bff
2 changed files with 10 additions and 10 deletions

View File

@ -108,7 +108,7 @@ template <typename OpClass> struct op_matcher {
/// Entry point for matching a pattern over an SSAValue.
template <typename Pattern>
inline bool match(SSAValue *value, const Pattern &pattern) {
inline bool matchPattern(SSAValue *value, const Pattern &pattern) {
// TODO: handle other cases
if (auto *op = value->getDefiningOperation())
return const_cast<Pattern &>(pattern).match(op);
@ -132,6 +132,11 @@ inline detail::constant_int_value_matcher<1> m_One() {
return detail::constant_int_value_matcher<1>();
}
/// Matches the given OpClass.
template <typename OpClass> inline detail::op_matcher<OpClass> m_Op() {
return detail::op_matcher<OpClass>();
}
/// Matches a constant scalar / vector splat / tensor splat integer zero.
inline detail::constant_int_value_matcher<0> m_Zero() {
return detail::constant_int_value_matcher<0>();

View File

@ -47,11 +47,6 @@ StandardOpsDialect::StandardOpsDialect(MLIRContext *context)
//===----------------------------------------------------------------------===//
namespace {
/// Matches a MemRefCastOp.
inline detail::op_matcher<MemRefCastOp> m_MemRefCast() {
return detail::op_matcher<MemRefCastOp>();
}
/// This is a common class used for patterns of the form
/// "someop(memrefcast) -> someop". It folds the source of any memref_cast
/// into the root operation directly.
@ -63,7 +58,7 @@ struct MemRefCastFolder : public Pattern {
std::pair<PatternBenefit, std::unique_ptr<PatternState>>
match(Operation *op) const override {
for (auto *operand : op->getOperands())
if (::match(operand, m_MemRefCast()))
if (matchPattern(operand, m_Op<MemRefCastOp>()))
return matchSuccess();
return matchFailure();
@ -122,7 +117,7 @@ struct SimplifyAddX0 : public Pattern {
match(Operation *op) const override {
auto addi = op->cast<AddIOp>();
if (::match(addi->getOperand(1), m_Zero()))
if (matchPattern(addi->getOperand(1), m_Zero()))
return matchSuccess();
return matchFailure();
@ -232,7 +227,7 @@ struct SimplifyAllocConst : public Pattern {
// Check to see if any dimensions operands are constants. If so, we can
// substitute and drop them.
for (auto *operand : alloc->getOperands())
if (::match(operand, m_ConstantIndex()))
if (matchPattern(operand, m_ConstantIndex()))
return matchSuccess();
return matchFailure();
}
@ -894,7 +889,7 @@ struct SimplifyMulX1 : public Pattern {
match(Operation *op) const override {
auto muli = op->cast<MulIOp>();
if (::match(muli->getOperand(1), m_One()))
if (matchPattern(muli->getOperand(1), m_One()))
return matchSuccess();
return matchFailure();