MLIR  21.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 
15 #include "mlir/IR/BuiltinOps.h"
16 #include "mlir/IR/PatternMatch.h"
17 
18 using namespace mlir;
19 using namespace mlir::x86vector;
20 
21 namespace {
22 
23 /// Generic one-to-one conversion of simply mappable operations into calls
24 /// to their respective LLVM intrinsics.
25 struct X86IntrinsicOpConversion
26  : public ConvertOpInterfaceToLLVMPattern<x86vector::X86IntrinsicOp> {
28 
29  LogicalResult
30  matchAndRewrite(x86vector::X86IntrinsicOp op, ArrayRef<Value> operands,
31  ConversionPatternRewriter &rewriter) const override {
32  const LLVMTypeConverter &typeConverter = *getTypeConverter();
34  op, rewriter.getStringAttr(op.getIntrinsicName()),
35  op.getIntrinsicOperands(operands, typeConverter, rewriter),
36  typeConverter, rewriter);
37  }
38 };
39 
40 } // namespace
41 
42 /// Populate the given list with patterns that convert from X86Vector to LLVM.
44  const LLVMTypeConverter &converter, RewritePatternSet &patterns) {
45  patterns.add<X86IntrinsicOpConversion>(converter);
46 }
47 
49  LLVMConversionTarget &target) {
50  target.addIllegalDialect<X86VectorDialect>();
51 }
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.
Utility class for operation conversions targeting the LLVM dialect that allows for matching and rewri...
Definition: Pattern.h:245
ConvertOpInterfaceToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
Definition: Pattern.h:247
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:356
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.