[ELF] Refactor merge-* tests
[llvm-project.git] / mlir / lib / Conversion / VectorToLLVM / ConvertVectorToLLVMPass.cpp
blob4623b9667998ccc65ce4765cb8baadd9ffa14d8e
1 //===- VectorToLLVM.cpp - Conversion from Vector to the LLVM dialect ------===//
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 //===----------------------------------------------------------------------===//
9 #include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h"
11 #include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
12 #include "mlir/Conversion/LLVMCommon/TypeConverter.h"
13 #include "mlir/Dialect/AMX/AMXDialect.h"
14 #include "mlir/Dialect/AMX/Transforms.h"
15 #include "mlir/Dialect/Arith/IR/Arith.h"
16 #include "mlir/Dialect/ArmNeon/ArmNeonDialect.h"
17 #include "mlir/Dialect/ArmSVE/IR/ArmSVEDialect.h"
18 #include "mlir/Dialect/ArmSVE/Transforms/Transforms.h"
19 #include "mlir/Dialect/Func/IR/FuncOps.h"
20 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
21 #include "mlir/Dialect/MemRef/IR/MemRef.h"
22 #include "mlir/Dialect/Tensor/IR/Tensor.h"
23 #include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
24 #include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
25 #include "mlir/Dialect/X86Vector/Transforms.h"
26 #include "mlir/Dialect/X86Vector/X86VectorDialect.h"
27 #include "mlir/Pass/Pass.h"
28 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
30 namespace mlir {
31 #define GEN_PASS_DEF_CONVERTVECTORTOLLVMPASS
32 #include "mlir/Conversion/Passes.h.inc"
33 } // namespace mlir
35 using namespace mlir;
36 using namespace mlir::vector;
38 namespace {
39 struct ConvertVectorToLLVMPass
40 : public impl::ConvertVectorToLLVMPassBase<ConvertVectorToLLVMPass> {
42 using Base::Base;
44 // Override explicitly to allow conditional dialect dependence.
45 void getDependentDialects(DialectRegistry &registry) const override {
46 registry.insert<LLVM::LLVMDialect>();
47 registry.insert<arith::ArithDialect>();
48 registry.insert<memref::MemRefDialect>();
49 registry.insert<tensor::TensorDialect>();
50 if (armNeon)
51 registry.insert<arm_neon::ArmNeonDialect>();
52 if (armSVE)
53 registry.insert<arm_sve::ArmSVEDialect>();
54 if (amx)
55 registry.insert<amx::AMXDialect>();
56 if (x86Vector)
57 registry.insert<x86vector::X86VectorDialect>();
59 void runOnOperation() override;
61 } // namespace
63 void ConvertVectorToLLVMPass::runOnOperation() {
64 // Perform progressive lowering of operations on slices and
65 // all contraction operations. Also applies folding and DCE.
67 RewritePatternSet patterns(&getContext());
68 populateVectorToVectorCanonicalizationPatterns(patterns);
69 populateVectorBitCastLoweringPatterns(patterns);
70 populateVectorBroadcastLoweringPatterns(patterns);
71 populateVectorContractLoweringPatterns(patterns, VectorTransformsOptions());
72 populateVectorMaskOpLoweringPatterns(patterns);
73 populateVectorShapeCastLoweringPatterns(patterns);
74 populateVectorInterleaveLoweringPatterns(patterns);
75 populateVectorTransposeLoweringPatterns(patterns,
76 VectorTransformsOptions());
77 // Vector transfer ops with rank > 1 should be lowered with VectorToSCF.
78 populateVectorTransferLoweringPatterns(patterns, /*maxTransferRank=*/1);
79 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
82 // Convert to the LLVM IR dialect.
83 LowerToLLVMOptions options(&getContext());
84 LLVMTypeConverter converter(&getContext(), options);
85 RewritePatternSet patterns(&getContext());
86 populateVectorMaskMaterializationPatterns(patterns, force32BitVectorIndices);
87 populateVectorTransferLoweringPatterns(patterns);
88 populateVectorToLLVMMatrixConversionPatterns(converter, patterns);
89 populateVectorToLLVMConversionPatterns(
90 converter, patterns, reassociateFPReductions, force32BitVectorIndices);
91 populateVectorToLLVMMatrixConversionPatterns(converter, patterns);
93 // Architecture specific augmentations.
94 LLVMConversionTarget target(getContext());
95 target.addLegalDialect<arith::ArithDialect>();
96 target.addLegalDialect<memref::MemRefDialect>();
97 target.addLegalOp<UnrealizedConversionCastOp>();
99 if (armNeon) {
100 // TODO: we may or may not want to include in-dialect lowering to
101 // LLVM-compatible operations here. So far, all operations in the dialect
102 // can be translated to LLVM IR so there is no conversion necessary.
103 target.addLegalDialect<arm_neon::ArmNeonDialect>();
105 if (armSVE) {
106 configureArmSVELegalizeForExportTarget(target);
107 populateArmSVELegalizeForLLVMExportPatterns(converter, patterns);
109 if (amx) {
110 configureAMXLegalizeForExportTarget(target);
111 populateAMXLegalizeForLLVMExportPatterns(converter, patterns);
113 if (x86Vector) {
114 configureX86VectorLegalizeForExportTarget(target);
115 populateX86VectorLegalizeForLLVMExportPatterns(converter, patterns);
118 if (failed(
119 applyPartialConversion(getOperation(), target, std::move(patterns))))
120 signalPassFailure();