MLIR  22.0.0git
LegalizeForLLVMExport.cpp
Go to the documentation of this file.
1 //===- LegalizeForLLVMExport.cpp - Prepare X86Vector 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 
14 #include "mlir/IR/PatternMatch.h"
15 
16 using namespace mlir;
17 using namespace mlir::x86vector;
18 
19 namespace {
20 
21 /// Generic one-to-one conversion of simply mappable operations into calls
22 /// to their respective LLVM intrinsics.
23 struct X86IntrinsicOpConversion
24  : public ConvertOpInterfaceToLLVMPattern<x86vector::X86IntrinsicOp> {
26 
27  LogicalResult
28  matchAndRewrite(x86vector::X86IntrinsicOp op, ArrayRef<Value> operands,
29  ConversionPatternRewriter &rewriter) const override {
30  const LLVMTypeConverter &typeConverter = *getTypeConverter();
32  op, rewriter.getStringAttr(op.getIntrinsicName()),
33  op.getIntrinsicOperands(operands, typeConverter, rewriter),
34  typeConverter, rewriter);
35  }
36 };
37 
38 } // namespace
39 
40 /// Populate the given list with patterns that convert from X86Vector to LLVM.
42  const LLVMTypeConverter &converter, RewritePatternSet &patterns) {
43  patterns.add<X86IntrinsicOpConversion>(converter);
44 }
45 
47  LLVMConversionTarget &target) {
48  target.addIllegalDialect<X86VectorDialect>();
49 }
StringAttr getStringAttr(const Twine &bytes)
Definition: Builders.cpp:261
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.
Utility class for operation conversions targeting the LLVM dialect that allows for matching and rewri...
Definition: Pattern.h:257
ConvertOpInterfaceToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
Definition: Pattern.h:259
Derived class that automatically populates legalization information for different LLVM ops.
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:35
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:347
Include the generated interface declarations.
void populateX86VectorLegalizeForLLVMExportPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
Collect a set of patterns to lower X86Vector ops to ops that map to LLVM intrinsics.
const FrozenRewritePatternSet & patterns
void configureX86VectorLegalizeForExportTarget(LLVMConversionTarget &target)
Configure the target to support lowering X86Vector ops to ops that map to LLVM intrinsics.