CIRCT  20.0.0git
MSFTExportTcl.cpp
Go to the documentation of this file.
1 //===- MSFTExportTcl.cpp - TCL export 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 #include "PassDetails.h"
11 #include "circt/Dialect/HW/HWOps.h"
19 
20 #include "mlir/IR/BuiltinOps.h"
21 #include "mlir/IR/PatternMatch.h"
22 #include "mlir/Pass/Pass.h"
23 #include "mlir/Pass/PassRegistry.h"
24 #include "mlir/Transforms/DialectConversion.h"
25 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
26 
27 namespace circt {
28 namespace msft {
29 #define GEN_PASS_DEF_EXPORTTCL
30 #include "circt/Dialect/MSFT/MSFTPasses.h.inc"
31 } // namespace msft
32 } // namespace circt
33 
34 using namespace circt;
35 using namespace msft;
36 
37 //===----------------------------------------------------------------------===//
38 // Export tcl -- create tcl verbatim ops
39 //===----------------------------------------------------------------------===//
40 
41 namespace {
42 template <typename PhysOpTy>
43 struct RemovePhysOpLowering : public OpConversionPattern<PhysOpTy> {
45  using OpAdaptor = typename OpConversionPattern<PhysOpTy>::OpAdaptor;
46 
47  LogicalResult
48  matchAndRewrite(PhysOpTy op, OpAdaptor adaptor,
49  ConversionPatternRewriter &rewriter) const final {
50  rewriter.eraseOp(op);
51  return success();
52  }
53 };
54 } // anonymous namespace
55 
56 namespace {
57 struct ExportTclPass : public circt::msft::impl::ExportTclBase<ExportTclPass> {
58  void runOnOperation() override;
59 };
60 } // anonymous namespace
61 
62 void ExportTclPass::runOnOperation() {
63  auto top = getOperation();
64  auto *ctxt = &getContext();
65  TclEmitter emitter(top);
66 
67  // Traverse MSFT location attributes and export the required Tcl into
68  // templated `sv::VerbatimOp`s with symbolic references to the instance paths.
69  for (const std::string &moduleName : tops) {
70  Operation *hwmod =
71  emitter.getDefinition(FlatSymbolRefAttr::get(ctxt, moduleName));
72  if (!hwmod) {
73  top.emitError("Failed to find module '") << moduleName << "'";
74  signalPassFailure();
75  return;
76  }
77  if (failed(emitter.emit(hwmod, tclFile))) {
78  hwmod->emitError("failed to emit tcl");
79  signalPassFailure();
80  return;
81  }
82  }
83 
84  ConversionTarget target(*ctxt);
85  target.addIllegalDialect<msft::MSFTDialect>();
86  target.addLegalDialect<hw::HWDialect>();
87  target.addLegalDialect<sv::SVDialect>();
88 
89  RewritePatternSet patterns(ctxt);
90  patterns.insert<RemovePhysOpLowering<PDPhysLocationOp>>(ctxt);
91  patterns.insert<RemovePhysOpLowering<PDRegPhysLocationOp>>(ctxt);
92  patterns.insert<RemovePhysOpLowering<PDPhysRegionOp>>(ctxt);
93  patterns.insert<RemovePhysOpLowering<InstanceHierarchyOp>>(ctxt);
94  patterns.insert<RemovePhysOpLowering<DynamicInstanceVerbatimAttrOp>>(ctxt);
95  patterns.insert<RemoveOpLowering<DeclPhysicalRegionOp>>(ctxt);
96  if (failed(applyPartialConversion(top, target, std::move(patterns))))
97  signalPassFailure();
98 }
99 
100 std::unique_ptr<Pass> circt::msft::createExportTclPass() {
101  return std::make_unique<ExportTclPass>();
102 }
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
std::unique_ptr< mlir::Pass > createExportTclPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: msft.py:1