CIRCT 20.0.0git
Loading...
Searching...
No Matches
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
19#include "mlir/Pass/Pass.h"
20
21namespace circt {
22namespace ssp {
23#define GEN_PASS_DEF_ROUNDTRIP
24#include "circt/Dialect/SSP/SSPPasses.h.inc"
25} // namespace ssp
26} // namespace circt
27
28using namespace circt;
29using namespace scheduling;
30using namespace ssp;
31
32template <typename ProblemT>
33static InstanceOp roundtripAs(InstanceOp instOp, bool check, bool verify,
34 OpBuilder &builder) {
35 auto prob = loadProblem<ProblemT>(instOp);
36
37 if (check && failed(prob.check()))
38 return {};
39 if (verify && failed(prob.verify()))
40 return {};
41
42 return saveProblem<ProblemT>(prob, builder);
43}
44
45static InstanceOp roundtrip(InstanceOp instOp, bool check, bool verify,
46 OpBuilder &builder) {
47 auto problemName = instOp.getProblemName();
48
49 if (problemName == "Problem")
50 return roundtripAs<Problem>(instOp, check, verify, builder);
51 if (problemName == "CyclicProblem")
52 return roundtripAs<CyclicProblem>(instOp, check, verify, builder);
53 if (problemName == "SharedOperatorsProblem")
54 return roundtripAs<SharedOperatorsProblem>(instOp, check, verify, builder);
55 if (problemName == "ModuloProblem")
56 return roundtripAs<ModuloProblem>(instOp, check, verify, builder);
57 if (problemName == "ChainingProblem")
58 return roundtripAs<ChainingProblem>(instOp, check, verify, builder);
59 if (problemName == "ChainingCyclicProblem")
60 return roundtripAs<ChainingCyclicProblem>(instOp, check, verify, builder);
61
62 llvm::errs() << "ssp-roundtrip: Unknown problem '" << problemName << "'\n";
63 return {};
64}
65
66namespace {
67struct RoundtripPass : public circt::ssp::impl::RoundtripBase<RoundtripPass> {
68 void runOnOperation() override;
69};
70} // end anonymous namespace
71
72void RoundtripPass::runOnOperation() {
73 auto moduleOp = getOperation();
74
75 // Solution constraint verification implies checking the input constraints.
76 bool check = checkInputConstraints || verifySolutionConstraints;
77 bool verify = verifySolutionConstraints;
78
79 SmallVector<InstanceOp> instanceOps;
80 OpBuilder builder(&getContext());
81 for (auto instOp : moduleOp.getOps<InstanceOp>()) {
82 builder.setInsertionPoint(instOp);
83 auto newInstOp = roundtrip(instOp, check, verify, builder);
84 if (!newInstOp)
85 return signalPassFailure();
86 instanceOps.push_back(instOp);
87 }
88
89 llvm::for_each(instanceOps, [](InstanceOp op) { op.erase(); });
90}
91
92std::unique_ptr<mlir::Pass> circt::ssp::createRoundtripPass() {
93 return std::make_unique<RoundtripPass>();
94}
static InstanceOp roundtrip(InstanceOp instOp, bool check, bool verify, OpBuilder &builder)
Definition Roundtrip.cpp:45
static InstanceOp roundtripAs(InstanceOp instOp, bool check, bool verify, OpBuilder &builder)
Definition Roundtrip.cpp:33
std::unique_ptr< mlir::Pass > createRoundtripPass()
Definition Roundtrip.cpp:92
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.