forked from OSchip/llvm-project
[MLIR] Add debug support for ignored patterns
The rewrite engine's cost model may determine some patterns to be irrelevant ahead of their application. These patterns were silently ignored previously and now cause a message in `--debug` mode. Differential Revision: https://reviews.llvm.org/D87290
This commit is contained in:
parent
2a52c3301a
commit
6a494e117c
|
@ -10,9 +10,12 @@
|
|||
#include "mlir/IR/BlockAndValueMapping.h"
|
||||
#include "mlir/IR/Operation.h"
|
||||
#include "mlir/IR/Value.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
#define DEBUG_TYPE "pattern-match"
|
||||
|
||||
PatternBenefit::PatternBenefit(unsigned benefit) : representation(benefit) {
|
||||
assert(representation == benefit && benefit != ImpossibleToMatchSentinel &&
|
||||
"This pattern match benefit is too large to represent");
|
||||
|
@ -207,8 +210,14 @@ void PatternApplicator::applyCostModel(CostModel model) {
|
|||
anyOpPatterns.clear();
|
||||
for (const auto &pat : owningPatternList) {
|
||||
// If the pattern is always impossible to match, just ignore it.
|
||||
if (pat->getBenefit().isImpossibleToMatch())
|
||||
if (pat->getBenefit().isImpossibleToMatch()) {
|
||||
LLVM_DEBUG({
|
||||
llvm::dbgs()
|
||||
<< "Ignoring pattern '" << pat->getRootKind()
|
||||
<< "' because it is impossible to match (by pattern benefit)\n";
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (Optional<OperationName> opName = pat->getRootKind())
|
||||
patterns[*opName].push_back(pat.get());
|
||||
else
|
||||
|
@ -223,8 +232,14 @@ void PatternApplicator::applyCostModel(CostModel model) {
|
|||
auto processPatternList = [&](SmallVectorImpl<RewritePattern *> &list) {
|
||||
// Special case for one pattern in the list, which is the most common case.
|
||||
if (list.size() == 1) {
|
||||
if (model(*list.front()).isImpossibleToMatch())
|
||||
if (model(*list.front()).isImpossibleToMatch()) {
|
||||
LLVM_DEBUG({
|
||||
llvm::dbgs() << "Ignoring pattern '" << list.front()->getRootKind()
|
||||
<< "' because it is impossible to match or cannot lead "
|
||||
"to legal IR (by cost model)\n";
|
||||
});
|
||||
list.clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -236,8 +251,14 @@ void PatternApplicator::applyCostModel(CostModel model) {
|
|||
// Sort patterns with highest benefit first, and remove those that are
|
||||
// impossible to match.
|
||||
std::stable_sort(list.begin(), list.end(), cmp);
|
||||
while (!list.empty() && benefits[list.back()].isImpossibleToMatch())
|
||||
while (!list.empty() && benefits[list.back()].isImpossibleToMatch()) {
|
||||
LLVM_DEBUG({
|
||||
llvm::dbgs() << "Ignoring pattern '" << list.back()->getRootKind()
|
||||
<< "' because it is impossible to match or cannot lead to "
|
||||
"legal IR (by cost model)\n";
|
||||
});
|
||||
list.pop_back();
|
||||
}
|
||||
};
|
||||
for (auto &it : patterns)
|
||||
processPatternList(it.second);
|
||||
|
|
Loading…
Reference in New Issue