CIRCT  19.0.0git
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 
12 #include "PassDetails.h"
15 #include "llvm/Support/raw_ostream.h"
16 
17 using namespace circt;
18 using namespace firrtl;
19 
20 namespace {
21 struct PrintFIRRTLFieldSourcePass
22  : public PrintFIRRTLFieldSourcePassBase<PrintFIRRTLFieldSourcePass> {
23  PrintFIRRTLFieldSourcePass(raw_ostream &os) : os(os) {}
24 
25  void visitValue(const FieldSource &fieldRefs, Value v) {
26  auto *p = fieldRefs.nodeForValue(v);
27  if (p) {
28  if (p->isRoot())
29  os << "ROOT: ";
30  else
31  os << "SUB: " << v;
32  os << " : " << p->src << " : {";
33  llvm::interleaveComma(p->path, os);
34  os << "} ";
35  os << ((p->flow == Flow::Source) ? "Source"
36  : (p->flow == Flow::Sink) ? "Sink"
37  : "Duplex");
38  if (p->isSrcWritable())
39  os << " writable";
40  if (p->isSrcTransparent())
41  os << " transparent";
42  os << "\n";
43  }
44  }
45 
46  void visitOp(const FieldSource &fieldRefs, Operation *op) {
47  for (auto r : op->getResults())
48  visitValue(fieldRefs, r);
49  // recurse in to regions
50  for (auto &r : op->getRegions())
51  for (auto &b : r.getBlocks())
52  for (auto &op : b)
53  visitOp(fieldRefs, &op);
54  }
55 
56  void runOnOperation() override {
57  auto modOp = getOperation();
58  os << "** " << modOp.getName() << "\n";
59  auto &fieldRefs = getAnalysis<FieldSource>();
60  for (auto port : modOp.getBodyBlock()->getArguments())
61  visitValue(fieldRefs, port);
62  for (auto &op : *modOp.getBodyBlock())
63  visitOp(fieldRefs, &op);
64 
65  markAllAnalysesPreserved();
66  }
67  raw_ostream &os;
68 };
69 } // end anonymous namespace
70 
71 std::unique_ptr<mlir::Pass> circt::firrtl::createFIRRTLFieldSourcePass() {
72  return std::make_unique<PrintFIRRTLFieldSourcePass>(llvm::errs());
73 }
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.
Definition: DebugAnalysis.h:21