mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 22:26:05 +00:00

The greedy rewriter is used in many different flows and it has a lot of convenience (work list management, debugging actions, tracing, etc). But it combines two kinds of greedy behavior 1) how ops are matched, 2) folding wherever it can. These are independent forms of greedy and leads to inefficiency. E.g., cases where one need to create different phases in lowering and is required to applying patterns in specific order split across different passes. Using the driver one ends up needlessly retrying folding/having multiple rounds of folding attempts, where one final run would have sufficed. Of course folks can locally avoid this behavior by just building their own, but this is also a common requested feature that folks keep on working around locally in suboptimal ways. For downstream users, there should be no behavioral change. Updating from the deprecated should just be a find and replace (e.g., `find ./ -type f -exec sed -i 's|applyPatternsAndFoldGreedily|applyPatternsGreedily|g' {} \;` variety) as the API arguments hasn't changed between the two.
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
//===- TestPDLByteCode.cpp - Test PDLL functionality ----------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "TestDialect.h"
|
|
#include "mlir/Dialect/PDL/IR/PDL.h"
|
|
#include "mlir/Dialect/PDLInterp/IR/PDLInterp.h"
|
|
#include "mlir/Interfaces/CastInterfaces.h"
|
|
#include "mlir/Parser/Parser.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
#include "mlir/Pass/PassManager.h"
|
|
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
|
|
|
|
using namespace mlir;
|
|
|
|
#include "TestPDLLPatterns.h.inc"
|
|
|
|
namespace {
|
|
struct TestPDLLPass : public PassWrapper<TestPDLLPass, OperationPass<>> {
|
|
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPDLLPass)
|
|
|
|
StringRef getArgument() const final { return "test-pdll-pass"; }
|
|
StringRef getDescription() const final { return "Test PDLL functionality"; }
|
|
void getDependentDialects(DialectRegistry ®istry) const override {
|
|
registry.insert<pdl::PDLDialect, pdl_interp::PDLInterpDialect, test::TestDialect>();
|
|
}
|
|
LogicalResult initialize(MLIRContext *ctx) override {
|
|
// Build the pattern set within the `initialize` to avoid recompiling PDL
|
|
// patterns during each `runOnOperation` invocation.
|
|
RewritePatternSet patternList(ctx);
|
|
populateGeneratedPDLLPatterns(patternList);
|
|
patterns = std::move(patternList);
|
|
return success();
|
|
}
|
|
|
|
void runOnOperation() final {
|
|
// Invoke the pattern driver with the provided patterns.
|
|
(void)applyPatternsGreedily(getOperation(), patterns);
|
|
}
|
|
|
|
FrozenRewritePatternSet patterns;
|
|
};
|
|
} // namespace
|
|
|
|
namespace mlir {
|
|
namespace test {
|
|
void registerTestPDLLPasses() { PassRegistration<TestPDLLPass>(); }
|
|
} // namespace test
|
|
} // namespace mlir
|