[mlir][spirv] NFC: Shuffle code around to better follow convention
[llvm-project.git] / mlir / lib / Conversion / SPIRVToLLVM / ConvertSPIRVToLLVMPass.cpp
blobb93ce48cb80427ea04bd125bf59acb41b0aab7e0
1 //===- ConvertSPIRVToLLVMPass.cpp - Convert SPIR-V ops to LLVM ops --------===//
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 MLIR SPIR-V ops into LLVM ops
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVMPass.h"
14 #include "../PassDetail.h"
15 #include "mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.h"
16 #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h"
17 #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
18 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
19 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
21 using namespace mlir;
23 namespace {
24 /// A pass converting MLIR SPIR-V operations into LLVM dialect.
25 class ConvertSPIRVToLLVMPass
26 : public ConvertSPIRVToLLVMBase<ConvertSPIRVToLLVMPass> {
27 void runOnOperation() override;
29 } // namespace
31 void ConvertSPIRVToLLVMPass::runOnOperation() {
32 MLIRContext *context = &getContext();
33 ModuleOp module = getOperation();
34 LLVMTypeConverter converter(&getContext());
36 // Encode global variable's descriptor set and binding if they exist.
37 encodeBindAttribute(module);
39 OwningRewritePatternList patterns;
41 populateSPIRVToLLVMTypeConversion(converter);
43 populateSPIRVToLLVMModuleConversionPatterns(context, converter, patterns);
44 populateSPIRVToLLVMConversionPatterns(context, converter, patterns);
45 populateSPIRVToLLVMFunctionConversionPatterns(context, converter, patterns);
47 ConversionTarget target(getContext());
48 target.addIllegalDialect<spirv::SPIRVDialect>();
49 target.addLegalDialect<LLVM::LLVMDialect>();
51 // Set `ModuleOp` and `ModuleTerminatorOp` as legal for `spv.module`
52 // conversion.
53 target.addLegalOp<ModuleOp>();
54 target.addLegalOp<ModuleTerminatorOp>();
55 if (failed(applyPartialConversion(module, target, std::move(patterns))))
56 signalPassFailure();
59 std::unique_ptr<OperationPass<ModuleOp>> mlir::createConvertSPIRVToLLVMPass() {
60 return std::make_unique<ConvertSPIRVToLLVMPass>();