CIRCT 20.0.0git
Loading...
Searching...
No Matches
ArcReductions.cpp
Go to the documentation of this file.
1//===- ArcReductions.cpp - Reduction patterns for the Arc Dialect -=-------===//
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
12#include "mlir/IR/Builders.h"
13#include "llvm/ADT/STLExtras.h"
14#include "llvm/Support/Debug.h"
15
16#define DEBUG_TYPE "arc-reductions"
17
18using namespace circt;
19using namespace arc;
20
21//===----------------------------------------------------------------------===//
22// Reduction patterns
23//===----------------------------------------------------------------------===//
24
25/// A sample reduction pattern that converts `arc.state` operations to the
26/// simpler `arc.call` operation and removes clock, latency, name attributes,
27/// enables, and resets in the process.
28struct StateElimination : public OpReduction<StateOp> {
29 LogicalResult rewrite(StateOp stateOp) override {
30 OpBuilder builder(stateOp);
31 ValueRange results =
32 builder
33 .create<arc::CallOp>(stateOp.getLoc(), stateOp->getResultTypes(),
34 stateOp.getArcAttr(), stateOp.getInputs())
35 ->getResults();
36 stateOp.replaceAllUsesWith(results);
37 stateOp.erase();
38 return success();
39 }
40
41 std::string getName() const override { return "arc-state-elimination"; }
42};
43
44//===----------------------------------------------------------------------===//
45// Reduction Registration
46//===----------------------------------------------------------------------===//
47
50 // Gather a list of reduction patterns that we should try. Ideally these are
51 // assigned reasonable benefit indicators (higher benefit patterns are
52 // prioritized). For example, things that can knock out entire modules while
53 // being cheap should be tried first (and thus have higher benefit), before
54 // trying to tweak operands of individual arithmetic ops.
55 patterns.add<PassReduction, 4>(getContext(), arc::createStripSVPass(), true,
56 true);
57 patterns.add<PassReduction, 3>(getContext(), arc::createDedupPass());
58 patterns.add<StateElimination, 2>();
59 patterns.add<PassReduction, 1>(getContext(),
61}
62
64 mlir::DialectRegistry &registry) {
65 registry.addExtension(+[](MLIRContext *ctx, ArcDialect *dialect) {
66 dialect->addInterfaces<ArcReducePatternDialectInterface>();
67 });
68}
std::unique_ptr< mlir::Pass > createArcCanonicalizerPass()
void registerReducePatternDialectInterface(mlir::DialectRegistry &registry)
Register the Arc Reduction pattern dialect interface to the given registry.
std::unique_ptr< mlir::Pass > createDedupPass()
Definition Dedup.cpp:744
std::unique_ptr< mlir::Pass > createStripSVPass()
Definition StripSV.cpp:186
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
A sample reduction pattern that converts arc.state operations to the simpler arc.call operation and r...
LogicalResult rewrite(StateOp stateOp) override
std::string getName() const override
Return a human-readable name for this reduction pattern.
A reduction pattern that applies an mlir::Pass.
Definition Reduction.h:99
A dialect interface to provide reduction patterns to a reducer tool.
void populateReducePatterns(circt::ReducePatternSet &patterns) const override