mirror of https://github.com/llvm/circt.git
[MooreToCore] Separate conversion pattern for moore.output (#7573)
Don't convert the output op in the module pattern because the operands will be of the wrong type since the body has not been converted yet, so it need to apply the hw output pattern afterwards anyway. Instead of relying on that pattern we should have a separate one for moore.output to hw.output that is applied once the rest of the body was converted. The HW output pattern is unnecessary because in the IR before conversion, no hw.output operation should be present (at least none that has a moore typed operand), thus its presence is only the consequence of a bad conversion process (if a target operation is inserted of which the operands are still of the source type, conversion casts should be inserted).
This commit is contained in:
parent
7ba7fc3051
commit
c102ea8832
|
@ -115,7 +115,6 @@ struct SVModuleOpConversion : public OpConversionPattern<SVModuleOp> {
|
|||
LogicalResult
|
||||
matchAndRewrite(SVModuleOp op, OpAdaptor adaptor,
|
||||
ConversionPatternRewriter &rewriter) const override {
|
||||
auto outputOp = op.getOutputOp();
|
||||
rewriter.setInsertionPoint(op);
|
||||
|
||||
// Create the hw.module to replace moore.module
|
||||
|
@ -133,16 +132,23 @@ struct SVModuleOpConversion : public OpConversionPattern<SVModuleOp> {
|
|||
rewriter.inlineRegionBefore(op.getBodyRegion(), hwModuleOp.getBodyRegion(),
|
||||
hwModuleOp.getBodyRegion().end());
|
||||
|
||||
// Rewrite the hw.output op
|
||||
rewriter.setInsertionPointToEnd(hwModuleOp.getBodyBlock());
|
||||
rewriter.replaceOpWithNewOp<hw::OutputOp>(outputOp, outputOp.getOperands());
|
||||
|
||||
// Erase the original op
|
||||
rewriter.eraseOp(op);
|
||||
return success();
|
||||
}
|
||||
};
|
||||
|
||||
struct OutputOpConversion : public OpConversionPattern<OutputOp> {
|
||||
using OpConversionPattern::OpConversionPattern;
|
||||
|
||||
LogicalResult
|
||||
matchAndRewrite(OutputOp op, OpAdaptor adaptor,
|
||||
ConversionPatternRewriter &rewriter) const override {
|
||||
rewriter.replaceOpWithNewOp<hw::OutputOp>(op, adaptor.getOperands());
|
||||
return success();
|
||||
}
|
||||
};
|
||||
|
||||
struct InstanceOpConversion : public OpConversionPattern<InstanceOp> {
|
||||
using OpConversionPattern::OpConversionPattern;
|
||||
|
||||
|
@ -946,17 +952,6 @@ struct ConversionOpConversion : public OpConversionPattern<ConversionOp> {
|
|||
// Statement Conversion
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
struct HWOutputOpConversion : public OpConversionPattern<hw::OutputOp> {
|
||||
using OpConversionPattern::OpConversionPattern;
|
||||
|
||||
LogicalResult
|
||||
matchAndRewrite(hw::OutputOp op, OpAdaptor adaptor,
|
||||
ConversionPatternRewriter &rewriter) const override {
|
||||
rewriter.replaceOpWithNewOp<hw::OutputOp>(op, adaptor.getOperands());
|
||||
return success();
|
||||
}
|
||||
};
|
||||
|
||||
struct HWInstanceOpConversion : public OpConversionPattern<hw::InstanceOp> {
|
||||
using OpConversionPattern::OpConversionPattern;
|
||||
|
||||
|
@ -1308,7 +1303,7 @@ static void populateOpConversion(RewritePatternSet &patterns,
|
|||
ConversionOpConversion, ReadOpConversion, NamedConstantOpConv,
|
||||
StructExtractOpConversion, StructExtractRefOpConversion,
|
||||
ExtractRefOpConversion, StructCreateOpConversion, ConditionalOpConversion,
|
||||
YieldOpConversion,
|
||||
YieldOpConversion, OutputOpConversion,
|
||||
|
||||
// Patterns of unary operations.
|
||||
ReduceAndOpConversion, ReduceOrOpConversion, ReduceXorOpConversion,
|
||||
|
@ -1360,7 +1355,7 @@ static void populateOpConversion(RewritePatternSet &patterns,
|
|||
CondBranchOpConversion, BranchOpConversion,
|
||||
|
||||
// Patterns of other operations outside Moore dialect.
|
||||
HWOutputOpConversion, HWInstanceOpConversion, ReturnOpConversion,
|
||||
HWInstanceOpConversion, ReturnOpConversion,
|
||||
CallOpConversion, UnrealizedConversionCastConversion
|
||||
>(typeConverter, context);
|
||||
// clang-format on
|
||||
|
|
Loading…
Reference in New Issue