CIRCT 22.0.0git
Loading...
Searching...
No Matches
RTGReductions.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
11
12using namespace mlir;
13using namespace circt;
14using namespace rtg;
15
16//===----------------------------------------------------------------------===//
17// Reduction patterns
18//===----------------------------------------------------------------------===//
19
20namespace {
21
22/// Replace virtual registers with a constant register.
23struct VirtualRegisterConstantifier : public OpReduction<VirtualRegisterOp> {
24 LogicalResult rewrite(VirtualRegisterOp op) override {
25 if (op.getAllowedRegs().getAllowedRegs().empty())
26 return failure();
27
28 OpBuilder builder(op);
29 auto constReg = ConstantOp::create(builder, op.getLoc(),
30 op.getAllowedRegs().getAllowedRegs()[0]);
31 op.getResult().replaceAllUsesWith(constReg);
32 op.erase();
33 return success();
34 }
35
36 std::string getName() const override {
37 return "rtg-virtual-register-constantifier";
38 }
39};
40
41} // namespace
42
43//===----------------------------------------------------------------------===//
44// Reduction Registration
45//===----------------------------------------------------------------------===//
46
47void RTGReducePatternDialectInterface::populateReducePatterns(
49 // Gather a list of reduction patterns that we should try. Ideally these are
50 // assigned reasonable benefit indicators (higher benefit patterns are
51 // prioritized). For example, things that can knock out entire modules while
52 // being cheap should be tried first (and thus have higher benefit), before
53 // trying to tweak operands of individual arithmetic ops.
54 patterns.add<VirtualRegisterConstantifier, 2>();
55}
56
57void rtg::registerReducePatternDialectInterface(
58 mlir::DialectRegistry &registry) {
59 registry.addExtension(+[](MLIRContext *ctx, RTGDialect *dialect) {
60 dialect->addInterfaces<RTGReducePatternDialectInterface>();
61 });
62}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition rtg.py:1
A reduction pattern for a specific operation.
Definition Reduction.h:112
virtual LogicalResult rewrite(OpTy op)
Definition Reduction.h:128
virtual std::string getName() const =0
Return a human-readable name for this reduction pattern.
A dialect interface to provide reduction patterns to a reducer tool.