17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
19 #define DEBUG_TYPE "aig-lower-variadic"
23 #define GEN_PASS_DEF_LOWERVARIADIC
24 #include "circt/Dialect/AIG/AIGPasses.h.inc"
28 using namespace circt;
36 static Value lowerVariadicAndInverterOp(AndInverterOp op, OperandRange operands,
37 ArrayRef<bool> inverts,
38 PatternRewriter &rewriter) {
39 switch (operands.size()) {
41 assert(0 &&
"cannot be called with empty operand range");
45 return rewriter.create<AndInverterOp>(op.getLoc(), operands[0],
true);
49 return rewriter.create<AndInverterOp>(op.getLoc(), operands[0], operands[1],
50 inverts[0], inverts[1]);
52 auto firstHalf = operands.size() / 2;
54 lowerVariadicAndInverterOp(op, operands.take_front(firstHalf),
55 inverts.take_front(firstHalf), rewriter);
57 lowerVariadicAndInverterOp(op, operands.drop_front(firstHalf),
58 inverts.drop_front(firstHalf), rewriter);
59 return rewriter.create<AndInverterOp>(op.getLoc(), lhs, rhs);
67 LogicalResult matchAndRewrite(AndInverterOp op,
68 PatternRewriter &rewriter)
const override {
69 if (op.getInputs().size() <= 2)
75 rewriter.replaceOp(op,
76 lowerVariadicAndInverterOp(op, op.getOperands(),
77 op.getInverted(), rewriter));
93 struct LowerVariadicPass :
public impl::LowerVariadicBase<LowerVariadicPass> {
94 void runOnOperation()
override;
98 void LowerVariadicPass::runOnOperation() {
99 RewritePatternSet
patterns(&getContext());
101 mlir::FrozenRewritePatternSet frozen(std::move(
patterns));
103 if (failed(mlir::applyPatternsAndFoldGreedily(getOperation(), frozen)))
104 return signalPassFailure();
assert(baseType &&"element must be base type")
static void populateLowerVariadicPatterns(RewritePatternSet &patterns)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.