16 #include "mlir/Pass/Pass.h"
17 #include "mlir/Transforms/DialectConversion.h"
18 #include "llvm/ADT/TypeSwitch.h"
21 #define GEN_PASS_DEF_LOWERHWTOSV
22 #include "circt/Conversion/Passes.h.inc"
26 using namespace circt;
32 case hw::EventControl::AtPosEdge:
33 return sv::EventControl::AtPosEdge;
34 case hw::EventControl::AtNegEdge:
35 return sv::EventControl::AtNegEdge;
36 case hw::EventControl::AtEdge:
37 return sv::EventControl::AtEdge;
39 llvm_unreachable(
"Unknown event control kind");
43 struct HWToSVPass :
public circt::impl::LowerHWToSVBase<HWToSVPass> {
44 void runOnOperation()
override;
51 matchAndRewrite(TriggeredOp op, OpAdaptor operands,
52 ConversionPatternRewriter &rewriter)
const override {
53 auto alwaysOp = rewriter.create<AlwaysOp>(
56 llvm::SmallVector<Value>{op.getTrigger()});
57 rewriter.mergeBlocks(op.getBodyBlock(), alwaysOp.getBodyBlock(),
58 operands.getInputs());
66 void HWToSVPass::runOnOperation() {
67 MLIRContext &context = getContext();
70 ConversionTarget target(context);
71 RewritePatternSet
patterns(&context);
73 target.addIllegalOp<TriggeredOp>();
74 target.addLegalDialect<sv::SVDialect>();
76 patterns.add<TriggeredOpConversionPattern>(&context);
78 if (failed(applyPartialConversion(module, target, std::move(
patterns))))
87 return std::make_unique<HWToSVPass>();
static sv::EventControl hwToSvEventControl(hw::EventControl ec)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< mlir::OperationPass< hw::HWModuleOp > > createLowerHWToSVPass()