@@ -92,6 +92,10 @@ class ConvertToLLVMPattern : public ConversionPattern {
92
92
PatternBenefit benefit = 1 );
93
93
94
94
protected:
95
+ // / See `ConversionPattern::ConversionPattern` for information on the other
96
+ // / available constructors.
97
+ using ConversionPattern::ConversionPattern;
98
+
95
99
// / Returns the LLVM dialect.
96
100
LLVM::LLVMDialect &getDialect () const ;
97
101
@@ -234,6 +238,47 @@ class ConvertOpToLLVMPattern : public ConvertToLLVMPattern {
234
238
using ConvertToLLVMPattern::matchAndRewrite;
235
239
};
236
240
241
+ // / Utility class for operation conversions targeting the LLVM dialect that
242
+ // / allows for matching and rewriting against an instance of an OpInterface
243
+ // / class.
244
+ template <typename SourceOp>
245
+ class ConvertOpInterfaceToLLVMPattern : public ConvertToLLVMPattern {
246
+ public:
247
+ explicit ConvertOpInterfaceToLLVMPattern (
248
+ const LLVMTypeConverter &typeConverter, PatternBenefit benefit = 1 )
249
+ : ConvertToLLVMPattern(typeConverter, Pattern::MatchInterfaceOpTypeTag(),
250
+ SourceOp::getInterfaceID(), benefit,
251
+ &typeConverter.getContext()) {}
252
+
253
+ // / Wrappers around the RewritePattern methods that pass the derived op type.
254
+ LogicalResult
255
+ matchAndRewrite (Operation *op, ArrayRef<Value> operands,
256
+ ConversionPatternRewriter &rewriter) const final {
257
+ return matchAndRewrite (cast<SourceOp>(op), operands, rewriter);
258
+ }
259
+ LogicalResult
260
+ matchAndRewrite (Operation *op, ArrayRef<ValueRange> operands,
261
+ ConversionPatternRewriter &rewriter) const final {
262
+ return matchAndRewrite (cast<SourceOp>(op), operands, rewriter);
263
+ }
264
+
265
+ // / Methods that operate on the SourceOp type. One of these must be
266
+ // / overridden by the derived pattern class.
267
+ virtual LogicalResult
268
+ matchAndRewrite (SourceOp op, ArrayRef<Value> operands,
269
+ ConversionPatternRewriter &rewriter) const {
270
+ llvm_unreachable (" matchAndRewrite is not implemented" );
271
+ }
272
+ virtual LogicalResult
273
+ matchAndRewrite (SourceOp op, ArrayRef<ValueRange> operands,
274
+ ConversionPatternRewriter &rewriter) const {
275
+ return matchAndRewrite (op, getOneToOneAdaptorOperands (operands), rewriter);
276
+ }
277
+
278
+ private:
279
+ using ConvertToLLVMPattern::matchAndRewrite;
280
+ };
281
+
237
282
// / Generic implementation of one-to-one conversion from "SourceOp" to
238
283
// / "TargetOp" where the latter belongs to the LLVM dialect or an equivalent.
239
284
// / Upholds a convention that multi-result operations get converted into an
0 commit comments