[ELF] Refactor merge-* tests
[llvm-project.git] / mlir / lib / Conversion / ComplexToSPIRV / ComplexToSPIRVPass.cpp
blob519a90e7f306a0f7fce250f7d155867ce4e20bdf
1 //===- ComplexToSPIRVPass.cpp - Complex to SPIR-V Passes ------------------===//
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 //
9 // This file implements a pass to convert Complex dialect to SPIR-V dialect.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Conversion/ComplexToSPIRV/ComplexToSPIRVPass.h"
15 #include "mlir/Conversion/ComplexToSPIRV/ComplexToSPIRV.h"
16 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
17 #include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
19 namespace mlir {
20 #define GEN_PASS_DEF_CONVERTCOMPLEXTOSPIRVPASS
21 #include "mlir/Conversion/Passes.h.inc"
22 } // namespace mlir
24 using namespace mlir;
26 namespace {
27 /// A pass converting MLIR Complex operations into the SPIR-V dialect.
28 class ConvertComplexToSPIRVPass
29 : public impl::ConvertComplexToSPIRVPassBase<ConvertComplexToSPIRVPass> {
30 void runOnOperation() override {
31 MLIRContext *context = &getContext();
32 Operation *op = getOperation();
34 auto targetAttr = spirv::lookupTargetEnvOrDefault(op);
35 std::unique_ptr<ConversionTarget> target =
36 SPIRVConversionTarget::get(targetAttr);
38 SPIRVConversionOptions options;
39 SPIRVTypeConverter typeConverter(targetAttr, options);
41 // Use UnrealizedConversionCast as the bridge so that we don't need to pull
42 // in patterns for other dialects.
43 target->addLegalOp<UnrealizedConversionCastOp>();
45 RewritePatternSet patterns(context);
46 populateComplexToSPIRVPatterns(typeConverter, patterns);
48 if (failed(applyPartialConversion(op, *target, std::move(patterns))))
49 return signalPassFailure();
52 } // namespace