MLIR 22.0.0git
LegalizeForLLVMExport.cpp
Go to the documentation of this file.
1//===- LegalizeForLLVMExport.cpp - Prepare AMX 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
10
16
17using namespace mlir;
18using namespace mlir::amx;
19
20namespace {
21
22/// Generic one-to-one conversion of simply mappable operations into calls
23/// to their respective LLVM intrinsics.
24struct AMXIntrinsicOpConversion
25 : public ConvertOpInterfaceToLLVMPattern<amx::AMXIntrinsicOp> {
27
28 LogicalResult
29 matchAndRewrite(amx::AMXIntrinsicOp op, ArrayRef<Value> operands,
30 ConversionPatternRewriter &rewriter) const override {
31 const LLVMTypeConverter &typeConverter = *getTypeConverter();
33 op, rewriter.getStringAttr(op.getIntrinsicName()),
34 op.getIntrinsicOperands(operands, typeConverter, rewriter),
35 typeConverter, rewriter);
36 }
37};
38
39} // namespace
40
43 patterns.add<AMXIntrinsicOpConversion>(converter);
44 converter.addConversion([&](amx::TileType type) {
45 return LLVM::LLVMX86AMXType::get(&converter.getContext());
46 });
47}
48
50 target.addIllegalDialect<AMXDialect>();
51}
52
53namespace {
54/// Implement the interface to convert AMX to LLVM.
55struct AMXToLLVMDialectInterface : public ConvertToLLVMPatternInterface {
57
58 void populateConvertToLLVMConversionPatterns(
60 RewritePatternSet &patterns) const final {
62 }
63};
64} // namespace
65
67 registry.addExtension(+[](MLIRContext *ctx, amx::AMXDialect *dialect) {
68 dialect->addInterfaces<AMXToLLVMDialectInterface>();
69 });
70}
Utility class for operation conversions targeting the LLVM dialect that allows for matching and rewri...
Definition Pattern.h:255
ConvertOpInterfaceToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
Definition Pattern.h:257
Base class for dialect interfaces providing translation to LLVM IR.
ConvertToLLVMPatternInterface(Dialect *dialect)
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Derived class that automatically populates legalization information for different LLVM ops.
Conversion from types to the LLVM IR dialect.
MLIRContext & getContext() const
Returns the MLIR context.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
LogicalResult intrinsicRewrite(Operation *op, StringRef intrinsic, ValueRange operands, const LLVMTypeConverter &typeConverter, RewriterBase &rewriter)
Replaces the given operation "op" with a call to an LLVM intrinsic with the specified name "intrinsic...
Definition Pattern.cpp:340
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
void populateAMXLegalizeForLLVMExportPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Collect a set of patterns to lower AMX ops to ops that map to LLVM intrinsics.
void configureAMXLegalizeForExportTarget(LLVMConversionTarget &target)
Configure the target to support lowering AMX ops to ops that map to LLVM intrinsics.
void registerConvertAMXToLLVMInterface(DialectRegistry &registry)
Register LLVM conversion interface for AMX dialect.