50 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Dialect/X86Vector/Transforms.h"10 11#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"12#include "mlir/Conversion/LLVMCommon/Pattern.h"13#include "mlir/Dialect/X86Vector/X86VectorDialect.h"14#include "mlir/IR/PatternMatch.h"15 16using namespace mlir;17using namespace mlir::x86vector;18 19namespace {20 21/// Generic one-to-one conversion of simply mappable operations into calls22/// to their respective LLVM intrinsics.23struct X86IntrinsicOpConversion24 : public ConvertOpInterfaceToLLVMPattern<x86vector::X86IntrinsicOp> {25 using ConvertOpInterfaceToLLVMPattern::ConvertOpInterfaceToLLVMPattern;26 27 LogicalResult28 matchAndRewrite(x86vector::X86IntrinsicOp op, ArrayRef<Value> operands,29 ConversionPatternRewriter &rewriter) const override {30 const LLVMTypeConverter &typeConverter = *getTypeConverter();31 return LLVM::detail::intrinsicRewrite(32 op, rewriter.getStringAttr(op.getIntrinsicName()),33 op.getIntrinsicOperands(operands, typeConverter, rewriter),34 typeConverter, rewriter);35 }36};37 38} // namespace39 40/// Populate the given list with patterns that convert from X86Vector to LLVM.41void mlir::populateX86VectorLegalizeForLLVMExportPatterns(42 const LLVMTypeConverter &converter, RewritePatternSet &patterns) {43 patterns.add<X86IntrinsicOpConversion>(converter);44}45 46void mlir::configureX86VectorLegalizeForExportTarget(47 LLVMConversionTarget &target) {48 target.addIllegalDialect<X86VectorDialect>();49}50