19#include "mlir/Pass/Pass.h"
23#define GEN_PASS_DEF_ROUNDTRIP
24#include "circt/Dialect/SSP/SSPPasses.h.inc"
32template <
typename ProblemT>
33static InstanceOp
roundtripAs(InstanceOp instOp,
bool check,
bool verify,
37 if (check && failed(prob.check()))
39 if (verify && failed(prob.verify()))
45static InstanceOp
roundtrip(InstanceOp instOp,
bool check,
bool verify,
47 auto problemName = instOp.getProblemName();
49 if (problemName ==
"Problem")
51 if (problemName ==
"CyclicProblem")
53 if (problemName ==
"SharedOperatorsProblem")
55 if (problemName ==
"ModuloProblem")
57 if (problemName ==
"ChainingProblem")
59 if (problemName ==
"ChainingCyclicProblem")
62 llvm::errs() <<
"ssp-roundtrip: Unknown problem '" << problemName <<
"'\n";
67struct RoundtripPass :
public circt::ssp::impl::RoundtripBase<RoundtripPass> {
68 void runOnOperation()
override;
72void RoundtripPass::runOnOperation() {
73 auto moduleOp = getOperation();
76 bool check = checkInputConstraints || verifySolutionConstraints;
77 bool verify = verifySolutionConstraints;
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);
85 return signalPassFailure();
86 instanceOps.push_back(instOp);
89 llvm::for_each(instanceOps, [](InstanceOp op) { op.erase(); });
93 return std::make_unique<RoundtripPass>();
static InstanceOp roundtrip(InstanceOp instOp, bool check, bool verify, OpBuilder &builder)
static InstanceOp roundtripAs(InstanceOp instOp, bool check, bool verify, OpBuilder &builder)
InstanceOp saveProblem(ProblemT &prob, std::tuple< OperationPropertyTs... > opProps, std::tuple< OperatorTypePropertyTs... > oprProps, std::tuple< ResourceTypePropertyTs... > rsrcProps, std::tuple< DependencePropertyTs... > depProps, std::tuple< InstancePropertyTs... > instProps, OpBuilder &builder)
Construct an InstanceOp from a given ProblemT instance, and create/attach attributes of the given cla...
ProblemT loadProblem(InstanceOp instOp, std::tuple< OperationPropertyTs... > opProps, std::tuple< OperatorTypePropertyTs... > oprProps, std::tuple< ResourceTypePropertyTs... > rsrcProps, std::tuple< DependencePropertyTs... > depProps, std::tuple< InstancePropertyTs... > instProps)
Construct an instance of ProblemT from instOp, and attempt to set properties from the given attribute...
std::unique_ptr< mlir::Pass > createRoundtripPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.