brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · f6b2b2b Raw
54 lines · cpp
1//===- TestPDLByteCode.cpp - Test PDLL functionality ----------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "TestDialect.h"10#include "mlir/Dialect/PDL/IR/PDL.h"11#include "mlir/Dialect/PDLInterp/IR/PDLInterp.h"12#include "mlir/Interfaces/CastInterfaces.h"13#include "mlir/Parser/Parser.h"14#include "mlir/Pass/Pass.h"15#include "mlir/Pass/PassManager.h"16#include "mlir/Transforms/GreedyPatternRewriteDriver.h"17 18using namespace mlir;19 20#include "TestPDLLPatterns.h.inc"21 22namespace {23struct TestPDLLPass : public PassWrapper<TestPDLLPass, OperationPass<>> {24  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPDLLPass)25 26  StringRef getArgument() const final { return "test-pdll-pass"; }27  StringRef getDescription() const final { return "Test PDLL functionality"; }28  void getDependentDialects(DialectRegistry &registry) const override {29    registry.insert<pdl::PDLDialect, pdl_interp::PDLInterpDialect, test::TestDialect>();30  }31  LogicalResult initialize(MLIRContext *ctx) override {32    // Build the pattern set within the `initialize` to avoid recompiling PDL33    // patterns during each `runOnOperation` invocation.34    RewritePatternSet patternList(ctx);35    populateGeneratedPDLLPatterns(patternList);36    patterns = std::move(patternList);37    return success();38  }39 40  void runOnOperation() final {41    // Invoke the pattern driver with the provided patterns.42    (void)applyPatternsGreedily(getOperation(), patterns);43  }44 45  FrozenRewritePatternSet patterns;46};47} // namespace48 49namespace mlir {50namespace test {51void registerTestPDLLPasses() { PassRegistration<TestPDLLPass>(); }52} // namespace test53} // namespace mlir54