Rename CODE_OWNERS -> Maintainers (#114544)
[llvm-project.git] / mlir / lib / Conversion / FuncToSPIRV / FuncToSPIRVPass.cpp
blob9fffc5e3182e99d8495533e6b426951eccd5de98
1 //===- FuncToSPIRVPass.cpp - Func 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 Func dialect to SPIR-V dialect.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h"
15 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.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_CONVERTFUNCTOSPIRV
21 #include "mlir/Conversion/Passes.h.inc"
22 } // namespace mlir
24 using namespace mlir;
26 namespace {
27 /// A pass converting MLIR Func operations into the SPIR-V dialect.
28 class ConvertFuncToSPIRVPass
29 : public impl::ConvertFuncToSPIRVBase<ConvertFuncToSPIRVPass> {
30 void runOnOperation() override;
32 } // namespace
34 void ConvertFuncToSPIRVPass::runOnOperation() {
35 MLIRContext *context = &getContext();
36 Operation *op = getOperation();
38 auto targetAttr = spirv::lookupTargetEnvOrDefault(op);
39 std::unique_ptr<ConversionTarget> target =
40 SPIRVConversionTarget::get(targetAttr);
42 SPIRVConversionOptions options;
43 options.emulateLT32BitScalarTypes = this->emulateLT32BitScalarTypes;
44 SPIRVTypeConverter typeConverter(targetAttr, options);
46 RewritePatternSet patterns(context);
47 populateFuncToSPIRVPatterns(typeConverter, patterns);
48 populateBuiltinFuncToSPIRVPatterns(typeConverter, patterns);
50 if (failed(applyPartialConversion(op, *target, std::move(patterns))))
51 return signalPassFailure();
54 std::unique_ptr<OperationPass<>> mlir::createConvertFuncToSPIRVPass() {
55 return std::make_unique<ConvertFuncToSPIRVPass>();