CIRCT  18.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 
47  llvm::errs() << "ssp-roundtrip: Unknown problem '" << problemName << "'\n";
48  return {};
49 }
50 
51 namespace {
52 struct RoundtripPass : public RoundtripBase<RoundtripPass> {
53  void runOnOperation() override;
54 };
55 } // end anonymous namespace
56 
57 void RoundtripPass::runOnOperation() {
58  auto moduleOp = getOperation();
59 
60  // Solution constraint verification implies checking the input constraints.
61  bool check = checkInputConstraints || verifySolutionConstraints;
62  bool verify = verifySolutionConstraints;
63 
64  SmallVector<InstanceOp> instanceOps;
65  OpBuilder builder(&getContext());
66  for (auto instOp : moduleOp.getOps<InstanceOp>()) {
67  builder.setInsertionPoint(instOp);
68  auto newInstOp = roundtrip(instOp, check, verify, builder);
69  if (!newInstOp)
70  return signalPassFailure();
71  instanceOps.push_back(instOp);
72  }
73 
74  llvm::for_each(instanceOps, [](InstanceOp op) { op.erase(); });
75 }
76 
77 std::unique_ptr<mlir::Pass> circt::ssp::createRoundtripPass() {
78  return std::make_unique<RoundtripPass>();
79 }
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:77
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
mlir::raw_indented_ostream & errs()
Definition: Utility.h:33