MLIR  21.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 #include "mlir/IR/BuiltinOps.h"
17 #include "mlir/IR/PatternMatch.h"
18 
19 using namespace mlir;
20 using namespace mlir::amx;
21 
22 namespace {
23 
24 /// Generic one-to-one conversion of simply mappable operations into calls
25 /// to their respective LLVM intrinsics.
26 struct AMXIntrinsicOpConversion
27  : public OpInterfaceConversionPattern<amx::AMXIntrinsicOp> {
29  amx::AMXIntrinsicOp>::OpInterfaceConversionPattern;
30 
31  AMXIntrinsicOpConversion(const LLVMTypeConverter &typeConverter,
32  PatternBenefit benefit = 1)
33  : OpInterfaceConversionPattern(typeConverter, &typeConverter.getContext(),
34  benefit),
35  typeConverter(typeConverter) {}
36 
37  LogicalResult
38  matchAndRewrite(amx::AMXIntrinsicOp op, ArrayRef<Value> operands,
39  ConversionPatternRewriter &rewriter) const override {
41  op, rewriter.getStringAttr(op.getIntrinsicName()),
42  op.getIntrinsicOperands(operands, typeConverter, rewriter),
43  typeConverter, rewriter);
44  }
45 
46 private:
47  const LLVMTypeConverter &typeConverter;
48 };
49 
50 } // namespace
51 
54  patterns.add<AMXIntrinsicOpConversion>(converter);
55  converter.addConversion([&](amx::TileType type) {
56  return LLVM::LLVMX86AMXType::get(&converter.getContext());
57  });
58 }
59 
61  target.addIllegalDialect<AMXDialect>();
62 }
static MLIRContext * getContext(OpFoldResult val)
StringAttr getStringAttr(const Twine &bytes)
Definition: Builders.cpp:260
This class implements a pattern rewriter for use with ConversionPatterns.
void addIllegalDialect(StringRef name, Names... names)
Register the operations of the given dialects as illegal, i.e.
Derived class that automatically populates legalization information for different LLVM ops.
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:35
MLIRContext & getContext() const
Returns the MLIR context.
OpInterfaceConversionPattern is a wrapper around ConversionPattern that allows for matching and rewri...
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
Definition: PatternMatch.h:34
void addConversion(FnT &&callback)
Register a conversion function.
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:356
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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
void configureAMXLegalizeForExportTarget(LLVMConversionTarget &target)
Configure the target to support lowering AMX ops to ops that map to LLVM intrinsics.