MLIR  14.0.0git
LegalizeForLLVMExport.cpp
Go to the documentation of this file.
1 //===- LegalizeForLLVMExport.cpp - Prepare ArmSVE for LLVM translation ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
14 #include "mlir/IR/BuiltinOps.h"
15 #include "mlir/IR/PatternMatch.h"
16 
17 using namespace mlir;
18 using namespace mlir::arm_sve;
19 
20 template <typename OpTy>
21 class ForwardOperands : public OpConversionPattern<OpTy> {
23 
25  matchAndRewrite(OpTy op, typename OpTy::Adaptor adaptor,
26  ConversionPatternRewriter &rewriter) const final {
27  if (adaptor.getOperands().getTypes() == op->getOperands().getTypes())
28  return rewriter.notifyMatchFailure(op, "operand types already match");
29 
30  rewriter.updateRootInPlace(
31  op, [&]() { op->setOperands(adaptor.getOperands()); });
32  return success();
33  }
34 };
35 
41  OneToOneConvertToLLVMPattern<ScalableMaskedAddIOp,
42  ScalableMaskedAddIIntrOp>;
44  OneToOneConvertToLLVMPattern<ScalableMaskedAddFOp,
45  ScalableMaskedAddFIntrOp>;
47  OneToOneConvertToLLVMPattern<ScalableMaskedSubIOp,
48  ScalableMaskedSubIIntrOp>;
50  OneToOneConvertToLLVMPattern<ScalableMaskedSubFOp,
51  ScalableMaskedSubFIntrOp>;
53  OneToOneConvertToLLVMPattern<ScalableMaskedMulIOp,
54  ScalableMaskedMulIIntrOp>;
56  OneToOneConvertToLLVMPattern<ScalableMaskedMulFOp,
57  ScalableMaskedMulFIntrOp>;
59  OneToOneConvertToLLVMPattern<ScalableMaskedSDivIOp,
60  ScalableMaskedSDivIIntrOp>;
62  OneToOneConvertToLLVMPattern<ScalableMaskedUDivIOp,
63  ScalableMaskedUDivIIntrOp>;
65  OneToOneConvertToLLVMPattern<ScalableMaskedDivFOp,
66  ScalableMaskedDivFIntrOp>;
67 
68 /// Populate the given list with patterns that convert from ArmSVE to LLVM.
70  LLVMTypeConverter &converter, OwningRewritePatternList &patterns) {
71  // Populate conversion patterns
72 
73  // clang-format off
76  ForwardOperands<ReturnOp>>(converter,
77  &converter.getContext());
78  patterns.add<SdotOpLowering,
90  ScalableMaskedDivFOpLowering>(converter);
91  // clang-format on
92 }
93 
95  LLVMConversionTarget &target) {
96  // clang-format off
97  target.addLegalOp<SdotIntrOp,
98  SmmlaIntrOp,
99  UdotIntrOp,
100  UmmlaIntrOp,
101  ScalableMaskedAddIIntrOp,
102  ScalableMaskedAddFIntrOp,
103  ScalableMaskedSubIIntrOp,
104  ScalableMaskedSubFIntrOp,
105  ScalableMaskedMulIIntrOp,
106  ScalableMaskedMulFIntrOp,
107  ScalableMaskedSDivIIntrOp,
108  ScalableMaskedUDivIIntrOp,
109  ScalableMaskedDivFIntrOp>();
110  target.addIllegalOp<SdotOp,
111  SmmlaOp,
112  UdotOp,
113  UmmlaOp,
114  ScalableMaskedAddIOp,
115  ScalableMaskedAddFOp,
116  ScalableMaskedSubIOp,
117  ScalableMaskedSubFOp,
118  ScalableMaskedMulIOp,
119  ScalableMaskedMulFOp,
120  ScalableMaskedSDivIOp,
121  ScalableMaskedUDivIOp,
122  ScalableMaskedDivFOp>();
123  // clang-format on
124 }
Include the generated interface declarations.
OneToOneConvertToLLVMPattern< UmmlaOp, UmmlaIntrOp > UmmlaOpLowering
Generic implementation of one-to-one conversion from "SourceOp" to "TargetOp" where the latter belong...
Definition: Pattern.h:188
OneToOneConvertToLLVMPattern< ScalableMaskedMulFOp, ScalableMaskedMulFIntrOp > ScalableMaskedMulFOpLowering
Derived class that automatically populates legalization information for different LLVM ops...
LogicalResult notifyMatchFailure(Operation *op, function_ref< void(Diagnostic &)> reasonCallback) override
PatternRewriter hook for notifying match failure reasons.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
OneToOneConvertToLLVMPattern< ScalableMaskedAddIOp, ScalableMaskedAddIIntrOp > ScalableMaskedAddIOpLowering
void updateRootInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around a root update of an operation.
Definition: PatternMatch.h:789
OpConversionPattern is a wrapper around ConversionPattern that allows for matching and rewriting agai...
OneToOneConvertToLLVMPattern< ScalableMaskedSDivIOp, ScalableMaskedSDivIIntrOp > ScalableMaskedSDivIOpLowering
OneToOneConvertToLLVMPattern< UdotOp, UdotIntrOp > UdotOpLowering
void addIllegalOp()
Register the given operation as illegal, i.e.
void populateArmSVELegalizeForLLVMExportPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Collect a set of patterns to lower ArmSVE ops to ops that map to LLVM intrinsics. ...
OneToOneConvertToLLVMPattern< ScalableMaskedAddFOp, ScalableMaskedAddFIntrOp > ScalableMaskedAddFOpLowering
OneToOneConvertToLLVMPattern< SmmlaOp, SmmlaIntrOp > SmmlaOpLowering
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&... args)
Add an instance of each of the pattern types &#39;Ts&#39; to the pattern list with the given arguments...
Definition: PatternMatch.h:930
OneToOneConvertToLLVMPattern< SdotOp, SdotIntrOp > SdotOpLowering
OneToOneConvertToLLVMPattern< ScalableMaskedMulIOp, ScalableMaskedMulIIntrOp > ScalableMaskedMulIOpLowering
Conversion from types in the Standard dialect to the LLVM IR dialect.
Definition: TypeConverter.h:30
void configureArmSVELegalizeForExportTarget(LLVMConversionTarget &target)
Configure the target to support lowering ArmSVE ops to ops that map to LLVM intrinsics.
void addLegalOp()
Register the given operations as legal.
OneToOneConvertToLLVMPattern< ScalableMaskedUDivIOp, ScalableMaskedUDivIIntrOp > ScalableMaskedUDivIOpLowering
This class implements a pattern rewriter for use with ConversionPatterns.
OneToOneConvertToLLVMPattern< ScalableMaskedSubIOp, ScalableMaskedSubIIntrOp > ScalableMaskedSubIOpLowering
MLIRContext * getContext() const
Return the MLIRContext used to create this pattern.
Definition: PatternMatch.h:132
OneToOneConvertToLLVMPattern< ScalableMaskedSubFOp, ScalableMaskedSubFIntrOp > ScalableMaskedSubFOpLowering