CIRCT 20.0.0git
Loading...
Searching...
No Matches
PrintFIRRTLFieldSource.cpp
Go to the documentation of this file.
1//===- PrintFIRRTLFieldSource.cpp - Print the Field Source ------*- 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// Print the FieldSource analysis.
9//
10//===----------------------------------------------------------------------===//
11
15#include "mlir/Pass/Pass.h"
16#include "llvm/Support/raw_ostream.h"
17
18namespace circt {
19namespace firrtl {
20#define GEN_PASS_DEF_PRINTFIRRTLFIELDSOURCEPASS
21#include "circt/Dialect/FIRRTL/Passes.h.inc"
22} // namespace firrtl
23} // namespace circt
24
25using namespace circt;
26using namespace firrtl;
27
28namespace {
29struct PrintFIRRTLFieldSourcePass
30 : public circt::firrtl::impl::PrintFIRRTLFieldSourcePassBase<
31 PrintFIRRTLFieldSourcePass> {
32 PrintFIRRTLFieldSourcePass(raw_ostream &os) : os(os) {}
33
34 void visitValue(const FieldSource &fieldRefs, Value v) {
35 auto *p = fieldRefs.nodeForValue(v);
36 if (p) {
37 if (p->isRoot())
38 os << "ROOT: ";
39 else
40 os << "SUB: " << v;
41 os << " : " << p->src << " : {";
42 llvm::interleaveComma(p->path, os);
43 os << "} ";
44 os << ((p->flow == Flow::Source) ? "Source"
45 : (p->flow == Flow::Sink) ? "Sink"
46 : "Duplex");
47 if (p->isSrcWritable())
48 os << " writable";
49 if (p->isSrcTransparent())
50 os << " transparent";
51 os << "\n";
52 }
53 }
54
55 void visitOp(const FieldSource &fieldRefs, Operation *op) {
56 for (auto r : op->getResults())
57 visitValue(fieldRefs, r);
58 // recurse in to regions
59 for (auto &r : op->getRegions())
60 for (auto &b : r.getBlocks())
61 for (auto &op : b)
62 visitOp(fieldRefs, &op);
63 }
64
65 void runOnOperation() override {
66 auto modOp = getOperation();
67 os << "** " << modOp.getName() << "\n";
68 auto &fieldRefs = getAnalysis<FieldSource>();
69 for (auto port : modOp.getBodyBlock()->getArguments())
70 visitValue(fieldRefs, port);
71 for (auto &op : *modOp.getBodyBlock())
72 visitOp(fieldRefs, &op);
73
74 markAllAnalysesPreserved();
75 }
76 raw_ostream &os;
77};
78} // end anonymous namespace
79
80std::unique_ptr<mlir::Pass> circt::firrtl::createFIRRTLFieldSourcePass() {
81 return std::make_unique<PrintFIRRTLFieldSourcePass>(llvm::errs());
82}
static Block * getBodyBlock(FModuleLike mod)
To use this class, retrieve a cached copy from the analysis manager: auto &fieldsource = getAnalysis<...
const PathNode * nodeForValue(Value v) const
std::unique_ptr< mlir::Pass > createFIRRTLFieldSourcePass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.