This essentially sets up mlir-pdll to function in a similar manner to mlir-tblgen. Aside from the boilerplate of configuring CMake and setting up a basic initial test, two new options are added to mlir-pdll to mirror options provided by tblgen: * -d This option generates a dependency file (i.e. a set of build time dependencies) while processing the input file. * --write-if-changed This option only writes to the output file if the data would have changed, which for the build system prevents unnecesarry rebuilds if the file was touched but not actually changed. Differential Revision: https://reviews.llvm.org/D124075
52 lines
1.8 KiB
C++
52 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 "mlir/Dialect/PDL/IR/PDL.h"
|
|
#include "mlir/Dialect/PDLInterp/IR/PDLInterp.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>();
|
|
}
|
|
LogicalResult initialize(MLIRContext *ctx) override {
|
|
// Build the pattern set within the `initialize` to avoid recompiling PDL
|
|
// patterns during each `runOnOperation` invocation.
|
|
RewritePatternSet patternList(&getContext());
|
|
populateGeneratedPDLLPatterns(patternList);
|
|
patterns = std::move(patternList);
|
|
return success();
|
|
}
|
|
|
|
void runOnOperation() final {
|
|
// Invoke the pattern driver with the provided patterns.
|
|
(void)applyPatternsAndFoldGreedily(getOperation(), patterns);
|
|
}
|
|
|
|
FrozenRewritePatternSet patterns;
|
|
};
|
|
} // namespace
|
|
|
|
namespace mlir {
|
|
namespace test {
|
|
void registerTestPDLLPasses() { PassRegistration<TestPDLLPass>(); }
|
|
} // namespace test
|
|
} // namespace mlir
|