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 OpInterfaceConversionPattern<x86vector::X86IntrinsicOp> {
28  x86vector::X86IntrinsicOp>::OpInterfaceConversionPattern;
29 
30  X86IntrinsicOpConversion(const LLVMTypeConverter &typeConverter,
31  PatternBenefit benefit = 1)
32  : OpInterfaceConversionPattern(typeConverter, &typeConverter.getContext(),
33  benefit),
34  typeConverter(typeConverter) {}
35 
36  LogicalResult
37  matchAndRewrite(x86vector::X86IntrinsicOp op, ArrayRef<Value> operands,
38  ConversionPatternRewriter &rewriter) const override {
40  op, rewriter.getStringAttr(op.getIntrinsicName()),
41  op.getIntrinsicOperands(operands, typeConverter, rewriter),
42  typeConverter, rewriter);
43  }
44 
45 private:
46  const LLVMTypeConverter &typeConverter;
47 };
48 
49 } // namespace
50 
51 /// Populate the given list with patterns that convert from X86Vector to LLVM.
53  const LLVMTypeConverter &converter, RewritePatternSet &patterns) {
54  patterns.add<X86IntrinsicOpConversion>(converter);
55 }
56 
58  LLVMConversionTarget &target) {
59  target.addIllegalDialect<X86VectorDialect>();
60 }
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
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
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.