CIRCT 24.0.0git
Loading...
Searching...
No Matches
EmitReductions.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
14#include "mlir/IR/SymbolTable.h"
15#include "llvm/Support/Debug.h"
16
17#define DEBUG_TYPE "emit-reductions"
18
19using namespace circt;
20using namespace emit;
21
22//===----------------------------------------------------------------------===//
23// Reduction patterns
24//===----------------------------------------------------------------------===//
25
26namespace {
27
28/// A reduction pattern that erases emit dialect operations.
29struct EmitOpEraser : public Reduction {
30 void beforeReduction(mlir::ModuleOp op) override {
31 innerSymUses = reduce::InnerSymbolUses(op);
32 }
33
34 uint64_t match(Operation *op) override {
35 if (!isa_and_nonnull<emit::EmitDialect>(op->getDialect()))
36 return 0;
37 if (innerSymUses.hasRef(op))
38 return 0;
39 return 1;
40 }
41
42 LogicalResult rewrite(Operation *op) override {
43 op->erase();
44 return success();
45 }
46
47 std::string getName() const override { return "emit-op-eraser"; }
48 bool acceptSizeIncrease() const override { return true; }
49
50 reduce::InnerSymbolUses innerSymUses;
51};
52
53} // namespace
54
55//===----------------------------------------------------------------------===//
56// Reduction Registration
57//===----------------------------------------------------------------------===//
58
59namespace {
60/// A dialect interface to provide reduction patterns to a reducer tool.
61struct EmitReducePatternDialectInterface
64 void populateReducePatterns(ReducePatternSet &patterns) const override {
65 patterns.add<EmitOpEraser, 1000>();
66 }
67};
68} // namespace
69
71 mlir::DialectRegistry &registry) {
72 registry.addExtension(+[](MLIRContext *ctx, EmitDialect *dialect) {
73 dialect->addInterfaces<EmitReducePatternDialectInterface>();
74 });
75}
return success()
void add(Args &&...args)
Definition Reduction.h:162
void registerReducePatternDialectInterface(mlir::DialectRegistry &registry)
Register the Emit Reduction pattern dialect interface to the given registry.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition emit.py:1
A dialect interface to provide reduction patterns to a reducer tool.
Definition Reduction.h:180
ReducePatternDialectInterface(Dialect *dialect)
Definition Reduction.h:181
An abstract reduction pattern.
Definition Reduction.h:24
A helper struct that scans a root operation and all its nested operations for InnerRefAttrs.