12#include "mlir/Transforms/DialectConversion.h" 
   13#include "llvm/ADT/TypeSwitch.h" 
   20#define GEN_PASS_DEF_LOWERCOMB 
   21#include "circt/Dialect/Comb/Passes.h.inc" 
   28  using OpConversionPattern::OpConversionPattern;
 
   34  Value getMux(Location loc, OpBuilder &b, Value t, Value f,
 
   35               ArrayRef<bool> table, Operation::operand_range inputs)
 const {
 
   36    assert(table.size() == (1ull << inputs.size()));
 
   37    if (table.size() == 1)
 
   38      return table.front() ? t : f;
 
   40    size_t half = table.size() / 2;
 
   42        getMux(loc, b, t, f, table.drop_front(half), inputs.drop_front());
 
   44        getMux(loc, b, t, f, table.drop_back(half), inputs.drop_front());
 
   45    return MuxOp::create(b, loc, inputs.front(), if1, if0, 
false);
 
   49  LogicalResult matchAndRewrite(TruthTableOp op, OpAdaptor adaptor,
 
   50                                ConversionPatternRewriter &b)
 const override {
 
   51    Location loc = op.getLoc();
 
   52    SmallVector<bool> table(
 
   53        llvm::map_range(op.getLookupTableAttr().getAsValueRange<IntegerAttr>(),
 
   54                        [](
const APInt &a) { return !a.isZero(); }));
 
   60    Value tree = getMux(loc, b, t, f, table, op.getInputs());
 
   61    b.modifyOpInPlace(tree.getDefiningOp(), [&]() {
 
   62      tree.getDefiningOp()->setDialectAttrs(op->getDialectAttrs());
 
   64    b.replaceOp(op, tree);
 
   71class LowerCombPass : 
public impl::LowerCombBase<LowerCombPass> {
 
   73  using LowerCombBase::LowerCombBase;
 
   75  void runOnOperation() 
override;
 
   79void LowerCombPass::runOnOperation() {
 
   80  auto module = getOperation();
 
   82  ConversionTarget target(getContext());
 
   83  RewritePatternSet 
patterns(&getContext());
 
   84  target.markUnknownOpDynamicallyLegal([](Operation *) { 
return true; });
 
   85  target.addIllegalOp<TruthTableOp>();
 
   89  if (failed(applyPartialConversion(module, target, std::move(
patterns))))
 
   90    return signalPassFailure();
 
assert(baseType &&"element must be base type")
 
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.