explicit RangeOpConversion(MLIRContext *context)
: ConversionPattern(linalg::RangeOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto rangeOp = cast<linalg::RangeOp>(op);
auto rangeDescriptorType =
linalg::convertLinalgType(rangeOp.getResult()->getType());
rangeDescriptor = insertvalue(rangeDescriptorType, rangeDescriptor,
operands[2], makePositionAttr(rewriter, 2));
rewriter.replaceOp(op, rangeDescriptor);
+ return matchSuccess();
}
};
explicit ViewOpConversion(MLIRContext *context)
: ConversionPattern(linalg::ViewOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto viewOp = cast<linalg::ViewOp>(op);
auto viewDescriptorType = linalg::convertLinalgType(viewOp.getViewType());
auto memrefType =
}
rewriter.replaceOp(op, viewDescriptor);
+ return matchSuccess();
}
};
explicit SliceOpConversion(MLIRContext *context)
: ConversionPattern(linalg::SliceOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto sliceOp = cast<linalg::SliceOp>(op);
auto newViewDescriptorType =
linalg::convertLinalgType(sliceOp.getViewType());
}
rewriter.replaceOp(op, newViewDescriptor);
+ return matchSuccess();
}
};
explicit DropConsumer(MLIRContext *context)
: ConversionPattern("some_consumer", 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
rewriter.replaceOp(op, llvm::None);
+ return matchSuccess();
}
};
// an LLVM IR load.
class LoadOpConversion : public LoadStoreOpConversion<linalg::LoadOp> {
using Base::Base;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
edsc::ScopedContext edscContext(rewriter, op->getLoc());
auto elementType = linalg::convertLinalgType(*op->result_type_begin());
Value *viewDescriptor = operands[0];
Value *ptr = obtainDataPtr(op, viewDescriptor, indices, rewriter);
Value *element = intrinsics::load(elementType, ptr);
rewriter.replaceOp(op, {element});
+ return matchSuccess();
}
};
// an LLVM IR store.
class StoreOpConversion : public LoadStoreOpConversion<linalg::StoreOp> {
using Base::Base;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
edsc::ScopedContext edscContext(rewriter, op->getLoc());
Value *viewDescriptor = operands[1];
Value *data = operands[0];
Value *ptr = obtainDataPtr(op, viewDescriptor, indices, rewriter);
intrinsics::store(data, ptr);
rewriter.replaceOp(op, llvm::None);
+ return matchSuccess();
}
};
explicit MulOpConversion(MLIRContext *context)
: ConversionPattern(toy::MulOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
using namespace edsc;
using intrinsics::constant_index;
using linalg::intrinsics::range;
auto resultView = view(result, {r0, r2});
rewriter.create<linalg::MatmulOp>(loc, lhsView, rhsView, resultView);
rewriter.replaceOp(op, {typeCast(rewriter, result, mul.getType())});
+ return matchSuccess();
}
};
/// the rewritten operands for `op` in the new function.
/// The results created by the new IR with the builder are returned, and their
/// number must match the number of result of `op`.
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto add = cast<toy::AddOp>(op);
auto loc = add.getLoc();
// Create a `toy.alloc` operation to allocate the output buffer for this op.
// Return the newly allocated buffer, with a type.cast to preserve the
// consumers.
rewriter.replaceOp(op, {typeCast(rewriter, result, add.getType())});
+ return matchSuccess();
}
};
explicit PrintOpConversion(MLIRContext *context)
: ConversionPattern(toy::PrintOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
// Get or create the declaration of the printf function in the module.
Function *printfFunc = getPrintf(*op->getFunction()->getModule());
// clang-format on
}
rewriter.replaceOp(op, llvm::None);
+ return matchSuccess();
}
private:
explicit ConstantOpConversion(MLIRContext *context)
: ConversionPattern(toy::ConstantOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
toy::ConstantOp cstOp = cast<toy::ConstantOp>(op);
auto loc = cstOp.getLoc();
auto retTy = cstOp.getResult()->getType().cast<toy::ToyArrayType>();
}
}
rewriter.replaceOp(op, result);
+ return matchSuccess();
}
};
explicit TransposeOpConversion(MLIRContext *context)
: ConversionPattern(toy::TransposeOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto transpose = cast<toy::TransposeOp>(op);
auto loc = transpose.getLoc();
Value *result = memRefTypeCast(
// clang-format on
rewriter.replaceOp(op, {typeCast(rewriter, result, transpose.getType())});
+ return matchSuccess();
}
};
explicit ReturnOpConversion(MLIRContext *context)
: ConversionPattern(toy::ReturnOp::getOperationName(), 1, context) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
// Argument is optional, handle both cases.
if (op->getNumOperands())
rewriter.replaceOpWithNewOp<ReturnOp>(op, operands[0]);
else
rewriter.replaceOpWithNewOp<ReturnOp>(op);
+ return matchSuccess();
}
};
MLIRContext *ctx)
: RewritePattern(rootName, benefit, ctx) {}
- /// Hook for derived classes to implement matching. Dialect conversion
- /// generally unconditionally match the root operation, so default to success
- /// here.
- virtual PatternMatchResult match(Operation *op) const override {
- return matchSuccess();
- }
-
/// Hook for derived classes to implement rewriting. `op` is the (first)
/// operation matched by the pattern, `operands` is a list of rewritten values
/// that are passed to this operation, `rewriter` can be used to emit the new
llvm_unreachable("unimplemented rewrite for terminators");
}
- /// Rewrite the IR rooted at the specified operation with the result of
- /// this pattern. If an unexpected error is encountered (an internal compiler
- /// error), it is emitted through the normal MLIR diagnostic hooks and the IR
- /// is left in a valid state.
- void rewrite(Operation *op, PatternRewriter &rewriter) const final;
+ /// Hook for derived classes to implement combined matching and rewriting.
+ virtual PatternMatchResult
+ matchAndRewrite(Operation *op, ArrayRef<Value *> properOperands,
+ ArrayRef<Block *> destinations,
+ ArrayRef<ArrayRef<Value *>> operands,
+ PatternRewriter &rewriter) const {
+ if (!match(op))
+ return matchFailure();
+ rewrite(op, properOperands, destinations, operands, rewriter);
+ return matchSuccess();
+ }
+
+ /// Hook for derived classes to implement combined matching and rewriting.
+ virtual PatternMatchResult matchAndRewrite(Operation *op,
+ ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const {
+ if (!match(op))
+ return matchFailure();
+ rewrite(op, operands, rewriter);
+ return matchSuccess();
+ }
+
+ /// Attempt to match and rewrite the IR root at the specified operation.
+ PatternMatchResult matchAndRewrite(Operation *op,
+ PatternRewriter &rewriter) const final;
private:
- using RewritePattern::matchAndRewrite;
using RewritePattern::rewrite;
};
lowering_),
dialect(dialect_) {}
- PatternMatchResult match(Operation *op) const override {
- return this->matchSuccess();
- }
-
// Get the LLVM IR dialect.
LLVM::LLVMDialect &getDialect() const { return dialect; }
// Get the LLVM context.
// Convert the type of the result to an LLVM type, pass operands as is,
// preserve attributes.
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
unsigned numResults = op->getNumResults();
Type packedType;
// If the operation produced 0 or 1 result, return them immediately.
if (numResults == 0)
- return rewriter.replaceOp(op, llvm::None);
+ return rewriter.replaceOp(op, llvm::None), this->matchSuccess();
if (numResults == 1)
- return rewriter.replaceOp(op, newOp.getOperation()->getResult(0));
+ return rewriter.replaceOp(op, newOp.getOperation()->getResult(0)),
+ this->matchSuccess();
// Otherwise, it had been converted to an operation producing a structure.
// Extract individual results from the structure and return them as list.
this->getIntegerArrayAttr(rewriter, i)));
}
rewriter.replaceOp(op, results);
+ return this->matchSuccess();
}
};
struct DeallocOpLowering : public LLVMLegalizationPattern<DeallocOp> {
using LLVMLegalizationPattern<DeallocOp>::LLVMLegalizationPattern;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
assert(operands.size() == 1 && "dealloc takes one operand");
OperandAdaptor<DeallocOp> transformed(operands);
op->getLoc(), getVoidPtrType(), bufferPtr);
rewriter.replaceOpWithNewOp<LLVM::CallOp>(
op, ArrayRef<Type>(), rewriter.getFunctionAttr(freeFunc), casted);
+ return matchSuccess();
}
};
struct LoadOpLowering : public LoadStoreOpLowering<LoadOp> {
using Base::Base;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto loadOp = cast<LoadOp>(op);
OperandAdaptor<LoadOp> transformed(operands);
auto type = loadOp.getMemRefType();
rewriter.replaceOpWithNewOp<LLVM::LoadOp>(op, elementType,
ArrayRef<Value *>{dataPtr});
+ return matchSuccess();
}
};
struct StoreOpLowering : public LoadStoreOpLowering<StoreOp> {
using Base::Base;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto type = cast<StoreOp>(op).getMemRefType();
OperandAdaptor<StoreOp> transformed(operands);
transformed.indices(), rewriter, getModule());
rewriter.replaceOpWithNewOp<LLVM::StoreOp>(op, transformed.value(),
dataPtr);
+ return matchSuccess();
}
};
using LLVMLegalizationPattern<SourceOp>::LLVMLegalizationPattern;
using Super = OneToOneLLVMTerminatorLowering<SourceOp, TargetOp>;
- void rewrite(Operation *op, ArrayRef<Value *> properOperands,
- ArrayRef<Block *> destinations,
- ArrayRef<ArrayRef<Value *>> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op,
+ ArrayRef<Value *> properOperands,
+ ArrayRef<Block *> destinations,
+ ArrayRef<ArrayRef<Value *>> operands,
+ PatternRewriter &rewriter) const override {
rewriter.replaceOpWithNewOp<TargetOp>(op, properOperands, destinations,
operands, op->getAttrs());
+ return this->matchSuccess();
}
};
struct ReturnOpLowering : public LLVMLegalizationPattern<ReturnOp> {
using LLVMLegalizationPattern<ReturnOp>::LLVMLegalizationPattern;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
unsigned numArguments = op->getNumOperands();
// If ReturnOp has 0 or 1 operand, create it and return immediately.
if (numArguments == 0) {
- return rewriter.replaceOpWithNewOp<LLVM::ReturnOp>(
+ rewriter.replaceOpWithNewOp<LLVM::ReturnOp>(
op, llvm::ArrayRef<Value *>(), llvm::ArrayRef<Block *>(),
llvm::ArrayRef<llvm::ArrayRef<Value *>>(), op->getAttrs());
+ return matchSuccess();
}
if (numArguments == 1) {
- return rewriter.replaceOpWithNewOp<LLVM::ReturnOp>(
+ rewriter.replaceOpWithNewOp<LLVM::ReturnOp>(
op, llvm::ArrayRef<Value *>(operands.front()),
llvm::ArrayRef<Block *>(), llvm::ArrayRef<llvm::ArrayRef<Value *>>(),
op->getAttrs());
+ return matchSuccess();
}
// Otherwise, we need to pack the arguments into an LLVM struct type before
rewriter.replaceOpWithNewOp<LLVM::ReturnOp>(
op, llvm::makeArrayRef(packed), llvm::ArrayRef<Block *>(),
llvm::ArrayRef<llvm::ArrayRef<Value *>>(), op->getAttrs());
+ return matchSuccess();
}
};
LLVMTypeConverter &lowering_)
: LLVMOpLowering(BufferAllocOp::getOperationName(), context, lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto indexType = IndexType::get(op->getContext());
auto voidPtrTy =
LLVM::LLVMType::getInt8Ty(lowering.getDialect()).getPointerTo();
desc = insertvalue(bufferDescriptorType, desc, size,
positionAttr(rewriter, 1));
rewriter.replaceOp(op, desc);
+ return matchSuccess();
}
};
: LLVMOpLowering(BufferDeallocOp::getOperationName(), context,
lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto voidPtrTy =
LLVM::LLVMType::getInt8Ty(lowering.getDialect()).getPointerTo();
// Insert the `free` declaration if it is not already present.
positionAttr(rewriter, 0)));
call(ArrayRef<Type>(), rewriter.getFunctionAttr(freeFunc), casted);
rewriter.replaceOp(op, llvm::None);
+ return matchSuccess();
}
};
BufferSizeOpConversion(MLIRContext *context, LLVMTypeConverter &lowering_)
: LLVMOpLowering(BufferSizeOp::getOperationName(), context, lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto int64Ty = lowering.convertType(operands[0]->getType());
edsc::ScopedContext context(rewriter, op->getLoc());
rewriter.replaceOp(
op, {extractvalue(int64Ty, operands[0], positionAttr(rewriter, 1))});
+ return matchSuccess();
}
};
explicit DimOpConversion(MLIRContext *context, LLVMTypeConverter &lowering_)
: LLVMOpLowering(linalg::DimOp::getOperationName(), context, lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto dimOp = cast<linalg::DimOp>(op);
auto indexTy = lowering.convertType(rewriter.getIndexType());
edsc::ScopedContext context(rewriter, op->getLoc());
{extractvalue(
indexTy, operands[0],
positionAttr(rewriter, {2, static_cast<int>(dimOp.getIndex())}))});
+ return matchSuccess();
}
};
// an LLVM IR load.
class LoadOpConversion : public LoadStoreOpConversion<linalg::LoadOp> {
using Base::Base;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
edsc::ScopedContext edscContext(rewriter, op->getLoc());
auto elementTy = lowering.convertType(*op->result_type_begin());
Value *viewDescriptor = operands[0];
ArrayRef<Value *> indices = operands.drop_front();
auto ptr = obtainDataPtr(op, viewDescriptor, indices, rewriter);
rewriter.replaceOp(op, {llvm_load(elementTy, ptr)});
+ return matchSuccess();
}
};
explicit RangeOpConversion(MLIRContext *context, LLVMTypeConverter &lowering_)
: LLVMOpLowering(RangeOp::getOperationName(), context, lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto rangeOp = cast<RangeOp>(op);
auto rangeDescriptorTy =
convertLinalgType(rangeOp.getResult()->getType(), lowering);
desc = insertvalue(rangeDescriptorTy, desc, operands[2],
positionAttr(rewriter, 2));
rewriter.replaceOp(op, desc);
+ return matchSuccess();
}
};
: LLVMOpLowering(RangeIntersectOp::getOperationName(), context,
lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto rangeIntersectOp = cast<RangeIntersectOp>(op);
auto rangeDescriptorTy =
convertLinalgType(rangeIntersectOp.getResult()->getType(), lowering);
desc = insertvalue(rangeDescriptorTy, desc, mul(step1, step2),
positionAttr(rewriter, 2));
rewriter.replaceOp(op, desc);
+ return matchSuccess();
}
};
explicit SliceOpConversion(MLIRContext *context, LLVMTypeConverter &lowering_)
: LLVMOpLowering(SliceOp::getOperationName(), context, lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto sliceOp = cast<SliceOp>(op);
auto viewDescriptorTy = convertLinalgType(sliceOp.getViewType(), lowering);
auto viewType = sliceOp.getBaseViewType();
}
rewriter.replaceOp(op, desc);
+ return matchSuccess();
}
};
// an LLVM IR store.
class StoreOpConversion : public LoadStoreOpConversion<linalg::StoreOp> {
using Base::Base;
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
edsc::ScopedContext edscContext(rewriter, op->getLoc());
Value *data = operands[0];
Value *viewDescriptor = operands[1];
Value *ptr = obtainDataPtr(op, viewDescriptor, indices, rewriter);
llvm_store(data, ptr);
rewriter.replaceOp(op, llvm::None);
+ return matchSuccess();
}
};
explicit ViewOpConversion(MLIRContext *context, LLVMTypeConverter &lowering_)
: LLVMOpLowering(ViewOp::getOperationName(), context, lowering_) {}
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto viewOp = cast<ViewOp>(op);
auto viewDescriptorTy = convertLinalgType(viewOp.getViewType(), lowering);
auto elementTy = getPtrToElementType(viewOp.getViewType(), lowering);
}
rewriter.replaceOp(op, desc);
+ return matchSuccess();
}
};
static StringRef libraryFunctionName() { return "linalg_dot"; }
- void rewrite(Operation *op, ArrayRef<Value *> operands,
- PatternRewriter &rewriter) const override {
+ PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ PatternRewriter &rewriter) const override {
auto *f =
op->getFunction()->getModule()->getNamedFunction(libraryFunctionName());
if (!f) {
op->emitError("Could not find function: " + libraryFunctionName() +
"in lowering to LLVM ");
- return;
+ return matchFailure();
}
auto fAttr = rewriter.getFunctionAttr(f);
auto named = rewriter.getNamedAttr("callee", fAttr);
rewriter.replaceOpWithNewOp<LLVM::CallOp>(op, operands,
ArrayRef<NamedAttribute>{named});
+ return matchSuccess();
}
};
// ConversionPattern
//===----------------------------------------------------------------------===//
-/// Rewrite the IR rooted at the specified operation with the result of this
-/// pattern. If an unexpected error is encountered (an internal compiler
-/// error), it is emitted through the normal MLIR diagnostic hooks and the IR is
-/// left in a valid state.
-void ConversionPattern::rewrite(Operation *op,
- PatternRewriter &rewriter) const {
+/// Attempt to match and rewrite the IR root at the specified operation.
+PatternMatchResult
+ConversionPattern::matchAndRewrite(Operation *op,
+ PatternRewriter &rewriter) const {
SmallVector<Value *, 4> operands;
auto &dialectRewriter = static_cast<DialectConversionRewriter &>(rewriter);
dialectRewriter.remapValues(op->getOperands(), operands);
// If this operation has no successors, invoke the rewrite directly.
if (op->getNumSuccessors() == 0)
- return rewrite(op, operands, rewriter);
+ return matchAndRewrite(op, operands, rewriter);
// Otherwise, we need to remap the successors.
SmallVector<Block *, 2> destinations;
}
// Rewrite the operation.
- rewrite(op,
- llvm::makeArrayRef(operands.data(),
- operands.data() + firstSuccessorOperand),
- destinations, operandsPerDestination, rewriter);
+ return matchAndRewrite(
+ op,
+ llvm::makeArrayRef(operands.data(),
+ operands.data() + firstSuccessorOperand),
+ destinations, operandsPerDestination, rewriter);
}
//===----------------------------------------------------------------------===//