17 #include "mlir/Pass/Pass.h"
18 #include "mlir/Transforms/DialectConversion.h"
21 #define GEN_PASS_DEF_CONVERTAIGTOCOMB
22 #include "circt/Conversion/Passes.h.inc"
25 using namespace circt;
37 matchAndRewrite(aig::AndInverterOp op, OpAdaptor adaptor,
38 ConversionPatternRewriter &rewriter)
const override {
40 auto width = op.getResult().getType().getIntOrFloatBitWidth();
42 rewriter.create<
hw::ConstantOp>(op.getLoc(), APInt::getAllOnes(width));
43 SmallVector<Value> operands;
44 operands.reserve(op.getNumOperands());
45 for (
auto [input, inverted] : llvm::zip(op.getOperands(), op.getInverted()))
46 operands.push_back(inverted ? rewriter.createOrFold<
comb::XorOp>(
47 op.getLoc(), input, allOnes,
true)
51 op, rewriter.createOrFold<
comb::AndOp>(op.getLoc(), operands,
true));
63 struct ConvertAIGToCombPass
64 :
public impl::ConvertAIGToCombBase<ConvertAIGToCombPass> {
66 void runOnOperation()
override;
67 using ConvertAIGToCombBase<ConvertAIGToCombPass>::ConvertAIGToCombBase;
75 void ConvertAIGToCombPass::runOnOperation() {
76 ConversionTarget target(getContext());
77 target.addLegalDialect<comb::CombDialect, hw::HWDialect>();
78 target.addIllegalDialect<aig::AIGDialect>();
80 RewritePatternSet
patterns(&getContext());
83 if (failed(mlir::applyPartialConversion(getOperation(), target,
85 return signalPassFailure();
static void populateAIGToCombConversionPatterns(RewritePatternSet &patterns)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.