CIRCT  19.0.0git
Print.cpp
Go to the documentation of this file.
1 //===- Print.cpp - Print 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 // Implements the Print (as a DOT graph) pass.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "circt/Dialect/HW/HWOps.h"
19 #include "mlir/Pass/Pass.h"
20 
22 
23 namespace circt {
24 namespace ssp {
25 #define GEN_PASS_DEF_PRINT
26 #include "circt/Dialect/SSP/SSPPasses.h.inc"
27 } // namespace ssp
28 } // namespace circt
29 
30 using namespace circt;
31 using namespace scheduling;
32 using namespace ssp;
33 
34 namespace {
35 struct PrintPass : public circt::ssp::impl::PrintBase<PrintPass> {
36  explicit PrintPass(raw_ostream &os) : os(os) {}
37  void runOnOperation() override;
38  raw_ostream &os;
39 };
40 } // end anonymous namespace
41 
42 template <typename ProblemT>
43 static void printInstance(InstanceOp instOp, raw_ostream &os) {
44  auto prob = loadProblem<ProblemT>(instOp);
45  dumpAsDOT(prob, os);
46 }
47 
48 void PrintPass::runOnOperation() {
49  auto moduleOp = getOperation();
50  for (auto instOp : moduleOp.getOps<InstanceOp>()) {
51  StringRef probName = instOp.getProblemName();
52  if (probName == "Problem")
53  printInstance<Problem>(instOp, os);
54  else if (probName == "CyclicProblem")
55  printInstance<CyclicProblem>(instOp, os);
56  else if (probName == "ChainingProblem")
57  printInstance<ChainingProblem>(instOp, os);
58  else if (probName == "SharedOperatorsProblem")
59  printInstance<SharedOperatorsProblem>(instOp, os);
60  else if (probName == "ModuloProblem")
61  printInstance<ModuloProblem>(instOp, os);
62  else if (probName == "ChainingCyclicProblem")
63  printInstance<ChainingCyclicProblem>(instOp, os);
64  else {
65  auto instName = instOp.getSymName().value_or("unnamed");
66  llvm::errs() << "ssp-print-instance: Unknown problem class '" << probName
67  << "' in instance '" << instName << "'\n";
68  return signalPassFailure();
69  }
70  }
71 }
72 
73 std::unique_ptr<mlir::Pass> circt::ssp::createPrintPass() {
74  return std::make_unique<PrintPass>(llvm::errs());
75 }
static void printInstance(InstanceOp instOp, raw_ostream &os)
Definition: Print.cpp:43
void dumpAsDOT(Problem &prob, StringRef fileName)
Export prob as a DOT graph into fileName.
Definition: Utilities.cpp:55
std::unique_ptr< mlir::Pass > createPrintPass()
Definition: Print.cpp:73
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21