Loading [MathJax]/extensions/tex2jax.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExcludeExecuteRegionCanonicalize.cpp
Go to the documentation of this file.
1//===- ExcludeExecuteRegion.cpp
2//----------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
11#include "mlir/Dialect/Affine/Utils.h"
12#include "mlir/Dialect/Arith/IR/Arith.h"
13#include "mlir/Dialect/Arith/Transforms/Passes.h"
14#include "mlir/Dialect/Func/IR/FuncOps.h"
15#include "mlir/Dialect/MemRef/IR/MemRef.h"
16#include "mlir/Dialect/SCF/IR/SCF.h"
17#include "mlir/IR/PatternMatch.h"
18#include "mlir/Pass/PassManager.h"
19#include "mlir/Support/LogicalResult.h"
20#include "mlir/Transforms/DialectConversion.h"
21#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
22
23namespace circt {
24namespace calyx {
25#define GEN_PASS_DEF_EXCLUDEEXECUTEREGIONCANONICALIZE
26#include "circt/Dialect/Calyx/CalyxPasses.h.inc"
27} // namespace calyx
28} // namespace circt
29
30using namespace mlir;
31using namespace mlir::arith;
32using namespace mlir::memref;
33using namespace mlir::scf;
34using namespace mlir::func;
35using namespace mlir::affine;
36using namespace circt;
37
38namespace {
39class ExcludeExecuteRegionCanonicalizePass
40 : public circt::calyx::impl::ExcludeExecuteRegionCanonicalizeBase<
41 ExcludeExecuteRegionCanonicalizePass> {
42 void runOnOperation() override;
43};
44} // namespace
45
46void ExcludeExecuteRegionCanonicalizePass::runOnOperation() {
47 MLIRContext *ctx = &getContext();
48 RewritePatternSet patterns(ctx);
49
50 // Add dialect-level canonicalization patterns
51 for (Dialect *dialect : ctx->getLoadedDialects())
52 dialect->getCanonicalizationPatterns(patterns);
53
54 // Add op-specific canonicalization patterns
55 for (const RegisteredOperationName &op : ctx->getRegisteredOperations()) {
56 if (op.getStringRef() == "scf.execute_region" ||
57 op.getStringRef() == "scf.parallel")
58 continue;
59
60 op.getCanonicalizationPatterns(patterns, ctx);
61 }
62
63 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns)))) {
64 getOperation()->emitError("Failed to apply canonicalization.");
65 signalPassFailure();
66 }
67
68 ConversionTarget target(*ctx);
69 target.addLegalDialect<arith::ArithDialect, memref::MemRefDialect,
70 scf::SCFDialect, affine::AffineDialect>();
71}
72
73std::unique_ptr<mlir::Pass>
75 return std::make_unique<ExcludeExecuteRegionCanonicalizePass>();
76}
std::unique_ptr< mlir::Pass > createExcludeExecuteRegionCanonicalizePass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.