CIRCT 20.0.0git
Loading...
Searching...
No Matches
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"
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
27namespace circt {
28namespace msft {
29#define GEN_PASS_DEF_EXPORTTCL
30#include "circt/Dialect/MSFT/MSFTPasses.h.inc"
31} // namespace msft
32} // namespace circt
33
34using namespace circt;
35using namespace msft;
36
37//===----------------------------------------------------------------------===//
38// Export tcl -- create tcl verbatim ops
39//===----------------------------------------------------------------------===//
40
41namespace {
42template <typename PhysOpTy>
43struct 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
56namespace {
57struct ExportTclPass : public circt::msft::impl::ExportTclBase<ExportTclPass> {
58 void runOnOperation() override;
59};
60} // anonymous namespace
61
62void 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
100std::unique_ptr<Pass> circt::msft::createExportTclPass() {
101 return std::make_unique<ExportTclPass>();
102}
std::unique_ptr< mlir::Pass > createExportTclPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition msft.py:1