CIRCT  19.0.0git
ClkResetInsertion.cpp
Go to the documentation of this file.
1 //===- ClkResetInsertion.cpp - Clock & reset insertion pass -----*- C++ -*-===//
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 //
9 // Adds assignments from a components 'clk' and 'reset' port to every
10 // component that contains an input 'clk' or 'reset' port.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "circt/Support/LLVM.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/OperationSupport.h"
19 #include "mlir/Transforms/DialectConversion.h"
20 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
21 
22 namespace circt {
23 namespace calyx {
24 #define GEN_PASS_DEF_CLKINSERTION
25 #define GEN_PASS_DEF_RESETINSERTION
26 #include "circt/Dialect/Calyx/CalyxPasses.h.inc"
27 } // namespace calyx
28 } // namespace circt
29 
30 using namespace circt;
31 using namespace calyx;
32 using namespace mlir;
33 
34 namespace {
35 
36 /// Iterates over the cells in 'comp' and connects any input port with attribute
37 /// 'portID' to 'fromPort'.
38 static void doPortPassthrough(ComponentOp comp, Value fromPort,
39  StringRef portID) {
40  MLIRContext *ctx = comp.getContext();
41  OpBuilder builder(ctx);
42  builder.setInsertionPointToStart(comp.getWiresOp().getBodyBlock());
43 
44  for (auto cell : comp.getOps<CellInterface>()) {
45  for (auto port : cell.getInputPorts()) {
46  if (!cell.portInfo(port).hasAttribute(portID))
47  continue;
48  builder.create<AssignOp>(cell.getLoc(), port, fromPort);
49  }
50  }
51 }
52 
53 struct ClkInsertionPass
54  : public circt::calyx::impl::ClkInsertionBase<ClkInsertionPass> {
55  void runOnOperation() override {
56  doPortPassthrough(getOperation(), getOperation().getClkPort(), "clk");
57  }
58 };
59 
60 struct ResetInsertionPass
61  : public circt::calyx::impl::ResetInsertionBase<ResetInsertionPass> {
62  void runOnOperation() override {
63  doPortPassthrough(getOperation(), getOperation().getResetPort(), "reset");
64  }
65 };
66 
67 } // end anonymous namespace
68 
69 std::unique_ptr<mlir::Pass> circt::calyx::createClkInsertionPass() {
70  return std::make_unique<ClkInsertionPass>();
71 }
72 
73 std::unique_ptr<mlir::Pass> circt::calyx::createResetInsertionPass() {
74  return std::make_unique<ResetInsertionPass>();
75 }
Builder builder
std::unique_ptr< mlir::Pass > createResetInsertionPass()
std::unique_ptr< mlir::Pass > createClkInsertionPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21