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