CIRCT  19.0.0git
Roundtrip.cpp
Go to the documentation of this file.
1 //===- Roundtrip.cpp - Roundtrip 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 Roundtrip pass.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "PassDetails.h"
14 
15 using namespace circt;
16 using namespace scheduling;
17 using namespace ssp;
18 
19 template <typename ProblemT>
20 static InstanceOp roundtripAs(InstanceOp instOp, bool check, bool verify,
21  OpBuilder &builder) {
22  auto prob = loadProblem<ProblemT>(instOp);
23 
24  if (check && failed(prob.check()))
25  return {};
26  if (verify && failed(prob.verify()))
27  return {};
28 
29  return saveProblem<ProblemT>(prob, builder);
30 }
31 
32 static InstanceOp roundtrip(InstanceOp instOp, bool check, bool verify,
33  OpBuilder &builder) {
34  auto problemName = instOp.getProblemName();
35 
36  if (problemName.equals("Problem"))
37  return roundtripAs<Problem>(instOp, check, verify, builder);
38  if (problemName.equals("CyclicProblem"))
39  return roundtripAs<CyclicProblem>(instOp, check, verify, builder);
40  if (problemName.equals("SharedOperatorsProblem"))
41  return roundtripAs<SharedOperatorsProblem>(instOp, check, verify, builder);
42  if (problemName.equals("ModuloProblem"))
43  return roundtripAs<ModuloProblem>(instOp, check, verify, builder);
44  if (problemName.equals("ChainingProblem"))
45  return roundtripAs<ChainingProblem>(instOp, check, verify, builder);
46  if (problemName.equals("ChainingCyclicProblem"))
47  return roundtripAs<ChainingCyclicProblem>(instOp, check, verify, builder);
48 
49  llvm::errs() << "ssp-roundtrip: Unknown problem '" << problemName << "'\n";
50  return {};
51 }
52 
53 namespace {
54 struct RoundtripPass : public RoundtripBase<RoundtripPass> {
55  void runOnOperation() override;
56 };
57 } // end anonymous namespace
58 
59 void RoundtripPass::runOnOperation() {
60  auto moduleOp = getOperation();
61 
62  // Solution constraint verification implies checking the input constraints.
63  bool check = checkInputConstraints || verifySolutionConstraints;
64  bool verify = verifySolutionConstraints;
65 
66  SmallVector<InstanceOp> instanceOps;
67  OpBuilder builder(&getContext());
68  for (auto instOp : moduleOp.getOps<InstanceOp>()) {
69  builder.setInsertionPoint(instOp);
70  auto newInstOp = roundtrip(instOp, check, verify, builder);
71  if (!newInstOp)
72  return signalPassFailure();
73  instanceOps.push_back(instOp);
74  }
75 
76  llvm::for_each(instanceOps, [](InstanceOp op) { op.erase(); });
77 }
78 
79 std::unique_ptr<mlir::Pass> circt::ssp::createRoundtripPass() {
80  return std::make_unique<RoundtripPass>();
81 }
Builder builder
static InstanceOp roundtrip(InstanceOp instOp, bool check, bool verify, OpBuilder &builder)
Definition: Roundtrip.cpp:32
static InstanceOp roundtripAs(InstanceOp instOp, bool check, bool verify, OpBuilder &builder)
Definition: Roundtrip.cpp:20
std::unique_ptr< mlir::Pass > createRoundtripPass()
Definition: Roundtrip.cpp:79
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21