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 
14 #include "PassDetails.h"
17 #include "circt/Support/LLVM.h"
18 #include "mlir/IR/BuiltinTypes.h"
19 #include "mlir/IR/OperationSupport.h"
20 #include "mlir/Transforms/DialectConversion.h"
21 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
22 
23 using namespace circt;
24 using namespace calyx;
25 using namespace mlir;
26 
27 namespace {
28 
29 /// Iterates over the cells in 'comp' and connects any input port with attribute
30 /// 'portID' to 'fromPort'.
31 static void doPortPassthrough(ComponentOp comp, Value fromPort,
32  StringRef portID) {
33  MLIRContext *ctx = comp.getContext();
34  OpBuilder builder(ctx);
35  builder.setInsertionPointToStart(comp.getWiresOp().getBodyBlock());
36 
37  for (auto cell : comp.getOps<CellInterface>()) {
38  for (auto port : cell.getInputPorts()) {
39  if (!cell.portInfo(port).hasAttribute(portID))
40  continue;
41  builder.create<AssignOp>(cell.getLoc(), port, fromPort);
42  }
43  }
44 }
45 
46 struct ClkInsertionPass : public ClkInsertionBase<ClkInsertionPass> {
47  void runOnOperation() override {
48  doPortPassthrough(getOperation(), getOperation().getClkPort(), "clk");
49  }
50 };
51 
52 struct ResetInsertionPass : public ResetInsertionBase<ResetInsertionPass> {
53  void runOnOperation() override {
54  doPortPassthrough(getOperation(), getOperation().getResetPort(), "reset");
55  }
56 };
57 
58 } // end anonymous namespace
59 
60 std::unique_ptr<mlir::Pass> circt::calyx::createClkInsertionPass() {
61  return std::make_unique<ClkInsertionPass>();
62 }
63 
64 std::unique_ptr<mlir::Pass> circt::calyx::createResetInsertionPass() {
65  return std::make_unique<ResetInsertionPass>();
66 }
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